* In computer science and information theory, Huffman coding is an entropy encoding algorithm used for lossless data compression. ...
en.wikipedia.org/wiki/Huffman_tree
Name:
Anonymous2010-12-30 3:03
>>7
C++ understands "Definitions of huffman tree on the Web"?
>>9
Lisp understands something, because it mutates likeitisliving!
Name:
Anonymous2010-12-30 8:22
I just found that semantics of `by` keyword to `sort` should be changed to column selector, instead of comparator, so with a little rethinking code got compressed into 3 lines of 80 columns each.
huff xs -> xs.sort.{[x@xs ys:_:@(nb x)]=>[[xs.len+1 x] @ys.rec]}
|> sort by=0 |> {[x]=>x|1;[a b @xs]=>nins a|0+b|0 [a|1 b|1] xs|>rec}
|> {bs x=>[[x bs]]; bs [a b]=>conc rec,[@bs 0],a rec,[@bs 1],b} []
Name:
Anonymous2010-12-30 8:26
>>13
Note, that the last line just converts tree to more readable linear form, so it is unrelated to actual computation.
>>15
His language (the one he invented) is supposedly written on top of CL, but he refuses to give it a name, and instead posts "*whatever in LISP" threads.
Usage example: (huff "The algorithm for generating a Huffman tree is very simple.")
This runs in constant time and space.
Name:
Anonymous2010-12-30 20:39
>>21 while (h.length > 1) h.push((function (x, y) [x[0] + y[0], [x, y]])(h.pop(), h.pop()));
looks like assembly code to me.
Name:
Anonymous2010-12-30 20:41
>>21 forEach(function (c) {f[c] |= 0; f[c]++});
looks like haskal code to me.
Name:
Anonymous2010-12-30 20:51
>>24
No, this code is pretty sepples, but JavaScript has operator for everything, just like Perl. The "|="-smile probably checks if Heap element isnt NIL.
>>25
``operator for everything'' refers to Perl6, which has hundreds upon hundreds of builtin operators (plus the option to define more). Supporting little more than the typical C ops doesn't count.
>>29
It's still relatively new, I wouldn't call it a meme just yet. Please post the source to the BBCode, though, it's much less obnoxious than some of the others.
>>31
I missed an [aa] {b.u.i.o.s.m.aa.sup.sub.code everything}{i !} [b][u][i][o][s][m][aa][sup][sub][code]everything[/code][/sub][/sup][/aa][/m][/s][/o][/i][/u][/b][i]![/i]
>>34
In Sepples |= does bitwise OR-ing, but to make >>21 code work, it needs to be logical OR.
Name:
Anonymous2010-12-31 3:32
>>35
Anyway, in my Lisp-dialect, addition treats NIL as 0, so I can write
length [x@xs] -> 1+xs.length
or, to simulate >>21 style, just
ncng c ?+1 f
ncng is a primitive operation for binary-searching and modification sorted b-tree lists in log2(n).
>>36 primitive operation for binary-searching
I'm sure Perl6 doesn't have an operator for that.
Name:
Anonymous2010-12-31 6:55
>>38
Internaly lists are implemented as trees, so most operations on them (like catenation and cutting) are primitive, just like "car" and "cdr" in traditional lisps.
Name:
Anonymous2010-12-31 6:58
Another example (taken from Wikipedia SQL article)
join a b by=0 -> fold {r x=>keep ?.by==x.by b |> map [x ?] |> conc r} [[]@a] (repl "class Employee name departmentId
class Department name departmentId