Re: [racket-users] reading s-expressions from a file

2020-07-17 Thread gfb
Shouldn't the for be (for ([expr (in-producer read eof)] ⋯). One could also 
specify the input port there, as shown in reference for in-producer 

 
, possibly inside call-with-input-file (although that vs 
with-input-from-file is probably a matter of taste).

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/d1583583-f98b-47fe-a6b8-5dd295bceef8n%40googlegroups.com.


Re: [racket-users] reading s-expressions from a file

2020-07-17 Thread George Neuner


On 7/17/2020 8:19 PM, Hendrik Boom wrote:

Yes,  I know the functino for reading s-expressions seems to be (read [in]).

I want a loop that reads S-expressions and does something to each one, until 
there are no more to be found in a file.

Now of course that's absurdly easy to do with a tail-recursice loop.

But I's like it to look like a loop, with (for ...) or (while ...) or
(loop ...) or something like that.

But I fail to fine any iterators that process a file, such as (in-file
...)

There's a long list of iterators in
https://docs.racket-lang.org/reference/for.html
and in
https://docs.racket-lang.org/guide/for.html

An I just looking in the wrong place, or are there really no iterators
for reading a stream of s-expressions from a file.

-- hendrik


This should work if you're reading the sexprs for value:

(with-input-from-file /filename/
  (lambda ()
    (for [(expr (read))]
  :
    )))

If your intent is to read/parse the sexprs as text, there isn't a simple 
way to do that.  Regex is problematic for nested expressions ... you 
could try "read-syntax" if you are familiar with macros, or "match" if 
you know what patterns to look for.


There's no "in-match" sequence, so if you want a loop that *appears* 
simple [match in the /"for-clause"/], you'll have to write some glue: a 
helper that returns one match result at a time so as to plug nicely into 
a loop.


George

--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/7184da64-a388-91bf-e027-a213a3d66c73%40comcast.net.


Re: [racket-users] reading s-expressions from a file

2020-07-17 Thread Sorawee Porncharoenwase
(with-input-from-file "abc" (thunk (sequence->list (in-port

Note that you need to “read” in the dynamic extent of with-input-from-file.
Outside it, the port is closed.

On Fri, Jul 17, 2020 at 5:19 PM Hendrik Boom  wrote:

> Yes,  I know the functino for reading s-expressions seems to be (read
> [in]).
>
> I want a loop that reads S-expressions and does something to each one,
> until there are no more to be found in a file.
>
> Now of course that's absurdly easy to do with a tail-recursice loop.
>
> But I's like it to look like a loop, with (for ...) or (while ...) or
> (loop ...) or something like that.
>
> But I fail to fine any iterators that process a file, such as (in-file
> ...)
>
> There's a long list of iterators in
>https://docs.racket-lang.org/reference/for.html
> and in
>https://docs.racket-lang.org/guide/for.html
>
> An I just looking in the wrong place, or are there really no iterators
> for reading a stream of s-expressions from a file.
>
> -- hendrik
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/20200718001905.elzyuu42gje45j7t%40topoi.pooq.com
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegvbps%3DtFJYg2UZ48s7uw1tVY8P58WnQYoZUMyShahCzhg%40mail.gmail.com.


[racket-users] reading s-expressions from a file

2020-07-17 Thread Hendrik Boom
Yes,  I know the functino for reading s-expressions seems to be (read [in]).

I want a loop that reads S-expressions and does something to each one, until 
there are no more to be found in a file.

Now of course that's absurdly easy to do with a tail-recursice loop.

But I's like it to look like a loop, with (for ...) or (while ...) or 
(loop ...) or something like that.

But I fail to fine any iterators that process a file, such as (in-file 
...)

There's a long list of iterators in 
   https://docs.racket-lang.org/reference/for.html
and in 
   https://docs.racket-lang.org/guide/for.html

An I just looking in the wrong place, or are there really no iterators 
for reading a stream of s-expressions from a file.

-- hendrik

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200718001905.elzyuu42gje45j7t%40topoi.pooq.com.