ThakeeNathees / pocketlang

A lightweight, fast embeddable scripting language.
https://thakeenathees.github.io/pocketlang/
MIT License
1.52k stars 80 forks source link

[Design] variale number of arguments and default values #278

Open khchen opened 2 years ago

khchen commented 2 years ago

Change the callable behavior: "extra arguments are thrown away; extra parameters get null" (like lua). Moreover, parameters can have default value, even if the default value is an expression.

Example:

def foo
  return "hello"
end

def test(a = 10, b = a * 2, c = foo())
  print(c, a, b)
end

test()
test(0)
test(5)
test(5, 100)
test(5, null, "hi")

Output:

hello 10 20
hello 0 0
hello 5 10
hello 5 100
hi 5 10