Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
New feature: Predicate macros
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
nathanmarz  
View profile  
 More options Jun 25 2010, 9:53 pm
From: nathanmarz <nathan.m...@gmail.com>
Date: Fri, 25 Jun 2010 18:53:59 -0700 (PDT)
Local: Fri, Jun 25 2010 9:53 pm
Subject: New feature: Predicate macros
Just pushed a powerful new feature to Cascalog today called "predicate
macros". Don't let the name scare you off, they're really easy to use!

Predicate macros allow you to arbitrarily compose together other
predicates. Predicate macros are defined when input or output vars are
explicitly defined using :> or :< within the declared variables of a
query.

When a predicate macro is used, it expands to one or more predicates.
For example, here's the how you can compose together "sum" and "count"
to create "average":

(def average (<- [!val :> !avg] (c/count !c) (c/sum !val :> !s) (div !
s !c :> !avg)))

Here's an example of how average is expanded within a query:

(<- [?avg-age] (age _ ?a) (average ?a :> ?avg-age))

expands to:

(<- [?avg-age] (age _ ?a) (count !c_1) (sum ?a :> !s_1) (div !s_1 !
c_1 :> ?avg-age))

Any non-declared variables used in a predicate macro, like !s and !c
in average, are given unique names so as not to conflict with other
variables when expanded.

Another example of a predicate macro is "distinct count", which will
count the number of unique occurrences of a value. distinct-count
secondary sorts the values and then does the computation in a single
scan of the values through a custom aggregator:

(def distinct-count (<- [!v :> !c] (:sort !v) (distinct-count-agg !
v :> !c)))

Enjoy!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »