Minor formatting changes
parent
ec95cef85e
commit
598bb166de
|
@ -5,21 +5,24 @@ namespaces combinators math bake locals.private accessors vectors syntax lisp.pa
|
||||||
IN: lisp
|
IN: lisp
|
||||||
|
|
||||||
DEFER: convert-form
|
DEFER: convert-form
|
||||||
|
DEFER: funcall
|
||||||
|
|
||||||
|
! Functions to convert s-exps to quotations
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
: convert-body ( s-exp -- quot )
|
: convert-body ( s-exp -- quot )
|
||||||
[ convert-form ] map reverse [ ] [ compose ] reduce ; inline
|
[ convert-form ] map reverse [ ] [ compose ] reduce ; inline
|
||||||
|
|
||||||
: convert-if ( s-exp -- quot )
|
: convert-if ( s-exp -- quot )
|
||||||
1 tail [ convert-form ] map reverse first3 [ % , , if ] bake ;
|
rest [ convert-form ] map reverse first3 [ % , , if ] bake ;
|
||||||
|
|
||||||
: convert-begin ( s-exp -- quot )
|
: convert-begin ( s-exp -- quot )
|
||||||
1 tail convert-body ;
|
rest convert-body ;
|
||||||
|
|
||||||
: convert-cond ( s-exp -- quot )
|
: convert-cond ( s-exp -- quot )
|
||||||
1 tail [ [ convert-body map ] map ] [ % cond ] bake ;
|
rest [ [ convert-body map ] map ] [ % cond ] bake ;
|
||||||
|
|
||||||
: convert-general-form ( s-exp -- quot )
|
: convert-general-form ( s-exp -- quot )
|
||||||
unclip swap convert-body [ % , ] bake ;
|
unclip swap convert-body [ % , funcall ] bake ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
: localize-body ( vars body -- newbody )
|
: localize-body ( vars body -- newbody )
|
||||||
|
@ -31,19 +34,39 @@ PRIVATE>
|
||||||
first3 -rot nip [ body>> ] bi@ reverse [ name>> ] map dup make-locals dup push-locals
|
first3 -rot nip [ body>> ] bi@ reverse [ name>> ] map dup make-locals dup push-locals
|
||||||
[ swap localize-body convert-body ] dipd pop-locals swap <lambda> ;
|
[ swap localize-body convert-body ] dipd pop-locals swap <lambda> ;
|
||||||
|
|
||||||
|
: convert-quoted ( s-exp -- quot )
|
||||||
|
second [ , ] bake ;
|
||||||
|
|
||||||
: convert-list-form ( s-exp -- quot )
|
: convert-list-form ( s-exp -- quot )
|
||||||
dup first dup lisp-symbol? [ name>>
|
dup first dup lisp-symbol?
|
||||||
|
[ name>>
|
||||||
{ { "lambda" [ convert-lambda ] }
|
{ { "lambda" [ convert-lambda ] }
|
||||||
|
{ "quote" [ convert-quoted ] }
|
||||||
{ "if" [ convert-if ] }
|
{ "if" [ convert-if ] }
|
||||||
{ "begin" [ convert-begin ] }
|
{ "begin" [ convert-begin ] }
|
||||||
{ "cond" [ convert-cond ] }
|
{ "cond" [ convert-cond ] }
|
||||||
[ drop convert-general-form ]
|
[ drop convert-general-form ]
|
||||||
} case ] [ drop convert-general-form ] if ;
|
} case ]
|
||||||
|
[ drop convert-general-form ] if ;
|
||||||
|
|
||||||
: convert-form ( lisp-form -- quot )
|
: convert-form ( lisp-form -- quot )
|
||||||
{ { [ dup s-exp? ] [ body>> convert-list-form ] }
|
{ { [ dup s-exp? ] [ body>> convert-list-form ] }
|
||||||
[ [ , ] [ ] make ]
|
[ [ , ] [ ] make ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
: lisp-string>factor ( str -- quot )
|
: lisp-string>factor ( str -- quot )
|
||||||
lisp-expr parse-result-ast convert-form ;
|
lisp-expr parse-result-ast convert-form ;
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
SYMBOL: lisp-env
|
||||||
|
|
||||||
|
H{ } clone lisp-env set
|
||||||
|
|
||||||
|
: define-lisp-word ( name body -- )
|
||||||
|
lisp-env get set-at ;
|
||||||
|
|
||||||
|
: get-lisp-word ( name -- word )
|
||||||
|
lisp-env get at ;
|
||||||
|
|
||||||
|
: funcall ( quot sym -- * )
|
||||||
|
name>> get-lisp-word call ;
|
Loading…
Reference in New Issue