Prolog 中的字幕

fal*_*lse 4 marquee prolog

来看,显然是语义网的顶峰。或者更确切地说,它的最低点与闪烁标签并排。无论如何,我们如何在 Prolog 中表示选取框?换句话说,如何定义一个关系marquee/2以使以下内容成立:

?- marquee("Prolog is marquee ready! ",M).
   M = "Prolog is marquee ready! "
;  M = "rolog is marquee ready! P"
;  M = "olog is marquee ready! Pr"
;  M = "log is marquee ready! Pro"
;  M = "og is marquee ready! Prol"
;  M = "g is marquee ready! Prolo"
;  M = " is marquee ready! Prolog"
;  M = "is marquee ready! Prolog "
;  M = "s marquee ready! Prolog i"
;  M = " marquee ready! Prolog is"
;  M = "marquee ready! Prolog is "
;  ... .
?- M=[m|_],marquee("Prolog is marquee ready! ",M).
   M = "marquee ready! Prolog is "
;  M = "marquee ready! Prolog is "
;  M = "marquee ready! Prolog is " % infinitely many redundant answers
;  ... .
Run Code Online (Sandbox Code Playgroud)

那么如何仅使用Prolog prologuemarquee/2ISO Prolog中进行定义呢?上面的双引号假设,并且需要设置答案写入选项才能获取整个字符串。set_prolog_flag(double_quotes, chars)max_depth(0)

我尝试过,member/2但它只描述了字符,然后我尝试了nth0/3nth1/3但它们只按顺序描述了两个字符,如下所示:

?- T = "Prolog is marquee ready! ", nth1(I,T,A),nth0(I,T,B).
   T = "Prolog is marquee ready! ", I = 1, A = 'P', B = r
;  T = "Prolog is marquee ready! ", I = 2, A = r, B = o
;  ... .
Run Code Online (Sandbox Code Playgroud)

编辑:关于重复的一项澄清。它们应该无缝地结合在一起,就像

?- marquee("! ",M).
   M = "! "
;  M = " !"
;  M = "! "
;  M = " !"
;  M = "! "
;  M = " !"
;  M = "! "
;  M = " !"
;  M = "! "
;  M = " !"
;  ... .
Run Code Online (Sandbox Code Playgroud)

rep*_*eat 6

首先,向这个答案和作者 @brebs致敬。

\n

我看着marquee_/3……,又用append/3混乱的论点回头看着我\xe2\x80\x94。

\n

所以这是最低限度更新的版本marquee/2

\n
\n选取框(L,M) :-\n 附加(L,R,LD),\n   附加(R,M,LD)。% 为:marquee_(LD,R,M)\n
\n

示例查询:

\n
?- marquee("prolog",Xs).\n   Xs = "prolog"\n;  Xs = "rologp"\n;  Xs = "ologpr"\n;  Xs = "logpro"\n;  Xs = "ogprol"\n;  Xs = "gprolo"\n;  Xs = "prolog"\n;  Xs = "rologp"\n;  ... .\n\n?- marquee("",Xs).\n   Xs = []\n;  Xs = []\n;  ... .\n
Run Code Online (Sandbox Code Playgroud)\n


dam*_*ano 5

这是一个替代解决方案(在评论中提出建议后更新),希望这可以解决任务

marquee(String,String).
marquee([H|T],R):-
    append(T,[H],NewEl),
    marquee(NewEl,R).


?- marquee("Prolog is marquee ready! ", M).
M = ['P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' '];
M = [r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P'];
...

?- M=[m|_],marquee("Prolog is marquee ready! ",M).
M = [m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' '];
M = [m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' '];
...
Run Code Online (Sandbox Code Playgroud)

  • 绝对没用。我已经更新了我的答案 (2认同)