prolog

Can higher order Prolog help closure expansion?

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-05 07:28:18
问题 If I enter this code in SWI-Prolog: goal_expansion(println(X), (write(X), nl)). test :- call(println, 'Hello World!'). Listing shows me this result: test :- call('__aux_wrapper_8a89205eca9a6ffb31dd01cc968a2aa022fa1f49', 'Hello World!'). '__aux_wrapper_8a89205eca9a6ffb31dd01cc968a2aa022fa1f49'(A) :- write(A), nl. Would a higher order Prolog do the same? Are there higher order Prologs that have goal expansion and/or closure expansion? 来源: https://stackoverflow.com/questions/65289298/can-higher

How do I create a DCG rule inverse to another in Prolog?

a 夏天 提交于 2021-01-04 06:40:43
问题 I am writing a Commodore BASIC interpreter in Prolog, and I am writing some DCGs to parse it. I have verified the DCGs below to work except for the variable one. My goal is this: for anything which isn't a boolean, integer, float, or a string, it's a variable. However, anything that I give it via phrase just results in no . bool --> [true]. bool --> [false]. integer --> [1]. % how to match nums? float --> [0.1]. string --> [Str], {atom_chars(Str, ['"' | Chars]), last(Chars, '"')}. literal -->

How do I create a DCG rule inverse to another in Prolog?

烈酒焚心 提交于 2021-01-04 06:39:29
问题 I am writing a Commodore BASIC interpreter in Prolog, and I am writing some DCGs to parse it. I have verified the DCGs below to work except for the variable one. My goal is this: for anything which isn't a boolean, integer, float, or a string, it's a variable. However, anything that I give it via phrase just results in no . bool --> [true]. bool --> [false]. integer --> [1]. % how to match nums? float --> [0.1]. string --> [Str], {atom_chars(Str, ['"' | Chars]), last(Chars, '"')}. literal -->

How do I create a DCG rule inverse to another in Prolog?

。_饼干妹妹 提交于 2021-01-04 06:39:26
问题 I am writing a Commodore BASIC interpreter in Prolog, and I am writing some DCGs to parse it. I have verified the DCGs below to work except for the variable one. My goal is this: for anything which isn't a boolean, integer, float, or a string, it's a variable. However, anything that I give it via phrase just results in no . bool --> [true]. bool --> [false]. integer --> [1]. % how to match nums? float --> [0.1]. string --> [Str], {atom_chars(Str, ['"' | Chars]), last(Chars, '"')}. literal -->

lists in new list in prolog without using flatten/2 [duplicate]

£可爱£侵袭症+ 提交于 2021-01-04 06:35:06
问题 This question already has answers here : Flatten a list in Prolog (7 answers) Closed last month . I am retrieving multiple lists from lists and put them into a new list. But I want to make the new list of individual items and not a list with lists. So say I have the list [[a,b],c,[d,e]] I would like to get [a,b,c,d,e]. How do I go about this? 回答1: To use an example code snipping from a random question today: assume you have a knowledge base as follows: step('pancakes', 1, 'mix butter and

How to draw right triangle using recursion in prolog?

折月煮酒 提交于 2021-01-04 04:34:31
问题 I get the answer for this right triangle as shown below: shape:- shape(0, 6). shape(S, A) :- S < A, count(0, S), S1 is S+1, shape(S1, A). shape(S, X) :- S >= X. count(A, B) :- A =< B, write('*'), A1 is A+1, count(A1,B). count(A, B) :- A > B, nl. * ** *** **** ***** ****** What should i modify to print the right triangle of this type? * ** *** **** ***** ****** 回答1: shape(S, _) :- S =< 0. shape(S, N) :- S > 0, S1 is S-1, count(0, S1, N), shape(S1, N). count(A, _, N) :- A >= N, nl. count(A, B,

How to draw right triangle using recursion in prolog?

久未见 提交于 2021-01-04 04:29:39
问题 I get the answer for this right triangle as shown below: shape:- shape(0, 6). shape(S, A) :- S < A, count(0, S), S1 is S+1, shape(S1, A). shape(S, X) :- S >= X. count(A, B) :- A =< B, write('*'), A1 is A+1, count(A1,B). count(A, B) :- A > B, nl. * ** *** **** ***** ****** What should i modify to print the right triangle of this type? * ** *** **** ***** ****** 回答1: shape(S, _) :- S =< 0. shape(S, N) :- S > 0, S1 is S-1, count(0, S1, N), shape(S1, N). count(A, _, N) :- A >= N, nl. count(A, B,

minimum in list of lists in prolog

旧时模样 提交于 2021-01-03 22:33:18
问题 hello i have a list like this: [[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]] list of lists... i want to find the minimum number on inner list in this case i want to return D=2 and L=[a,b,d] i tried this code: minway([[N|L]],N,L). minway([[M|L1]|L2],D,_):- M<D, minway(L2,M,L1). minway([[M|_]|L2],D,L):- M>=D, minway(L2,D,L). but i got error: </2: Arguments are not sufficiently instantiated Exception: (8) minway([[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]], _G7777, _G7778) ? creep for this run sentence:

minimum in list of lists in prolog

送分小仙女□ 提交于 2021-01-03 22:32:32
问题 hello i have a list like this: [[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]] list of lists... i want to find the minimum number on inner list in this case i want to return D=2 and L=[a,b,d] i tried this code: minway([[N|L]],N,L). minway([[M|L1]|L2],D,_):- M<D, minway(L2,M,L1). minway([[M|_]|L2],D,L):- M>=D, minway(L2,D,L). but i got error: </2: Arguments are not sufficiently instantiated Exception: (8) minway([[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]], _G7777, _G7778) ? creep for this run sentence:

minimum in list of lists in prolog

ぃ、小莉子 提交于 2021-01-03 22:28:38
问题 hello i have a list like this: [[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]] list of lists... i want to find the minimum number on inner list in this case i want to return D=2 and L=[a,b,d] i tried this code: minway([[N|L]],N,L). minway([[M|L1]|L2],D,_):- M<D, minway(L2,M,L1). minway([[M|_]|L2],D,L):- M>=D, minway(L2,D,L). but i got error: </2: Arguments are not sufficiently instantiated Exception: (8) minway([[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]], _G7777, _G7778) ? creep for this run sentence: