X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme-primitives.4th;h=b347d8add9b005cb67e2d92d10bc43412daa0b81;hb=13e038552e84df8c480b101b09e4c5a650bad2d0;hp=c1f3626babffbe2971cb9d4f84a9346cf1e3ae06;hpb=d1107557350ae9101bfa387dd2af2cad541193cc;p=scheme.forth.jl.git diff --git a/scheme-primitives.4th b/scheme-primitives.4th index c1f3626..b347d8a 100644 --- a/scheme-primitives.4th +++ b/scheme-primitives.4th @@ -45,7 +45,7 @@ :noname ( args -- boolobj ) 2dup 1 ensure-arg-count - car primitive-type istype? -rot 2drop boolean-type + car primitive-proc-type istype? -rot 2drop boolean-type ; make-primitive procedure? ( = Type conversions = ) @@ -212,6 +212,73 @@ mod fixnum-type ; make-primitive remainder +variable relcfa + +: test-relation ( args -- bool ) + + 2dup nil objeq? if + 2drop + true boolean-type exit + then + + ( args ) + + 2dup car fixnum-type ensure-arg-type ( args arg0 ) + 2swap cdr ( arg0 args' ) + + 2dup nil objeq? if + 2drop 2drop + true boolean-type exit + then + + ( arg0 args' ) + + begin + 2dup nil objeq? false = + while + 2dup car fixnum-type ensure-arg-type ( arg0 args' arg1 ) + 2rot 2swap 2dup 2rot 2swap ( args' arg1 arg1 arg0 ) + relcfa @ execute false = if + 2drop 2drop + false boolean-type exit + then + + 2swap cdr ( arg0 args'' ) + repeat + + 2drop 2drop + true boolean-type +; + +: fixnum-lt ( obj1 obj2 -- bool ) + drop swap drop < +; + +:noname + ['] fixnum-lt relcfa ! + test-relation +; make-primitive < + +: fixnum-gt ( obj1 obj2 -- bool ) + drop swap drop > +; + +:noname + ['] fixnum-gt relcfa ! + test-relation +; make-primitive > + +: fixnum-eq ( obj1 obj2 -- bool ) + drop swap drop = +; + +:noname + ['] fixnum-eq relcfa ! + test-relation +; make-primitive = + +hide relcfa + ( = Pairs and Lists = ) :noname ( args -- pair ) @@ -221,13 +288,9 @@ cons ; make-primitive cons -:noname ( args -- pair ) - 2dup 1 ensure-arg-count - - - 2dup car 2swap cdr car - cons -; make-primitive cons +:noname ( args -- list ) + \ args is already a list! +; make-primitive list :noname ( args -- pair ) 2dup 1 ensure-arg-count @@ -245,20 +308,30 @@ :noname ( args -- pair ) 2dup 2 ensure-arg-count - 2dup car pair-type ensure-arg-type - swap cdr car + 2dup cdr car + 2swap car pair-type ensure-arg-type - 2swap set-car! + set-car! ok-symbol ; make-primitive set-car! :noname ( args -- pair ) 2dup 2 ensure-arg-count - 2dup car pair-type ensure-arg-type - swap cdr car + 2dup cdr car + 2swap car pair-type ensure-arg-type - 2swap set-cdr! + set-cdr! ok-symbol ; make-primitive set-cdr! + +( = Polymorphic equality testing = ) + +:noname ( args -- bool ) + 2dup 2 ensure-arg-count + 2dup cdr car + 2swap car + + objeq? boolean-type +; make-primitive eq?