Created
December 1, 2011 03:57
-
-
Save harishtella/1413440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; you can just take the first two ?b's because they come into | |
; bufferop sorted | |
(defbufferop top-2 [tuples] | |
(take 2 tuples)) | |
; let cascalog do the sorting (grouped by ?a) for you | |
(??<- [?a ?b-out] | |
(data ?a ?b) | |
(:sort ?b) | |
(:reverse true) | |
(top-2 ?b :> ?b-out)) | |
; and when you have more vars that you want to define the grouping with | |
; you just add them to the output vars | |
; this gives you the top-2 ?b for every ?a ?c ?d ?e | |
??<- [?a ?b-out ?c ?d ?e] | |
(data ?a ?b ?c ?d ?e) | |
(:sort ?b) | |
(:reverse true) | |
(top-2 ?b :> ?b-out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment