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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:09:07+00:00 2026-05-21T22:09:07+00:00

I’m reading over Peter Norvig’s Paradigms of Artificial Intelligence Programming, and I’ve come across

  • 0

I’m reading over Peter Norvig’s Paradigms of Artificial Intelligence Programming, and I’ve come across an issue I cannot resolve on my own (this is my introduction to Lisp). The issue is quite a small one, really, but obviously not one my little brain can solve.

Why is it that when a function’s value is a lambda, it is an error to use that function as the first element to a list. For example:

Lisp:

(defun some-func ()
  #'(lambda (x) x))

;; At REPL
;; Does not work
> ((some-func) 1)
;; Does work
> ((lambda (x) x) 1)
;; Also works
> (funcall (some-func) 1)

I hope that makes sense!

  • 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-21T22:09:08+00:00Added an answer on May 21, 2026 at 10:09 pm

    This is a good question, and one where Common Lisp can be pretty confusing. The thing is that due to historical reasons, Common Lisp has two namespaces — one for functions and another for values. To make this happen, there are two different evaluation rules for the head position of a function application and for the rest — the first will evaluate a symbol as a function name, and the second will evaluate a symbol as a variable reference. There are obviously cases when the value is actually a function — for example, if you write a mapcar function, you’ll want to do something like

    (defun my-mapcar (f l)
      (if (null l)
        '()
        (cons (f (car l)) (my-mapcar f (cdr l)))))
    

    but this won’t work — it will complain about f being an unknown function. For these cases there is a special function called funcall, which receives a function and argument for the function, and will apply the function as usual — and since funcall is a plain function, its arguments are all evaluated as usual (as values). So the above should be fixed by using it:

    (defun my-mapcar (f l)
      (if (null l)
        '()
        (cons (funcall f (car l)) (my-mapcar f (cdr l)))))
    

    As you probably suspect now, there are the mirror cases — where you want to evaluate something as a function and not as a value. For example, this doesn’t work:

    (my-mapcar 1+ '(1 2 3))
    

    because it refers to the 1+ variable and not the function. For these cases there is a special form called function that evaluates its contents as a function and returns it as a value:

    (my-mapcar (function 1+) '(1 2 3))
    

    and it can be abbreviated with #':

    (my-mapcar #'1+ '(1 2 3))
    

    That’s not the end of this story — to give a few examples:

    • in some cases a simple quoted name can work as a function — for example '1+ in the last example works — but this is a kind of a hack that can see only globally bound names, so #' is almost always better

    • a similar hack can be used with lambda — so you can use (my-mapcar '(lambda (x) (1+ x)) '(1 2 3)), in fact, you could use (list 'lambda '(x) '(1+ x)) which is even worse (and IIRC, non-portable), but using (lambda (x) (1+ x)) works since it’s implicitly wrapped in a #' (try expanding a lambda form as a macro and you’ll see it). A related hack makes it fine to use a lambda expression as the head of a function application (which is one of the things you’ve tried).

    • let etc bind local values, and in some cases you’ll want to bind local functions instead — for this, there are new binding constructs: flet and labels

    If all of this looks weird and/or overly complicated, then you’re not alone. It’s one of the main differences between Common Lisp and Scheme. (The difference then leads to changes in common idioms in both languages: Scheme code tends to use higher order functions much more frequently than Common Lisp code. As usual with these kind of religious questions, some people argue in favor of what CL does, claiming that higher order functions are confusing so they like the explicit in-code reminder.)

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.