Re: named parameter

126 views
Skip to first unread message

Moritz Eysholdt

unread,
Oct 16, 2012, 3:57:16 AM10/16/12
to xtend...@googlegroups.com
Hi,

you can have something like named parameters already when using closures:

class X {
def hello((Param) => void param) {
val p = new Param
param.apply(p)
println('''level=«p.level» message=«p.message»''')
}


def call() {
hello[message="world" level="info"]
}
}

class Param {
@Property String message
@Property String level
}

regards,
  Moritz

On Oct 16, 2012, at 9:20 AM, b.po...@gmail.com wrote:

Hi,

 xtend look pretty promising. i wondering if you will add "named parameter" in roadmap.

example:
---------------

def hello(String message, String level){...}

hello(message="world", level="info")

best regards,

Roger Gilliar

unread,
Mar 27, 2013, 6:21:43 AM3/27/13
to xtend...@googlegroups.com, mor...@eysholdt.de, ziyu4...@gmail.com
+1 for named arguments

Regards
 Roger

Micael Pedrosa

unread,
Mar 30, 2017, 5:56:03 AM3/30/17
to Xtend Programming Language, mor...@eysholdt.de
I would also love to see this as a native feature of Xtend. Also default values and shorter constructor definitions.
This is a common feature for many modern languages, specially useful on enforcing rules in constructing objects. 

It will be nice to use constructors like:
new(val String name, val int value = 10) {}
Avoiding to set the values in the constructor body, and repeat the declaration in the class.

Karsten Thoms

unread,
Mar 30, 2017, 6:43:45 AM3/30/17
to xtend...@googlegroups.com
The „val“ keyword should be obsolete in this case
new(String name, int value = 10) {}

Besides that this could be a valid feature.

For enhancement requests please file an issue to https://github.com/eclipse/xtext-xtend/issues

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Micael Pedrosa

unread,
Apr 5, 2017, 4:55:25 AM4/5/17
to Xtend Programming Language
Something should mark the parameter as a class field also, but maybe there's another way.
Reply all
Reply to author
Forward
0 new messages