[racket] Size matters

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Jun 10 09:08:55 EDT 2013

On Jun 10, 2013, at 8:18 AM, Tim Brown wrote:

> On 09/06/13 18:54, Matthias Felleisen wrote:
>> I have taken the liberty to rewrite the code according to the Style
>> gide, since I am the author of this document:
> 
> I've found this (and I have seen it before):
> http://www.ccs.neu.edu/home/matthias/Style/style/index.html
> but is it included in the Racket documentation?
> If so, where?


It will be moved into the core documentation as soon as Eli finds the time to run the appropriate git command. 



>  (fill-sack items 0.25 25 null 0) ; stated problem
> 
> So, thanks for your "honesty" Matthias, but you're being too kind :-)

The honesty was with respect to Eli's rewrite. 

If you really are in need of such a function, I think it is clearer to have two: 

 fill-sack/public 
 fill-sack/private

If this is a library, export the first. If this is plain old code in an application, make the second one local to the first. 

> The <identifier>* notation... is that Style?

No. My personal convention. 


On Jun 10, 2013, at 8:20 AM, Tim Brown wrote:

> 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?


Why not struct-copy: 

(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 gold)))
(define fools-gold2 (struct-copy item gold (value 2.50)))

(equal? fools-gold fools-gold2)



Posted on the users mailing list.