Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the equivalent of EXPLODE and IMPLODE in Common Lisp?

0
Posted

What is the equivalent of EXPLODE and IMPLODE in Common Lisp?

0

Hopefully, the only reason you need to do this is as part of trying to port some old MacLisp code to Common Lisp. These functions predated the inclusion of strings as a first-class data type in Lisp; symbols were used as strings, and they ere EXPLODEd to allow the individual characters to be manipulated in a list. Probably the best approximations of these are: (defun explode (object) (loop for char across (prin1-to-string object) collect (intern (string char)))) (defun implode (list) (read-from-string (coerce (mapcar #’character list) ‘string))) An alternate definition of EXPLODE which uses MAP instead of LOOP is: (defun explode (object) (map ‘list #'(lambda (char) (intern (string char))) (prin1-to-string object))) The creation of N conses of garbage to process a string of N characters is a hideously inefficient way of doing the job. Rewrite EXPLODE code with PRIN1-TO-STRING, or better STRING if the arguments are symbols without funny characters. For IMPLODE, try to make its caller use

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123