Am I missing some important fact about interning symbols in LISP?

前端 未结 3 970
北荒
北荒 2021-01-21 17:50

To be brief. Here is my several tries to intern and use a symbol in clisp.

 [1]> (setq sym (intern \"foo\"))
 |foo|
 [2]> (eq sym \'foo)
 NIL
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 18:03

    The case-sensitivity of the Common Lisp reader is determined by the readtable:

    (readtable-case *readtable*)
    

    Typically the reader will initially intern symbols in uppercase (unless you explicitly escape characters). Hence:

    (eq (intern "foo") 'foo) => NIL

    (eq (intern "FOO") 'foo) => T

    (eq (intern "FOo") 'fo\o) => T

    You can use backquote syntax to build the form for eval:

    (let ((abc 2))
      (eval `(+ 2 ,abc)))
    

    => 4

提交回复
热议问题