aboutsummaryrefslogtreecommitdiff
path: root/vb
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /vb
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'vb')
-rw-r--r--vb/core.vb34
-rw-r--r--vb/env.vb14
-rw-r--r--vb/printer.vb4
-rw-r--r--vb/reader.vb6
-rw-r--r--vb/step3_env.vb15
-rw-r--r--vb/step4_if_fn_do.vb9
-rw-r--r--vb/step5_tco.vb9
-rw-r--r--vb/step6_file.vb13
-rw-r--r--vb/step7_quote.vb13
-rw-r--r--vb/step8_macros.vb21
-rw-r--r--vb/step9_try.vb21
-rw-r--r--vb/stepA_interop.vb21
-rw-r--r--vb/types.vb4
13 files changed, 106 insertions, 78 deletions
diff --git a/vb/core.vb b/vb/core.vb
index 43fc30f..771d0cc 100644
--- a/vb/core.vb
+++ b/vb/core.vb
@@ -69,6 +69,24 @@ Namespace Mal
End If
End Function
+ Shared Function keyword(a As MalList) As MalVal
+ Dim s As String = DirectCast(a(0),MalString).getValue()
+ return new MalString(ChrW(&H029e) & s)
+ End Function
+
+ Shared Function keyword_Q(a As MalList) As MalVal
+ If TypeOf a(0) Is MalString Then
+ Dim s As String = DirectCast(a(0),MalString).getValue()
+ If s.Substring(0,1) = Strings.ChrW(&H029e) Then
+ return MalTrue
+ Else
+ return MalFalse
+ End If
+ Else
+ return MalFalse
+ End If
+ End Function
+
' Number functions
Shared Function lt(a As MalList) As MalVal
@@ -258,7 +276,13 @@ Namespace Mal
End Function
Shared Function nth(a As MalList) As MalVal
- return DirectCast(a(0),MalList)( DirectCast(a(1),MalInt).getValue() )
+ Dim idx As Integer = DirectCast(a(1),MalInt).getValue()
+ If (idx < DirectCast(a(0),MalList).size()) Then
+ return DirectCast(a(0),MalList)( idx )
+ Else
+ throw new Mal.types.MalException(
+ "nth: index out of range")
+ End If
End Function
Shared Function first(a As MalList) As MalVal
@@ -278,7 +302,11 @@ Namespace Mal
End Function
Shared Function count(a As MalList) As MalVal
- return new MalInt(DirectCast(a(0),MalList).size())
+ If a(0) Is Nil Then
+ return new MalInt(0)
+ Else
+ return new MalInt(DirectCast(a(0),MalList).size())
+ End If
End Function
Shared Function conj(a As MalList) As MalVal
@@ -371,6 +399,8 @@ Namespace Mal
ns.Add("false?", New MalFunc(AddressOf false_Q))
ns.Add("symbol", new MalFunc(AddressOf symbol))
ns.Add("symbol?", New MalFunc(AddressOf symbol_Q))
+ ns.Add("keyword", new MalFunc(AddressOf keyword))
+ ns.Add("keyword?", New MalFunc(AddressOf keyword_Q))
ns.Add("pr-str",New MalFunc(AddressOf pr_str))
ns.Add("str", New MalFunc(AddressOf str))
diff --git a/vb/env.vb b/vb/env.vb
index 3095344..a2c4628 100644
--- a/vb/env.vb
+++ b/vb/env.vb
@@ -26,8 +26,8 @@ Namespace Mal
Next
End Sub
- Public Function find(key As String) As Env
- If data.ContainsKey(key) Then
+ Public Function find(key As MalSymbol) As Env
+ If data.ContainsKey(key.getName()) Then
return Me
Else If outer IsNot Nothing Then
return outer.find(key)
@@ -36,18 +36,18 @@ Namespace Mal
End If
End Function
- Public Function do_get(key As String) As MalVal
+ Public Function do_get(key As MalSymbol) As MalVal
Dim e As Env = find(key)
If e Is Nothing Then
throw New Mal.types.MalException(
- "'" & key & "' not found")
+ "'" & key.getName() & "' not found")
Else
- return e.data(key)
+ return e.data(key.getName())
End If
End Function
- Public Function do_set(key As String, value As MalVal) As Env
- data(key) = value
+ Public Function do_set(key As MalSymbol, value As MalVal) As Env
+ data(key.getName()) = value
return Me
End Function
End Class
diff --git a/vb/printer.vb b/vb/printer.vb
index 212b89c..3f3e6e2 100644
--- a/vb/printer.vb
+++ b/vb/printer.vb
@@ -22,7 +22,9 @@ Namespace Mal
print_readably As Boolean) As String
Dim strs As New List(Of String)
For Each entry As KeyValuePair(Of String, MalVal) In value
- If print_readably Then
+ If entry.Key.Length > 0 and entry.Key(0) = ChrW(&H029e) Then
+ strs.Add(":" & entry.Key.Substring(1))
+ Else If print_readably Then
strs.Add("""" & entry.Key.ToString() & """")
Else
strs.Add(entry.Key.ToString())
diff --git a/vb/reader.vb b/vb/reader.vb
index 121aac2..9d4e03d 100644
--- a/vb/reader.vb
+++ b/vb/reader.vb
@@ -64,7 +64,7 @@ Namespace Mal
Shared Function read_atom(rdr As Reader) As MalVal
Dim token As String = rdr.get_next()
- Dim pattern As String = "(^-?[0-9]+$)|(^-?[0-9][0-9.]*$)|(^nil$)|(^true$)|(^false$)|^("".*"")$|(^[^""]*$)"
+ Dim pattern As String = "(^-?[0-9]+$)|(^-?[0-9][0-9.]*$)|(^nil$)|(^true$)|(^false$)|^("".*"")$|^:(.*)|(^[^""]*$)"
Dim regex As Regex = New Regex(pattern)
Dim match As Match = regex.Match(token)
'Console.WriteLine("token: ^" + token + "$")
@@ -86,7 +86,9 @@ Namespace Mal
.Replace("\""", """") _
.Replace("\n", Environment.NewLine))
Else If match.Groups(7).Value <> String.Empty Then
- return New Mal.types.MalSymbol(match.Groups(7).Value)
+ return New Mal.types.MalString(ChrW(&H029e) & match.Groups(7).Value)
+ Else If match.Groups(8).Value <> String.Empty Then
+ return New Mal.types.MalSymbol(match.Groups(8).Value)
Else
throw New ParseError("unrecognized '" & match.Groups(0).Value & "'")
End If
diff --git a/vb/step3_env.vb b/vb/step3_env.vb
index 5793fdb..dfee614 100644
--- a/vb/step3_env.vb
+++ b/vb/step3_env.vb
@@ -21,8 +21,7 @@ Namespace Mal
' eval
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -66,7 +65,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -77,7 +76,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
return EVAL(a2, let_env)
Case Else
@@ -119,10 +118,10 @@ Namespace Mal
Dim args As String() = Environment.GetCommandLineArgs()
repl_env = New MalEnv(Nothing)
- repl_env.do_set("+", New MalFunc(AddressOf add))
- repl_env.do_set("-", New MalFunc(AddressOf minus))
- repl_env.do_set("*", New MalFunc(AddressOf mult))
- repl_env.do_set("/", New MalFunc(AddressOf div))
+ repl_env.do_set(new MalSymbol("+"), New MalFunc(AddressOf add))
+ repl_env.do_set(new MalSymbol("-"), New MalFunc(AddressOf minus))
+ repl_env.do_set(new MalSymbol("*"), New MalFunc(AddressOf mult))
+ repl_env.do_set(new MalSymbol("/"), New MalFunc(AddressOf div))
If args.Length > 1 AndAlso args(1) = "--raw" Then
diff --git a/vb/step4_if_fn_do.vb b/vb/step4_if_fn_do.vb
index 4cf8721..470ae86 100644
--- a/vb/step4_if_fn_do.vb
+++ b/vb/step4_if_fn_do.vb
@@ -21,8 +21,7 @@ Namespace Mal
' eval
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -83,7 +82,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -94,7 +93,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
return EVAL(a2, let_env)
Case "do"
@@ -152,7 +151,7 @@ Namespace Mal
' core.vb: defined using VB.NET
For Each entry As KeyValuePair(Of String,MalVal) In core.ns()
- repl_env.do_set(entry.Key, entry.Value)
+ repl_env.do_set(new MalSymbol(entry.Key), entry.Value)
Next
' core.mal: defined using the language itself
diff --git a/vb/step5_tco.vb b/vb/step5_tco.vb
index 3c1f51c..bb36b22 100644
--- a/vb/step5_tco.vb
+++ b/vb/step5_tco.vb
@@ -21,8 +21,7 @@ Namespace Mal
' eval
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -85,7 +84,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -96,7 +95,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
orig_ast = a2
env = let_env
@@ -161,7 +160,7 @@ Namespace Mal
' core.vb: defined using VB.NET
For Each entry As KeyValuePair(Of String,MalVal) In core.ns()
- repl_env.do_set(entry.Key, entry.Value)
+ repl_env.do_set(new MalSymbol(entry.Key), entry.Value)
Next
' core.mal: defined using the language itself
diff --git a/vb/step6_file.vb b/vb/step6_file.vb
index 58f8cd2..9ea0e9f 100644
--- a/vb/step6_file.vb
+++ b/vb/step6_file.vb
@@ -22,8 +22,7 @@ Namespace Mal
' eval
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -86,7 +85,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -97,7 +96,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
orig_ast = a2
env = let_env
@@ -166,9 +165,9 @@ Namespace Mal
' core.vb: defined using VB.NET
For Each entry As KeyValuePair(Of String,MalVal) In core.ns()
- repl_env.do_set(entry.Key, entry.Value)
+ repl_env.do_set(new MalSymbol(entry.Key), entry.Value)
Next
- repl_env.do_set("eval", new MalFunc(AddressOf do_eval))
+ repl_env.do_set(new MalSymbol("eval"), new MalFunc(AddressOf do_eval))
Dim fileIdx As Integer = 1
If args.Length > 1 AndAlso args(1) = "--raw" Then
Mal.readline.SetMode(Mal.readline.Modes.Raw)
@@ -178,7 +177,7 @@ Namespace Mal
For i As Integer = fileIdx+1 To args.Length-1
argv.conj_BANG(new MalString(args(i)))
Next
- repl_env.do_set("*ARGV*", argv)
+ repl_env.do_set(new MalSymbol("*ARGV*"), argv)
' core.mal: defined using the language itself
REP("(def! not (fn* (a) (if a false true)))")
diff --git a/vb/step7_quote.vb b/vb/step7_quote.vb
index 3f2d614..f38741e 100644
--- a/vb/step7_quote.vb
+++ b/vb/step7_quote.vb
@@ -51,8 +51,7 @@ Namespace Mal
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -115,7 +114,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -126,7 +125,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
orig_ast = a2
env = let_env
@@ -199,9 +198,9 @@ Namespace Mal
' core.vb: defined using VB.NET
For Each entry As KeyValuePair(Of String,MalVal) In core.ns()
- repl_env.do_set(entry.Key, entry.Value)
+ repl_env.do_set(new MalSymbol(entry.Key), entry.Value)
Next
- repl_env.do_set("eval", new MalFunc(AddressOf do_eval))
+ repl_env.do_set(new MalSymbol("eval"), new MalFunc(AddressOf do_eval))
Dim fileIdx As Integer = 1
If args.Length > 1 AndAlso args(1) = "--raw" Then
Mal.readline.SetMode(Mal.readline.Modes.Raw)
@@ -211,7 +210,7 @@ Namespace Mal
For i As Integer = fileIdx+1 To args.Length-1
argv.conj_BANG(new MalString(args(i)))
Next
- repl_env.do_set("*ARGV*", argv)
+ repl_env.do_set(new MalSymbol("*ARGV*"), argv)
' core.mal: defined using the language itself
REP("(def! not (fn* (a) (if a false true)))")
diff --git a/vb/step8_macros.vb b/vb/step8_macros.vb
index 1a7f211..400dbe7 100644
--- a/vb/step8_macros.vb
+++ b/vb/step8_macros.vb
@@ -52,8 +52,8 @@ Namespace Mal
If TypeOf ast Is MalList Then
Dim a0 As MalVal = DirectCast(ast,MalList)(0)
If TypeOf a0 Is MalSymbol AndAlso _
- env.find(DirectCast(a0,MalSymbol).getName()) IsNot Nothing Then
- Dim mac As MalVal = env.do_get(DirectCast(a0,MalSymbol).getName())
+ env.find(DirectCast(a0,MalSymbol)) IsNot Nothing Then
+ Dim mac As MalVal = env.do_get(DirectCast(a0,MalSymbol))
If TypeOf mac Is MalFunc AndAlso _
DirectCast(mac,MalFunc).isMacro() Then
return True
@@ -66,7 +66,7 @@ Namespace Mal
Shared Function macroexpand(ast As MalVal, env As MalEnv) As MalVal
While is_macro_call(ast, env)
Dim a0 As MalSymbol = DirectCast(DirectCast(ast,MalList)(0),MalSymbol)
- Dim mac As MalFunc = DirectCast(env.do_get(a0.getName()),MalFunc)
+ Dim mac As MalFunc = DirectCast(env.do_get(a0),MalFunc)
ast = mac.apply(DirectCast(ast,MalList).rest())
End While
return ast
@@ -74,8 +74,7 @@ Namespace Mal
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -143,7 +142,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -154,7 +153,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
orig_ast = a2
env = let_env
@@ -167,7 +166,7 @@ Namespace Mal
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
DirectCast(res,MalFunc).setMacro()
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "macroexpand"
Dim a1 As MalVal = ast(1)
@@ -237,9 +236,9 @@ Namespace Mal
' core.vb: defined using VB.NET
For Each entry As KeyValuePair(Of String,MalVal) In core.ns()
- repl_env.do_set(entry.Key, entry.Value)
+ repl_env.do_set(new MalSymbol(entry.Key), entry.Value)
Next
- repl_env.do_set("eval", new MalFunc(AddressOf do_eval))
+ repl_env.do_set(new MalSymbol("eval"), new MalFunc(AddressOf do_eval))
Dim fileIdx As Integer = 1
If args.Length > 1 AndAlso args(1) = "--raw" Then
Mal.readline.SetMode(Mal.readline.Modes.Raw)
@@ -249,7 +248,7 @@ Namespace Mal
For i As Integer = fileIdx+1 To args.Length-1
argv.conj_BANG(new MalString(args(i)))
Next
- repl_env.do_set("*ARGV*", argv)
+ repl_env.do_set(new MalSymbol("*ARGV*"), argv)
' core.mal: defined using the language itself
REP("(def! not (fn* (a) (if a false true)))")
diff --git a/vb/step9_try.vb b/vb/step9_try.vb
index 5bf600d..d4a7af4 100644
--- a/vb/step9_try.vb
+++ b/vb/step9_try.vb
@@ -52,8 +52,8 @@ Namespace Mal
If TypeOf ast Is MalList Then
Dim a0 As MalVal = DirectCast(ast,MalList)(0)
If TypeOf a0 Is MalSymbol AndAlso _
- env.find(DirectCast(a0,MalSymbol).getName()) IsNot Nothing Then
- Dim mac As MalVal = env.do_get(DirectCast(a0,MalSymbol).getName())
+ env.find(DirectCast(a0,MalSymbol)) IsNot Nothing Then
+ Dim mac As MalVal = env.do_get(DirectCast(a0,MalSymbol))
If TypeOf mac Is MalFunc AndAlso _
DirectCast(mac,MalFunc).isMacro() Then
return True
@@ -66,7 +66,7 @@ Namespace Mal
Shared Function macroexpand(ast As MalVal, env As MalEnv) As MalVal
While is_macro_call(ast, env)
Dim a0 As MalSymbol = DirectCast(DirectCast(ast,MalList)(0),MalSymbol)
- Dim mac As MalFunc = DirectCast(env.do_get(a0.getName()),MalFunc)
+ Dim mac As MalFunc = DirectCast(env.do_get(a0),MalFunc)
ast = mac.apply(DirectCast(ast,MalList).rest())
End While
return ast
@@ -74,8 +74,7 @@ Namespace Mal
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -143,7 +142,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -154,7 +153,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
orig_ast = a2
env = let_env
@@ -167,7 +166,7 @@ Namespace Mal
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
DirectCast(res,MalFunc).setMacro()
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "macroexpand"
Dim a1 As MalVal = ast(1)
@@ -260,9 +259,9 @@ Namespace Mal
' core.vb: defined using VB.NET
For Each entry As KeyValuePair(Of String,MalVal) In core.ns()
- repl_env.do_set(entry.Key, entry.Value)
+ repl_env.do_set(new MalSymbol(entry.Key), entry.Value)
Next
- repl_env.do_set("eval", new MalFunc(AddressOf do_eval))
+ repl_env.do_set(new MalSymbol("eval"), new MalFunc(AddressOf do_eval))
Dim fileIdx As Integer = 1
If args.Length > 1 AndAlso args(1) = "--raw" Then
Mal.readline.SetMode(Mal.readline.Modes.Raw)
@@ -272,7 +271,7 @@ Namespace Mal
For i As Integer = fileIdx+1 To args.Length-1
argv.conj_BANG(new MalString(args(i)))
Next
- repl_env.do_set("*ARGV*", argv)
+ repl_env.do_set(new MalSymbol("*ARGV*"), argv)
' core.mal: defined using the language itself
REP("(def! not (fn* (a) (if a false true)))")
diff --git a/vb/stepA_interop.vb b/vb/stepA_interop.vb
index 01702fa..f9af038 100644
--- a/vb/stepA_interop.vb
+++ b/vb/stepA_interop.vb
@@ -52,8 +52,8 @@ Namespace Mal
If TypeOf ast Is MalList Then
Dim a0 As MalVal = DirectCast(ast,MalList)(0)
If TypeOf a0 Is MalSymbol AndAlso _
- env.find(DirectCast(a0,MalSymbol).getName()) IsNot Nothing Then
- Dim mac As MalVal = env.do_get(DirectCast(a0,MalSymbol).getName())
+ env.find(DirectCast(a0,MalSymbol)) IsNot Nothing Then
+ Dim mac As MalVal = env.do_get(DirectCast(a0,MalSymbol))
If TypeOf mac Is MalFunc AndAlso _
DirectCast(mac,MalFunc).isMacro() Then
return True
@@ -66,7 +66,7 @@ Namespace Mal
Shared Function macroexpand(ast As MalVal, env As MalEnv) As MalVal
While is_macro_call(ast, env)
Dim a0 As MalSymbol = DirectCast(DirectCast(ast,MalList)(0),MalSymbol)
- Dim mac As MalFunc = DirectCast(env.do_get(a0.getName()),MalFunc)
+ Dim mac As MalFunc = DirectCast(env.do_get(a0),MalFunc)
ast = mac.apply(DirectCast(ast,MalList).rest())
End While
return ast
@@ -74,8 +74,7 @@ Namespace Mal
Shared Function eval_ast(ast As MalVal, env As MalEnv) As MalVal
If TypeOf ast Is MalSymbol Then
- Dim sym As MalSymbol = DirectCast(ast, MalSymbol)
- return env.do_get(sym.getName())
+ return env.do_get(DirectCast(ast, MalSymbol))
Else If TypeOf ast Is MalList Then
Dim old_lst As MalList = DirectCast(ast, MalList)
Dim new_lst As MalList
@@ -143,7 +142,7 @@ Namespace Mal
Dim a1 As MalVal = ast(1)
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "let*"
Dim a1 As MalVal = ast(1)
@@ -154,7 +153,7 @@ Namespace Mal
For i As Integer = 0 To (DirectCast(a1,MalList)).size()-1 Step 2
key = DirectCast(DirectCast(a1,MalList)(i),MalSymbol)
val = DirectCast(a1,MalList)(i+1)
- let_env.do_set(key.getName(), EVAL(val, let_env))
+ let_env.do_set(key, EVAL(val, let_env))
Next
orig_ast = a2
env = let_env
@@ -167,7 +166,7 @@ Namespace Mal
Dim a2 As MalVal = ast(2)
Dim res As MalVal = EVAL(a2, env)
DirectCast(res,MalFunc).setMacro()
- env.do_set(DirectCast(a1,MalSymbol).getName(), res)
+ env.do_set(DirectCast(a1,MalSymbol), res)
return res
Case "macroexpand"
Dim a1 As MalVal = ast(1)
@@ -260,9 +259,9 @@ Namespace Mal
' core.vb: defined using VB.NET
For Each entry As KeyValuePair(Of String,MalVal) In core.ns()
- repl_env.do_set(entry.Key, entry.Value)
+ repl_env.do_set(new MalSymbol(entry.Key), entry.Value)
Next
- repl_env.do_set("eval", new MalFunc(AddressOf do_eval))
+ repl_env.do_set(new MalSymbol("eval"), new MalFunc(AddressOf do_eval))
Dim fileIdx As Integer = 1
If args.Length > 1 AndAlso args(1) = "--raw" Then
Mal.readline.SetMode(Mal.readline.Modes.Raw)
@@ -272,7 +271,7 @@ Namespace Mal
For i As Integer = fileIdx+1 To args.Length-1
argv.conj_BANG(new MalString(args(i)))
Next
- repl_env.do_set("*ARGV*", argv)
+ repl_env.do_set(new MalSymbol("*ARGV*"), argv)
' core.mal: defined using the language itself
REP("(def! *host-language* ""VB.NET"")")
diff --git a/vb/types.vb b/vb/types.vb
index 303a02e..4da75bd 100644
--- a/vb/types.vb
+++ b/vb/types.vb
@@ -232,7 +232,9 @@ namespace Mal
return """" & value & """"
End Function
Public Overrides Function ToString(print_readably As Boolean) As String
- If print_readably Then
+ If value.Length > 0 AndAlso value(0) = ChrW(&H029e) Then
+ return ":" & value.Substring(1)
+ Else If print_readably Then
return """" & _
value.Replace("\", "\\") _
.Replace("""", "\""") _