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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:31:03+00:00 2026-06-17T20:31:03+00:00

I need to write a function in lisp with two arguments – list of

  • 0

I need to write a function in lisp with two arguments – list of argumentless functions and list of integers.
I need to evaluate functions from first list in order given by a second, i.e. (fun ‘(#’a #’b #’c) ‘(2 0 1)) should evaluate c, a, b.
I tried such function:

(defun z4(funs kols)
    (funcall (nth (first kols) funs))
    (z4 funs (rest kols))
)

but in funcall I am geting error

NIL is not of type CONS.

What does it means? I am getting same error by calling simply

(funcall (first funs))

so I assume it is something with with getting function from the list of functions. How can I evaluate function get from list of functions?

  • 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-17T20:31:04+00:00Added an answer on June 17, 2026 at 8:31 pm

    With each recursive call you reduce the kols parameter untill it becomes nil. When kols becomes nil you should terminate the recursion, so you should add the test for the terminating condition (i.e., for empty list):

    (defun foo (funcs order)
      (unless (endp order)
        (funcall (nth (first order) funcs))
        (foo funcs (rest order))))
    

    I suggest a more readable solution (it’s also more preferrable since ANSI Common Lisp Standard doesn’t force implementations to perform tail call optimization):

    (defun foo (funcs order)
      (loop for n in order do (funcall (nth n funcs))))
    

    In the previous examples I assume that you run your functions for their side effects, not for the return values.


    Edit 1

    As Vatine noted, using nth and lists to provide a collection with random access is not good for the performance, so it might be worth to store functions in a vector (that is a one-dimensional array) rathen than in a list. So, assuming that funcs is a vector of functions, the function can be defined as follows:

    (defun foo (funcs order)
      (loop for n in order do (funcall (aref funcs n))))
    

    Moreover, we can replace aref with svref if the array of functions is a simple vector (glossary entry). The former is more general, but the latter may be faster in some implementations.

    One can create a simple vector of functions using either

    (vector #'func-a #'func-b ...)
    

    or

    #(func-a func-b ...)
    

    A simple vector of functions can be created using the make-array function as well, but only if :adjustable and :fill-pointer keyword arguments are unspecified or nil.

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

Sidebar

Related Questions

Need to write a union function in lisp that takes two lists as arguments
i need to write a function, which takes positive integers list. If list begins
I need to write a function which returns an list of sum functions, adding
I need to write a function that downloads and stores the today's list of
I need to write a function to satisfy this input -> output list: 0
I need to write authentication function with asynchronous callback from remote Auth API. Simple
I need to write a function that read from a file and put every
i need to write a function which calculates how many elements on list with
I need to write a function that takes a list and bisects it (like
I need to write a function that dynamically extracts the progid from a COM

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.