diff options
| author | Miki Tebeka <miki.tebeka@gmail.com> | 2015-03-01 06:12:42 +0200 |
|---|---|---|
| committer | Miki Tebeka <miki.tebeka@gmail.com> | 2015-03-01 06:12:42 +0200 |
| commit | 9fb199e2cb2cf44cd61c2a226193a70f6013aadc (patch) | |
| tree | 325a2a8e33e3e8d18217d10854152cab82ac8b61 /forth/tests/stepA_mal.mal | |
| parent | 49916f9402e30a5277146355be878b32ec30f46d (diff) | |
| parent | 2cb013877c4ed41d245ce7c5525405c4833c503d (diff) | |
| download | mal-9fb199e2cb2cf44cd61c2a226193a70f6013aadc.tar.gz mal-9fb199e2cb2cf44cd61c2a226193a70f6013aadc.zip | |
Merge branch 'master' of https://github.com/kanaka/mal
Diffstat (limited to 'forth/tests/stepA_mal.mal')
| -rw-r--r-- | forth/tests/stepA_mal.mal | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/forth/tests/stepA_mal.mal b/forth/tests/stepA_mal.mal new file mode 100644 index 0000000..c4a0e75 --- /dev/null +++ b/forth/tests/stepA_mal.mal @@ -0,0 +1,41 @@ +;; Basic interop +(. 5 'MalInt.) +;=>5 +(. 11 31 '+ 'MalInt.) +;=>42 +(. "greetings" 'MalString.) +;=>"greetings" +(. "hello" 'type 'cr 'mal-nil) +; hello +;=>nil + +;; Interop on non-literals +(. (+ 15 27) 'MalInt.) +;=>42 +(let* [a 17] (. a 25 '+ 'MalInt.)) +;=>42 +(let* [a "hello"] (. a 1 '- 'MalString.)) +;=>"hell" + +;; Use of annoyingly-named forth words +(. 1 'MalInt. (symbol ",") 'here (symbol "@")) +;=>1 +(let* (i 'MalInt.) (. 5 i)) +;=>5 +(let* (comma (symbol ",") fetch (symbol "@")) (. 'here 42 'MalInt. comma fetch)) +;=>42 + +;; Multiple .-forms interacting via heap memory and mal locals +(def! string-parts (fn* (s) (. s 'MalInt. 'swap 'MalInt. 'here '-rot (symbol ",") (symbol ",") 'here>MalList))) +(first (rest (string-parts "sketchy"))) +;=>7 +(def! prn-chars (fn* (start count) (if (> count 0) (do (prn (. start 1 'MalString.)) (prn-chars (+ start 1) (- count 1)))))) +(let* (msg (string-parts "sketchy")) (prn-chars (first msg) (first (rest msg)))) +; "s" +; "k" +; "e" +; "t" +; "c" +; "h" +; "y" +;=>nil |
