Variables are not shared between interactive goals. So,
1 ?- use_module(library(http/json)).
true.
2 ?- open('file.json',read,X), json_read_dict(X,Config), close(X).
X = <stream>(0xf16b70),
Config = _G1894{port:8080}.
If you do this in a program, use something like this:
file_json(File, JSON) :-
setup_call_cleanup(
open(File, read, In),
json_read_dict(In, JSON),
close(In)).
Using setup_call_cleanup/3 you don't have to worry about leaking stream
handles, no matter what happens.
Cheers --- Jan
P.s. You can refer to old toplevel variables in a new query using
$X instead of plain X. This however is only a shorthand for
interactive usage.
>
> Thank you.
>
> --
> 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
http://groups.google.com/group/swi-prolog.
> For more options, visit
https://groups.google.com/d/optout.