projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altos/scheme: Make for-each tail recursive
[fw/altos]
/
src
/
scheme
/
ao_scheme_const.scheme
diff --git
a/src/scheme/ao_scheme_const.scheme
b/src/scheme/ao_scheme_const.scheme
index 422bdd635cca897f87cb759518cd20cb494c99d8..29f000b3c58c976a6513a72a42f3246183c673fe 100644
(file)
--- a/
src/scheme/ao_scheme_const.scheme
+++ b/
src/scheme/ao_scheme_const.scheme
@@
-248,7
+248,7
@@
(macro (first . rest)
; check for alternate lambda definition form
(macro (first . rest)
; check for alternate lambda definition form
- (cond ((
list
? first)
+ (cond ((
pair
? first)
(set! rest
(append
(list
(set! rest
(append
(list
@@
-512,12
+512,13
@@
(unless #f (write 'unless))
(define (reverse list)
(unless #f (write 'unless))
(define (reverse list)
- (let ((result ()))
- (while (not (null? list))
- (set! result (cons (car list) result))
- (set! list (cdr list))
- )
- result)
+ (define (_r old new)
+ (if (null? old)
+ new
+ (_r (cdr old) (cons (car old) new))
+ )
+ )
+ (_r list ())
)
(reverse '(1 2 3))
)
(reverse '(1 2 3))
@@
-640,8
+641,8
@@
(char-whitespace? #\0)
(char-whitespace? #\space)
(char-whitespace? #\0)
(char-whitespace? #\space)
-(define
(char->integer c) c
)
-(define
(integer->char c) char-
integer)
+(define
char->integer (macro (v) v)
)
+(define
integer->char char->
integer)
(define (char-upcase c) (if (char-lower-case? c) (+ c (- #\A #\a)) c))
(define (char-upcase c) (if (char-lower-case? c) (+ c (- #\A #\a)) c))
@@
-664,36
+665,46
@@
(define map
(lambda (proc . lists)
(define map
(lambda (proc . lists)
- (define (
args
lists)
+ (define (
_a
lists)
(cond ((null? lists) ())
(else
(cond ((null? lists) ())
(else
- (cons (caar lists) (
args
(cdr lists)))
+ (cons (caar lists) (
_a
(cdr lists)))
)
)
)
)
)
)
- (define (
next
lists)
+ (define (
_n
lists)
(cond ((null? lists) ())
(else
(cond ((null? lists) ())
(else
- (cons (cdr (car lists)) (
next
(cdr lists)))
+ (cons (cdr (car lists)) (
_n
(cdr lists)))
)
)
)
)
)
)
- (define (
domap
lists)
+ (define (
_m
lists)
(cond ((null? (car lists)) ())
(else
(cond ((null? (car lists)) ())
(else
- (cons (apply proc (
args lists)) (domap (next
lists)))
+ (cons (apply proc (
_a lists)) (_m (_n
lists)))
)
)
)
)
)
)
- (
domap
lists)
+ (
_m
lists)
)
)
(map cadr '((a b) (d e) (g h)))
)
)
(map cadr '((a b) (d e) (g h)))
-(define for-each (lambda (proc . lists)
- (apply map proc lists)
- #t))
+(define for-each
+ (lambda (proc . lists)
+ (define (_f lists)
+ (cond ((null? (car lists)) #t)
+ (else
+ (apply proc (map car lists))
+ (_f (map cdr lists))
+ )
+ )
+ )
+ (_f lists)
+ )
+ )
(for-each display '("hello" " " "world" "\n"))
(for-each display '("hello" " " "world" "\n"))
@@
-708,8
+719,9
@@
(string-map (lambda (x) (+ 1 x)) "HAL")
(string-map (lambda (x) (+ 1 x)) "HAL")
-(define string-for-each (lambda (proc . strings)
- (apply for-each proc (_string-ml strings))))
+(define string-for-each
+ (lambda (proc . strings)
+ (apply for-each proc (_string-ml strings))))
(string-for-each write-char "IBM\n")
(string-for-each write-char "IBM\n")
@@
-805,9
+817,3
@@
)
(case 12 (1 "one") (2 "two") (3 => (lambda (x) (write "the value is" x))) (12 "twelve") (else "else"))
)
(case 12 (1 "one") (2 "two") (3 => (lambda (x) (write "the value is" x))) (12 "twelve") (else "else"))
-
-;(define number->string (lambda (arg . opt)
-; (let ((base (if (null? opt) 10 (car opt)))
- ;
-;
-