Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-22 Thread Philip McGrath
To work with strings for the database, do something like this: (define (serialize-to-string v) (with-output-to-string (λ () (write (serialize v) (define (deserialize-from-string str) (with-input-from-string str (λ () (deserialize (read) On Tuesday, March 21, 2017 at 8:52:55 PM

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Marc Kaufmann
Thanks, I will give that a try in the future, once I have time to look at PG database (as I have some experience with Mysql, but none with PG). But that would be exactly the kind of thing I was looking for. Cheers, Marc On Tue, Mar 21, 2017 at 8:47 PM, George Neuner wrote:

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread George Neuner
On 3/21/2017 8:36 PM, Marc Kaufmann wrote: Thanks. But I have to turn it into a string before storing it in the database; when I tried to store a serialized list in it (in a VARCHAR field), it complained that it expected a string. That's where all the trouble came from. The trouble I had was

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Jon Zeppieri
Oh, never mind. I see what you mean. On Tue, Mar 21, 2017 at 8:42 PM, Jon Zeppieri wrote: > Did you try a using a bytea field? > > On Tue, Mar 21, 2017 at 8:36 PM, Marc Kaufmann > wrote: >> Thanks. But I have to turn it into a string before storing

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Marc Kaufmann
Thanks. But I have to turn it into a string before storing it in the database; when I tried to store a serialized list in it (in a VARCHAR field), it complained that it expected a string. That's where all the trouble came from. The trouble I had was parsing the string back into the serialized

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Marc Kaufmann
Regarding not using deserialize directly: I may be using deserialize in the wrong way, but the following doesn't work (and I had tried that before posting): > (define-values (in out) (make-pipe)) > (write (~a (serialize '((0 1) (1 0) "((3) 0 () 0 () () (q (0 1) (1 0)))" > (write (~a

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread George Neuner
On 3/21/2017 5:48 PM, Jon Zeppieri wrote: Ah, except apparently `pg-array` only supports arrays with dimension 1. So... that won't help. I *think* Ryan Culpepper fixed that a long time ago ... though the docs may never have been updated. I had a workaround at the time and unfortunately I

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Philip McGrath
I would do: (with-input-from-string from-db (λ () (deserialize (read On Tue, Mar 21, 2017 at 4:48 PM Jon Zeppieri wrote: > On Tue, Mar 21, 2017 at 5:44 PM, Jon Zeppieri wrote: > > However, postgres (if that's what you're using) > > has

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Jon Zeppieri
On Tue, Mar 21, 2017 at 5:44 PM, Jon Zeppieri wrote: > However, postgres (if that's what you're using) > has multidimensional arrays as a native type, so you could use those > [https://www.postgresql.org/docs/current/static/arrays.html]. The > Racket db package has a

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Jon Zeppieri
On Tue, Mar 21, 2017 at 5:34 PM, Marc Kaufmann wrote: > Hi, > > I want to store matrices of the following form (but larger) in a database: > > (define m '((0 1) (1 0))) > > Currently I manage to store them by turning them into strings first via: > > (~a (serialize m));

[racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Marc Kaufmann
Hi, I want to store matrices of the following form (but larger) in a database: (define m '((0 1) (1 0))) Currently I manage to store them by turning them into strings first via: (~a (serialize m)); Or just drop the serialize, but I figured I might benefit from it later. The problem is that