Re: serialization of math/array

Berthold Bäuml <[email protected]>
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <[email protected]>
Thanks, but this does not solve the problem. I would need a solution which also works more generally, e.g., for arrays nested in structs etc.. 

As far as I understand, the canonical way to extend serialize is to add the prop:serializable property to the struct representing an array. But that was not possible back in 2014 as Typed Racket did not fully support properties. Is there meanwhile a solution for such cases?

Berthold
> On 30 Mar 2016, at 17:00, Benjamin Greenman <[email protected]> wrote:
> 
> Here's one hack.
> 
> #lang racket/base
> 
> (require
>   math/array
>  (prefix-in rkt: racket/serialize))
> 
> (define secret-key 'array)
> 
> (define (serialize val)
>   (if (array? val)
>     (rkt:serialize (cons secret-key (array->list val)))
>     (rkt:serialize val)))
> 
> (define (deserialize val)
>   (define d (rkt:deserialize val))
>   (if (and (pair? d) (eq? secret-key (car d)))
>     (list->array (cdr d))
>     d))
> 
> (define arr (array #[0 1 2]))
> (serialize arr)
> (deserialize (serialize arr))
> 
> 
> (Part of the issue serializing math/array is that it represents arrays as functions under the hood)
> 
> 

-- 
-----------------------------------------------------------------------
Berthold Bäuml -- Head of Autonomous Learning Robots Lab
DLR, Robotics and Mechatronics Center (RMC)
Münchner Str. 20, D-82234 Wessling
Phone +49 8153 282489
http://www.robotic.de/Berthold.Baeuml <http://www.robotic.de/Berthold.Baeuml>

-- 
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.