From: Tim Vaughan Date: Thu, 21 Jul 2016 08:29:26 +0000 (+1200) Subject: Adding pair/list primitives. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=d1107557350ae9101bfa387dd2af2cad541193cc;p=scheme.forth.jl.git Adding pair/list primitives. --- diff --git a/scheme-primitives.4th b/scheme-primitives.4th index c99a0c0..c1f3626 100644 --- a/scheme-primitives.4th +++ b/scheme-primitives.4th @@ -211,3 +211,54 @@ mod fixnum-type ; make-primitive remainder + +( = Pairs and Lists = ) + +:noname ( args -- pair ) + 2dup 2 ensure-arg-count + + 2dup car 2swap cdr car + cons +; make-primitive cons + +:noname ( args -- pair ) + 2dup 1 ensure-arg-count + + + 2dup car 2swap cdr car + cons +; make-primitive cons + +: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 car pair-type ensure-arg-type + swap cdr car + + 2swap 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 + + 2swap set-cdr! + + ok-symbol +; make-primitive set-cdr!