[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: LISP to Ruby translation

Neville Burnell

12/15/2005 2:58:00 AM

I think that's the first time I have seen an emoticon in ruby code

:-)

-----Original Message-----
From: Neil Stevens [mailto:neil@hakubi.us]
Sent: Thursday, 15 December 2005 1:48 PM
To: ruby-talk ML
Subject: Re: LISP to Ruby translation

Douglas Livingstone wrote:
> Jut a quick one, how do you translate this:
>
> ((if (zero? 0) + -) 3 4)
> => 7
>
> to Ruby?

Well, these kind of questions are rarely helpful; translating an
idiomatic expression out of context from one language is often useless,
because in a greater context the ruby code might be doing something
completely different to begin with.

But, if you want a one-liner...

3.method(0.zero? ? :+ : :-).call(4)

--
Neil Stevens - neil@hakubi.us

'A republic, if you can keep it.' -- Benjamin Franklin



6 Answers

Neil Stevens

12/15/2005 3:01:00 AM

0

Neville Burnell wrote:
> I think that's the first time I have seen an emoticon in ruby code
>
> :-)

Oh wow, you're right. I need to fit that into some real code sometime,
heh. Well, not really, since I abhor such one-liners outside of
demonstrations, but it'd be nice....
--
Neil Stevens - neil@hakubi.us

'A republic, if you can keep it.' -- Benjamin Franklin

Ilmari Heikkinen

12/15/2005 2:55:00 PM

0

# A bit of fun to while away a boring afternoonclass Fixnum def prev self - 1 endenddef add a, b return a if b.zero? if b > 0 add a.succ, b.prev else add a.prev, b.succ endenddef leval(args) return args unless args.is_a? Array args.map!{|a| if a.is_a? Array leval a else a end } op, *args = args functions[op][args]enddef functions { :if => lambda{|args| if leval(args.first) then args[1] else args[2] end }, :zero? => lambda{|args| not (args.first > 0 or args.first < 0) }, :+ => lambda{|args| args.inject{|s,i| add s, i}}, :- => lambda{|args| args.inject{|s,i| add s, -i}} }endp leval([[:if, [:zero?, 0], :+, :-], 3,4])

Robibnikoff

7/15/2008 10:43:00 PM

0


"john w @yahoo.com>" <j<no> whined and lied....
--
Robyn
Resident Witchypoo
BAAWA Knight!
#1557
If you can't be a good example....
You'll just have to be a horrible warning.


Robibnikoff

7/15/2008 10:44:00 PM

0


"john w @yahoo.com>" <j<no> lied:

>
> bye now!

Until you reply to her next post.
>
> I think the less we say to each other, the happier we'll / I'll be.

Except that you have no self-control and will never stop replying.
--
Robyn
Resident Witchypoo
BAAWA Knight!
#1557
If you can't be a good example....
You'll just have to be a horrible warning.


Robibnikoff

7/15/2008 10:45:00 PM

0


"john w @yahoo.com>" <j<no> lied:

>
> I was making a joke.

No one buys this bullshit excuse, johnnie.
>
> And if you had been off-duty, it wouldn't have involved your gun.

You think some cops don't carry a gun when they're off duty? Are you really
this stupid?
--
Robyn
Resident Witchypoo
BAAWA Knight!
#1557
If you can't be a good example....
You'll just have to be a horrible warning.


Robibnikoff

7/15/2008 10:45:00 PM

0


"john w @yahoo.com>" <j<no> babbled bullshit....
--
Robyn
Resident Witchypoo
BAAWA Knight!
#1557
If you can't be a good example....
You'll just have to be a horrible warning.