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