News for hackers. Stuff that matters.
Re:Creating a Swift syntax extension: the Lisp 'cond' function by mappu on Sunday June 08, 2014 @06:48PM (#7866217)
Incredibly cool hack.

But i'm going to be the first one to point out that having function arguments not evaluated at call time is very, very unintuitive. Anyone with a background in traditional (procedural/OO) languages is reasonably going to expect both `perform_side_effects` calls to be invoked here.

    var ctest = cond_1(a == 1, 2 + perform_side_effects1(),
                       a == 2, 3 + perform_side_effects2(),
                       0)
Re:Creating a Swift syntax extension: the Lisp 'cond' function by adrusi on Sunday June 08, 2014 @08:23PM (#7866455)
This is why the rust people require a bang in macro names. The behavior is just too confusing if what looks like a normal function is actually evaluating its arguments in a non-strict manner.

Scala is another language that supports declaration-site opt-in for non-strict evaluation, very similarly to how swift seems to be doing it. I'm not the biggest fan of Scala, but my limited experience with it has left me with the impression that you can't trust any normal-looking code to actually be normal until you look at its documentation and/or source.

Re:Creating a Swift syntax extension: the Lisp 'cond' function by MaulingMonkey on Sunday June 08, 2014 @08:46PM (#7866499)
To play devil's advocate, they already have to worry about:

- exceptions short circuiting one of the side effects (C++, C#, etc.)

- the indeterminate order of execution of the side effects (C, C++)

- macros with conditional evaluation behavior (such as assert depending on... _DEBUG? NDEBUG?)

Re:Creating a Swift syntax extension: the Lisp 'cond' function by ludamad on Sunday June 08, 2014 @09:17PM (#7866571)
So everything is fair game therefore?
Re:Creating a Swift syntax extension: the Lisp 'cond' function by rayiner on Sunday June 08, 2014 @09:58PM (#7866641)
No, but macro names give a lot more context about whether an argument will be evaluated than function names give about side effects and exceptions.