[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?



> 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