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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:53:24+00:00 2026-05-19T14:53:24+00:00

(defun make-it-5 (num) (setq num 5)) (setq a 0) (make-it-5 a) ;; now a

  • 0
(defun make-it-5 (num)
  (setq num 5))
(setq a 0)
(make-it-5 a)
;; now a is still 0, not 5.

In the above code, it seems neither (setq a 5) nor (setq 0 5) happens. If (setq a 5) happened, then a would have changed to 5, but a is still 0. If (setq 0 5) happened, Lisp error would have occurred. What does happen? That is my question.

For some of you who got here by googling and wondering how to make make-it-5 work as its name suggest, one way is

(defmacro make-it-7 (num) ; defmacro instead of defun
  `(setq ,num 7))
(setq a 0)
(make-it-7 a)
;; now a is 7.

Another is:

(defun make-it-plus (num-var)
  (set num-var (+ 1 (symbol-value num-var))) ; `set' instead of `setq'
) 
(setq a 0)
(make-it-plus 'a) ; 'a instead of a
;; now a is 1.
  • 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-19T14:53:25+00:00Added an answer on May 19, 2026 at 2:53 pm

    The short answer is that the (setq num 5) changes the binding for num, which is a binding local to the make-it-5 function.

    A breakdown follows. It’s good to make sure you’re familiar with the notion of evaluation.

    When the (make-it-5 a) is evaluated, the interpreter looks for a function in the first element of the expression. In this case, the first element is a symbol (make-it-5 – which means it is a named function), so it looks in the symbol’s function cell. Note: this lookup can repeat itself, see Symbol Function Indirection.

    The rest of the elements of the expression are evaluated to find values. In this case, there’s just one symbol (a), and so the interpreter returns the contents of its value cell, which is 0.

    The interpreter then applies the function to the list of arguments, which involves making local bindings between its arguments to the values passed in. In this case, a local binding between the symbol num and the value 0 is made. Then the body of the function is evaluated in that environment.

    The body is just a single expression which is a “call” to setq. I put “call” in quotes because setq is a special form and doesn’t evaluate its first argument, but looks up the symbol and sets the most local existing binding, which is the binding created inside the function make-it-5.

    So, you’re changing the binding for the symbol num which is local to the function make-it-5.

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

Sidebar

Related Questions

Why does this code not print out the content of the array - (defun
The following code will raise: SYSTEM::%EXPAND-FORM: (SETQ NUM (SUBSTRING LINE 6)) should be a
I thought this would work: (defun my-node () (interactive) (pop-to-buffer (make-comint my-node node))) But
I have the following Common Lisp code: (defun micro-read-eval-print () (format t Micro >
I modified my .emacs file to make auto-backups hidden files via the following code:
I have this ecl-make.lisp: (asdf:oos 'asdf:compile-op :stumpwm) (defun system-objects (system) (loop for component in
The Emacs code for apply-partially is this: (defun apply-partially (fun &rest args) Return a
I have the following code (defun avg-damp(f) #'(lambda(x) (/ (+ (funcall f x) x)
(defun foo () message hello) I want to binding the function foo to key
I use the following smart-tab defun in my .emacs for either completion on a

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.