wish for new nemerle feature: Java like anonymous classes

6 views
Skip to first unread message

jens

unread,
Feb 3, 2009, 11:37:00 PM2/3/09
to nemerle-dev

example:

foo(i : int) : SomeType {
SomeType(i) /* syntax and semantic as constructor call but SomeType
may be abstract or interface (no arg for interface though) */
{
/* syntax as class body, semantic as local functions body */
public bar() : bool{
i > 0
}
}
}

=>

class UniqueName : SomeType{
UniqueName(i : int) : SomeType(i){
}
public bar() : bool{
i > 0
}
}
foo(i : int){
UniqueName(i)
}

catbert

unread,
Feb 23, 2009, 4:47:09 AM2/23/09
to nemerle-dev
Hmm, when I'm in need of anonymous classes, I always can get this
behaviour using local functions.

E. g., for your case you can write something like:

def foo = x => x > 0;

And you can for example sort a list:

List[string] x;
FillListWithRandomStrings(x);
x.Sort(foo);

jens odborg

unread,
Feb 23, 2009, 11:32:14 AM2/23/09
to nemer...@googlegroups.com
Sure you can do the behaviour part with local functions but other net components expect you to fullfill an interface, unless that interface is enumerable (where you can use cofunctions and yield) you currently have to create some glue code to map the local functions to the interfacess, basically what you want is to return a class where your local functions fullfill an interface or overload methods in an existing class

catbert

unread,
Feb 23, 2009, 1:03:32 PM2/23/09
to nemerle-dev
Now I see. It would probably be interesting to implement such a
feature using Nemerle macros.

jens odborg

unread,
Feb 23, 2009, 1:49:26 PM2/23/09
to nemer...@googlegroups.com
Yes, I guess so but for different reasons it seems that it cant be done as a pure syntax extension instead you probably have to rely on calling compiler internal parser functions.
 
e.g. the most elegan syntax would be
 
constructor_name (parameter_to_base) { new class members }

but (among other)
  • syntax must start with a keyword
  • "{" ... "}" is not supported in "syntax(...)"
  • there is currently no hook for parsing class body members
 
 
 
On 2/23/09, catbert <catbe...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages