[eclipse-clp-users] PyCLP inconsistency in treating 0 (zero)

From: Federico Ferri <federico.ferri.it_at_...6...>
Date: Fri, 13 Dec 2013 11:45:09 +0100
I found a problem in how pyclp builds terms for eclipse.

Let's say I want to post the goal X is 2+3:

  import pyclp
  pyclp.init()
  X=pyclp.Var()
  goal=pyclp.Compound('is', X, pyclp.Compound('+', 2, 3))
  print('goal: %s' % goal)
  goal.post_goal()
  ret,arg=pyclp.resume()
  print('X = %s' % X.value() if ret else 'goal failed')

gives the expected output:

goal: is(_,+(2,3))
X = 5


Now if I want to post the goal X is 0+3, I use the very same program as
above, just replacing 2 with 0, and here's the output:

goal: is(_,+(_,3))
X = None

Apparently, 0 becomes a variable, which does not look correct.

I thought that this was my mistake, and I should have been explicitly
creating numbers with a pyclp constructor, but building the goal as:

  goal=pyclp.Compound('is', X, pyclp.Compound('+', pyclp.Term(0),
pyclp.Term(3)))

or as:

  goal=pyclp.Compound('is', X, pyclp.Compound('+', pyclp.Atom('0'),
pyclp.Atom('3')))

yields to the same output:

goal: is(_,+(_,3))
X = None


Additionally, building the goal as:

  goal=pyclp.Compound('is', X, pyclp.Compound('+', '0', '3'))

yields to a different stringification:

goal: is(_,+("0","3"))
X = None

I'm not sure if "0" and "3" are truly strings, because in an interactive
eclipse interpreter, I get those results instead:

[eclipse 1]: X is 0 + 3.
X = 3
Yes (0.00s cpu)

[eclipse 2]: X is '0' + '3'.
calling an undefined procedure '0'(_209) in module eclipse
Abort

[eclipse 3]: X is "0" + "3".
number expected in +("0", "3", _281)
Abort



Some interesting facts from the python console:

>>> str(pyclp.Atom('0'))
'0'

>>> str(pyclp.PList([1,0,1,0]))
'[1,_,1,_]'

>>> str(pyclp.PList(list(pyclp.Atom(str(x)) for x in [1,0,1,0])))
'[1,0,1,0]'


I'm a bit puzzled, I think I will file a bug report to PyCLP
Has anyone encountered this before?
Received on Fri Dec 13 2013 - 10:45:16 CET

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:21 CEST