On 09/06/13 18:54, Matthias Felleisen wrote:
      (define item (first items))
      (define weight (item-weight item))
      (define volume (item-volume item))
      (define value (item-value item))

Now I understand that the three lines of extracting the content of the
first struct are painful. While I understand and agree with the match
here, I have also experimented with a struct-open construct for my
latest project, and I find this code as readable as the one with match:

I also find structs quite cumbersome to use, although infinitely better
than (define name (first item)) etc.

Is there a lot of work going into structs at the moment?

I find them particulary hard to use in a purely functional (non-mutable)
way, since there is no shorthand way of copying a struct. AFAICT, at the
moment, to copy an item I need to:

  (struct item (name explanation value weight volume) #:prefab)
  (define gold (item "gold (bars)" "Shiney shiney" 2500 2.0 0.002))
  (define fools-gold
   (item
    (item-name gold)
    (item-explanation gold)
    2.50
    (item-weight gold)
    (item-volume)))

Possibly with some variation on extracting the fields, using match or
whatever. Even with a match, you still need to evaluate each of the
fields; and if I want to copy one field from an n-field struct, I need n
field accessors, and n fields in the constructor (with one of them
modified).

What I would really like to have is the following defined by (struct item):

  (define fools-gold (copy-item gold #:value 2.50))

Am I missing a trick?

Tim
____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to