Tue Apr 29 14:35:02 EDT 2008
structure types and inheritance
now i feel stupid
delimited control isn't necessary at all here.. simple inheritance
will do the trick just fine.
one thing i didn't get though is: inheritance works nice for read, but
what's needed is to construct the right output type, so the update
function needs to be abstracted somewhere..
-> all derived structs now have an 'update' function in the first
field, and a direct constructor as in:
(update-compilation-state state ctrl
((state ctrl asm)
(update-compilation-state state ctrl asm
((state ctrl asm current words)
(driver-make-compilation-state ctrl asm current words))))
(define (driver-make-compilation-state ctrl asm current words)
ctrl asm current words))
ok.. done feeling stupid. works, and is a lot easier to understand.
this can be implemented more efficiently using lists: less copying,
more sharing. not important atm.
this abstraction makes it a bit easier to use:
;; state matcher which introduces 'update'
(define-syntax (state-lambda stx)
(syntax-case stx ()
((_ type (var ...) . expr)
((struct type (update var ...))
(let ((#,(datum->syntax #'type 'update)
(apply update state args))))
maybe use syntax parameters instead of introducing a symbol?