Well known from html, marquee is clearly the pinnacle of the Semantic Web. Or rather its nadir side by side with the blink tag. In any case, how can we represent marquee in Prolog? In other words, how to define a relation marquee/2
such that the following holds:
?- 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
; ... .
So how can I define marquee/2
in ISO Prolog just using the Prolog prologue? The double quotes above assume set_prolog_flag(double_quotes, chars)
, and the answer write option max_depth(0)
needs to be set to get the entire string.
What I have tried is member/2
but it only describes the characters and then I tried nth0/3
and nth1/3
but they only described two characters in sequence as in:
?- 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
; ... .
Edit: one clarification about the repetitions. They should fit together seamlessly, as in
?- marquee("! ",M).
M = "! "
; M = " !"
; M = "! "
; M = " !"
; M = "! "
; M = " !"
; M = "! "
; M = " !"
; M = "! "
; M = " !"
; ... .
First, hat tip to this answer and the author, @brebs.
I looked at marquee_/3
... and append/3
looked back at me—with shuffled arguments.
So here's the minimally updated version of marquee/2
:
marquee(L,M) :- append(L,R,LD), append(R,M,LD). % was: marquee_(LD,R,M)
Sample queries:
?- marquee("prolog",Xs).
Xs = "prolog"
; Xs = "rologp"
; Xs = "ologpr"
; Xs = "logpro"
; Xs = "ogprol"
; Xs = "gprolo"
; Xs = "prolog"
; Xs = "rologp"
; ... .
?- marquee("",Xs).
Xs = []
; Xs = []
; ... .