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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:28:21+00:00 2026-06-13T18:28:21+00:00

I wanted to create a function, that returns a composition of several other functions,

  • 0

I wanted to create a function, that returns a composition of several other functions, such that

(funcall (compose 'f 'g) x) == (f (g x))

I feel that I miserably failed on this. My best attempt so far:

(defun compose (funcs)
  "composes several funcitons into one"
  (lambda (arg)
    (if funcs
        (funcall (car funcs) (funcall (compose (cdr funcs)) arg))
        arg)))

But for some reason, the following still returns 0:

(funcall (compose '(
           (lambda (a) (* a 3))
           (lambda (a) (+ a 2))
)) 0)

Is there a way to fix that?

  • 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-13T18:28:22+00:00Added an answer on June 13, 2026 at 6:28 pm

    Your code requires lexically scoped lambdas, which Emacs Lisp doesn’t support by default. If you use Emacs 24, set lexical-binding to t and your example will work as written.

    If you’re using an older Emacs, you can create a lexically scoped lambda using an explicit lexical-let form:

    (require 'cl)
    
    (defun compose (funcs)
      "composes several funcitons into one"
      (lexical-let ((funcs funcs))
        (lambda (arg)
          (if funcs
              (funcall (car funcs) (funcall (compose (cdr funcs)) arg))
            arg))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As an exercise I'm trying to create a function that returns a generic list
I wanted to create graphs for some math functions and tried to do this
I wanted to create a very simple method that switches between views in a
I wanted to create a function which would return the path of the current
I have the following code and I wanted to create a class that encapsulates
I wanted to create a string padding function for the use of left-padding a
I have a wrapper function that returns a function. Is there a way to
I wanted to create this kind of output var s1 = [['Sony',7],['Samsung',5],['LG',8]]; so that
For an assignment we were asked to create a function that would reverse all
I'm trying to create a function that will grab all posts within a table.

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.