[nem-en] Nemerle meets Linq
Alejandro Serrano
trupill at yahoo.es
Sun Jan 29 12:50:09 CET 2006
Michal Moskal escribió:
> On 1/29/06, Alejandro Serrano <trupill at yahoo.es> wrote:
>
>> I've created some type of F#-like Linq integration in Nemerle as a set
>> of macros, using the same |> extension.
>> However, I need some help with macros, firstly with orderby clauses,
>> where I don't know where to start, because
>>
>> orderby (_.Country), (_.Telephone) descending
>>
>> must be converted into
>>
>> |> System.Query.Sequence.ThenByDescending (_, _.Telephone)
>> |> System.Query.Sequence.OrderBy (_, _.Country)
>>
>
> Maybe it could be:
>
> orderby [(_.Country), (_.Telephone)] descending
>
> ?
>
> This should parse, and be possible to be eaten by a macro:
>
> syntax("orderby", expr, Optional("descending"))
>
> or something like that. Maybe even:
>
> syntax("orderby", expr, Optional(desc))
>
> and check if desc is <[ descending ]>, <[ ascending ]> or whatever.
>
> I don't know if this is what you meant.
>
>
The problem is that the parsing is for each order sequence, maybe:
|> orderby [(_.Country), (_.Telephone) descending]
>> Secondly, I don't know how to make:
>>
>> def n = ["12/03/2004", "1/08/1998"];
>> def r = n
>> |> orderby (fun (x) { x })
>> |> select (System.DateTime.Parse(_));
>>
>> to be parsed as:
>>
>> def n = ["12/03/2004", "1/08/1998"];
>> def r = ( n
>> |> orderby (fun (x) { x }) )
>> |> select (System.DateTime.Parse(_));
>>
>> instead of:
>>
>> def n = ["12/03/2004", "1/08/1998"];
>> def r = n
>> |> ( orderby (fun (x) { x })
>> |> select (System.DateTime.Parse(_)) );
>>
>
> OK, this one is simple:
>
> [assembly: Nemerle.Internal.OperatorAttribute ("Nemerle.Linq",
> "|>", false, 170, 171)]
>
> Just set a priority, you think makes sense, look at macros/core.n for
> examples.
>
> Though I think operators should be left-associative by default. Kamil?
>
>
>> Finally I would like to know if there is a better way to say this:
>>
>> def r = n |> orderby (fun (x) {x} );
>>
>> to order something by itself, because _ alone gives error.
>>
>
> We once had an idea to include Nemerle.Core.identity or something like
> that. 'x => x' once we have this syntax also won't be bad.
>
A syntax like x => x.Telephone is really good
Well, the C# is a bit cleaner, but I think this Nemerle-like one is
better for extension. In fact, we would not need extension methods for
this, because |> can be used as it. However, I don't know whether:
[1, 2, 4, 3, 7] |> where _ > 3
|> orderby _
or
[1, 2, 4, 3, 7] |> where x => x > 3
|> orderby x => x
looks better. Any more ideas?
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
More information about the devel-en
mailing list