The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Choice Python Hack: Infix Operators

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Choice Python Hack: Infix Operators Posted: Feb 22, 2005 2:50 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Choice Python Hack: Infix Operators
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

Pencils down. Cool hack for Python right here. I guess this was up on LtU a few days ago. I saw it on The Farm, so.

Works like:

 # simple multiplication
 x=Infix(lambda x,y: x*y)
 print 2 |x| 4
 # => 8

 # class checking
 isa=Infix(lambda x,y: x.__class__==y.__class__)
 print [1,2,3] |isa| []
 print [1,2,3] <> []
 # => True

 # inclusion checking
 is_in=Infix(lambda x,y: y.has_key(x))
 print 1 |is_in| {1:'one'}
 print 1 <> {1:'one'}
 # => True

Anyway, this hacker—Ferdinand Jamitzky—sure would fit in well over here. He’s tread so close to our territory. What with the Ruby-like syntatic sugar he supplied for Python last year.

 5 *times(lambda: printf("Hello"))
 [1,2,3,4] *each(lambda x: printf("Count:"+str(x)))
 print [1,2,3,4,5] *length
 ['a','b','c','d','e'] *each(lambda char: char+'!')

I mean if he can make Python look like Ruby, maybe he can make Ruby look like dolphin sonar. Can you best these??

Read: Choice Python Hack: Infix Operators

Topic: The RedHanded+Safari "Yep or Nope?" Game Previous Topic   Next Topic Topic: Ed Dumbill on Choosing XML or RDF

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use