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.