2

I am taking a beginner prolog course. We are supposed to use swi-prolog, here's what mine says

% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,856 bytes
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.10.4)

We are asked to develop the arithmetic predicate add(X,Y,Z). using the successor s(X) [= X+1] functor. This predicate fails on my machine with the following error:

ERROR: toplevel: Undefined procedure: s/1 (DWIM could not correct goal)

Does anyone have a solution? Must I downgrade my swipl, maybe?

Thanks!

pouzzler
  • 1,800
  • 2
  • 20
  • 32

2 Answers2

2

Your SWI-Prolog it's fine, but you misunderstood the assignment. You must write your definition of add/3, using instead of usual numbers the Peano representation, where, for instance, 2 become s(s(0)). You could search for similar questions, for instance I answered to help understanding actual Prolog execution in the very same context you're facing.

Community
  • 1
  • 1
CapelliC
  • 59,646
  • 5
  • 47
  • 90
1

You don't have to downgrade your interpreter version because s/1 isn't an actual predicate (that's why you are getting this error). s/1 just stands for "successor" as you already know, and it's used to represent numbers in a recursive way.

The natural numbers in Prolog are built from two constructs, the constant symbol 0 and the successor function s of arity 1. All the natural numbers are then recursively given as 0, s(0), s(s(0)), s(s(s(0))), .... We adopt the convention that sn(0) denotes the integer n, that is, n applications of the successor function to 0

[Sterling L., Shaphiro E., "The Art of Prolog", 2nd ed. - MIT Press]

I think you'll find this related question interesting.

Community
  • 1
  • 1
Carles Araguz
  • 1,157
  • 1
  • 17
  • 37