Published by Julius Chrobak on 2012 12 20.
The latest version of Bandicoot language (still in development) comes with two new built in functions. Normally, I would not consider this to be important enough to write a blog about it but this time it is different. Those two functions are the first built in Bandicoot functions developers can use in primitive expressions, and more are coming. So stay tuned!
In order to support various built in functions in the future we decided to use a simple concept of packages to group them together according to their meaning and not to overload the user's namespace.
There are two packages available right now:
The Time package groups together all functions related to time manipulation. The list of functions implemented is short:
The String package groups together all functions which help to manipulate string attributes. This list is also very short:
Let's imagine we have a set of orders with an attribute called "created" which captures the time stamp when an order was created. There are two simple examples which come to my mind immediately and nicely demonstrate the use of the Time.Now function:
var orders {id int, user string, created long}; # extend the input with the current time fn StoreOrder(in {id int, user string}) void { orders += extend (created = Time.Now) in; } # returns order ids of the recent orders only (not older than 1 hour) fn Recent() {id int} { return select (created > Time.Now - 3600L * 1000L) orders; }
The String.Index function is also straightforward so I am going to put down only one example. It finds out the first occurrence of a word in each sentence from the input set in one go:
fn GetIndex(sentences {value string}, s string) {value string, idx int} { return extend (idx = (String.Index value s)) sentences; }
$ cat sentences.csv value Hello World! This world is great. Isn't it? $ curl --data-binary @sentences.csv 'http://localhost:12345/GetIndex?s=world' idx,value 5,This world is great. Isn't it? -1,Hello World!
Checkout the latest code from the master branch and give it a try!
In the near future you can expect more functions to be built. Feel free to raise a github issue or drop me an email (julius at bandilab dot org) if you have any suggestions or ideas on what the next batch of functions added to the language should be.