Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> A ton of responses and no one mentions the one-word answer?

Statements like "You can easily do this is Ruby" hint that author understood exactly nothing and focused on some random uninteresting example code while missing big picture.

Does Ruby have COND?

If it doesn't, can one implement it using existing Ruby constructs?

If it does, can one implement it using existing Ruby constructs except COND?



I don't believe this is a good example. Ruby has case..when instead of COND, though it's a language construct, not a function; but I think COND can be trivially implemented in any language that has anonymous functions. In Ruby:

  def COND(*args)
      args.each_slice(2){ |s| return s[1].call if s[0].call }
  end

  COND(lambda{ false }, lambda{ "not this"}, lambda{ true }, lambda{ "this" })
(not a lisper, though, so I might be missing something).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: