Merging symbols in common lisp

前端 未结 3 1915
南旧
南旧 2021-01-14 18:07

I want to insert a char into a list. However, I want to merge this char with the last symbol in the list. With appends and cons the result is always two different symbols.

3条回答
  •  情歌与酒
    2021-01-14 18:22

    Define this:

    (defun symbol-append (&rest symbols) 
      (intern (apply #'concatenate 'string 
                     (mapcar #'symbol-name symbols))))
    

    and then use it as:

    * (symbol-append 'a 'b 'c)
    ABC
    
    * (apply #'symbol-append '(a b c))
    ABC
    

    If you expect your arguments to contain stuff besides symbols, then replace symbol-name with:

       (lambda (x)
         (typecase x ...)) 
    

    or a pre-existing CL function (that I've forgotten :() that stringifies anything.

提交回复
热议问题