summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKEnvironment.h2
-rw-r--r--MLKEnvironment.m16
2 files changed, 17 insertions, 1 deletions
diff --git a/MLKEnvironment.h b/MLKEnvironment.h
index 0789b1a..bfa5f2b 100644
--- a/MLKEnvironment.h
+++ b/MLKEnvironment.h
@@ -37,6 +37,8 @@
-(MLKEnvironment *) parent;
-(NSSet *) bindings;
+-(void) addBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol;
+-(void) setBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol;
-(void) addBindingForSymbol:(MLKSymbol *)symbol;
-(void) addBindings:(NSDictionary *)bindings;
-(void) addValues:(NSDictionary *)bindings;
diff --git a/MLKEnvironment.m b/MLKEnvironment.m
index 29f7740..7119bac 100644
--- a/MLKEnvironment.m
+++ b/MLKEnvironment.m
@@ -137,10 +137,24 @@
-(void) addBindingForSymbol:(MLKSymbol *)symbol
{
- [_bindings setObject:[MLKBinding binding]
+ [self addBinding:[MLKBinding binding] forSymbol:symbol];
+}
+
+-(void) addBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol
+{
+ [_bindings setObject:binding
forKey:(symbol ? (id)symbol : (id)[NSNull null])];
}
+-(void) setBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol
+{
+ if (![self bindingForSymbol:symbol])
+ [NSException raise:@"MLKUnboundVariableError"
+ format:@"The variable %@ is unbound.",
+ [symbol descriptionForLisp]];
+ [self addBinding:binding forSymbol:symbol];
+}
+
-(MLKEnvironment *) environmentForSymbol:(MLKSymbol *)symbol
{
if ([_bindings objectForKey:symbol])