Re: [racket-users] copying prefab structs

2017-12-07 Thread Sam Tobin-Hochstadt
I would write the latter as

#lang racket
(require racket/struct)
(define (copy-prefab s)
  (apply make-prefab-struct (prefab-struct-key s)
 (struct->list s)))

Sam

On Thu, Dec 7, 2017 at 11:53 AM, David Vanderson
 wrote:
> I would appreciate any advice on the best way to copy a prefab struct that
> could be a sub-struct.  I have been using write/read but felt bad about it.
> Trying again now gave me a new option. Is there a better solution out there?
>
> (define (copy-writable s)
>   (read (open-input-string (with-output-to-string (lambda () (write s))
>
> (define (copy-prefab s)
>   (call-with-values (lambda () (vector->values (struct->vector s) 1))
> (lambda args (apply make-prefab-struct
> (prefab-struct-key s) args
>
> Thanks,
> Dave
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] copying prefab structs

2017-12-07 Thread David Vanderson
I would appreciate any advice on the best way to copy a prefab struct that
could be a sub-struct.  I have been using write/read but felt bad about it.
Trying again now gave me a new option. Is there a better solution out there?

(define (copy-writable s)
  (read (open-input-string (with-output-to-string (lambda () (write s))

(define (copy-prefab s)
  (call-with-values (lambda () (vector->values (struct->vector s) 1))
(lambda args (apply make-prefab-struct
(prefab-struct-key s) args

Thanks,
Dave

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.