Skip to content
This repository has been archived by the owner on Mar 16, 2018. It is now read-only.

Commit

Permalink
fix README number->string string->number
Browse files Browse the repository at this point in the history
  • Loading branch information
zaoqi committed Nov 18, 2017
1 parent 0d0734d commit 216cf50
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Map | Lua | Javas
`(define map)` |`local map` |`var map`
`(define a 0)` |`local a=0` |`var a=0`
`(set! x 1)` |`x=1` |`x=1`
`(lambda (x) (return x))` |`(function(x)return x end)` |`(function(x){return x})`
`(lambda (x) x)` |`(function(x)return x end)` |`(function(x){return x})`
`(! [x 132] [y 343] [z 912])`|`{x=132, y=343, z=912}` |`{x:132, y:343, z:912}`
`(ref t "x")` |`t["x"]` |`t["x"]`
`(@ t x)` |`t.x` |`t.x`
Expand All @@ -14,3 +14,12 @@ Map | Lua | Javas
`(vector-ref v 1)` |`v[1+1]` |`v[1]`
`(set! (vector-ref v 1) 1)` |`v[1+1]=1` |`v[1]=1`
`(apply f t)` | |

与Scheme的区别
============
+ 无char,pair,symbol,`vector-set!`,`vector->string`,`call/cc`
+`define-record-type`
+ `<` `>` `=` 等只能有2个参数
+ 所有primitive不是值
+ 没有宏
+ 数字只有float
14 changes: 8 additions & 6 deletions js.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@
(EVAL `(begin ,@c) ig)
"}\n"
(f undefined)))))))))]
[`(number? ,x) (EVAL x (λ (xx) (++ "(typeof " xx "=='number')")))]
[`(boolean? ,x) (EVAL x (λ (xx) (++ "(typeof " xx "=='boolean')")))]
[`(procedure? ,x) (EVAL x (λ (xx) (++ "(typeof " xx "=='function')")))]
[`(string? ,x) (EVAL x (λ (xx) (++ "(typeof " xx "=='string')")))]
[`(!/vectror? ,x) (EVAL x (λ (xx) (++ "(typeof " xx "=='object')")))]
[`(vector? ,x) (EVAL x (λ (xx) (++ "(" xx " instanceof Array")))]
[`(number? ,x) (EVAL x (λ (xx) (f (++ "(typeof " xx "=='number')"))))]
[`(boolean? ,x) (EVAL x (λ (xx) (f (++ "(typeof " xx "=='boolean')"))))]
[`(procedure? ,x) (EVAL x (λ (xx) (f (++ "(typeof " xx "=='function')"))))]
[`(string? ,x) (EVAL x (λ (xx) (f (++ "(typeof " xx "=='string')"))))]
[`(!/vectror? ,x) (EVAL x (λ (xx) (f (++ "(typeof " xx "=='object')"))))]
[`(vector? ,x) (EVAL x (λ (xx) (f (++ "(" xx " instanceof Array"))))]
[`(number->string ,x) (EVAL x (λ (xx) (f (++ xx".toString()"))))]
[`(string->number ,x) (EVAL x (λ (xx) (f (++ "parseFloat("xx")"))))]
[`(host ,@c) (match c [`(,_ ... [js ,v] ,_ ...) (f v)])]
[`(raise ,e) (EVAL e (λ (ee) (++ "throw "ee"\n")))]
[`(with-exception-handler ,handler ,thunk)
Expand Down
4 changes: 3 additions & 1 deletion lua.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
[`(vector? ,x)
(EVAL x (λ (xx)
(store! xx (λ (v) (f (++ "(" v "[1] or next(" v ")==nil)"))))))]
[`(number->string ,x) (EVAL x (λ (xx) (f (++ "tostring("xx")"))))]
[`(string->number ,x) (EVAL x (λ (xx) (f (++ "tonumber("xx")"))))]
[`(host ,@c) (match c [`(,_ ... [lua ,v] ,_ ...) (f v)])]
[`(raise ,e) (EVAL e (λ (ee)
(++ "E_="ee"\n"
Expand All @@ -154,7 +156,7 @@
(λ (t)
(let ([s (genvar!)] [x (genvar!)])
(++ "local "s","x"=pcall("t")\n"
"if "s"==false and string.sub("x",-6)==\"MapErr\" then\n"
"if not "s" and string.sub("x",-6)==\"MapErr\" then\n"
x"="h"(E_)\n"
"end\n"
(f x)))))))]
Expand Down

0 comments on commit 216cf50

Please sign in to comment.