On 29/01/2019 02:09, Peter Ludemann wrote:
> Thank-you for the fix.
>
> However, something seems to have broken with at_end_of_stream (or with
> json_read_dict). I have 2 JSON terms, and expect at_end_of_stream after
> reading them. This works with the current PPA swipl but at_end_of_stream
> fails with the code at github.
Only if the input has one character following the JSON document
(typically \n). If the input has no characters after the JSON document
at_end_of_stream/1 succeeds. Tested using:
:- use_module(library(http/json)).
t :-
open('t.json', read, In),
json_read_dict(In, Dict),
pp(Dict),
( at_end_of_stream(In)
-> format('At end of stream~n', [])
; format('Not at end of stream~n', [])
),
close(In).
101 ?- t.
_{a:1}At end of stream
true.
So, yes this breaks your code (and this won't go into 8.0 stable), but
it is because you code is fragile. Add another newline or whatever to
your input and it breaks the same way. You should skip all white space
and then check for end-of-file or, more easily, call the JSON reader
again and check it returns the end-of-file code you specified.
> As to why ^C and "g" doesn't suffice -- I'm running swipl in the
> *compilation* window under Emacs (there's a *lot* of debug output). Of
> course, I could switch to running it in a shell, but I'd have to run the
> commands by hand, whereas currently they're in a Makefile.
>
> On Monday, January 28, 2019 at 5:45:08 AM UTC-8, Jan Wielemaker wrote:
>
> On 28/01/2019 08:55, Jan Wielemaker wrote:
> > Seems throw doesn't work anymore. Probably stopped working when
> > exceptions no longer used longjmp(), years ago. I'll have a look.
> > Binding to a predicate and then throwing an exception probably works
> > fine.
>
> This assumption was correct. Pushed a fix.
>
> Cheers --- Jan
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
swi-prolog+...@googlegroups.com
> <mailto:
swi-prolog+...@googlegroups.com>.
> Visit this group at
https://groups.google.com/group/swi-prolog.
> For more options, visit
https://groups.google.com/d/optout.