Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

Tau Prolog behaving differently from sandbox

$
0
0

Issue: Program that works perfectly in Tau Prolog online interpretator behaves differently when executed on a local machine. [Using HTML and Javascript]

Error has been traced to the if,else if, else predicate used in Prolog(E.g (X->A;B->C;D) Tried to fix: Using --> instead of ->, adding in round brackets around the whole expression.

Might be helpful: when list library is imported, some parts of the library is able to be used, while others cannot when run on the local computer. Specifically, the subtract function is the list library. Therefore, suspected that there might be an issue with the javascript file downloaded from Tau Prolog where everything is selected. Although the snippet below does not include the subtract function, it is brought up in case it is a hint to the problem. Editor used: Visual Studio code. http://tau-prolog.org/downloads

:-use_module(library(lists)).
memberchk(X,[X|_]) :- !.
memberchk(X,[_|T]):- memberchk(X,T).
subtract([], _, []).
subtract([Head|Tail], L2, L3) :-
                memberchk(Head, L2),
                !,
                subtract(Tail, L2, L3).
subtract([Head|Tail1], L2, [Head|Tail3]) :-
                subtract(Tail1, L2, Tail3).
main([chicken, tuna]).
meals([healthy,vegan,veggie,value]).
:-dynamic(chosen_main/1).
:-dynamic(chosen_meals/1). 
chosen_main([]).
chosen_meals([]).
ask_meals(X):-
            meals(X).
ask_main(X):-chosen_meals([vegan])->X = [nothing];
             chosen_meals([veggie])->X = [nothing];
             main(X).

Expected output of ask_main(X) query: X = [chicken, tuna]. This is true when the online Tau Prolog Interpreter is used. However, the result is as below when done using the following query on Javascript:

    var session = pl.create(1000);
    var program = document.getElementById("program").innerHTML;
    session.consult(program);
    console.log("ask_main(X).");
    session.query("ask_main(X).");
    session.answers(showResults(), 1000);

Result: Term {ref: 7051, id: "throw", args: Array(1), indicator: "throw/1"},

which when expanded gives:

args: (2) [Term, Term]
id: "existence_error"
indicator: "existence_error/2"
ref: 7047

Note: The query

session.query("ask_meals(X).");
session.answers(showResults(), 1000);

when executed locally prints out[healthy, vegan, veggie, value], which is valid. Please help, I think I'm going crazy soon.


Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>