News for hackers. Stuff that matters.
Re:IF-less programming by Bootvis on Friday December 28, 2012 @09:47AM (#4977855)
Also R and I think were mostly in agreement here. However I'm of the opinion that more than just these languages (languages with lazy evaluation or macro's) are decent and that in for example Ruby there are differences between if and a function, as this example shows (my first lines of Ruby)

    def iff(cond, x, y)
      if cond then
        x
      else
        y
      end
    end

    puts iff(true, 1, puts('2'))
echoes

    2
    1
if may behave as a function, but you can't write a function that acts like if.

edit: R does have real lazy evalution, e.g.

    > iff <- function(cond, x, y) { if (cond) x else y }
    > iff(TRUE, 1, cat('foo'))
    [1] 1

There are no comments on this comment yet.