brunoalano / pyswip

Automatically exported from code.google.com/p/pyswip
MIT License
0 stars 0 forks source link

empty list are returned as atom '[]' #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
from pyswip import *

p = Prolog()

assertz = Functor("assertz")
f = Functor("f", 1)

call(assertz(f([])))
call(assertz(f(['a', 'b', 'c'])))

X = Variable()
q = Query(f(X))

while q.nextSolution():
    print type(X.value), str(X.value)

q.closeQuery()

expected output:
<type 'list'> []
<type 'list'> [Atom('251908'), Atom('251780'), Atom('233348')]

actual output:
<class 'pyswip.easy.Atom'> []
<type 'list'> [Atom('251908'), Atom('251780'), Atom('233348')]

The problem lies in the order a term is tested for being a list. The
following getTerm() produces the expected result:  

def getTerm(t):    
    p = PL_term_type(t)
    if PL_is_list(t):
        return getList(t)
    elif p < PL_TERM:
        return _getterm_router[p](t)
    else:
        return getFunctor(t)

Original issue reported on code.google.com by pre...@cosy.sbg.ac.at on 18 Mar 2008 at 4:28

GoogleCodeExporter commented 9 years ago
Thanks for spotting the error; I'll incorporate your fix in the next version.

Original comment by yucete...@gmail.com on 21 Mar 2008 at 9:53

GoogleCodeExporter commented 9 years ago
Applied. Thanks for you contribution.

Original comment by rotter.m...@gmail.com on 11 May 2011 at 11:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The problem was not solved. Now is:
    p = PL_term_type(t)
    if p < PL_TERM:
        res = _getterm_router[p](t)
    elif PL_is_list(t):
        res = getList(t)
    else:
        res = getFunctor(t)
    mappedTerms[t] = res
    return res

but, never execute getList(t).

Original comment by fernando...@gmail.com on 2 Apr 2015 at 10:00