Wiki

Changes between Version 6 and Version 7 of UseDirective

Show
Ignore:
Timestamp:
03/29/14 05:47:34 (11 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseDirective

    v6 v7  
    22 
    33{{{ 
     4use [ <alias = ] <namespace> [ from <library-name> ] 
     5 
    46use <namespace> 
    57use <namespace> from <library-name> 
     8use <alias> = <namespace> 
    69}}} 
    710 
    811Specify a namespace whose contents are made available to this module. 
    912 
    10 When using the first form if the compiler cannot immediately locate the namespace,[[BR]] 
     13When using a form without a 'from' clause, if the compiler cannot immediately locate the namespace,[[BR]] 
    1114i.e if its not in the default loaded libraries,[[BR]] 
    12 it will look for a (platform dependent) library-name of the same form as  
    13 the namespace. 
    14  
    15  
    16 If the filename of the library differs from the namespace, you can specify  
    17 it with the second form.[[BR]] 
    18   
    19 <library-name> can be a simple identifier, qualified identifier (Foo.Bar)  
    20 or a string literal. 
     15The compiler will look for a (platform dependent) library-name of the same form as the namespace. 
     16 
     17 
     18If the filename of the library differs from the namespace, you can specify it with the second form.[[BR]] 
     19<library-name> can be a simple identifier, qualified identifier (Foo.Bar)  or a string literal. 
     20 
    2121 
    2222{{{ 
     
    2424use Foo.Bar from SomeLib 
    2525}}} 
    26 You can put single or double quotes around the file name if its components  
    27 are not legal identifiers [[BR]] 
     26You can put single or double quotes around the file name if its components are not legal identifiers [[BR]] 
    2827(for example, the filename has a space or punctuation mark in it). 
    2928{{{ 
     
    3231}}} 
    3332 
     33The alias clause (third form above)  can be used where you want to use a different (or simplified) name for the namespace than that provided.[[BR]] 
     34This is useful for a lengthy fully qualified namespace name that is widely used. 
    3435 
    3536== Platform == 
     
    109110}}} 
    110111 
     112{{{ 
     113#!cobra 
     114 
     115use Cons = System.Console 
     116use CC = Cobra.Core.CobraCore 
     117         
     118class Test 
     119    def main is shared 
     120        Cons.writeLine('Display Version') 
     121        ver = CC.version 
     122        v1 = Cobra.Core.CobraCore.version 
     123        assert ver == v1 
     124        Cons.writeline(ver) 
     125}}} 
     126 
    111127 
    112128 
     
    114130 
    115131In most cases this syntax means you dont need to specify the commandline 
    116 -reference switch to provide the filename for a referenced namespace. 
     132-reference switch to provide the filename for a referenced namespace if the namespace dll follows 
     133usual naming conventions. 
    117134 
    118135 
     
    136153cobra MyProg.cobra 
    137154}}} 
     155 
     156[[BR]] 
     157[[BR]] 
     158 
     159 
     160 
     161 
     162If the dll filename containing the namespace code differs from the namespace name you can wire the namespace/filename relationship into the 
     163source file rather than having to always remember (or script) a specific separate compiler commandline reference.. 
     164 
     165e.g Assuming a namespace Augmented.!ExtendedConsole kept in a utility dll (!AugmentationLibrary.dll) say [[BR]] 
     166 
     167rather than program !MyProg.cobra containing something like 
     168{{{ 
     169#!cobra 
     170... 
     171use Augmented.ExtendedConsole 
     172... 
     173    # use as  
     174    input = ExtendedConsole.input('Enter text:') 
     175 
     176}}} 
     177and compilation commandline  
     178{{{ 
     179cobra -ref:AugmentationLibrary MyProg.cobra 
     180}}} 
     181 
     182you can just have: 
     183{{{ 
     184#!cobra 
     185... 
     186use Augmented.ExtendedConsole from AugmentionLibrary 
     187... 
     188}}} 
     189and use a non -ref compilation invocation. 
     190 
     191{{{ 
     192cobra MyProg.cobra 
     193}}} 
     194 
     195[[BR]] 
     196[[BR]] 
     197 
     198 
     199Here (where the name is a lttle cumbersome) for more convenience use both features... 
     200{{{ 
     201#!cobra 
     202... 
     203use AugCons = Augmented.ExtendedConsole from AugmentationLibrary 
     204... 
     205    # use as  
     206    input = AugCons.input('Enter text:') 
     207 
     208}}}