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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:48:54+00:00 2026-06-04T03:48:54+00:00

This is #7 of of 99 Lisp problems : transform a list, possibly holding

  • 0

This is #7 of of 99 Lisp problems: transform a list, possibly holding lists as elements into a `flat’ list by replacing each list with its elements (recursively). I have tried several solutions, e.g from #2680864 or from here. They all work, but I run into a problem if I am flattening a list containing a quoted element. E.g.:

> '(a 'b c)
(A 'B C)

> '(a (quote b) c)
(A 'B C)

> (flatten '(a 'b c))
(A QUOTE B C)

In the latter case I would like to get:

(A 'B C)

It seems that the internal representation of ‘ gets in the way for this task! SBCL, CLISP, ECL, … they all behave the same way.

  • 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-06-04T03:48:55+00:00Added an answer on June 4, 2026 at 3:48 am

    Quoted elements in a list? That usually does not make sense. Why would you have it quoted?

    (a b c) is a list of three symbols. Why would you quote elements in the list? like in (a 'b c)? Why? What would be the purpose of the quote?

    In Common Lisp ' is a readmacro which expands 'a into (QUOTE A). Since this is a normal list, a typical flatten operation will collect the symbols QUOTE and A into the flat list. This is because a flatten function typicall checks whether something is an atom or not. If you don’t want this, your flatten function needs to check if something is an atom or a two-element list with QUOTE as its first symbol.

    But as I said above, the default usage is just to flatten symbols, since quoted symbols are usually not useful inside a list. You need to extend the flatten function otherwise.

    For example:

    (defun flatten (l &key (test #'atom))
      (cond ((null l) nil)
            ((funcall test l) (list l))
            (t (loop for a in l nconc (flatten a :test test)))))
    
    
    CL-USER > (flatten '(a (('b) c) ('d) )
                       :test (lambda (item)
                               (or (atom item)
                                   (and (eq (first item) 'quote)
                                        (null (cddr item))))))
    
    (A (QUOTE B) C (QUOTE D))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Still working on lisp recipes and idioms. I have a list like this: ((a
I am reading On lisp and encountered this code (I simplified it a bit).
I've got this snippet of code: (define-key lisp-interaction-mode-map (kbd C-c C-e) (lambda () (let
I'm a few days into learning Clojure and are having some teething problems, so
In common lisp I can do this: src-> (defmacro macro-hello () `hello) (eval '(macro-hello))
I've been slowly working my way through the list of Project Euler problems, and
I'm going through Casting SPELs in Lisp and this is the proposed solution to
This a conceptual question on how one would implement the following in Lisp (assuming
I am having two problems while working in Lisp and I can't find any
I'm trying to translate the following macro from land of lisp into clojure: (defmacro

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.