1
Name:
Anonymous
2013-01-17 2:23
I remember a post a while back where the author said that it's better to avoid using binding constructs like let in languages like Scheme. I was wondering how you'd rewrite something like this:
(let ((s (find (lambda (a) (char=? x (first a))) *translation-list*)))
(if s (second s) x))
24
Name:
Anonymous
2013-01-20 18:45
I think I'm loebing. Am I doing it right?
(define fix-helper (lambda (self f)
(lambda args
(apply f (cons (self self f) args)))))
(define fix (lambda (f) (fix-helper fix-helper f)))
(define rev (fix (lambda (f lis acc)
(if (null? lis)
acc
(f (cdr lis) (cons (car lis) acc))))))
(define rev-map1 (fix (lambda (f fn lis acc)
(if (null? lis)
acc
(f fn (cdr lis) (cons (fn (car lis)) acc))))))
(define map1 (lambda (fn lis)
(rev (rev-map1 fn lis '()) '())))
(define loeb (fix (lambda (f fns)
(map1 (lambda (fn)
(lambda args
(apply fn (cons (f fns) args))))
fns))))
(define is-even_ (lambda (fs n)
(apply (lambda (is-even is-odd)
(if (= n 0)
#t
(is-odd (- n 1))))
fs)))
(define is-odd_ (lambda (fs n)
(apply (lambda (is-even is-odd)
(if (= n 0)
#f
(is-even (- n 1))))
fs)))
(define functions (loeb (list is-even_ is-odd_)))
(define is-even (car functions))
(define is-odd (cadr functions))