Added unseal operator.
h3rald h3rald@h3rald.com
Thu, 23 Feb 2017 12:05:14 +0100
3 files changed,
16 insertions(+),
2 deletions(-)
M
core/scope.nim
→
core/scope.nim
@@ -41,11 +41,11 @@ scope.symbols.excl(key)
return true return false -proc setSymbol*(scope: ref MinScope, key: string, value: MinOperator): bool {.discardable.}= +proc setSymbol*(scope: ref MinScope, key: string, value: MinOperator, override = false): bool {.discardable.}= result = false # check if a symbol already exists in current scope if not scope.isNil and scope.symbols.hasKey(key): - if scope.symbols[key].sealed: + if not override and scope.symbols[key].sealed: raiseInvalid("Symbol '$1' is sealed." % key) scope.symbols[key] = value result = true
M
lib/min_lang.nim
→
lib/min_lang.nim
@@ -745,6 +745,13 @@ var s = i.scope.getSymbol(sym.getString)
s.sealed = true i.scope.setSymbol(sym.getString, s) + .symbol("unseal") do (i: In): + var sym: MinValue + i.reqStringLike sym + var s = i.scope.getSymbol(sym.getString) + s.sealed = false + i.scope.setSymbol(sym.getString, s, true) + .symbol("quote-bind") do (i: In): var s, m: MinValue i.reqString(s)
M
tests/lang.min
→
tests/lang.min
@@ -130,6 +130,13 @@
(((2 :a1 'a1 seal 3 :a1) ("failed")) try "failed" ==) assert ( + 1 :a1 + 'a1 seal + 'a1 unseal + 2 :a1 + 2 a1 ==) assert + + ( ( (((error "TestError")(message "Test Message")) raise) ('error dget)