dash.el icon indicating copy to clipboard operation
dash.el copied to clipboard

[discussion] API changes [breaks backward compatibility]

Open Fuco1 opened this issue 11 years ago • 2 comments
trafficstars

  • -split-at, -split-with and -separate should return (a . b) instead of a list. It makes accessing the elements needlessly obtrusive (cadr instead of cdr for the 2nd item). These functions will most likely never return tripples so the list return value has little meaning there.
  • -partition-by should be renamed to -partition-with. the -by prefix should be kept for predicative use. There can be, in fact, a new -partition-by that would compare the element to the previous via some equivalence (now this uses equal by default). So it would take a comparator or predicate. This is related to #49, a -partition-by with a predicate is basically groupBy from 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-by could also be made more powerful. As I see it, it basically computes "quotient sets" of equivalence relations, but the one supplied is implicit by equal here. An actual -quotient-by would be also cool (it would work much like -partition-with but without respecting the order, that is it would truly merge all equivalent partitions). So, -group-by should be renamed -group-with, and -group-by should take a predicate to compare the "keys" too. -quotient-by is 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-at returns ((-take n list) . (-drop n list))
  • -split-with is renamed to -split-by and returns ((-take-while pred list) . (-drop-while pred list)). Alternative name is -split-while.
  • -separate returns ((-filter pred list) . (-remove pred list))
  • -partition-by renamed to -partition-with, takes (fn list)
  • -partition-by takes (comp list), splits each time the successive elements aren't equal by comp. Note that -partition-with is -partition-by (-on 'equal fn)
  • -partition-by-header, same as above.
  • -group-by renamed to -group-with, takes (fn list), returns alist ((result1 x11 x12 ...) (result2 x21 y22 ...)) where xij maps to result_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 -by suffix 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-by takes (comp list) and calculates the quotient set of list by eqv induced by comp. The union of all the partitions gives back original list (not necessarily in same order). There can be a variant that makes all the elements in the subsets unique as well. Note that -group-with is same as (--map (cons (fn (car it)) it) (-quotient-by (-on 'equal fn) list))

Ideas, comments?

Fuco1 avatar Dec 12 '13 11:12 Fuco1

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"

Fuco1 avatar Dec 12 '13 16:12 Fuco1

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.

magnars avatar Dec 13 '13 12:12 magnars