X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme-primitives.4th;h=97c098ff8ae6716db18fe94ecd8df132fdb0e722;hb=eb78b40c04fd1d78cdb0a3050575c9acdf4c6cbb;hp=1d2e21cce5fad83704e5d38776a28e55a1995945;hpb=5241c399e654d473a6e86135937ed7af7965d0a2;p=scheme.forth.jl.git diff --git a/scheme-primitives.4th b/scheme-primitives.4th index 1d2e21c..97c098f 100644 --- a/scheme-primitives.4th +++ b/scheme-primitives.4th @@ -1,4 +1,4 @@ -( = Type predicates = ) +( ==== Type predicates ==== ) :noname ( args -- boolobj ) 2dup 1 ensure-arg-count @@ -48,7 +48,7 @@ car primitive-proc-type istype? -rot 2drop boolean-type ; make-primitive procedure? -( = Type conversions = ) +( ==== Type conversions ==== ) :noname ( args -- fixnum ) 2dup 1 ensure-arg-count @@ -153,7 +153,7 @@ charlist>symbol ; make-primitive string->symbol -( = Arithmetic = ) +( ==== Arithmetic ==== ) : add-prim ( args -- fixnum ) 2dup nil objeq? if @@ -284,7 +284,7 @@ variable relcfa hide relcfa -( = Pairs and Lists = ) +( ==== Pairs and Lists ==== ) :noname ( args -- pair ) 2dup 2 ensure-arg-count @@ -331,7 +331,7 @@ hide relcfa ok-symbol ; make-primitive set-cdr! -( = Polymorphic equality testing = ) +( ==== Polymorphic equality testing ==== ) :noname ( args -- bool ) 2dup 2 ensure-arg-count @@ -340,3 +340,91 @@ hide relcfa objeq? boolean-type ; make-primitive eq? + +( ==== Input/Output ==== ) + +:noname ( args -- finalResult ) + 2dup 1 ensure-arg-count + car string-type ensure-arg-type + + drop pair-type + pad charlist>cstr + pad swap load +; make-primitive load + +' read make-primitive read + +defer display +:noname ( args -- none ) + 2dup 1 ensure-arg-count + + car print + + none +; make-primitive write + +: displaypair ( pairobj -- ) + 2dup + car display + cdr + nil-type istype? if 2drop exit then + pair-type istype? if space recurse exit then + ." . " display +; + +: displaychar ( charobj -- ) + drop emit +; + +:noname ( obj -- ) + pair-type istype? if ." (" displaypair ." )" exit then + character-type istype? if displaychar exit then + string-type istype? if (printstring) exit then + + print +; is display + +:noname ( args -- none ) + 2dup 1 ensure-arg-count + car string-type ensure-arg-type + + (printstring) + + none +; make-primitive display-string + +:noname ( args -- none ) + 2dup 1 ensure-arg-count + car character-type ensure-arg-type + + displaychar + + none +; make-primitive display-character + +:noname ( args -- none ) + 2dup 1 ensure-arg-count + car + + display + + none +; make-primitive display + +:noname ( args -- none ) + 0 ensure-arg-count + + cr + + none +; make-primitive newline + +( ==== Evaluation ==== ) + +:noname ( args -- result ) + 2dup car 2swap cdr + + nil? false = if car then ( proc argvals ) + + apply +; make-primitive apply