towerofnix / tlnccuwagnf

The Language Nobody Could Come Up With A Good Name For
MIT License
18 stars 3 forks source link

If/else-if control structure? #42

Open towerofnix opened 8 years ago

towerofnix commented 8 years ago

We should probably implement else if. I'm thinking of making it have a syntax like this:

ifelif(cond, fun, cond, fun, cond, fun...);

That doesn't look good until you read it like this:

ifelif(
  cond, {

  },
  cond {

  },
  cond {

  }
);

As an example:

input => 40;
number => 42;

ifelif(
  (input = number), {
    print('It\'s the number!');
  },
  (input < number), {
    print('Not quite the number.');
  },
  (input > number), {
    print('Over the number.');
  }
);

Maybe if there's an odd number of inputs the last input will be a fallback, as if all the above conditions were false?

ifelif(
  cond1, if-cond1,
  cond2, if-cond2,
  cond3, if-cond3,
  else
);

(having both the issue number and number be 42 was purely coincidental 📦)

As a side note, I need to implement unevaluated arguments into JS functions for this to work.

bates64 commented 8 years ago

Maybe we should have a then that behaves like if, so people can do the amazing surround function (true then {print(false);}); :tada:

towerofnix commented 8 years ago

If a user wants that..

then => if;

:P

No support for adding to built-in library anyways.