Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mystery

40 views
Skip to first unread message

the.davis...@gmail.com

unread,
Jun 13, 2017, 8:18:10 AM6/13/17
to
Every Prolog I have tried gives a different result to this 'simple' query:

:- initialization(main).

mangle_char(C, [C]) :- (C >= 97, C =< 122; C >= 48, C =< 57), !.
mangle_char(C1, [95, C2, C3]) :-
N is C1 // 16, hexdigit(N, C2),
M is C1 - N * 16, hexdigit(M, C3).

hexdigit(N, M) :- N < 10, M is N + 48, !.
hexdigit(N, M) :- M is N + 87.

main :- findall(CS, (member(C, [100,101,102,97,117,108,116,95,115,101,116,116,105,110,103]), mangle_char(C,CS)), MSTRING), write(MSTRING), nl, halt.

I have tried SWI (7.2.3):

[[100],[101],[102],[97],[117],[108],[116],[95,53,102],[115],[101],[116],[116],[105],[110],[103]]

Yap (6.2.2):

[]

and GProlog (1.4.5):

warning: samples/test.pl:1: user directive caused exception: error(existence_error(procedure,'$mangle_char/2_$aux1'/0),mangle_char/0)

Any ideas?

Ulrich Neumerkel

unread,
Jun 13, 2017, 9:00:21 AM6/13/17
to
Yap does not have member/2 predefined, and older
versions simply fail by default for member(1,[1]). if it is not
defined.

Not sure how you call GNU Prolog - I don't get that
message.

Finally, it seems you want to use integer codes to represent
characters. There is also another way to do this: using
atoms of length one, called characters. At least you
get much better readable results. In fact, a
list

[d,e,f,a,u,l,t,'_',s,e,t,t,i,n,g]

is much easier to read than

[100,101,102,97,117,108,116,95,115,101,116,116,105,110,103]

The double quote notation can be used to this end with
the following directive:

:- set_prolog_flag(double_quotes, chars).

?- writeq("default").
[d,e,f,a,u,l,t]

Andrew Davison

unread,
Jun 13, 2017, 9:44:12 AM6/13/17
to
Thanks, but not my code. Fell for the old "yap doesn't have member/2" trick. With GProlog I just consulted a file with that exact code.

burs...@gmail.com

unread,
Jun 13, 2017, 10:29:02 AM6/13/17
to
If a predicate doesn't exist or isn't loaded (via an
appropriate load module directive :- use_module(<path>)),
then you should get an error message (an not [] as you show):

YAP 6.3.3 (i686-mingw32): Sun Jan 20 18:27:56 GMTST 2013
?- member(X, [1,2,3]).
ERROR!!
EXISTENCE ERROR- procedure member/2 is undefined, called from context prolog:$enter_top_level/0
Goal was user:member(_131502,[1,2,3])

For YAP, member is for example part of this module:
http://www.dcc.fc.up.pt/~vsc/Yap/yap.html#Lists

And you don't get the error anymore, if you load
the module beforehand:

YAP 6.3.3 (i686-mingw32): Sun Jan 20 18:27:56 GMTST 2013
?- use_module(library(lists)).
% reconsulting c:/program files/yap64/share/lists.yap...
% reconsulting c:/program files/yap64/share/error.pl...
% reconsulted c:/program files/yap64/share/error.pl in module error, 0 msec 0 bytes
% reconsulted c:/program files/yap64/share/lists.yap in module lists, 0 msec 0 bytes
yes
?- member(X,[1,2,3]).
X = 1 ? ;

X = 2 ? ;

X = 3 ? ;

no

As you see member leaves a choice point, so I guess
its a pretty weak member implementation in YAP through
the module lists. Compare this to SWI-Prolog:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.5.8)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- member(X,[1,2,3]).
X = 1 ;
X = 2 ;
X = 3.

No choice point left in the last answer. Anyway, its still
a correct implementation in YAP I guess. Choice point
elimination is a non-functional requirement.

Is there an explanation why YAP shows []. Does findall
in YAP supress error messages?

Bye

the.davis...@gmail.com

unread,
Jun 13, 2017, 6:34:40 PM6/13/17
to
Yes, use_module(library(lists)) works for Yap.

The code actually comes from a Prolog compiler written in Prolog, apparently it only bootstraps with SWI Prolog.

Dhu on Gate

unread,
Jun 17, 2017, 4:57:28 AM6/17/17
to
not sure what you're doing with gprolog there.
I get the same result as SWI:

# more mangle.pl

:- initialization(main).

mangle_char(C, [C]) :- (C >= 97, C =< 122; C >= 48, C =< 57), !.
mangle_char(C1, [95, C2, C3]) :-
N is C1 // 16, hexdigit(N, C2),
M is C1 - N * 16, hexdigit(M, C3).

hexdigit(N, M) :- N < 10, M is N + 48, !.
hexdigit(N, M) :- M is N + 87.

main :- findall(CS, (member(C, [100,101,102,97,117,108,116,95,115,101,116,116,105,110,103]), mangle_char(C,CS)), MSTRING), write(MSTRING), nl, halt.


# gprolog
GNU Prolog 1.4.5 (64 bits)
Compiled Jun 17 2017, 02:50:22 with gcc
By Daniel Diaz
Copyright (C) 1999-2014 Daniel Diaz
| ?- [mangle].
compiling /usr/local/gprolog-1.4.5/Dlib/mangle.pl for byte code...
/usr/local/gprolog-1.4.5/Dlib/mangle.pl compiled, 14 lines read - 3800 bytes written, 8 ms
[[100],[101],[102],[97],[117],[108],[116],[95,53,102],[115],[101],[116],[116],[105],[110],[103]]

Dhu

--
Je suis Canadien. Ce n'est pas Francais ou Anglaise.
C'est une esp`ece de sauvage: ne obliviscaris, vix ea nostra voco;-)

http://babayaga.neotext.ca/PublicKeys/Duncan_Patton_a_Campbell_pubkey.txt
0 new messages