Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

lambda, brainf*ck machine, y combinator...

Name: Anonymous 2011-08-20 9:01

I'll just bookmark this here:
http://matt.might.net/articles/implementing-a-programming-language/

Below is the 7-line, 3-minute interpreter for the lambda calculus, in R5RS Scheme. In technical terms (explained below), it's an environment-based denotational interpreter.


; eval takes an expression and an environment to a value
(define (eval e env) (cond
  ((symbol? e)       (cadr (assq e env)))
  ((eq? (car e) 'λ)  (cons e env))
  (else              (apply (eval (car e) env) (eval (cadr e) env)))))

; apply takes a function and an argument to a value
(define (apply f x)
  (eval (cddr (car f)) (cons (list (cadr (car f)) x) (cdr f))))

; read and parse stdin, then evaluate:
(display (eval (read) '())) (newline)

Name: Anonymous 2011-08-22 13:14

>>1
implementing lambda in a language that already has lambda.

AMAZING!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List