2009/8/10 Christian Kellermann <ck...@pestilenz.org>: > [...] > I'd like to define a record (srfi-9) style or similar but I'd also > like to be able to pass a slot a default value. Bigloo scheme for > example has had define-structures for that. Can this be done in > chicken as well with existing tools? > [...]
Hello, one possible and rather portable solution is to define the record type as usual but also define an alternative constructor procedure that has non-mandatory arguments: (module foo (make-foo foo? foo-a foo-b) (import scheme chicken) (define-record-type foo (%make-foo a b) foo? (a foo-a) (b foo-b)) (define (make-foo #!key [a 42] [b 23]) (%make-foo a b))) The easiest way probably is to use the defstruct egg, though, which internally works similar to the code above, but has a more convenient interface: (module foo (make-foo foo? foo-a foo-b) (import scheme chicken) (use defstruct) (defstruct foo [a 42] [b 23])) cu, Thomas -- When C++ is your hammer, every problem looks like your thumb. _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users