On Mon, Apr 29, 2013 at 5:02 PM, Ben Wolfson <wolf...@gmail.com> wrote:

> On Mon, Apr 29, 2013 at 1:57 PM, noahlz <nzuc...@gmail.com> wrote:
>
>> Ok. The parser reads a single complete expression and discards the rest.
>> It understands that once it has hit a new character that represents the
>> beginning of a new expression, it doesn't care.
>>
>> I suppose I thought the parser would raise an error on detecting an
>> unmatched parenthesis, but that's wrong.
>>
>> Interestingly, when I try this at the repl (1.5.1) it errors as I
>> expected (probably why I expected it in the first place):
>>
>> user=> 1000N)
>> 1000N
>>
>> RuntimeException Unmatched delimiter: )
>> clojure.lang.Util.runtimeException (Util.java:219)
>>
>>
>> Of course, the repl doesn't use "read-string." So, the next step in my
>> journey is to investigate the source of clojure.main. But - someone wants
>> to take the opportunity to ruin the surprise for me - with a more detailed
>> explanation / theory discussion - I'm open to it :)
>>
>
> But notice that this *also* returns 1000N, first. So the cases aren't that
> different: it managed to read a complete expression, and evaluated it. Then
> it tried to read *another* expression from the unconsumed input. The
> difference is only that read-string doesn't attempt to exhaust its input
> argument.
>

If you want to exhaust read-string's input argument, getting back a vector
of all of the objects in the input and an error if any of them are
syntactically invalid, just call (read-string (str "[" in-string "]")).
This also deals with empty inputs in a non-blowing-up manner, returning an
empty vector, which might allow uniform handling of the cases (empty?
in-string) and (not (empty? in-string)) in some instances.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to