5
\$\begingroup\$

This question already has an answer here:

What general tips do you have for golfing in Common Lisp? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Common Lisp (e.g. "remove comments" is not an answer).

Please post one tip per answer.

\$\endgroup\$

marked as duplicate by primo code-golf Dec 15 '18 at 6:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Narrower version of Tips for golfing in Lisp. \$\endgroup\$ – user48538 Aug 9 '16 at 11:18
  • 2
    \$\begingroup\$ @zyabin101 right. I thought that since original topic didn't have too many answers, and Lisp itself is a huge family, I might as well ask for a specific language. \$\endgroup\$ – MatthewRock Aug 9 '16 at 11:19
2
\$\begingroup\$

Use ' (quote) as synonym for "" for single words.

Quote stops evaluation of symbol, allowing you to e.g. print it. Note that the casing is dependant on *print-case* variable (most of the time it's in the upcase).

(print"yes")
(print'yes) ; saved a byte!
\$\endgroup\$
1
\$\begingroup\$

Use the best looping construct for the job

Use looping constructs that are as short as possible - loop for is rarely the way to go:

  • (dotimes(i <number>)) to loop a certain number of times
  • (mapcan lambda list) to map a list
  • (mapcar lambda list) to map and flatten a list
  • (do((var1 initialvalue1 nextvalue1)(var2 initialvalue2 nextvalue2)...)((endcondition)returnvalue)) for more complex loops
  • (map'string body list) to map string -> string
  • (map nil body list) to iterate over a list
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.