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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:24:32+00:00 2026-06-13T07:24:32+00:00

I am trying to write a function that returns a list of atoms in

  • 0

I am trying to write a function that returns a list of atoms in a list,lets say i have a list which has both atoms and a list in it and when I run the function it should return a list of atoms inside..

For example:

(func '(2 34 5 (12) 7 (A B C) +))
 -> (2 34 7 +)

And I want to try if the arguments inside the result are true such that when I run:

(ATOM ( (func '(2 34 5 (12) 7 (A B C) +)) )
->T

Any ideas on how I can go about it? Books or references?

  • 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-13T07:24:34+00:00Added an answer on June 13, 2026 at 7:24 am

    Using standard CL functions,

    [3]> (remove-if-not #'atom '(1 2 (12) +))
    (1 2 +)
    
    [6]> (every #'atom (remove-if-not #'atom '(1 2 (12) +)))
    T
    

    If you want to write them yourself, you can fuse the #'atom in and make two specialized functions, say remove-atoms and every-is-atom. But “atom” is a name of a built-in function atom.

    One way to write the first is

    (defun remove-atoms (xs &aux (ys (list 1)))
      (let ((p ys))
        (dolist (x xs (cdr ys))
          (if (atom x) (setf (cdr p) (list x) p (cdr p))))))
    

    This builds the result list in a top-down manner using destructive update, which doesn’t violate the spirit of functional programming here because it is used locally, as an implementation technique. This can be seen as a Common-LISP–specific translation of the general functional tail-recursive-modulo-cons code from the other answer.

    And the second function:

    (defun every-is-atom (xs)
      (dolist (x xs T)
        (if (not (atom x)) 
          (return-from every-is-atom NIL))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a function that returns a list of cities from
I have a stored procedure that returns a list. Now I'm trying to write
Trying to write function that numerize items of list and returns list of tuples
I'm trying to write a plugin that calls a function (icalendar-import-file) which has the
I'm trying to write a function that returns a list of all files on
I am trying to write a function that returns the index of the passed
I'm trying to write a simple recursive function that look over list and return
I'm new to lisp and trying to write a recursive function that returns minimum
I am trying to write a function that returns T/F in regards to if
Im trying to write a simple scheme function that returns the last element of

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.