wiki:Languages/Scheme

Version 5 (modified by schiptsov, 3 years ago) ( diff )

--

Scheme

Esoteric expressions

((lambda x x) (lambda x x))
(define id ((lambda (x) x) (lambda (x) x)))
((lambda xs xs))
(define list (lambda xs xs))
(define (atom? x) (not (pair? x)))

'() is a List but not a Pair

Lists

(define (list? xs)
  (cond ((null? xs) #t)
        ((and (pair? xs) (null? (cdr xs))) #t)
        (else #f)))
(define (list? xs)
  (or (null? xs) (and (pair? xs) (null? (cdr xs)))))

map

(define (map f xs)
  (if (null? xs)
      '()
      (cons (f (car xs))
            (map f (cdr xs)))))
(define (map f xs)
  (define (recur ys)
    (if (null? ys)
        '()
        (cons (f (car ys))
              (recur (cdr ys)))))
  (recur xs))
(define (map f xs)
  (letrec ((recur (lambda (xs)
                   (if (null? xs)
                       '()
                       (cons (f (car xs))
                             (recur (cdr xs)))))))
    (recur xs)))
(define (map f xs)
  (let recur ((ys xs))
    (if (null? ys)
        '()
        (cons (f (car ys))
              (recur (cdr ys))))))
== folds ==

{{{#!scheme

}}}
{{{#!scheme
}}}
{{{#!scheme
}}}
 

== Newton's method ==

------
see also [wiki:Languages/StandardML Standard ML]
Note: See TracWiki for help on using the wiki.