[plt-scheme] dotted structs again
Hi,
Finally I managed to prepare a language for dotted struct-field-references and assignments that do what I want them to do. See attachments. For example:
(module example records
(define-values (make-person person?)
(make-record-type 'person #f '(name maried-with children)))
(define jacob (make-person 'jacob #f ()))
(define maria (make-person 'maria #f ()))
(define (mary man woman)
(set! man.maried-with woman)
(set! woman.maried-with man))
(define (birth mother father name)
(let ((child (make-person name #f ())))
(set! mother.children (cons child mother.children))
(set! father.children (cons child father.children))))
(define (names-of-children person)
(map (lambda (person) person.name) person.children))
(mary jacob maria)
(birth maria jacob 'son)
(birth maria jacob 'doughter)
(printf "~s~n" (names-of-children maria)))
(require example) ;prints (doughter son)
BUT this has a high price: field-names must be looked up during run-time such as to relate them to those of the structure actually present in the variable of the field-ref variable.field-name.field-name.field-name etc.
Because of this required lookup, it makes no sense to memorize accessor and mutator procs. In stead I made the lookup directly access an assoc-list that pairs field-names with their values.
I am still working on a mod that allows (lambda (person) person.name) to be written as .name This should not be too difficult.
(((((lambda(x)((((((((x x)x)x)x)x)x)x)x))
(lambda(x)(lambda(y)(x(x y)))))
(lambda(x)(x)x))
(lambda()(printf "Greetings, Jos~n"))))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070408/746531c3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: records.ss
Type: application/octet-stream
Size: 8979 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070408/746531c3/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-records.scm
Type: application/octet-stream
Size: 5679 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070408/746531c3/attachment-0001.obj>