String matching: Difference between revisions

→‎{{header|Lang5}}: rev. rotation of string
(→‎{{header|Lang5}}: rev. rotation of string)
Line 822:
 
=={{header|Lang5}}==
<lang lang5>: 2array 2 compress ; : bi* '_ set dip _ execute ; : bi@ dup bi* ;
: comb "" split ; : concat "" join ; : dip swap '_ set execute _ ;
: first 0 extract swap drop ; : flip comb reverse concat ;
 
: contains
"swap 'comb length" bi@ swaplength do 4 3 _roll 2 compress reshape # create a matrix.
1 - "dup 1 1 compress rotate" dip dup 0 == if break then
shape dup first iota swap reshape -1 transpose first -rot # position.
loop drop length compress swap drop
"length 1 -" bi@ rot 0 0 "'2array dip" '2array bi* swap 2array slice reverse
: concat.(*) concat ;
'concat "'concat. apply" bi* eq 1 1 compress index collapse
length if expand drop else drop 0 then ; # r: position.
extract swap drop ; # result: positon.
: end-with 'flip bi@ start-with ;
: start-with 'comb bi@ length rot swap iota subscript 'concat bi@ eq ;
Anonymous user