combining two variables into one function name in macro

后端 未结 4 1284
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 22:18

I was toying around with macros and clos, where I created an \"object\" macro to create instances

(defmacro object (class &rest args)
  `(make-instance \         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 22:40

    This function creates symbols from string designators:

    (defun symb (&rest args)
      (intern (format nil "~{~a~^-~}" (mapcar #'string args))))
    

    The function uses format, yet passes Joshua's test:

    CL-USER> (symb 'foo :bar "BAZ")
    FOO-BAR-BAZ
    NIL
    CL-USER> (defun foo-bar ()
               (print 'hello))
    FOO-BAR
    CL-USER> (foo-bar)
    
    HELLO 
    HELLO
    CL-USER> (setf *print-case* :capitalize)
    :Capitalize
    CL-USER> (funcall (symb 'foo 'bar))
    
    Hello 
    Hello
    

提交回复
热议问题