diff --git a/README.md b/README.md index bededc8..2fc0566 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 diff --git a/js.rkt b/js.rkt index 83b3fae..0bfe477 100644 --- a/js.rkt +++ b/js.rkt @@ -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) diff --git a/lua.rkt b/lua.rkt index d630a82..35312b9 100644 --- a/lua.rkt +++ b/lua.rkt @@ -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" @@ -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)))))))]