[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
WITH construct in record package
- To: Lisp, LispCore^
- Subject: WITH construct in record package
- From: Masinter at PARC-MAXC
- Date: Thu, 15 Apr 1982 10:17:52 -8000
- Date: 15 Apr 1982 10:17 PST
- Cc: Goldman@ISIF, Masinter
This feature has been in the system for a while, but there were a few minor
problems which prevented me from advertising it. I fixed them a couple of
months ago:
(WITH <record-name> <record-instance> . <forms>) [special form]
The WITH construct can be used to talk about the fields of a record as if they
were variables within a lexical scope. <record-name> is the name of a record,
and <record-instance> is an expression which evaluates to an instance of that
record. The expressions in <forms> are evaluated in a way where references to
variables which are field-names of <record-name> are implemented via
field-fetches and SETQs of those variables are implemented via
field-replacement.
For example, given
(RECORD RECN (FLD1 FLD2))
(SETQ INST (CREATE RECN FLD1 _ 10 FLD2 _ 20))
Then the construct
(with RECN INST
(SETQ FLD2 (PLUS FLD1 FLD2]
is equivalent to
(replace FLD2 of INST with (PLUS (fetch FLD1 of INST) (fetch FLD2 of INST]
Note that the substitution is lexical: this operates by actually doing a substitution
inside <forms>.
Larry