[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*To*: scheme@mc.lcs.mit.edu*Subject*: case-lambda and interpreter environments*From*: titan!dorai@rice.edu (Dorai Sitaram)*Date*: Thu ,20 Oct 88 19:14:22 EDT*Organization*: Rice University, Houston*Sender*: scheme-request@mc.lcs.mit.edu

Since there's been some talk of case-lambda, thought I'd say something about a simple use of this syntax to get a nice implementation of interpreter environments. The definition of the initial environment (which doesn't associate any identifier with any value) goes as follows: (define init-env (letrec ([extend (lambda (r x v) (rec r1 (case-lambda [(y) (if (eq? y x) v (r y))] [(y w) (extend r1 y w)])))]) (rec r (case-lambda [(x) (error "unbound ~a" x)] [(x v) (extend r x v)])))) No other function is required! When called with a single argument (an identifier), the environment yields the value of the identifier; when called with two arguments (an identifier and a value) a new environment is produced which is the extension of the original one associating the new identifier with the new value. One attraction (fatal? |-]) with this is that the use of the environment closely mimics denotational semantics notation, viz., r[x] ;for looking up identifier x in environment r; and r[x/v] ;for extending environment r to associate x with v. --dorai

- Prev by Date:
**Where/how to get Scheme for Suns?** - Next by Date:
**Re: Where/how to get Scheme for Suns?** - Previous by thread:
**Where/how to get Scheme for Suns?** - Next by thread:
**Re: self-replicating-code, self-replicating-messages** - Index(es):