diff options
| author | Joel Martin <github@martintribe.org> | 2014-11-15 23:15:09 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:47 -0600 |
| commit | ee7cd5859e56423983f025088c8cef36b7ed09dd (patch) | |
| tree | da9f2011f4feaa34c96a63407fa4e8720eb1d4dc /vb/env.vb | |
| parent | c3b508af92800f63bf99f41af68f026535f454f5 (diff) | |
| download | mal-ee7cd5859e56423983f025088c8cef36b7ed09dd.tar.gz mal-ee7cd5859e56423983f025088c8cef36b7ed09dd.zip | |
VB.Net: port of C# version.
Diffstat (limited to 'vb/env.vb')
| -rw-r--r-- | vb/env.vb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vb/env.vb b/vb/env.vb new file mode 100644 index 0000000..3095344 --- /dev/null +++ b/vb/env.vb @@ -0,0 +1,55 @@ +Imports System.Collections.Generic +Imports Mal +Imports MalVal = Mal.types.MalVal +Imports MalSymbol = Mal.types.MalSymbol +Imports MalList = Mal.types.MalList + +Namespace Mal + Public Class env + Public Class Env + Dim outer As Env = Nothing + Dim data As Dictionary(Of String, MalVal) = New Dictionary(Of String, MalVal) + + Public Sub New(new_outer As Env) + outer = new_outer + End Sub + Public Sub New(new_outer As Env, binds As MalList, exprs As MalList) + outer = new_outer + For i As Integer = 0 To binds.size()-1 + Dim sym As String = DirectCast(binds.nth(i),MalSymbol).getName() + If sym = "&" Then + data(DirectCast(binds.nth(i+1),MalSymbol).getName()) = exprs.slice(i) + Exit For + Else + data(sym) = exprs.nth(i) + End If + Next + End Sub + + Public Function find(key As String) As Env + If data.ContainsKey(key) Then + return Me + Else If outer IsNot Nothing Then + return outer.find(key) + Else + return Nothing + End If + End Function + + Public Function do_get(key As String) As MalVal + Dim e As Env = find(key) + If e Is Nothing Then + throw New Mal.types.MalException( + "'" & key & "' not found") + Else + return e.data(key) + End If + End Function + + Public Function do_set(key As String, value As MalVal) As Env + data(key) = value + return Me + End Function + End Class + End Class +End Namespace |
