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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:09:10+00:00 2026-05-28T07:09:10+00:00

I wonder, how can I print in LISP each new value from loop for

  • 0

I wonder, how can I print in LISP each new value from loop “for” in new list, which each time creates by calling the function.

I have created the func:

(defun make (id name surname) (list :id id :name name :surname surname) )

Here I created the global variable:

(defvar *db* nil)

And here I defined the func for adding each new value to store it in db:

(defun add (cd) (push cd *db*))

So, I’m able to add each new data to db, like that:

(add (make 0 "Oleg" "Orlov" ) )

To look the content of my db , I can use:

*db*

So, I wonder how to put each new record-list to db using “for” loop, I print values in “for” loop in lisp like this:

 (loop for i from 1 to 10 do ( ... ))

If , I use:

 (loop for i from 0 to 10 do (add (make i "Oleg" "Orlov") ) )

If you read db using *db* you will see, that all evelen records were added, but after calling the last line, you will get NIL result in return.

Why do I catch NIL result, not T and what does it mean?

Thanks, best regards!

  • 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-28T07:09:10+00:00Added an answer on May 28, 2026 at 7:09 am

    Every form in Lisp evaluates to something.

    If a form you type in doesn’t return a value, it will evaluate to NIL by default (otherwise, it evaluates to the value(s) it returns). Your loop doesn’t actually return a value itself; it just performs 10 assignments (each of the intermediate expressions do return a value, but you don’t collect and return them). Therefore, that code will return NIL.

    If you haven’t done so already, check out chapter 3 of Practical Common Lisp, in which Peter Seibel goes step-by-step through creating a simple database. It might give you some insights into the basics of how Lisp works. The specific question you ask (why forms return NIL by default, and what it means specifically in the context of Common Lisp) is answered in chapter 2 of the same book

    As for how you would explicitly cause your loop to emit the list of items it added to *db*, try the following

    (loop for i from 1 to 10
          for elem = (make i "Oleg" "Orlov")
          do (add elem)
          collect elem)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python there is a really neat function called zip which can be used
I wonder how I can explode the value inside the item of an array,
I wonder how can I export a Visual Studio C++ project to Qt? I
I am going to develop ICQ client and I just wonder where can I
Out of curiosity, I wonder what can people do with parsers, how they are
I'd like to start coding for NVIDIA 3D Vision and wonder where can I
Wonder if anyone can help me understand how to sum up the column of
wonder whether someone can help me with the following one... I have a struct
I wonder if They can work perfectly together...
I wonder if anyone can provide me with the regular expressions needed to parse

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.