Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 124 lines (77 sloc) 3.334 kb
ee0e230 @ajlopez IBehavior.Scope, BaseBehavior scope taken from machine.CurrentScope, Mac...
authored
1
b7d4b12 @ajlopez Environment new:in: with tests in EnvironmentTests.st
authored
2 | env myglobal subenv myobj |
ee0e230 @ajlopez IBehavior.Scope, BaseBehavior scope taken from machine.CurrentScope, Mac...
authored
3
d197a3c @ajlopez Added Environment current class method in Library.st, tested in Environm...
authored
4 "Current environment is Smalltalk"
5
6 [Environment current == Smalltalk] assert.
7
ee0e230 @ajlopez IBehavior.Scope, BaseBehavior scope taken from machine.CurrentScope, Mac...
authored
8 env := Environment new: #MyEnvironment.
9
eba3e7d @ajlopez Updated EnvironmentTests.st
authored
10 "The new environment was defined as global at Smalltalk"
45e8172 @ajlopez Improved EnvironmentTests.st
authored
11
ee0e230 @ajlopez IBehavior.Scope, BaseBehavior scope taken from machine.CurrentScope, Mac...
authored
12 [(Smalltalk at: #MyEnvironment) isNil not] assert.
13 [(Smalltalk at: #MyEnvironment) == MyEnvironment] assert.
f20f8f1 @ajlopez Improved EnvironmentTests.st
authored
14 [(Smalltalk at: #MyEnvironment) == env] assert.
ee0e230 @ajlopez IBehavior.Scope, BaseBehavior scope taken from machine.CurrentScope, Mac...
authored
15
45e8172 @ajlopez Improved EnvironmentTests.st
authored
16 [MyEnvironment isNil not] assert.
17 [MyEnvironment == env] assert.
18
a0b8654 @ajlopez Dotted Name in ModelParser; DottedName used in EnvironmentTests.st
authored
19 "Dotted expression syntax sugar for MyEnvironment at: #Smalltalk"
20
21 [MyEnvironment.Smalltalk == Smalltalk] assert.
eba3e7d @ajlopez Updated EnvironmentTests.st
authored
22
23 "Dotted expression syntax sugar for Smalltalk at: #MyEnvironment"
24
a0b8654 @ajlopez Dotted Name in ModelParser; DottedName used in EnvironmentTests.st
authored
25 [Smalltalk.MyEnvironment == MyEnvironment] assert.
26
ee0e230 @ajlopez IBehavior.Scope, BaseBehavior scope taken from machine.CurrentScope, Mac...
authored
27 [(env at: #Smalltalk) == Smalltalk] assert.
f20f8f1 @ajlopez Improved EnvironmentTests.st
authored
28 [(MyEnvironment at: #Smalltalk) == Smalltalk] assert.
ee0e230 @ajlopez IBehavior.Scope, BaseBehavior scope taken from machine.CurrentScope, Mac...
authored
29
2935b2a @ajlopez Fix renaming negate: to negateboolean: in Library.st; Adding test to Env...
authored
30 "Define a global at Smalltalk environment"
31
32 MyGlobal := Object new.
33
34 "Switch to env environment"
35
36 env setCurrent.
37
d197a3c @ajlopez Added Environment current class method in Library.st, tested in Environm...
authored
38 "Current environment check"
39
40 [Environment current == env] assert.
41 [Environment current == Smalltalk.MyEnvironment] assert.
42
43 "The current environment is a referenced by a global variable at Smalltalk environment"
44 [Environment current == MyEnvironment] assert.
45
2935b2a @ajlopez Fix renaming negate: to negateboolean: in Library.st; Adding test to Env...
authored
46 "Define a 'global' at current env environment"
47
48 MyGlobal := Object new.
49
2008863 @ajlopez Todo updated
authored
50 "Define a class at current env environment, no change to syntax"
51
52 Object subclass:#MyClass
9fdcc39 @ajlopez Convert tabs to spaces
authored
53 instanceVariableNames:''
54 classVariableNames:''
55 poolDictionaries:''
56 category:''
2401699 @ajlopez EnvironmentTests.st updated
authored
57 .
58
59 [(env at: #MyClass) isNil not] assert.
ceff979 @ajlopez nil isNil returns true. Updated EnvironmentTests.st
authored
60 [(Smalltalk at: #MyClass) isNil] assert.
2008863 @ajlopez Todo updated
authored
61
d385954 @ajlopez Improving comments in EnvironmentTests.st
authored
62 "Compile class method to get MyGlobal from its environment
63 (at MyClass creation time:
64 each class has an Scope pointing to the environment that was current
65 at the time of class definition. The 'globals' in their methods are resolved using that
66 scope"
45e8172 @ajlopez Improved EnvironmentTests.st
authored
67
68 MyClass class compile: 'global ^MyGlobal'.
69
2935b2a @ajlopez Fix renaming negate: to negateboolean: in Library.st; Adding test to Env...
authored
70 "Back to Smalltalk environment"
71
72 Smalltalk setCurrent.
73
f20f8f1 @ajlopez Improved EnvironmentTests.st
authored
74 "MyClass is not defined here, at env environment"
50cc495 @ajlopez Improved EnvironmentTests.st
authored
75
76 [MyClass isNil] assert.
45e8172 @ajlopez Improved EnvironmentTests.st
authored
77 [(env at: #MyClass) isNil not] assert.
78
79 myglobal := (env at: #MyClass) global.
80
81 "The retrieved myglobal is MyGlobal at env, and it's different from MyGlobal at Smalltalk"
82
83 [myglobal isNil not] assert.
84 [myglobal == (env at: #MyGlobal)] assert.
85 [myglobal ~~ MyGlobal] assert.
50cc495 @ajlopez Improved EnvironmentTests.st
authored
86
eba3e7d @ajlopez Updated EnvironmentTests.st
authored
87 "Accesing the same global using dotted name"
88
89 [myglobal == MyEnvironment.MyGlobal] assert.
90
50cc495 @ajlopez Improved EnvironmentTests.st
authored
91 "MyGlobal here is different from MyGlobal at env"
92
2935b2a @ajlopez Fix renaming negate: to negateboolean: in Library.st; Adding test to Env...
authored
93 [MyGlobal isNil not] assert.
94 [(Smalltalk at: #MyGlobal) isNil not] assert.
95 [MyGlobal == (Smalltalk at: #MyGlobal)] assert.
96 [(env at: #MyGlobal) isNil not] assert.
97 [MyGlobal ~~ (env at: #MyGlobal)] assert.
b7d4b12 @ajlopez Environment new:in: with tests in EnvironmentTests.st
authored
98
99 "Sub enviroment"
100
101 subenv := Environment new: #MySubenvironment in: MyEnvironment.
102
103 [MyEnvironment.MySubenvironment == subenv] assert.
104
105 "Smalltalk environment is still accesible from subenvironment"
106
107 [MyEnvironment.MySubenvironment.Smalltalk == Smalltalk] assert.
108
109 "You can create an object instance of MyEnviroment class"
110
111 myobj := MyEnvironment.MyClass new.
112
113 [myobj isNil not] assert.
114 [myobj class == MyEnvironment.MyClass] assert.
115
116 "
117 TODO: to have a way of import (locate, load and set in current environment) a package/module
118 Maybe:
119
120 Package import: #MyLisp.
121 Package import: #MyWeb.WebServer.
122
123 As in Python, a 'package' already imported is retrieved from a cache
124 "
Something went wrong with that request. Please try again.