dash.el
dash.el copied to clipboard
[discussion] API changes [breaks backward compatibility]
-split-at,-split-withand-separateshould return(a . b)instead of a list. It makes accessing the elements needlessly obtrusive (cadrinstead ofcdrfor the 2nd item). These functions will most likely never return tripples so the list return value has little meaning there.-partition-byshould be renamed to-partition-with. the-byprefix should be kept for predicative use. There can be, in fact, a new-partition-bythat would compare the element to the previous via some equivalence (now this usesequalby default). So it would take a comparator or predicate. This is related to #49, a-partition-bywith a predicate is basicallygroupByfrom haskell (in the thread is also the implementation of proposed-partition-with)- same goes to
-partition-by-header, in fact, it can also be implemented in terms of the above function (I think). -group-bycould also be made more powerful. As I see it, it basically computes "quotient sets" of equivalence relations, but the one supplied is implicit byequalhere. An actual-quotient-bywould be also cool (it would work much like-partition-withbut without respecting the order, that is it would truly merge all equivalent partitions). So,-group-byshould be renamed-group-with, and-group-byshould take a predicate to compare the "keys" too.-quotient-byis the same but with dropping the car of the results (which means it doesn't need explicit transformation argument either)
Note that all the "implicit split functions" can be implemented in terms of the predicative versions, either by -on combinator or by explicitely stating the transformation for keys.
The new api:
-split-atreturns((-take n list) . (-drop n list))-split-withis renamed to-split-byand returns((-take-while pred list) . (-drop-while pred list)). Alternative name is-split-while.-separatereturns((-filter pred list) . (-remove pred list))-partition-byrenamed to-partition-with, takes(fn list)-partition-bytakes(comp list), splits each time the successive elements aren't equal bycomp. Note that-partition-withis-partition-by (-on 'equal fn)-partition-by-header, same as above.-group-byrenamed to-group-with, takes(fn list), returns alist((result1 x11 x12 ...) (result2 x21 y22 ...))wherexijmaps toresult_i. This function makes a little bit of sense also with the name-group-by, but I think for consistency it's better if all the functions where there is a transformation of input to something via(a -> b)function should be called the same, that is with suffix-with. The argument for-bysuffix is that it partitions by equivalence on the result of the transformation, so two elements are equal if they map to the same thing => this is the kernel of the map. But the fact that it makes it into alist is "dirty" form algebraic POV :P-quotient-bytakes(comp list)and calculates the quotient set of list by eqv induced by comp. The union of all the partitions gives back originallist(not necessarily in same order). There can be a variant that makes all the elements in the subsets unique as well. Note that-group-withis same as(--map (cons (fn (car it)) it) (-quotient-by (-on 'equal fn) list))
Ideas, comments?
And another issue: we should make all the macros return the forms expanded to lambdas and call the function variants, instead of functions expanding to macros. That is very dirty, e.g. when I macrostep through code and --map turns into 50 lines of garbage. This shouldn't break anything, but is a big enough change to be in "breakage discussion thread"
Hi!
Good issues both. However, I am totally swamped with work.
My first reaction is that I don't want to break backwards compatibility. Could we find some way to distinguish these new versions that isn't overly cheesy? Maybe some sort of opt-in?
As for the macro-function-flip, I am all for it.