An introduction to Kerf
scottlocklin.wordpress.com
scottlocklin.wordpress.com
"Kerf is a programming language built on pragmatism, borrowing ideas from many popular tools. The syntax of Kerf will be familiar enough to anyone who has programmed in C, Python or VBA. Data is described using syntax from JSON (JavaScript Object Notation), a text-based data interchange format. Queries to search, sort and aggregate data can be performed using SQL syntax. Kerf’s built-in commands have aliases which allow programmers to use names and terms they are already used to."
Let me emphasize that while I'm about to implement most of his blog post in numpy/pandas, I don't mean to come off as critical or dismiss building a new one. Kerf looks pretty cool. I just don't think this post gives much reason to believe there is nothing comparable to it.
Idiomatic numpy:
def wavg(x,y):
return sum(x*y) / sum(x)
Less idiomatic, but analogous to kerf or J: def wavg(x,y):
return add.reduce(x*y) / add.reduce(x)
arange(1,6) is equivalent to his range(5), and full((5,), 1) is equivalent to repeat(5,1).The SQL-ish engine looks fairly similar to pandas:
df = pandas.DataFrame({'a' : arange(5), 'b' : ['a', 'b', 'c', 'd', 'e']})
#Result is:
a b
0 0 a
1 1 b
2 2 c
3 3 d
4 4 e
df[df.a > 2]
#Result is
a b
3 3 d
4 4 e
Pandas similarly has joins, averages and other aggregates, etc. E.g.: pandas.merge(df1, df2, how='inner', left_on='a', right_on='b')
is equivalent to: SELECT * FROM df1 INNER JOIN df2 ON df1.a = df2.b;
Syntactically it's a bit different (embedded SQL is pretty cool) but from this blog post I don't see any major semantic differences.However, if there are important differences under the hood, I'd love to hear about them. Again, I'm really not trying to criticize Locklin for rolling his own, I'm just disputing a minor point.
That's what the APL world brings to the table.
FWIIW, you can read about my comparing Jd (another APL related columnar database) to a Blaze like tool (Spark bigDF) on the J list:
http://jsoftware.com/pipermail/database/2015-May/000076.html
Kerf github: https://github.com/kevinlawler/kerf
There's a way to make J look more readable, but by the time you're able to accomplish this, you can read the J runes, and have realized the syntax sugar just slows down the parser.
Yes, it's harder to read... You can combine wise naming scheme with good use of spaces - and also short lines, which anyway carry a lot of work - to make programs more readable. Comments are also available :) - in fact, I found that J really encourages the literate programming style. As they say, "in APL you solve a problem in 5 minutes, then spend an hour trying to write a most elegant and short solution". Indeed.
Gonna grab the current binary to play around with, I love learning new styles of programming and kerf seems rather approachable compared to the others in it's family.
This version is technically unrestricted, but cannot be used for commercial purposes.