| strings.arc defines endmatch as (mac endmatch (pat string)
(w/uniq (gstring glen)
`(withs (,gstring ,string ,glen (len ,gstring))
(unless (> ,(len pat) (len ,gstring))
(and ,@(let acc nil
(forlen i pat
(push `(is ,(pat (- (len pat) 1 i))
(,gstring (- ,glen 1 ,i)))
acc))
(rev acc)))))))
yet, this seems to do the expected job: (def match-end (pat str)
(is (cut str (-:len pat)) pat))
What's more, this doesn't work (endmatch (get-a-string-from-somewhere) str)
, because endmatch is expecting a literal string for its "pat" argument - "pat" is not unquoted anywhere inside endmatch.Is endmatch more efficient? Or what is the advantage of writing it this way? |