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

The Archive Base Latest Questions

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

I recently stumbled across this article which describes how to code FizzBuzz using only

  • 0

I recently stumbled across this article which describes how to code FizzBuzz using only Procs in Ruby, and since I was bored, thought it would be neat to try and implement the same thing in Python using lambdas.

I got to the section where you create numbers using nested functions, and wrote the following Python script:

#!/usr/bin/env python

zero  = lambda p : (lambda x: x)
one   = lambda p : (lambda x: p(x))
two   = lambda p : (lambda x: p(p(x)))
three = lambda p : (lambda x: p(p(p(x))))
five  = lambda p: (lambda x: p(p(p(p(p(x))))))

fifteen = lambda p : (lambda x: p(p(p(p(p( \
                                p(p(p(p(p( \
                                p(p(p(p(p(x))))))))))))))))


hundred = lambda p: (lambda x: p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p( \
                               p(p(p(p(p(p(p(p(p(p(x)))))))))))))))))))))))))))) \
                                                     ))))))))))))))))))))))))))) \
                                                     ))))))))))))))))))))))))))) \
                                                     )))))))))))))))))))

def to_int(func):
    return func(lambda n: n + 1)(0)

print to_int(zero)
print to_int(one)
print to_int(two)
print to_int(three)
print to_int(five)
print to_int(fifteen)
print to_int(hundred)

Numbers zero through fifteen works fine, but if I try creating the number 100, the file won’t run due to the following error:

s_push: parser stack overflow
MemoryError

I have to comment it out in order for the file to run at all.

This sort of sucks — is there any way around this limitation so that I can arbitrarily nest lambdas and function calls without Python falling over and running out of memory?

Or alternatively, is there some kind of lambda-calculus trick I can use to express the number 100 without having so many nested 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-13T14:28:45+00:00Added an answer on June 13, 2026 at 2:28 pm

    express the number 100 without having so many nested functions?

    here you go:

    >>> test = lambda f: f(lambda x: x + 1)(0)
    >>> z = lambda f: lambda x: x
    >>> test(z)
    0
    >>> succ = lambda n: lambda f: lambda x: f(n(f)(x))
    >>> _1 = succ(z)
    >>> test(_1)
    1
    >>> _2 = succ(_1)
    >>> test(_2)
    2
    >>> plus = lambda m: lambda n: lambda f: lambda x: m(f)(n(f)(x))
    >>> _3 = plus(_1)(_2)
    >>> test(_3)
    3
    >>> mult = lambda m: lambda n: lambda f: lambda x: m(n(f))(x)
    >>> _6 = mult(_2)(_3)
    >>> test(_6)
    6
    >>> _5 = plus(_2)(_3)
    >>> _25 = mult(_5)(_5)
    >>> _4 = plus(_2)(_2)
    >>> _100 = mult(_25)(_4)
    >>> test(_100)
    100
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I stumbled across this code recently: void strcat( char* dest, char* src ) {
Recently I stumbled over this code snippet in Ruby: @data = 3.chr * 5
I'm refactoring some code that a friend wrote and recently stumbled across this function:
I recently stumbled across an article that claims Microsoft is banning the memcpy() function
I've recently stumbled across the ability to use boomarks in Visual Studio. ( http://www.codeproject.com/Articles/42973/Using-Bookmark-in-Visual-Studio.aspx
I recently stumbled across an issue in silverlight with using the datacontext changed event.
I recently stumbled across DBslayer ( http://code.nytimes.com/projects/dbslayer/wiki/WhyUseIt ) and wondered what is the actual
Apparently, BDB-XML has been around since at least 2003 but I only recently stumbled
I recently stumbled across this problem while testing my C# program. parsing ) -
I recently stumbled across a difficult problem.. I'm normally using a NSFetchedResultsController to get

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.