An Elisp Puzzle

Xah Lee points to this interesting tweet The three S’s of SUCCESS by Gary Fredericks and asks for something similar in Elisp. Fredericks’ code is

(map (vec "SUCCESS") [0 5 6])

which certainly isn’t Elisp.

My first attempt at Elisp is

(mapcar (apply-partially #'aref "SUCCESS") '(0 5 6))

which does the trick but outputs the results as integers

(83 83 83)

because that’s how Emacs represents characters.

If we want to print out the actual S’s we need to wrap the above in some extra code

(mapcar #'char-to-string (mapcar (apply-partially #'aref "SUCCESS") '(0 5 6)))

which yields

("S" "S" "S")

What we really need here is something like the Common Lisp char function that outputs the actual characters but, of course, Emacs can only do this my making strings. On the other hand, CL lacks the nice currying function apply-partially so I don’t see a nice succinct solution in it either.

Update Noam has a much better solution in the comments.

This entry was posted in Programming and tagged , . Bookmark the permalink.