Hacker News new | ask | show | jobs
by nerdponx 3260 days ago
Just hopping on the bandwagon to point out that R can do it too, since everything in R is an expression:

    z <- if (x > y) 5 else 7
And of course this is trivial in Lisp:

    (setf z (> x y) 5 7)
1 comments

You lost an "if" there :). setf will complain on trying to set 5 to 7.

What you meant is:

  (setf z (if (> x y) 5 7))
A nicer thing that I like about Lisp's "everything is an expression" is something that is considered as code smell by some:

  (setf foo (or var (compute-default-value) +some-default-constant+))
This works in Common Lisp, where the only value considered logically false is NIL, because or will short-circuit (as expected), returning not T, but the value of the first logically true result.

So e.g.

  (let ((a nil) (b 2) (c :foo))
    (or a b c))
returns 2.