rzimmerman / kal

A powerful, easy-to-use, and easy-to-read programming language for the future.
http://rzimmerman.github.io/kal
MIT License
394 stars 18 forks source link

Add default argument values #96

Closed dijs closed 11 years ago

dijs commented 11 years ago

This would be so cool!

rzimmerman commented 11 years ago

This actually sounds like a pretty useful feature. Something like:

function my_function(x=1,y=2)
   print x + y

my_function() # prints 3
my_function(10) # prints 12
my_function(10,20) # prints 30

Implemented as something like:

function my_function (x, y) {
  if (x == null) x = 1;
  if (y == null) y = 2;
  console.log(x+y);
}

my_function();
my_function(10);
my_function(10,20);

Any other ideas?

dijs commented 11 years ago

Exactly! Shouldn't be too hard to add.

rzimmerman commented 11 years ago

Thank you for the suggestion, @rompetoto. This is a great feature to have.