Skip to content

Commit

Permalink
Enhanced the update special form. Now instead of returning void, it r…
Browse files Browse the repository at this point in the history
…eturns the new value of the updated slot.
  • Loading branch information
David St-Hilaire committed Oct 14, 2009
1 parent 524039e commit c2be9fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/class_.scm
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-macro (update! obj class field f)
(let ((objval (gensym 'objval)))
`(let ((,objval ,obj))
(,(gen-setter-name class field) ,objval
(,f (,(gen-accessor-name class field) ,objval))))))
(let ((objval (gensym 'objval))
(newval (gensym 'newval)))
`(let* ((,objval ,obj)
(,newval (,f (,(gen-accessor-name class field) ,objval))))
(,(gen-setter-name class field) ,objval ,newval)
,newval)))

(define-macro (set-fields! obj class field-val-list)
(let ((obj-ptr (gensym 'obj)))
Expand Down
4 changes: 2 additions & 2 deletions tests/class-tests.scm
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@
'ok
'no)))

(define-test test-update! "" 'ok
(define-test test-update! "2" 'ok
(let ((obj (make-A 1)))
(update! obj A a (lambda (x) (+ x 1)))
(display (update! obj A a (lambda (x) (+ x 1))))
(if (= (A-a obj) 2)
'ok
'no)))
Expand Down

0 comments on commit c2be9fa

Please sign in to comment.