Forum: Ruby Re: LISP to Ruby translation

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
332b27a7e8304eaaf473752432a3f244?d=identicon&s=25 Neville Burnell (Guest)
on 2005-12-15 04:01
(Received via mailing list)
I think that's the first time I have seen an emoticon in ruby code

3c155ef399326d533efc2eb91ac992e5?d=identicon&s=25 Neil Stevens (Guest)
on 2005-12-15 04:04
(Received via mailing list)
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 -

'A republic, if you can keep it.' -- Benjamin Franklin
E20e89d58211a3631842daecc1245de2?d=identicon&s=25 Ilmari Heikkinen (Guest)
on 2005-12-15 15:57
(Received via mailing list)
# A bit of fun to while away a boring afternoon

class Fixnum
  def prev
    self - 1

def add a, b
  return a if
  if b > 0
    add a.succ, b.prev
    add a.prev, b.succ

def leval(args)
 return args unless args.is_a? Array!{|a|
  if a.is_a? Array
    leval a
 op, *args = args

def 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}}

p leval([[:if, [:zero?, 0], :+, :-], 3,4])
This topic is locked and can not be replied to.