Added display primitives.
authorTim Vaughan <tgvaughan@gmail.com>
Mon, 31 Oct 2016 10:50:23 +0000 (23:50 +1300)
committerTim Vaughan <tgvaughan@gmail.com>
Mon, 31 Oct 2016 10:50:23 +0000 (23:50 +1300)
scheme-library.scm [moved from testing.scm with 83% similarity]
scheme-primitives.4th
scheme.4th

similarity index 83%
rename from testing.scm
rename to scheme-library.scm
index 0b7d95b..207bb30 100644 (file)
@@ -1,22 +1,8 @@
-;; Some simple procedures useful for implementation testing.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Standard Library Procedures and Macros ;; 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
-; Basic iterative summation.  Run this on large numbers to
-; test garbage collection and tail-call optimization.
-(define (sum n)
-
-  (define (sum-iter total count maxcount)
-    (if (> count maxcount)
-      total
-      (sum-iter (+ total count) (+ count 1) maxcount)))
-  
-  (sum-iter 0 1 n))
-
-; Recursive summation. Use this to compare with tail call
-; optimized iterative algorithm.
-(define (sum-recurse n)
-  (if (= n 0)
-    0
-    (+ n (sum-recurse (- n 1)))))
+;; LISTS
 
 (define (null? args)
   (eq? args ()))
 
 (define (null? args)
   (eq? args ()))
       (car lists)
       (join (car lists) (apply append (cdr lists))))))
 
       (car lists)
       (join (car lists) (apply append (cdr lists))))))
 
-; Macro definitions
+
+;; LIBRARY FORMS
 (define-macro (let value . body )
               (list (list 'lambda (list (car value)) body)) (cdr value))
 (define-macro (let value . body )
               (list (list 'lambda (list (car value)) body)) (cdr value))
+
+;; TESTING
+
+; Basic iterative summation.  Run this on large numbers to
+; test garbage collection and tail-call optimization.
+(define (sum n)
+
+  (define (sum-iter total count maxcount)
+    (if (> count maxcount)
+      total
+      (sum-iter (+ total count) (+ count 1) maxcount)))
+  
+  (sum-iter 0 1 n))
+
+; Recursive summation. Use this to compare with tail call
+; optimized iterative algorithm.
+(define (sum-recurse n)
+  (if (= n 0)
+    0
+    (+ n (sum-recurse (- n 1)))))
index 56ecab0..e446b2e 100644 (file)
@@ -354,7 +354,8 @@ hide relcfa
 
 ' read make-primitive read
 
 
 ' read make-primitive read
 
-:noname ( args -- )
+defer display
+:noname ( args -- none )
     2dup 1 ensure-arg-count
 
     car print cr
     2dup 1 ensure-arg-count
 
     car print cr
@@ -362,6 +363,62 @@ hide relcfa
     none
 ; make-primitive write
 
     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) cr
+
+    none
+; make-primitive display-string
+
+:noname ( args -- none )
+    2dup 1 ensure-arg-count
+    car character-type ensure-arg-type
+
+    displaychar cr
+
+    none
+; make-primitive display-character
+
+:noname ( args -- none )
+    2dup 1 ensure-arg-count
+    car
+
+    display cr
+
+    none
+; make-primitive display
+
+:noname ( args -- none )
+    0 ensure-arg-count
+
+    cr
+
+    none
+; make-primitive newline
+
 ( ==== Evaluation ==== )
 
 :noname 
 ( ==== Evaluation ==== )
 
 :noname 
index f96fec9..64d4b40 100644 (file)
@@ -1620,6 +1620,12 @@ include scheme-primitives.4th
 
 \ }}}
 
 
 \ }}}
 
+\ ---- Standard Library ---- {{{
+
+    s" scheme-library.scm" load 2drop
+    
+\ }}}
+
 \ ---- REPL ----
 
 : repl
 \ ---- REPL ----
 
 : repl