hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Tuesday

2005.02.22

Choice Python Hack: Infix Operators #

by why in bits

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] <<isa>> []
 # => True

 # inclusion checking
 is_in=Infix(lambda x,y: y.has_key(x))
 print 1 |is_in| {1:'one'}
 print 1 <<is_in>> {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??

The Ruby Mix Tape, Day Two #

by why in cult

Hang in there on the drb. And I’d suggest just getting only 0[34]*.mp3 today, wouldn’t you say so?

Today’s songs are tinted.

Frank Black “Big Red”

Most people who wrote a song about terraforming Mars would write something like “Oh, we’re going to terraform Mars / Hi-Ho / Yeah, we’re gonna colonize the place / Sha-na.”

However, Frank Black really does want to terraform Mars. He’s thought about it. He’s got this picture in his head.

They got a mule they call sal
Bulldozing up canal walls
They’re gonna tap that icecap too
When they do they’re gonna make that green map blue

A red song. A space song. And the idea of Ruby on Mars—well, come on now!!

Gorky’s Zygotic Mynci “Y Fford Oren”

The title of this song is Welsh for “The Orange Way.” Which is a psychedelic variation of The Ruby Way. The song is just that.

Why do we do what we do? How do we think the way we do? Huh, what ya doing? Oh, I don’t know, can’t say—it’s The Orange Way. Do I really have to explain it up here inside your ears with these searing guitars??

`ruby -h`.unpack(%w[x558 155ax95 277 1a].join('aX')).join #

by why in cult

The obfuscated code in the advert is a tiny ETA interpreter wizarded by Stephen Sykes in 2004—it took him two years to refactor off the last 81 bytes!

Here’s the code nicely printed:

 i=*$<;_=a=$==-1;i[_].scan(/\w/){!p='htaoinse'=~$&or
 a<0?i<<eval(%w^,>0?i.slice!(a-p):i[p+a] ,,==0||(_=c-2;break), _+2
 ,utc(p), getc||a a=0, ,,-c ,,;i<<p/c;p%c^[p].gsub',',';c,p=p,i.pop
 p'):a=p>6?i<<a&&~0:a*7+p}until(_+=1)/$.!=0

Look for the ensuing flamewar over the wrongness of this all on ruby-talk. Obfuscation still pops up as a controversy. If you let stuff like obfuscated Ruby get under your bonnet, uh.. well.. why is it that you’re wearing a bonnet again?? (whoops, via ~matz.)