News for hackers. Stuff that matters.
Re:Why I love Smalltalk by redxaxder on Friday July 29, 2011 @04:02PM (#2823554)
To implement a usable if, you need to tie it to some form of logical branching. Haskell can tie it to pattern matches. C compiles them to conditional jumps in asm. The asm jump instructions are implemented in hardware. The meat of the if definition lies in how you tie it to whatever form of conditional behavior your language has. This is missing from the article.

Smalltalk (presumably) has a form of logical branching in it somewhere. To finish the if, just pick one.

For a satisfying conclusion, you want to use one that doesn't already look like an if statement.

Re:Why I love Smalltalk by more_original on Saturday July 30, 2011 @07:16AM (#2825506)
> Smalltalk (presumably) has a form of logical branching in it somewhere. To finish the if, just pick one.

It uses dynamic binding.

In Java it would look like something this (but it's less useful without proper closures):

  abstract class Bool {
    void ifTrue(Runnable f, Runnable g); 
  }

  class True extends Bool {
    void ifTrue(Function f, Function g) {
      f.run();
    }
  }

  class False extends Bool {
    void ifTrue(Function f, Function g) {
      g.run();
    }
  }
Then, given a variable

  Bool b;
the if-then-else becomes

  b.ifTrue(new Runnable() {
      public void run() {
         System.out.println("It's true!");
      }
    }
  , new Runnable() {
      public void run() {
         System.out.println("Not true!");
      }
    }
  );
It's a bit more verbose, though...
Re:Why I love Smalltalk by more_original on Saturday July 30, 2011 @10:21AM (#2825821)
s/Function/Runnable/g