Hacker News new | ask | show | jobs
by pmontra 1114 days ago
This feature is not so bad:

> In case you really need to vary a variable, the when keyword lets you check a variable each time it mutates.

  const var health = 10!
  when (health = 0) {
    print("You lose")!
  }
If it can really be triggered when the variable changes to any value it makes it a truly reactive paradigm programming language. By the way, could that be hacked to implement loops?

  const var i = 10
  when (i >= 0) {
    do_something()
    i = i  - 1
  }
8 comments

Yes, when is the way to do loops in this language. From the hidden examples page

  functi fibonacci (n) => {
     const var sum = 1!
     const var i = 0!
     when (i < n) {
        sum += sum + previous sum!
        i++!
     }
  }

  when (i < 10) {
     fibonacci(i)?
     i++!
  }
And if you don't want your code to loop back by accident you can just use lifetimes! Truly an elegant language
Oh please tell me you can specify the length of your loops in lines of code executed.

  var var i<10> = 0!!
  var var i = false!
  when (i) {
    print(i)!
    i++!
  }
I think this should print 0,1,2 and then stop, assuming checking the condition is a line of code, and that lifetimes are for lines executed and not just the syntax.
Yeah honestly I was really interested in that. Kind of like a logic language?

Maybe Prolog is the perfect language.

Isn't that basically a computed COME FROM?
It's basically a syntactic sugar on an Observer pattern but I like it. You would need a way to turn off 'when' observers. And I suppose it does couple the observer to the observable pretty tightly.
Delete the observed variable?

About coupling, an implementation could send state change events to a message bus and observers could subscribe only the events they care about.

It's pretty easy to turn off the when observers, simply `delete when`.

Side-effect is that it will delete all the whens, so only use it if you need it!

This feels sort of like key-value observation in obj-c
I like this feature, but to really make it pop I would like it to be combined with comefrom control flow.
Doesn't Tcl's "trace" feature do this?
Looks a little like FRP.