From 0790efd585b4d73a7f9561854d09fb09f78a98f9 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Wed, 14 Sep 2011 12:07:05 -0600 Subject: [PATCH] [honu] add order-by clause --- collects/tests/honu/linq.honu | 2 ++ collects/tests/honu/linq.rkt | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/collects/tests/honu/linq.honu b/collects/tests/honu/linq.honu index c669154050..35624b7db2 100644 --- a/collects/tests/honu/linq.honu +++ b/collects/tests/honu/linq.honu @@ -38,6 +38,8 @@ printf("table1: ~a\n", xml.Descendants("Table1")); struct test{name, address}; var addresses = linq from add in xml.Descendants("Table1") + where true + orderby add.Element("familyName").Value() select test(add.Element("familyName").Value(), add.Element("address").Value()); diff --git a/collects/tests/honu/linq.rkt b/collects/tests/honu/linq.rkt index 4adbd6a6ff..d073a913a5 100644 --- a/collects/tests/honu/linq.rkt +++ b/collects/tests/honu/linq.rkt @@ -11,9 +11,11 @@ syntax/parse)) (define-literal+set linq-literals - linq-from linq-select linq-where) + linq-from linq-select linq-where + linq-order-by) (provide linq (rename-out [linq-from from] [linq-where where] + [linq-order-by orderby] [linq-select select])) (define-honu-syntax linq @@ -23,10 +25,20 @@ [(_ linq-from name:id honu-in (~var store honu-expression) (~optional (~seq linq-where where:honu-expression)) + (~optional (~seq linq-order-by order-by:honu-expression)) linq-select select:honu-expression . rest) (define out - #'(for/list ([name store.result]) - select.result)) + (with-syntax ([(guard ...) + (if (attribute where) + #'(#:when where.result) + #'())] + [order (if (attribute order-by) + #'(sort store.result string