Using set_prolog_flag/2 in SWISH

20 views
Skip to first unread message

Stefan Kral

unread,
Jan 26, 2016, 1:20:39 PM1/26/16
to SWI-Prolog
Hello,

now and again I'd like to use some DCG in SWISH.

With ...

num1 --> [one]|[two]|[three]|[four]|[five].

num2 --> "one"|"two"|"three"|"four"|"five".

... I get:

?- phrase(num1, S).
S = [one] ;
S = [two] ;
S = [three] ;
S = [four] ;
S = [five].

?- phrase(num2, S).
S = [111, 110, 101] ;
S = [116, 119, 111] ;
S = [116, 104, 114, 101, 101] ;
S = [102, 111, 117, 114] ;
S = [102, 105, 118, 101].

50% fine, 50% ... not so fine: I'd much prefer getting answers like `S = [o,n,e]`.

However, it appears to me like `set_prolog_flag(double_quotes, chars)` is not allowed in sandboxed mode... what can I do? Options? Workarounds? Hacks?

Best Regards,
Stefan.

Markus Triska

unread,
Jan 26, 2016, 1:31:18 PM1/26/16
to SWI-Prolog
+1000!

Especially "chars" is extremely useful! A list of characters is much more readable than a list of codes.

Therefore, I would also really greatly appreciate a way to set this flag in the sandbox, in such away that only the given program is affected.

All the best,
Markus

Anne Ogborn

unread,
Jan 26, 2016, 4:03:01 PM1/26/16
to SWI-Prolog
predicates can be partially whitelisted.

The real issue is more complex. If a pengine is a virtual VM, it should have it's own settings. Which probably just points out that global settings is an iffy notion on it's face.

Jan Wielemaker

unread,
Jan 27, 2016, 5:11:33 AM1/27/16
to Anne Ogborn, SWI-Prolog
That is mostly the case as flags are copied from the creating thread and
thus changes only affect the calling thread and the threads it creates
... except for files that may be compiled by any thread and are
subsequently shared between threads. The double_quotes flag affects
_how_ these files that are subsequently shared are compiled.

One way out might be to load library files always with the system
default settings. This is similar to the fact that library files
get their global operators and predicates from `system` instead of
`user` to avoid user declarations from breaking the libraries.

Not sure what the consequences are. I can imagine both positive and
negative consequences.

Cheers --- Jan

Markus Triska

unread,
Jan 30, 2016, 10:24:51 AM1/30/16
to SWI-Prolog
Hi Jan,


On Wednesday, January 27, 2016 at 11:11:33 AM UTC+1, Jan Wielemaker wrote:

One way out might be to load library files always with the system
default settings.  This is similar to the fact that library files
get their global operators and predicates from `system` instead of
`user` to avoid user declarations from breaking the libraries.

To me, this definitely sounds worth trying out!

At least for the concrete flag under discussion (double_quotes), I think this would work very nicely.

All the best,
Markus
Reply all
Reply to author
Forward
0 new messages