From d1107557350ae9101bfa387dd2af2cad541193cc Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Thu, 21 Jul 2016 20:29:26 +1200 Subject: [PATCH] Adding pair/list primitives. --- scheme-primitives.4th | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) 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! -- 2.20.1