diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-06 22:27:28 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-10-06 22:27:28 -0500 |
| commit | ad95503cea8ca85e9188effa87681275283157bf (patch) | |
| tree | f4e5919aeb2351f2ceb60fee4ab988324bfb5dd1 /go/src/core | |
| parent | 17e1c5f9f4006399398e8bb7e219a79962ebf3f0 (diff) | |
| download | mal-ad95503cea8ca85e9188effa87681275283157bf.tar.gz mal-ad95503cea8ca85e9188effa87681275283157bf.zip | |
go: add step6_file
Diffstat (limited to 'go/src/core')
| -rw-r--r-- | go/src/core/core.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/go/src/core/core.go b/go/src/core/core.go index 9df71a6..94e2452 100644 --- a/go/src/core/core.go +++ b/go/src/core/core.go @@ -2,11 +2,13 @@ package core import ( "errors" + "io/ioutil" "fmt" ) import ( . "types" + "reader" "printer" ) @@ -31,6 +33,12 @@ func println(a []MalType) (MalType, error) { return nil, nil } +func slurp(a []MalType) (MalType, error) { + b, e := ioutil.ReadFile(a[0].(string)) + if e != nil { return nil, e } + return string(b), nil +} + // Sequence functions @@ -62,6 +70,9 @@ var NS = map[string]MalType{ "str": func(a []MalType) (MalType, error) { return str(a) }, "prn": func(a []MalType) (MalType, error) { return prn(a) }, "println": func(a []MalType) (MalType, error) { return println(a) }, + "read-string": func(a []MalType) (MalType, error) { + return reader.Read_str(a[0].(string)) }, + "slurp": slurp, "<": func(a []MalType) (MalType, error) { return a[0].(int) < a[1].(int), nil }, |
