GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - erezsh/lambdaX: Partial evaluation for Python with syntactic sugar

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
lambdax
lambdax
 
 
README.md
README.md
 
 
setup.py
setup.py
 
 

Repository files navigation

X is a composition class. It's a lambda replacement which is shorter, pickle-able, and cooler.

X has two main features:

  1. It acts as an identity function ( so X(object) == object, etc. )
  2. When performing operations on it, it returns a new class that acts as a corresponding function.

So, evaluating (X+2) will result in an instance of X, that whenever called with an argument, will return that argument plus 2:

>>> map( X+2, [1, 2, 3] )
[3, 4, 5]

>>> pow = X**X
>>> pow(2,8)
256

>>> filter( X>0, [5, -3, 2, -1, 0, 13] )
[5, 2, 13]

>>> l = ["oh", "brave", "new", "world"]
>>> sorted(l,key=X[-1])
['world', 'brave', 'oh', 'new']

These operations can be chained and composed:

>>> map(2**(X+1), range(10))
[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]

>>> sqr = X ** 2
>>> sqr_sum = sqr + sqr
>>> sqr_sum(3, 4)
25

>>> sec_per_min = 60 * X
>>> sec_per_hour = 60 * sec_per_min
>>> sec_per_day = 24 * sec_per_hour
>>> sec_per_day(1)
86400

>>> head, tail = X[0], X[1:]
>>> (head(tail))([1,2,3])
2

Another feature is SameX, which is experimental (like everything here ;)

>>> map(X**SameX, range(10))
[1, 1, 4, 27, 256, 3125, 46656, 823543, 16777216, 387420489]

>>> (X+SameX+SameX)('ha')
'hahaha'

>>> (X + ' ' + SameX[::-1])('hello!')
'hello! !olleh'

Some operations aren't as smooth:

>>> map( X.upper._(), "use underscore for calling a function".split() )
['USE', 'UNDERSCORE', 'FOR', 'CALLING', 'A', 'FUNCTION']
>>> filter( X.in_(range(10)), range(4,20,2))
[4, 6, 8]

License

MIT

About

Partial evaluation for Python with syntactic sugar

erezsh.wordpress.com/2008/11/01/fun-while-avoiding-lambda/

Resources

Readme
Activity

Stars

36 stars

Watchers

1 watching

Forks

6 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.