Skip to content

Instantly share code, notes, and snippets.

@harishtella
Created December 1, 2011 03:57
Show Gist options
  • Save harishtella/1413440 to your computer and use it in GitHub Desktop.
Save harishtella/1413440 to your computer and use it in GitHub Desktop.
; 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