[nem-en] Nemerle meets Linq
Michal Moskal
michal.moskal at gmail.com
Sun Jan 29 12:38:30 CET 2006
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.
>
> 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.
> I attah by implementation plus a free Linq implementation.
Great! I'll have a look.
--
Michal Moskal,
http://nemerle.org/~malekith/
More information about the devel-en
mailing list