We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

LambdaPython

From Esolang
Jump to navigation Jump to search

LambdaPython is Python, but if your program includes def, it raises a syntax error (that means you must use built-in functions or lambda functions instead of normal ones, thus the name). It is named by User:None1 and inspired by UnnumericJS which is inspired by MangularJS.

Examples

Most programs are the same (as Python), but here is an example that computes the n-th Fibonacci number using recursion (reads n and outputs the n-th Fibonacci number):

exec('\x64\x65\x66\x20\x66\x69\x62\x28\x6e\x29\x3a\x0a\x09\x69\x66\x20\x6e\x3d\x3d\x30\x3a\x0a\x09\x09\x72\x65\x74\x75\x72\x6e\x20\x30\x0a\x09\x69\x66\x20\x6e\x3d\x3d\x31\x3a\x0a\x09\x09\x72\x65\x74\x75\x72\x6e\x20\x31\x0a\x09\x72\x65\x74\x75\x72\x6e\x28\x66\x69\x62\x28\x6e\x2d\x31\x29\x2b\x66\x69\x62\x28\x6e\x2d\x32\x29\x29\x0a\x70\x72\x69\x6e\x74\x28\x66\x69\x62\x28\x69\x6e\x74\x28\x69\x6e\x70\x75\x74\x28\x29\x29\x29\x29')

Athough it uses recursion, it does not include def, so it is still allowed.

Alternatively, every def can be transformed into a lambda. The above Fibonacci function can be expressed as:

f = lambda n: 0 if n == 0 else 1 if n == 1 else f(n - 1) + f(n - 2)

Here is a lambda-only version of an iterative Fibonacci function which doesn't use recursion:

f = lambda i, l=[0, 1]: [l.append(l[-1] + l[-2]) for _ in range(i + 1 - len(l))] and l[i]

Interpreter in Python

import sys
code=sys.stdin.read()
if 'def' in code:
    raise Exception('Syntax error')
else:
    exec(code)

Self interpreter

import sys
code=sys.stdin.read()
if '\x64\x65\x66' in code:
    raise Exception('Syntax error')
else:
    exec(code)

This is also an interpreter in Python.

Turing completeness

We can use exec() and the hexadecimal escape to run any Python code, so it is Turing complete.