-;; 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 ()))
(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))
+
+;; 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)))))
' read make-primitive read
-:noname ( args -- )
+defer display
+:noname ( args -- none )
2dup 1 ensure-arg-count
car print cr
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
\ }}}
+\ ---- Standard Library ---- {{{
+
+ s" scheme-library.scm" load 2drop
+
+\ }}}
+
\ ---- REPL ----
: repl