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 8833455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:47:00+00:00 2026-06-14T08:47:00+00:00

I’m confused about the difference between a macro and a function; specifically why PART

  • 0

I’m confused about the difference between a macro and a function; specifically why PART TWO fails below given that PART ONE succeeds.

(defun foo () "foo")
(setf a 3) ;; sets the symbol value cell to 3
(setf a #'foo) ;; PART ONE
(funcall a) ;; returns foo

(defmacro bar () "bar")
(setf b #'bar) ;; Error the macro name bar was found as an argument to function PART TWO
  • 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-14T08:47:01+00:00Added an answer on June 14, 2026 at 8:47 am

    The # (sharpsign) is a standard macro character which is a dispatch macro character. It’s supposed to compose with another character. The #' (sharpsign single-quote) combination expects a function name or lambda expression after it, and it expands to (function expression).

    So, #'foo is expanded at read-time to (function foo). If foo is a function, function will evaluate to it. In a lexical scope, it may be a foo fbound by a flet or labels. If there’s no such lexical definition, it’ll try to fetch the global function definition from the symbol’s function.

    Now, (function bar) signals an error when bar represents a macro, be it a lexical macrolet or a global defmacro. You may, however, use (macro-function 'bar) to fetch the macro function of the global bar macro. If it exists, it’s a function of two arguments: a form and an environment.

    Unless you’re going to apply bar‘s macro function to forms, it’s probably not what you want. Let’s think about applying the macro function of and: it will not do a logical boolean operation, it’ll probably expand the given form into an if.

    However, if this is what you want, remember that macro-function has a second optional parameter, an environment. You may get an environment as argument in a defmacro or in a define-setf-expander. Within the latter, it’s usually needed so that get-setf-expansion takes into account the lexical environment in expanding a subform.

    Try this out:

    (funcall (macro-function 'and) '(and form1 form2 form3) nil)
    

    Exercise: Implement your own macroexpand-1 and macroexpand.

    Exercise: Implement a macroexpand-all, a macroexpand that recurses into subforms, recognizing Common Lisp’s special operators.

    Note: Don’t get too far with macroexpand-all, it needs a code walker, which is implementation-specific.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

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.