X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme-primitives.4th;h=03d885bebd3cce1f9b02e4be224c4e020fbb9869;hb=9ad6e6f21fbbefe9e38bc6b4b8d2a78f8cbca229;hp=c99a0c000bc3ccc64a20e9298dcfec54d407a20c;hpb=8a9d83b586844a04f7ee19f98b56f460063bdcad;p=scheme.forth.jl.git diff --git a/scheme-primitives.4th b/scheme-primitives.4th index c99a0c0..03d885b 100644 --- a/scheme-primitives.4th +++ b/scheme-primitives.4th @@ -211,3 +211,95 @@ mod fixnum-type ; make-primitive remainder + +:noname ( args -- bool ) + + 2dup nil objeq? if + 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 2dup 2rot ( args' arg0 arg0 arg1 ) + objeq? false = if + 2drop 2drop + false boolean-type exit + then + + 2swap cdr ( arg0 args'' ) + repeat + + 2drop 2drop + true boolean-type +; make-primitive = + +( = Pairs and Lists = ) + +:noname ( args -- pair ) + 2dup 2 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 + car pair-type ensure-arg-type + + car +; make-primitive car + +:noname ( args -- pair ) + 2dup 1 ensure-arg-count + car pair-type ensure-arg-type + + cdr +; make-primitive cdr + +:noname ( args -- pair ) + 2dup 2 ensure-arg-count + 2dup cdr car + 2swap car pair-type ensure-arg-type + + set-car! + + ok-symbol +; make-primitive set-car! + +:noname ( args -- pair ) + 2dup 2 ensure-arg-count + 2dup cdr car + 2swap car pair-type ensure-arg-type + + 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?