2

I am trying to write a definite class grammar that takes a singleton list and determines if it is a 1 or 0.It keeps returning false and i can't figure out why it is not working.

zeroorone-->validnum.
validnum-->[0].
validnum-->[1].

2 Answers 2

0

The language you've posted matches

0

and

1

but not

[0, 0, 1, 1, 0, 1, 1, 1, 0, 0]

is that what you expected?

phrase(zeroorone, X). should respond

X = [0]. X = [1].

Now, it's also possible that you're confusing 'code' style Prolog strings

"100" with [1,0,0] The former is ['1', '0', '0']

An example of your code failing would be useful

0

Anniepoo is right. This works in SWI-Prolog.

I put your code into a file a.pl and load it using consult(a). Then I can run the following.

zeroorone([0], []).
true .

zeroorone([1], []).
true .

And as Anniepoo said running the following works after you press enter and then space to get the second answer

phrase(zeroorone, X).
X = [ 0 ] ;
X = [ 1 ].

However, as she said it does not work for anything but the two lists [ 0 ] and [ 1 ].

e.g.

zeroorone([1,0,0], []).
false.

In order to get a better answer you may need to specify what is actually required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.