Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:22:38+00:00 2026-06-16T09:22:38+00:00

There is something I can’t understand about Common lisp. Assume I’m writing a macro

  • 0

There is something I can’t understand about Common lisp.

Assume I’m writing a macro similar to this:

(defmacro test-macro () 
   (let ((result (gensym))) 
      `(let ((,result 1))
         (print (incf ,result))))) 

Than I can do

> (test-macro)
2
2

Now I want to see how it expands

> (macroexpand-1 '(test-macro))
(LET ((#:G4315 1)) (PRINT (INCF #:G4315))) ;
T

Ok. There are unique symbols generated with gensym that were printed as uninterned.

So as far as I know the uninterned symbols are the symbols for which the evaluator does’t create symbol-data binding internally.

So, if we macro-expand to that form there should be an error on (incf #:G4315).
To test this we can just evaluate that form in the REPL:

> (LET ((#:G4315 1)) (PRINT (INCF #:G4315)))
*** - SETQ: variable #:G4315 has no value

So why does the macro that expands to this string works perfectly and the form itself does not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:22:40+00:00Added an answer on June 16, 2026 at 9:22 am

    Symbols can be interned in a package or not. A symbol interned in a package can be looked up and found. An uninterned symbol can’t be looked up in a package. Only one symbol of a certain name can be in a package. There is only one symbol CL-USER::FRED.

    You write:

    So as far as I know the uninterned symbols are the symbols for which the evaluator does’t create symbol-data binding internally.

    That’s wrong. Uninterned symbols are symbols which are not interned in any package. Otherwise they are perfectly fine. interned means registered in the package’s registry for its symbols.

    The s-expression reader does use the symbol name and the package to identify symbols during reading. If there is no such symbol, it is interned. If there is one, then this one is returned.

    The reader does look up symbols by their name, here in the current package:

     (read-from-string "FOO") -> symbol `FOO`
    

    a second time:

     (read-from-string "FOO") -> symbol `FOO`
    

    it is always the same symbol FOO.

     (eq (read-from-string "FOO") (read-from-string "FOO"))  -> T
    

    #:FOO is the syntax for an uninterned symbol with the name FOO. It is not interned in any package. If the reader sees this syntax, it creates a new uninterned symbol.

     (read-from-string "#:FOO") -> new symbol `FOO`
    

    a second time:

     (read-from-string "#:FOO") -> new symbol `FOO`
    

    Both symbols are different. They have the same name, but they are different data objects. There is no other registry for symbols, than the packages.

     (eq (read-from-string "#:FOO") (read-from-string "#:FOO"))  -> NIL
    

    Thus in your case (LET ((#:G4315 1)) (PRINT (INCF #:G4315))), the uninterned symbols are different objects. The second one then is a different variable.

    Common Lisp has a way to print data, so that the identity is preserved during printing/reading:

    CL-USER 59 > (macroexpand-1 '(test-macro))
    (LET ((#:G1996 1)) (PRINT (INCF #:G1996)))
    T
    
    CL-USER 60 > (setf *print-circle* t)
    T
    
    CL-USER 61 > (macroexpand-1 '(test-macro))
    (LET ((#1=#:G1998 1)) (PRINT (INCF #1#)))
    T
    

    Now you see that the printed s-expression has a label #1= for the first symbol. It then later references the same variable. This can be read back and the symbol identities are preserved – even though the reader can’t identify the symbol by looking at the package.

    Thus the macro creates a form, where there is only one symbol generated. When we print that form and want to read it back, we need to make sure that the identity of uninterned symbols is preserved. Printing with *print-circle* set to T helps to do that.

    Q: Why do we use uninterned generated symbols in macros by using GENSYM (generate symbol)?

    That way we can have unique new symbols which do not clash with other symbols in the code. They get a name by the function gensym– usually with a counted number at the end. Since they are fresh new symbols not interned in any package, there can’t be any naming conflict.

    CL-USER 66 > (gensym)
    #:G1999
    
    CL-USER 67 > (gensym)
    #:G2000
    
    CL-USER 68 > (gensym "VAR")
    #:VAR2001
    
    CL-USER 69 > (gensym "PERSON")
    #:PERSON2002
    
    CL-USER 70 > (gensym)
    #:G2003
    
    CL-USER 71 > (describe *)
    
    #:G2003 is a SYMBOL
    NAME          "G2003"
    VALUE         #<unbound value>
    FUNCTION      #<unbound function>
    PLIST         NIL
    PACKAGE       NIL                      <------- no package
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way of going about this. Is there something I can put
Is there something I can do like this (perhap via a plugin) if (
There is something I can't digest. I'm learning some assembler and right now I'm
Is there an IDE/Tool/script/something that can show call hierarchy and/or data flow in Scala+Java
Is there any way that you can detect the resizeHandlers moment of completion? something
Is there any way I can send an email, like any frameworks or something.
Is there a function that can round a float in Fsharp? Something like round(3.21156,3)
Is there a command that can append one array of char onto another? Something
Just curious, is there a format string I can use to output something like
I have some path c:\server\folderName1\another name\something\another folder\ . How i can extract from there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.