[racket] struct with default value per field

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Sat Jun 22 10:54:56 EDT 2013

Jay has a really nice `sstruct' macro that may do what you want.
    https://github.com/jeapostrophe/exp/blob/master/sstruct.rkt
Examples in
    https://github.com/jeapostrophe/exp/blob/master/sstruct-tests.rkt

IMO, there are a lot of good ideas in there that would be nice to have
for Racket's `struct', or at least installable as a package.

Vincent



At Sat, 22 Jun 2013 10:23:51 +0200,
Patrick Useldinger wrote:
> 
> Hi
> 
> I can't find a way to have a per-field default value in a struct, such 
> as in Common Lisp:
> 
> ? (defstruct person (name "James" :type string) (age 1 :type number))
> PERSON
> ? (defparameter p (make-person))
> P
> ? p
> #S(PERSON :NAME "James" :AGE 1)
> ? (defparameter p (make-person :name "Paul"))
> P
> ? p
> #S(PERSON :NAME "Paul" :AGE 1)
> ? (defparameter p (make-person :name "Paul" :age 10))
> P
> ? p
> #S(PERSON :NAME "Paul" :AGE 10)
> 
> 
> The only thing I find is #:auto-value, which applies to all fields.
> 
> Is there a way to do the same in Racket? If not, is there a specific 
> reason for this choice?
> 
> -pu
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.