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

  • Home
  • SEARCH
  • 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 1091425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:31:32+00:00 2026-05-16T23:31:32+00:00

Little help here please . I am trying to create this lisp macro which

  • 0

Little help here please . I am trying to create this lisp macro which takes a list (of numbers) as input and returns the sum of those numbers. The code

(setf g (list 1 2 3 4))

(defmacro add-test(var)
    `(+ ,@var))

(add-test g) gives this error

The value G is not of type LIST.
[Condition of type TYPE-ERROR]

At the same time (add-test (1 2 3 4)) gives the correct result which is 10.

Can you please explain , why is it not working when variable is passed in to the function?

Other details –

Lispbox – SBCL

Ubuntu Linux

Thanks in advance

  • 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-05-16T23:31:33+00:00Added an answer on May 16, 2026 at 11:31 pm

    That’s easy and one of the most common macro questions.

    (add-test g)
    

    Now on macro expansion, the macro ADD-TEST is called with the parameter VAR getting the value G, a symbol.

    Then you try a list operation. The backquote expression

    `(+ ,@var)
    

    The value of VAR is G, and you try to splice that into the list (+ ... ). Now the returned expression is (+ . G).

    CL-USER 12 > (macroexpand '(add-test g))
    (+ . G)
    T
    

    (+ . G) is not a valid Lisp form. It’s not valid source code.

    Remember, the parameters to a Macro are the unevaluated source expressions.

    Compare that with the following:

    CL-USER 13 > (macroexpand '(add-test (1 2 3 4)))
    (+ 1 2 3 4)
    T
    

    You said: ‘Can you please explain, why is it not working when variable is passed in to the function?’

    Remember, ADD-TEST is NOT a function, it is a macro. A macro gets the source code passed and returns a new form – that form is then later evaluated.

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

Sidebar

Related Questions

I need a little help here please.What am trying to do is pull all
A little help here to figure out what error to run this piece of
I would need little help here. I'm trying to get the git respository from
I was hoping someone could offer me a little help here please. I have
I need a little help here: I get a file from an HTML upload
hy, i need a little help here: i use SWFupload to upload images! in
Need a little help with my jquery here I want all my button with
I need a little help with an if statement in php. I'm trying to
Could someone help me with this issue. I'm trying to figure out how to
Would anyone be able to help me here please. I'm fairly new to VB.net

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.