list - Prolog code gives two different results -
so i'm making code there's function receives 2 arguments , tells if 1 of them not list.
the code following:
/*** list check ***/ islist(l) :- l == [], !. islist(l) :- nonvar(l), aux_list(l). aux_list([_|_]). /*** double list check ***/ double_check(l, l1) :- \+islist(l) -> write("list 1 invalid"); \+islist(l1)-> write("list 2`invalid"); write("success").
it shuold working. online code want to. on prolog console of computer gives different answer:
?- double_check(a, [a]). [76,105,115,116,97,32,49,32,105,110,118,97,108,105,100,97] true.
example. have no idea list came from. can tell me error , me fix please? thank all!
quick fix: use format/2
instead of write/1
! more information on built-in predicate format/2
, click here.
$ swipl --traditional welcome swi-prolog (multi-threaded, 64 bits, version 7.1.37) [...] ?- write("abc"). [97,98,99] % output write/1 via side-effect true. % truth value of query (success) ?- format('~s',["abc"]). abc % output format/2 via side-effect true. % truth value (success)
however different command line arguments:
$ swipl welcome swi-prolog (multi-threaded, 64 bits, version 7.1.37) [...] ?- write("abc"). abc true. ?- format('~s',["abc"]). abc true.
even though may seem nuisance, recommend using command-line option --traditional
swi-prolog, in combination format/2
instead of write/1
. preserve portability!
Comments
Post a Comment