Questions tagged [swi-prolog-for-sharing]

SWI-Prolog for Sharing, or SWISh for short, is an online version of SWI-Prolog

SWI-Prolog for Sharing, or SWISh for short, is an online implementation of a limited subset of SWI-Prolog.

It's found at swish.swi-prolog.org.

23 questions
7
votes
2 answers

Reading a cut ! in Prolog

I am reading through Learn Prolog Now! 's chapter on cuts and at the same time Bratko's Prolog Programming for Artificial Intelligence, Chapter 5: Controlling Backtracking. At first it seemed that a cut was a straight-forward way to mimic an if-else…
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
2
votes
1 answer

Extracting list of items between two values in a list - prolog

Say I have a unique list of length 9 of the values between 1 and 9 inclusive in a random order (think sudoku), and I want to extract a the sub-list of the items that occur between the values 1 and 9 (exclusive). IE:…
Tim Hope
  • 784
  • 1
  • 7
  • 17
2
votes
1 answer

Binomial Coefficient [Prolog]

bc(0,N,R,R):- N>0,R is 1,!. bc(M,0,R,R):- M>0,R is 1,!. bc(N,N,R,R):- R is 1,!. bc(M,N,R,R1):- M1 is M - 1, N1 is N - 1, bc(M1,N1,R,R2), bc(M1,N,R,R3), R1 is R2+R3. Why does it return false? Task is: Write recursive procedure…
2
votes
1 answer

Error while using the write predicate in Prolog

I was exploring the write predicate in Prolog but it behaves differently at times. I did go through some posts but I am unable to spot the catch. Predicate : explore_write_predicate(InputList,Index):- TempIndex is Index+1, …
Akash Chugh
  • 65
  • 2
  • 8
1
vote
1 answer

Prolog Can't get to the predicate

The prolog is supposed to find the order of five statements statements. Everything is working fine but when i call the query solution([A, B, C, D, E]) I get a sandbox error like this: The Error: Sandbox restriction! Could not derive which predicate…
RoboC
  • 75
  • 5
1
vote
1 answer

Evaluate a string term in prolog

I'm trying to create a prolog program which receives the queries to run as strings (via json) and then print the result (succeed or fails). :- use_module(library(http/json)). happy(alice). happy(albert). with_albert(alice). does_alice_dance :-…
Amdouni Mohamed Ali
  • 410
  • 1
  • 4
  • 18
1
vote
0 answers

Reliably find quasi_quotations implementations

How to find which quasi_quotations implementations are available in a given SWI-Prolog, installed from source, or a locally installed SWISH ? I tried to search for the key implementation quasi_quotation_syntax or quasi_quotation, and found just the…
CapelliC
  • 59,646
  • 5
  • 47
  • 90
1
vote
2 answers

Two lists have at least one common element without Prolog built-in predicates

I am new to prolog.I want to write compare_lists/2 which will compare 2 lists and return true if they have at least one common element. I know this can be done with something like that common_list([H|_],T) :- member(H,T). common_list([_|T],L) :-…
1
vote
2 answers

How to remove the repeated members in a simple list [ prolog ]

EDIT : How can I remove the repeated members in a simple list for example : [a,b,b,b,c,c,e] in this list the are 2 c and 3 b and I want to remove all members that's repeated the result should be like this [a,e] keep in mind I'm just learning…
1
vote
1 answer

How to bypass arguments not instantiated on SWI-Prolog online editor?

I'm using SWISH to write Prolog and I've got a program that converts minutes into hours. My output for minutes is fine however my hours outputs as H = 0+1+1 rather than H = 2. Is there any way that I can fix this? I've tried using a #= instead of =…
ParadAUX
  • 53
  • 1
  • 8
1
vote
2 answers

Defining a type hierarchy including function types in Prolog

I'm revisiting Prolog after studying it in college, and would like to describe a type hierarchy that includes function types. So far, this is what I got (SWISH link): % subtype/2 is true if the first argument is a direct subtype of % the…
Bruno Kim
  • 2,300
  • 4
  • 17
  • 27
1
vote
0 answers

How to use python flask to read/write from/to pyswip?

I was trying to use pyswip to create a Q&A (interactive user) python swi-prolog program and I couldn't find a good way to read/write from/to pyswip using python flask. The app is originally a web application and I'm using flask to run the python…
1
vote
1 answer

How to bound all combinations prolog search with clp(fd)?

The thing I wanted to do was generate all combinations of elements from a given list. E.g.: From [a,b,c], I might want: [] [a] [b] [c] [a,a] [a,b] [a,c] [b,a] ... And so on. Perhaps there is a magical prolog one-liner that does this. If so, I…
Stephen Foster
  • 389
  • 1
  • 8
1
vote
1 answer

Swish import RDF

Is it possible to import an rdf file from a URL into Swish? I.e. something like: myload:- load_rdf('www.myrdf.com'). Then I could query ?-rdf(A,B,C)
user27815
  • 4,767
  • 14
  • 28
1
vote
2 answers

Using insert predicate in SWI-Prolog swish?

I'm trying to execute what seems like a simple three lines of code insert(X,[],[X]). insert(X,[H|T],Z):-X>=H,Z=[X,H|T]. insert(X,[H|T],Z):-X
Aaron_H
  • 1,623
  • 1
  • 12
  • 26
1
2