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

Commit

Permalink
lua
Browse files Browse the repository at this point in the history
  • Loading branch information
zaoqi committed Oct 14, 2017
1 parent 2c21386 commit c9ced02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
26 changes: 2 additions & 24 deletions lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,29 +198,7 @@ local function scmto(x)
elseif x==null or is_pair(x) then
error("NULL/PAIR!")
elseif is_vector(x) then
local t=sym2str(vector_ref(x,0))
if t=="_v" then
local v=x[2]
local r={}
for i=2,#v do
r[i-1]=scmto(v[i])
end
return r
elseif t=="hashv" then
local v=vector_ref(x,1)
local r={}
while not is_null(v) do
local x=car(v)
local k=tostr(car(x))
if r[k]==nil then
r[k]=scmto(cdr(x))
end
local v=cdr(v)
end
return r
else
error("STRUCT!")
end
error("VECTOR!")
elseif is_symbol(x) then
return sym2str(x)
elseif is_atom(x) then
Expand Down Expand Up @@ -256,7 +234,7 @@ toscm=function(x)
for k,v in pairs(x) do
r=cons(cons(symbol(tostring(x)),toscm(v)),r)
end
return vector(symbol("hashv"),r)
error("HASH!")
end
elseif is_procedure(x) then
return function(...)
Expand Down
24 changes: 15 additions & 9 deletions lua.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,23 @@
[(string? x) (format "~s" x)]
[(char? x) (++ "char(" (format "~s" (string x)) ")")]
[else (error 'quote x)]))
(define max-len 55)
(define (%QUOTE x var c)
(define max-c 10)
(define (%QUOTE x c f)
(if (pair? x)
(if (> c max-c)
(let ([as (gensym)] [ds (gensym)])
(let ([a (%QUOTE (car x) as 0)] [d (QUOTE (cdr x) ds 0)])
(++
a
d
(newvar+set var (++ "cons(" a "," d ")")))))
(
(let ([var (symbol->string (gensym))])
(%QUOTE (car x) 0 (λ (a c)
(%QUOTE (cdr x) c (λ (d c)
(++
(newvar+set var (++ "cons(" a "," d ")"))
(f var (+ c 1))))))))
(%QUOTE (car x) c (λ (a c)
(%QUOTE (cdr x) c (λ (d c)
(f (++ "cons(" a "," d ")") (+ c 1)))))))
(f (QUOTE1 x) (+ c 1))))
(define (QUOTE x)
(block
(%QUOTE x 0 (λ (x c) (return x)))))

(define (feval x)
(++
Expand Down

0 comments on commit c9ced02

Please sign in to comment.