Prolog 中的字幕

问题描述 投票:0回答:1

众所周知, 显然是语义网的顶峰。或者更确切地说,它的最低点与闪烁标签并排。无论如何,我们如何在 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
;  ... .

那么如何仅使用

Prolog prologue
在 ISO Prolog 中定义 marquee/2?上面的双引号假设为
set_prolog_flag(double_quotes, chars)
,并且需要设置答案写入选项
max_depth(0)
才能获取整个字符串。

我尝试过的是

member/2
,但它只描述了字符,然后我尝试了
nth0/3
nth1/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
;  ... .

(将给予赏金。对于今年迄今为止的赏金接受者,请不要发帖。)

prolog marquee
1个回答
0
投票

我不确定这是否满足您的所有要求,希望如此

marquee(Ls, M):- 
    length(Ls, Len), 
    Max is Len-1,
    between(0, Max, Roll),
    roll(Ls, M, Roll).

lis_pos_elem(Lis, Pos, Elem) :- nth1(Pos, Lis, Elem).

new_index(Shift, Max, I1, I2):-
    I is I1 - Shift,
    ( 
        I < 1,
        I2 is Max + I
    ;
        I2 = I
    ), !.

roll(L,L,0).
roll(L1,L2,R):-
    R > 0,
    length(L1, Len),
    numlist(1, Len, Index),
    maplist(new_index(R, Len), Index, ShiftedIndexes), 
    maplist(lis_pos_elem(L1), ShiftedIndexes, L2).
?-
marquee("Prolog is marquee ready! ", M); true.
M = ['P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' '] ;
M = [' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !] ;
M = [!, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y] ;
M = [y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d] ;
M = [d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a] ;
M = [a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e] ;
M = [e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r] ;
M = [r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' '] ;
M = [' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e] ;
M = [e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e] ;
M = [e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u] ;
M = [u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r, q] ;
M = [q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a, r] ;
M = [r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', m, a] ;
M = [a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i, s, ' ', 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] ;
M = [s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' ', i] ;
M = [i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g, ' '] ;
M = [' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o, g] ;
M = [g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l, o] ;
M = [o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o, l] ;
M = [l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r, o] ;
M = [o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P', r] ;
M = [r, o, l, o, g, ' ', i, s, ' ', m, a, r, q, u, e, e, ' ', r, e, a, d, y, !, ' ', 'P'] ;
true.
© www.soinside.com 2019 - 2024. All rights reserved.