X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme.4th;h=d3555a4e1bcdbb2e29ff737addd9ea8efba40eeb;hb=d75e232b614baf3d82abf447daacc8fcefefbe85;hp=e69c63d7c902b640e32d826ef24969f68b1e726e;hpb=d40d4d337456d3a096749cc4dcf23f86944f325f;p=scheme.forth.jl.git diff --git a/scheme.4th b/scheme.4th index e69c63d..d3555a4 100644 --- a/scheme.4th +++ b/scheme.4th @@ -13,7 +13,7 @@ include defer-is.4th 4 constant nil-type 5 constant pair-type 6 constant symbol-type -: istype? ( obj -- obj b ) +: istype? ( obj type -- obj bool ) over = ; \ ------ Memory ------ @@ -51,6 +51,7 @@ variable nextfree ; : nil 0 nil-type ; +: nil? nil-type istype? ; : objvar create 0 , 0 , ; @@ -343,9 +344,63 @@ parse-idx-stack parse-idx-sp ! cons ; +: charlist-equiv ( charlist charlist -- bool ) + + 2over 2over + + \ One or both nil + nil? -rot 2drop + if + nil? -rot 2drop + if + true exit + else + false exit + then + else + nil? -rot 2drop + if + false exit + then + then + + 2over 2over + + \ Neither nil + car drop -rot car drop = if + cdr 2swap cdr recurse + else + 2drop 2drop false + then +; + +: charlist>symbol ( charlist -- symbol-obj ) + + symbol-table fetchobj + + begin + nil? false = + while + 2over 2over + car drop pair-type + charlist-equiv if + 2swap 2drop + car + exit + else + cdr + then + repeat + + 2drop + drop symbol-type 2dup + symbol-table fetchobj cons + symbol-table setobj +; + defer read -: readpair ( -- obj ) +: readpair ( -- pairobj ) eatspaces \ Empty lists @@ -422,12 +477,7 @@ defer read then symbol? if - readsymbol - drop symbol-type - 2dup - symbol-table fetch - cons - symbol-table set + readsymbol charlist>symbol exit then