Page 1 of 1

ends-with

Posted: Fri Feb 12, 2010 9:52 pm
by Kazimir Majorinc
currently:

(ends-with "hiho" "ho") => true
(ends-with '(h i h o) 'o) => true

should it be:

(ends-with '(h i h o) '(o)) => true
(ends-with '(h i h o) '(h o)) => true ?

same for starts-with

Re: ends-with

Posted: Sat Feb 13, 2010 1:30 am
by Lutz
I believe when using lists, you mostly look for the single element with 'starts/ends-with'.

But you could use 'match' for that case:

Code: Select all

> (match '(* h o) '(h i h o))
((h i))
> (match '(h i *) '(h i h o))
((h o)) 
> (match '(x y *) '(h i h o))
nil
> 
the first two cases are Boolean 'true'

Ps: there was a time when 'match' could also be used for strings, but it got deprecated for the more powerful regex string matching. Although less powerful, perhaps the string matching with 'match' had some attractiveness to it? It definitely was easier to grasp mentally.