Re: [racket-users] Re: read-from-string(-all)

2019-02-07 Thread Laurent
aha, here it is!
The closest form is then `(call-with-input-string str (λ(in)(port->list
read in)))'.
Thanks Sam and Alex!

On Wed, Feb 6, 2019 at 10:01 PM Sam Tobin-Hochstadt 
wrote:

> Also, almost that `read-all` function is provided as `port->list` from
> `racket/port`.
>
> Sam
>
> On Wed, Feb 6, 2019 at 6:25 AM Alex Harsanyi 
> wrote:
> >
> > (read-from-string "123") is equivalent to `(call-with-input-string "123"
> read)` while read-from-string-all can be replaced by:
> >
> > (define (read-all in)
> >   (let loop ([result '()])
> > (let ((v (read in)))
> >   (if (eof-object? v)
> >   (reverse result)
> >   (loop (cons v result))
> >
> > > (call-with-input-string "123 456" read-all)
> > '(123 456)
> >
> > although I am not sure it is a good idea to call read on strings
> received from the user...
> >
> > Alex.
> > On Wednesday, February 6, 2019 at 6:49:57 PM UTC+8, Laurent Orseau wrote:
> >>
> >> read-from-string and read-from-string-all are convenient functions, but
> they belong to the mzlib/string library, which is deprecated. I can't find
> an existing replacement in racket/string or racket/base. Is there one with
> a different name?
> >
> > --
> > 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.
>

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


Re: [racket-users] Re: read-from-string(-all)

2019-02-06 Thread Sam Tobin-Hochstadt
Also, almost that `read-all` function is provided as `port->list` from
`racket/port`.

Sam

On Wed, Feb 6, 2019 at 6:25 AM Alex Harsanyi  wrote:
>
> (read-from-string "123") is equivalent to `(call-with-input-string "123" 
> read)` while read-from-string-all can be replaced by:
>
> (define (read-all in)
>   (let loop ([result '()])
> (let ((v (read in)))
>   (if (eof-object? v)
>   (reverse result)
>   (loop (cons v result))
>
> > (call-with-input-string "123 456" read-all)
> '(123 456)
>
> although I am not sure it is a good idea to call read on strings received 
> from the user...
>
> Alex.
> On Wednesday, February 6, 2019 at 6:49:57 PM UTC+8, Laurent Orseau wrote:
>>
>> read-from-string and read-from-string-all are convenient functions, but they 
>> belong to the mzlib/string library, which is deprecated. I can't find an 
>> existing replacement in racket/string or racket/base. Is there one with a 
>> different name?
>
> --
> 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.


Re: [racket-users] Re: read-from-string(-all)

2019-02-06 Thread Alex Harsanyi


On Wednesday, February 6, 2019 at 7:58:47 PM UTC+8, Laurent Orseau wrote:
>
> Oh nice, I didn't know we could do that one!
> Point taken :)
>
> I suppose (hope?) you can still use sandboxing with memory limits for this?
>


You could make your own read table which disables all special treatment of 
chars, and parameterize it on every read invocation, but the code will not 
look elegant -- in my opinion anyway.

If I had read a list of strings, I would just use:

(map string->number (string-split "123 345"))

and maybe check for #f in the resulting list.  To read other things the 
code will be more complex... 

Alex.

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


Re: [racket-users] Re: read-from-string(-all)

2019-02-06 Thread Laurent
Oh nice, I didn't know we could do that one!
Point taken :)

I suppose (hope?) you can still use sandboxing with memory limits for this?

On Wed, Feb 6, 2019 at 11:52 AM Alex Harsanyi 
wrote:

>
>
> On Wednesday, February 6, 2019 at 7:36:40 PM UTC+8, Laurent Orseau wrote:
>>
>> On Wed, Feb 6, 2019 at 11:25 AM Alex Harsanyi 
>> wrote:
>>
>> although I am not sure it is a good idea to call read on strings received
>>> from the user...
>>>
>>
>> They're not eval'ed,
>>
>>
> Try: (call-with-input-string "#100[]" read)
>
> Alex.
>
> --
> 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.


Re: [racket-users] Re: read-from-string(-all)

2019-02-06 Thread Alex Harsanyi


On Wednesday, February 6, 2019 at 7:36:40 PM UTC+8, Laurent Orseau wrote:
>
> On Wed, Feb 6, 2019 at 11:25 AM Alex Harsanyi  > wrote:
>
> although I am not sure it is a good idea to call read on strings received 
>> from the user...
>>
>
> They're not eval'ed,
>
>  
Try: (call-with-input-string "#100[]" read)

Alex.

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


Re: [racket-users] Re: read-from-string(-all)

2019-02-06 Thread Laurent
On Wed, Feb 6, 2019 at 11:25 AM Alex Harsanyi 
wrote:

> (read-from-string "123") is equivalent to `(call-with-input-string "123"
> read)` while read-from-string-all can be replaced by:
>
> (define (read-all in)
>   (let loop ([result '()])
> (let ((v (read in)))
>   (if (eof-object? v)
>   (reverse result)
>   (loop (cons v result))
>
> > (call-with-input-string "123 456" read-all)
> '(123 456)
>

Thanks Alex. I just wanted to make sure I wasn't overlooking something
before writing my own version.  (and I'm particularly interested in the
-all variant.)


> although I am not sure it is a good idea to call read on strings received
> from the user...
>

They're not eval'ed, it's only data (for plotting, etc.). And the user is
me, using text copied from the output of some program (after some
grep/sed-ing).

-- 
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] Re: read-from-string(-all)

2019-02-06 Thread Alex Harsanyi
(read-from-string "123") is equivalent to `(call-with-input-string "123" 
read)` while read-from-string-all can be replaced by:

(define (read-all in)
  (let loop ([result '()])
(let ((v (read in)))
  (if (eof-object? v)
  (reverse result)
  (loop (cons v result))

> (call-with-input-string "123 456" read-all)
'(123 456)

although I am not sure it is a good idea to call read on strings received 
from the user...

Alex.
On Wednesday, February 6, 2019 at 6:49:57 PM UTC+8, Laurent Orseau wrote:
>
> read-from-string and read-from-string-all are convenient functions, but 
> they belong to the mzlib/string library, which is deprecated. I can't find 
> an existing replacement in racket/string or racket/base. Is there one with 
> a different name?
>

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