Hi, I think I found a fix for the 0 conversion problem in PyCLP. In class Term, the line if init_arg: needs to be changed into if init_arg is not None: As for the booleans, I added code to class Term that I copied from class Atom: #Booleans elif isinstance(init_arg,bool): if init_arg: string = "true" else: string = "false" #Convert to byte array py_byte_string = tobytes(string) c_string = py_byte_string # Create dictionary entry ptr=pyclp.ec_did(c_string,0) temp=pyclp.ec_atom(ptr) self.ref.set(temp) A cdef definition needs to be added to the class Term before the definition of function __init__(): cdef char* c_string Also, when the ECLiPSe boolean is read out in Python, it should be transformed into a Python Boolean. For this, I changed the handling of atoms in pword2object(): elif pyclp.ec_get_atom(in_pword,&dummy_dident)== pyclp.PSUCCEED: result=Atom(None) (<Atom>result).set_pword(in_pword) if str(result) == "true": result = True elif str(result) == "false": result = False With these changes, I was able to pass zeros and Python booleans to ECLiPSe and back. I'm not sure, though, whether the handling of Booleans is the best way - it was rather quick&dirty to see whether I can get this to work. Regards, Thorsten Am 13.12.2013 11:56, schrieb Thorsten Winterer: > Hi, > > as I was fighting the very same problem this morning, I would like to > point to another related problem: > the Python booleans True and False are not transformed into ECLiPSe > booleans true and false, but instead treated as integers, resulting in > 1 and _ values, respectively. > > Unfortunately, these two issues are showstoppers for me, so if anyone > has a suggestion how to fix PyCLP's Term class, I'd be very grateful... > > Thorsten > > > Am 13.12.2013 11:45, schrieb Federico Ferri: >> 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? >> >> >> >> ------------------------------------------------------------------------------ >> Rapidly troubleshoot problems before they affect your business. Most IT >> organizations don't have a clear picture of how application performance >> affects their revenue. With AppDynamics, you get 100% visibility into your >> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! >> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk >> >> >> _______________________________________________ >> ECLiPSe-CLP-Users mailing list >> ECLiPSe-CLP-Users_at_lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users > > > > ------------------------------------------------------------------------------ > Rapidly troubleshoot problems before they affect your business. Most IT > organizations don't have a clear picture of how application performance > affects their revenue. With AppDynamics, you get 100% visibility into your > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk > > > _______________________________________________ > ECLiPSe-CLP-Users mailing list > ECLiPSe-CLP-Users_at_lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/eclipse-clp-usersReceived on Fri Dec 13 2013 - 16:11:17 CET
This archive was generated by hypermail 2.2.0 : Mon Dec 16 2013 - 06:13:47 CET