Variable A and atom 'A' indistinguishable in JSON results. · Issue #3 · simularity/JavaPengine · GitHub
Skip to content

Variable A and atom 'A' indistinguishable in JSON results. #3

Open

Description

@aindilis

Hi anniepoo!

I have a use for JavaPengine, and I'm trying to get variables to work: If one, in ManualAsk.java, changes the following line:

for(Query q = p.ask("member(X, [a(taco),2,c])"); q.hasNext() ; ) {

to use instead:

member(X, [a(taco,A,_A,'A','C D'),b,dag,2,'2',c])

The following JSON is returned.

{"A":"A","X":{"args":["taco","A","_","A","C D"],"functor":"a"}}
{"A":"_","X":"b"}
{"A":"_","X":"dag"}
{"A":"_","X":2}
{"A":"_","X":"2"}
{"A":"_","X":"c"}

You can see that numbers are working correctly (it returns atom 2 as "2" but number 2 as 2). But with variables I do not see here any way to distinguish them, and I'm not sure what is happening to the _A, it looks like it may be becoming simply "_". I would expect this to read something like:

{"X":{"args":["taco",{"variable":"A"},{"variable":"_A"},"A","C D"],"functor":"a"}}

This is how SWIPL is handling it:

?- member(X, [a(taco,A,_A,'A','C D'),b,dag,2,'2',c]).
X = a(taco, A, _A, 'A', 'C D') ;
;
X = b .

?- 

Please let me know if I need to provide more information.

Best,
aindilis

Activity

  1. aindilis commented on Aug 9, 2020

    @aindilis
    Author

    My solution was that I wrote a wrapper that gives me the information needed on the Prolog side to piece the answer (including variables) together on the other side. It works for basic queries haven't tested on much advanced. But I do processing on the other side in Perl which is accessing JavaPengine using the Inline::Java module, so pretty soon I should have a much quicker Perl -> Prolog interface working thanks to this work, which is a big help with my projects. Thank you! If you are interested I can upload the wrapper.

  2. Anniepoo commented on Aug 9, 2020

    @Anniepoo
    Collaborator

    if you publish the wrapper I'm sure it'd be useful for somebody. Let me know, I'll announce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions