Re:Anti-if: The Missing Patterns
by dfox on Thursday June 09, 2016 @11:17PM
(#11874054)
If you want extreme case of removing all ifs, see how ifTrue: and friends are implemented in Smalltalk (ie. true and false are instances of different classes), although essentially all compiler implementations turn that into normal conditional branches in generated bytecode.
[ Parent
| on HN ]
Re:Anti-if: The Missing Patterns
by chriswarbo on Friday June 10, 2016 @06:15AM
(#11875366)
Also, from the functional programming side, Church Booleans:
function true(x, y) { return x; }
function false(x, y) { return y; }
There's an example of Church encoding used in anger at http://www.haskellforall.com/2016/04/data-is-code.html
Re:Anti-if: The Missing Patterns
by aaron-santos on Friday June 10, 2016 @11:36AM
(#11877108)
I think I'm looking at an implementation of ifTrue[1], but it's a bit dense to someone who's not familiar with Smalltalk. Maybe you could walk me through it?
[1] - http://git.savannah.gnu.org/gitweb/?p=smalltalk.git;a=blob;f...
That's the compiler part that optimizes the elegance away :). The interesting part is here [1], note that it will work without any support from the compiler.
[1] - http://git.savannah.gnu.org/gitweb/?p=smalltalk.git;a=blob;f... and http://git.savannah.gnu.org/gitweb/?p=smalltalk.git;a=blob;f...
Re:Anti-if: The Missing Patterns
by aaron-santos on Saturday June 11, 2016 @05:35PM
(#11885447)
Much more straight forward. If I'm reading it correctly, True and False are subclasses of Boolean and each of which implements a complementary pair of ifTrue and ifFalse methods? Elegantly symmetric. :)