[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Is a syntax such as (update my-record-type my-record (x 3) (y 4)) possible?
- To: srfi-76@xxxxxxxxxxxxxxxxx
- Subject: Is a syntax such as (update my-record-type my-record (x 3) (y 4)) possible?
- From: Andrew Wilcox <awilcox@xxxxxxxxxxxxxxxxx>
- Date: Mon, 12 Dec 2005 21:01:33 -0500
- Delivered-to: srfi-76@xxxxxxxxxxxxxxxxx
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=tPR4KZCae0zfw4D7WOyWvhMETG9FMI4QodyRaXKw4+hvZf5Jed2/+FKrvsrTsmMu9j1RrYGaR0CrAPZ07D5mGntPc54t91cFk1Fi1Y/qvrW36zONXmgglgha+A7L4tAzflA8ZRV9o9wwBQO21ZA4Pu1yhq1zJpR7BfXQvJWA0HY=
- Sender: andrew.wilcox@xxxxxxxxx
> Should the operations for access and mutation be augmented
> by functional update?
I think functional programming will become increasing important (see e.g.
A Fundamental Turn Toward Concurrency in Software
http://www.gotw.ca/publications/concurrency-ddj.htm).
> If any of these are added, what should the syntax in the syntactic
> layers look like?
I don't understand enough about the capabilities of macros to know
what is possible. For example, could we have a syntax such as:
(update <record name> record-expr (<field name> expr) ...)
where <record name> and <field name>'s must be identifiers,
record-expr must evaluate to a record of type or a subtype of <record
name>, and UPDATE expands into code which will efficiently return a
new record of the type of record-expr (the subtype) copying all fields
except for <field name>'s which are given the new values?
For example,
(define-type (position make-position position?) (x y)
(fields (x immutable x)
(y immutable y)))
(define-type (thing make-thing thing?) (x y color)
(parent position x y)
(fields (color immutable color)))
(define t1 (make-thing 3.4 5.8 'green))
(define t2 (update position t1 (y 18)))
(define t3 (update thing t1 (x 10) (color 'red)))
(position-x t1) => 3.4
(position-y t1) => 5.8
(thing-color t1) => green
(position-x t2) => 3.4
(position-y t2) => 18
(thing-color t2) => green
(position-x t3) => 10
(position-y t3) => 5.8
(thing-color t3) => red
Thanks,
Andrew