On Tue, Feb 15, 2022 at 06:34:58PM +0100, pd wrote: > > It tries the first one but does not succeed. The second one matches, so the > > others are not tried because of the cut. > > This is interesting, in my understanding when matching the first rule it > should try to unify @C to the result of @A + @B but since @B is @X you > have @B unified to a variable or symbol
This is right. > and thus @B is not instantiated, it > has no value and so you cannot do the + operation, On the Pilog level, @B is indeed unified with @X. But in the Lisp call @B has the value NIL. > in my understanding you > should have got an exception or an error It is an important feature of PicoLisp that arithmetic functions treat NIL as "not a number" and not as an error: : (+ 3 'a 4) !? (+ 3 'a 4) a -- Number expected ? : (+ 3 NIL 4) -> NIL > I suppose what happens is first rule don't give an error trying to add @A > and @B, it simply fails and returns with @C not unified (not binded) and > thus the cut is never executed so it tries next rule, the second one, now > it succeeds and executes the cut stopping further matching. Exactly. ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe