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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:13:04+00:00 2026-05-28T15:13:04+00:00

I have a function that does something with whatever is passed to it, and

  • 0

I have a function that does something with whatever is passed to it, and returns a list based on that.

How would one go about processing and mashing whatever arguments are passed to it into one list that contains every value?

Also, the ' is bugging me, as it makes calling somefunction2 from within somefunction1 problematic. Is there a way around this? It would be useful in my case to have an overly generic function that can take more or less anything as an argument, even other functions.

Possible arguments to the function:

  • NIL (should be treated as 0)
  • a number
  • a list of numbers
  • an empty list (should be treated as 0)
  • several lists some of which may or may not contain NIL, numbers, or
  • even more lists

Basically, what I want:

(somefunction '() 1 2 3 4 '(1 2 3 4 ) '(1))

…should be merged/mashed into:

(0 1 2 3 4 1 2 3 4 1)

… before being processed

Note: this is a follow-up to this question

  • 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-28T15:13:05+00:00Added an answer on May 28, 2026 at 3:13 pm

    This should do it:

    (defun weird-flatten (a)
        (cond ((null a) (list 0))
              ((atom a) (list a))
              (t (mapcan #'weird-flatten a))))
    
    (defun foo (&rest args) (weird-flatten args))
    

    EDIT: Noticed you’re trying to do this as a learning exercise, so I guess I should explain. The first function is a pretty basic recursion. The only odd thing about it is that it uses mapcan rather than mapcar, so the result is merged into a flat list rather than retaining the same shape as the argument (um…mapcar takes an n-ary function and n lists as arguments and applies the function to each element of the lists, returning the resulting sequence; not sure whether that’s too basic for you).

    The foo function is a bit special in that it takes a &rest arg. This means that you can pass any number of things in to the function and the symbol args will be bound to the list of all arguments passed.

    Why do you need NILs to be treated as zeros, out of curiosity?

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

Sidebar

Related Questions

This is a C# console application. I have a function that does something like
Here's the story... I have a jQuery function that does something, this function is
I have a small JS function that does Ajax for me and another like
How do I create a Ruby function that does not have an explicit number
I have a class named toto which I send to a function that does
I need to write a little ruby function that does word wrapping. I have
When you have a function with a string parameter, does that create another instance
Does .NET have some type of built in function that allows filtering on Gridviews?
Does Actionscript have a built-in function that accepts a number and can return a
Note that this function does not have a { and } body. Just a

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.