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

The Archive Base Latest Questions

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

I’ve looked through On Lisp , Practical Common Lisp and the SO archives in

  • 0

I’ve looked through On Lisp, Practical Common Lisp and the SO archives in order to answer this on my own, but those attempts were frustrated by my inability to name the concept I’m interested in. I would be grateful if anyone could just tell me the canonical term for this sort of thing.

This question is probably best explained by an example. Let’s say I want to implement Python-style list comprehensions in Common Lisp. In Python I would write:

[x*2 for x in range(1,10) if x > 3]

So I begin by writing down:

(listc (* 2 x) x (range 1 10) (> x 3))

and then defining a macro that transforms the above into the correct comprehension. So far so good.

The interpretation of that expression, however, would be opaque to a reader not already familiar with Python list comprehensions. What I’d really like to be able to write is the following:

(listc (* 2 x) for x in (range 1 10) if (> x 3)) 

but I haven’t been able to track down the Common Lisp terminology for this. It seems that the loop macro does exactly this sort of thing. What is it called, and how can I implement it? I tried macro-expanding a sample loop expression to see how it’s put together, but the resulting code was unintelligible. Could anyone guide me in the right direction?

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

    Well, what for does is essentially, that it parses the forms supplied as its body. For example:

    (defmacro listc (expr &rest forms)
      ;; 
      ;;
      ;; (listc EXP for VAR in GENERATOR [if CONDITION])
      ;;
      ;;
      (labels ((keyword-p (thing name)
                 (and (symbolp thing)
                      (string= name thing))))
        (destructuring-bind (for* variable in* generator &rest tail) forms
          (unless (and (keyword-p for* "FOR") (keyword-p in* "IN"))
            (error "malformed comprehension"))
          (let ((guard (if (null tail) 't
                           (destructuring-bind (if* condition) tail
                             (unless (keyword-p if* "IF") (error "malformed comprehension"))
                             condition))))
            `(loop 
                :for ,variable :in ,generator 
                :when ,guard 
                :collecting ,expr)))))
    
    
    (defun range (start end &optional (by 1))
      (loop
         :for k :upfrom start :below end :by by
         :collecting k))
    

    Apart from the hackish “parser” I used, this solution has a disadvantage, which is not easily solved in common lisp, namely the construction of the intermediate lists, if you want to chain your comprehensions:

    (listc x for x in (listc ...) if (evenp x))
    

    Since there is no moral equivalent of yield in common lisp, it is hard to create a facility, which does not require intermediate results to be fully materialized. One way out of this might be to encode the knowledge of possible “generator” forms in the expander of listc, so the expander can optimize/inline the generation of the base sequence without having to construct the entire intermediate list at run-time.

    Another way might be to introduce “lazy lists” (link points to scheme, since there is no equivalent facility in common lisp — you had to build that first, though it’s not particularily hard).

    Also, you can always have a look at other people’s code, in particular, if they tries to solve the same or a similar problem, for example:

    • Iterate
    • Loop in SBCL
    • Pipes (which does the lazy list thing)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including 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.