pocketlang icon indicating copy to clipboard operation
pocketlang copied to clipboard

Can parameter be declared with a default value ?

Open khchen opened this issue 2 years ago • 2 comments

For example:

  def inc(v, n = 1)
    return v + n
  end

  v = 0
  print(inc(v))
  print(inc(v, 2))

-- I love this little script language very much, please keep going on.

khchen avatar Jun 19 '22 01:06 khchen

Hi, thanks for the suggestion, I've been busy lately and not been able to maintain this, anyways I'm adding this to the todo list. This is doable, even if the default value is an expression example:

def some_function(v = other_function())
end

ThakeeNathees avatar Jun 21 '22 22:06 ThakeeNathees

I create a pull request for this isssue. https://github.com/ThakeeNathees/pocketlang/pull/278

khchen avatar Jul 22 '22 14:07 khchen