What's the difference between ' and #' in Lisp?

后端 未结 3 664
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 07:39

It seems both

(mapcar \'car \'((foo bar) (foo1 bar1))) 

and

(mapcar #\'car \'((foo bar) (foo1 bar1)))

w

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 08:12

    Try passing an anonymous function (lambda) to your mapcar and you'll see that #' is required since the quote by itself expects a symbol that is bound to a function, but the symbol doesn't exist in an un-named function:

    CL-USER> (mapcar '(lambda (x) (format t "it is ~d" x)) (list 3 5 7))
    ; Evaluation aborted on #.
    

    vs:

    CL-USER> (mapcar #'(lambda (x) (format t "it is ~d" x)) (list 3 5 7))
    it is 3it is 5it is 7
    (NIL NIL NIL)
    

提交回复
热议问题