This Lisp code demonstrates various string operations, similar to the original example. Here’s a breakdown of the functions used:
search: Finds a substring within a string.
count: Counts occurrences of a character in a string.
string= with :end1 or :start1: Checks for prefixes or suffixes.
position: Finds the index of a character in a string.
format with ~{~a~^-~}: Joins strings with a separator.
make-string: Creates a repeated string.
cl-ppcre:regex-replace-all and cl-ppcre:regex-replace: Replace substrings.
cl-ppcre:split: Splits a string into a list.
string-downcase and string-upcase: Convert string case.
To run this program, save it as string-functions.lisp and use your Lisp interpreter. For example, with SBCL:
The output will be similar to:
Note that Lisp uses zero-based indexing, so the “Index” result is 1 (second position) for the ’e’ in “test”. Also, Lisp’s boolean values are T (true) and NIL (false).
The cl-ppcre library is used for regular expression operations, which may need to be installed separately depending on your Lisp environment.