SWI-Prolog / swipl-devel

SWI-Prolog Main development repository
http://www.swi-prolog.org
Other
959 stars 175 forks source link

nth1 broken with set_prolog_flag(unknown, fail) #155

Closed cbarrick closed 7 years ago

cbarrick commented 8 years ago

EDIT updated with minimal example

When the unknown flag is set to fail, nth1/3 does not work. If it is traced, that query will fail, but subsequent queries will succeed.

Here is the behavior I am seeing:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.24)
Copyright (c) 1990-2016 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- debug.
true.

[debug]  ?- nth1(1, [foo, bar], X).
false.

?- trace, nth1(1, [foo, bar], X).
   Call: (8) nth1(1, [foo, bar], _G1223) ? creep
false.

[trace]  ?- notrace.
true.

[debug]  ?- nth1(1, [foo, bar], X).
X = foo.

[debug]  ?- trace, nth1(1, [foo, bar], X).
   Call: (8) lists:nth1(1, [foo, bar], _G1362) ? creep
   Exit: (8) lists:nth1(1, [foo, bar], foo) ? creep
X = foo.

I can confirm this bug on V7.2.3, V7.3.21, and 3750df9817c79b7f45af6f146104542d486bb8ac.

wouterbeek commented 7 years ago

Hi @cbarrick , I cannot reproduce this. The following is what I get:

?- set_prolog_flag(unknown, fail).
Warning: Using a non-error value for unknown in the global module
Warning: causes most of the development environment to stop working.
Warning: Please use :- dynamic or limit usage of unknown to a module.
Warning: See http://www.swi-prolog.org/howto/database.html

?- debug.
false.

IOW, I never get the chance to reproduce your issues with nth1/3. Are you using other means to set the unknown flag? I see no call to set_prolog_flag/2 in your example.

cbarrick commented 7 years ago

I guess I can close this. I can't seem to reproduce it.

When I originally reported this, I was trying to use dicts in a portable way. My approach was to use set_prolog_flag(unknown, fail) in my module so that dict predicates would silently fail on systems where they weren't available. While debugging that module, I discovered this issue where nth1/3 would fail when it shouldn't.

In my module, the issue occurred when I set_prolog_flag(unknown, fail). But I could also reproduce the issue from the REPL by enabling debug mode. So the minimum example I gave above was eaxactly what I was doing. I don't use any config scripts, and I wasn't setting the unknown flag at the REPL.

I just tried, and I can no longer reproduce this. I have since upgraded my OS and compiler, so maybe that has something to do with it. I build SWI for macOS using homebrew, and the only changes they've made to the build script since my original report were tracking the dev releases and forcing a rebuild when they upgraded readline.

I'm closing this and chalking it up to an incompatible/buggy dependency in the build.

wouterbeek commented 7 years ago

@cbarrick Thanks for confirming that this no longer reproduces.

BTW, if you're interested in portability then you can try to load SWI with command-line flag --traditional. See the documentation) for more info.