Strings and Pattern Matching
The polyadic function @s can be used to concatenate n (n >= 2) strings. The
polyadicity is a syntactic fiction maintained by the Shen reader. (@s "a" "b" "c")
is parsed as (@s "a" (@s "b" "c")) exactly in the manner of @p.
The Shen reader parses (@s "123" "456") in a special way; as (@s "1" (@s "2" (@s "3" "456"))).
The leading argument, if a string, is decomposed into a series of concatenations of unit strings.
The significance of this is realised in the use of @s for pattern-matching over strings.
@s is not a fast operation because many platforms represent strings as vectors and in these
cases @s runs in linear time in respect of the size of the arguments.
Within a function @s may be used for pattern-matching. For example; the following removes
all occurences of my Christian name from a string.
(define remove-my-name
{string --> string}
"" -> ""
(@s "Mark" Str) -> (remove-my-name Str)
(@s S Str) -> (@s S (remove-my-name Str)))
which is parsed into the following.
(define remove-my-name
{string --> string}
"" -> ""
(@s "M" (@s "a" (@s "r" (@s "k" Str)))) -> (remove-my-name Str)
(@s S Str) -> (@s S (remove-my-name Str))) |