diff options
| author | 2024-08-26 17:52:19 -0400 | |
|---|---|---|
| committer | 2024-08-26 17:52:19 -0400 | |
| commit | 1b5675972680a28f6c1abf4fdeb8e0db62912779 (patch) | |
| tree | 85e8fc89294680241abade50488ae0a6200b94b2 /miniscm/init.scm | |
| parent | miniscm: add ports (diff) | |
miniscm: add mutable string emulation and char->integer
Diffstat (limited to 'miniscm/init.scm')
| -rw-r--r-- | miniscm/init.scm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/miniscm/init.scm b/miniscm/init.scm index 6db7145..c3f5612 100644 --- a/miniscm/init.scm +++ b/miniscm/init.scm @@ -1,6 +1,8 @@ ; This is a init file for Mini-Scheme. ; Modified for UNSLISP. +(define modulo remainder) + (define (caar x) (car (car x))) (define (cadr x) (car (cdr x))) (define (cdar x) (cdr (car x))) @@ -48,6 +50,16 @@ (define vector-ref list-ref) (define vector-set! list-set!) +(define make-vector + (lambda (num) + (letrec + ((loop + (lambda (iter cell) + (if (= iter 0) + cell + (loop (- iter 1) (cons #f cell)))))) + (loop num '())))) + (define (head stream) (car stream)) (define (tail stream) (force (cdr stream))) @@ -75,3 +87,30 @@ (equal? (cdr x) (cdr y))) (and (not (pair? y)) (eqv? x y)))) + +;;; Emulation of mutable strings. + +(define string-ref list-ref) +(define string-set! list-set!) +(define string list) + +(define list<=> + (lambda (x y <=>) + (cond + ((and (null? x) (null? y)) '=) + ((null? x) '<) + ((null? y) '>) + (else + (let ((dir (<=> (car x) (car y)))) + (if (eq? dir '=) + (list<=> (cdr x) (cdr y) <=>) + dir)))))) + +(define string<=> + (lambda (x y) + (list<=> x y (lambda (x y) + (if (eqv? x y) + '= + (if (< (char->integer x) (char->integer y)) + '< + '>)))))) |
