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 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

I have a emacs mode hook code (defun php-mode-hook () (setq tab-width 4 c-basic-offset
I have this ecl-make.lisp: (asdf:oos 'asdf:compile-op :stumpwm) (defun system-objects (system) (loop for component in
I have the following code (defun avg-damp(f) #'(lambda(x) (/ (+ (funcall f x) x)
Is it possible to write an interactive defun with code r that has an
Still struggling to understand what best practices are with respect to macros. I'm attempting
I wrote the function (defun test () (let ((str1 foo) (str2 bar)) (loop for
I am trying to make a simple keybinding to the na function. When I
I have a function to compress my pdf file using pdftk: (defun compresspdf (filename)
I have the following code that runs figlet that has input as a range.
(defun returnFirstCharacter(p) (if (symbolp p) (char (symbol-name p) 0) nil) ) (defun returnRestCharacters (p)

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.