X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Fscheme-primitives.4th;h=dbb68bc63aa56f57386a9b9d7c96eadcd4558cff;hb=HEAD;hp=1ed995b2439a3a5169105dd535f97fe3bd4d9e70;hpb=bc2450b4b29d6bb8ba5422fb9eb7a75d1b6b5a57;p=scheme.forth.jl.git diff --git a/src/scheme-primitives.4th b/src/scheme-primitives.4th index 1ed995b..dbb68bc 100644 --- a/src/scheme-primitives.4th +++ b/src/scheme-primitives.4th @@ -46,6 +46,10 @@ -rot 2drop boolean-type ; 1 make-fa-primitive procedure? +:noname ( args -- boolobj ) + port-type istype? -rot 2drop boolean-type +; 1 make-fa-primitive port? + \ }}} \ ==== Type conversions ==== {{{ @@ -276,6 +280,13 @@ drop swap drop f> boolean-type ; 2 make-fa-primitive flo:> +:noname ( flonum flonum -- bool ) + drop swap drop f<= boolean-type +; 2 make-fa-primitive flo:<= + +:noname ( flonum flonum -- bool ) + drop swap drop f>= boolean-type +; 2 make-fa-primitive flo:>= :noname ( flonum -- bool ) drop 0.0 = boolean-type @@ -471,6 +482,36 @@ current-input-port obj@ ; 0 make-fa-primitive current-input-port +:noname ( args -- charobj ) + nil? if + 2drop current-input-port obj@ + else + car port-type ensure-arg-type + then + + read-char +; make-primitive read-char + +:noname ( args -- charobj ) + nil? if + 2drop current-input-port obj@ + else + car port-type ensure-arg-type + then + + peek-char +; make-primitive peek-char + +:noname ( args -- stringobj ) + nil? if + 2drop current-input-port obj@ + else + car port-type ensure-arg-type + then + + read-line +; make-primitive read-line + : charlist>cstr ( charlist addr -- n ) dup 2swap ( origaddr addr charlist ) @@ -560,12 +601,32 @@ defer display :noname ( args -- result ) 2dup car 2swap cdr - + nil? false = if car then ( proc argvals ) - - apply + + 2swap apply ; make-primitive apply +:noname ( proc -- result ) + make-continuation + + ( Note that we get to this point either when + make-continuation is originally called or when + restore-continuation is called. Since we don't + want to call proc again following a restore, + we use the boolean values placed on the parameter + stack by make-continuation and restore-continuation + to detect which call got us here and act accordingly. ) + + drop if + nil cons + 2swap apply + else + 2swap 2drop + then + +; 1 make-fa-primitive call-with-current-continuation + \ }}} \ ==== Miscellaneous ==== {{{ @@ -577,7 +638,17 @@ defer display nil? if ." Error." else - ." Error: " car display + ." Error:" + + 2dup car space display + cdr nil? invert if + begin + 2dup car space print + cdr nil? + until + then + + 2drop then reset-term