Changes between Version 6 and Version 7 of UseDirective
- Timestamp:
- 03/29/14 05:47:34 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UseDirective
v6 v7 2 2 3 3 {{{ 4 use [ <alias = ] <namespace> [ from <library-name> ] 5 4 6 use <namespace> 5 7 use <namespace> from <library-name> 8 use <alias> = <namespace> 6 9 }}} 7 10 8 11 Specify a namespace whose contents are made available to this module. 9 12 10 When using the first formif the compiler cannot immediately locate the namespace,[[BR]]13 When using a form without a 'from' clause, if the compiler cannot immediately locate the namespace,[[BR]] 11 14 i.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. 15 The compiler will look for a (platform dependent) library-name of the same form as the namespace. 16 17 18 If 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 21 21 22 22 {{{ … … 24 24 use Foo.Bar from SomeLib 25 25 }}} 26 You can put single or double quotes around the file name if its components 27 are not legal identifiers [[BR]] 26 You can put single or double quotes around the file name if its components are not legal identifiers [[BR]] 28 27 (for example, the filename has a space or punctuation mark in it). 29 28 {{{ … … 32 31 }}} 33 32 33 The 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]] 34 This is useful for a lengthy fully qualified namespace name that is widely used. 34 35 35 36 == Platform == … … 109 110 }}} 110 111 112 {{{ 113 #!cobra 114 115 use Cons = System.Console 116 use CC = Cobra.Core.CobraCore 117 118 class 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 111 127 112 128 … … 114 130 115 131 In 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 133 usual naming conventions. 117 134 118 135 … … 136 153 cobra MyProg.cobra 137 154 }}} 155 156 [[BR]] 157 [[BR]] 158 159 160 161 162 If the dll filename containing the namespace code differs from the namespace name you can wire the namespace/filename relationship into the 163 source file rather than having to always remember (or script) a specific separate compiler commandline reference.. 164 165 e.g Assuming a namespace Augmented.!ExtendedConsole kept in a utility dll (!AugmentationLibrary.dll) say [[BR]] 166 167 rather than program !MyProg.cobra containing something like 168 {{{ 169 #!cobra 170 ... 171 use Augmented.ExtendedConsole 172 ... 173 # use as 174 input = ExtendedConsole.input('Enter text:') 175 176 }}} 177 and compilation commandline 178 {{{ 179 cobra -ref:AugmentationLibrary MyProg.cobra 180 }}} 181 182 you can just have: 183 {{{ 184 #!cobra 185 ... 186 use Augmented.ExtendedConsole from AugmentionLibrary 187 ... 188 }}} 189 and use a non -ref compilation invocation. 190 191 {{{ 192 cobra MyProg.cobra 193 }}} 194 195 [[BR]] 196 [[BR]] 197 198 199 Here (where the name is a lttle cumbersome) for more convenience use both features... 200 {{{ 201 #!cobra 202 ... 203 use AugCons = Augmented.ExtendedConsole from AugmentationLibrary 204 ... 205 # use as 206 input = AugCons.input('Enter text:') 207 208 }}}