1 #import
<Foundation
/Foundation.h
>
8 @synthesize data
= _data
;
9 @synthesize outer
= _outer
;
11 - (id
)initWithBindings
:(Env
*)outer binds
:(NSArray
*)binds exprs
:(NSArray
*)exprs
{
15 _data
= [NSMutableDictionary dictionary
];
17 for (int i
=0; i
< [binds count
]; i
++) {
18 if ([(NSString
*)binds
[i
] isEqualTo
:@"
&"
]) {
19 if ([exprs count
] > i
) {
20 NSRange r
= NSMakeRange
(i
, [exprs count
] - i
);
21 _data
[binds
[i
+1]] = [exprs subarrayWithRange
:r
];
23 _data
[binds
[i
+1]] = @
[];
27 _data
[binds
[i
]] = exprs
[i
];
34 - (id
)initWithOuter
:(Env
*)outer
{
35 return [self initWithBindings
:outer binds
:@
[] exprs
:@
[]];
39 return [self initWithBindings
:nil binds
:@
[] exprs
:@
[]];
42 + (id
)fromOuter
:(Env
*)outer
{
43 return [[Env alloc
] initWithOuter
:outer
];
46 + (id
)fromBindings
:(Env
*)outer binds
:(NSArray
*)binds exprs
:(NSArray
*)exprs
{
47 return [[Env alloc
] initWithBindings
:outer binds
:binds exprs
:exprs
];
50 - (NSObject
*) set:(MalSymbol
*)key val
:(NSObject
*)val
{
55 - (Env
*) find:(MalSymbol
*)key
{
66 - (NSObject
*) get:(MalSymbol
*)key
{
67 Env
* e
= [self
find:key
];
71 @throw
[NSString stringWithFormat
:@"
'%@' not found"
, key
];