Replies: 2 comments 2 replies
-
Because First you need a good name for your relation, maybe
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I copied that code from here: https://www.swi-prolog.org/pldoc/man?predicate=is_list/1. Moving the last clause to the beginning like this fixed the issue: :- use_module(library(si)).
list_not_chars([]).
list_not_chars(X) :- chars_si(X), !, fail.
list_not_chars(X) :- var(X), !, fail.
list_not_chars([_|Xs]) :- list_not_chars(Xs). How can I get the same behavior without using cuts? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I know I can use the
list_si
predicate inlibrary(is)
to determine if something is a list, but I have a case where I'd like to treat lists of character atoms different from other kinds of lists. So I wrote this:Seems pretty straightforward, but when I load this and enter
is_list([foo, bar]).
it saysfalse
.Removing the first clause fixes it, but I don't understand why I can't keep the first clause.
Entering
chars_si([foo, bar]).
givesfalse
as expected, so I didn't think that clause would be used.It seems to me that I should be able to replace the first two clauses with these:
But that doesn't work either. I'm stumped on this.
Beta Was this translation helpful? Give feedback.
All reactions