[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Proposal: Function Definition Named/Default Argument Syntax Sugar
- From: Andrew Starks <andrew.starks@...>
- Date: Wed, 13 Jun 2012 15:56:31 -0500
On Wed, Jun 13, 2012 at 2:11 PM, Patrick Rapin <toupie300@gmail.com> wrote:
> With a metatable and some helper functions, you can have almost what you need :
<snip>
> function person(args)
> args = get_args(args, {
> name = required "Please provide a name", -- your name
> age = check_type("number"), -- your age
> address = "(no street address)", -- your street address
> })
>
> print(args.name, args.age, args.address)
> end
>
> person{name = "John Doo", age=56}
> --> John Doo 56 (no street address)
> person{}
> -- Error: Please provide a name
>
Hmmm.. Automating required arguments is neat and useful, but I see it
as different than what I see as perhaps two different language
changes/enhancements/(painted toenails):
Providing named argument syntax for defining function arguments,
similar to the named argument syntax used to call functions
Providing a way to place default argument assignments within the
argument definition, as an alternative to re-assigning them as a
second step within the function.
--Andrew