Timeline for Element-wise test on list elements
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 12, 2020 at 19:55 | comment | added | Leonid Shifrin |
@user106860 I think, the simplest way to think of l is that it is similar to a decorator in python. It takes a function and returns a modified function which adds listability (which happens to be implemented using Function , but that's an implementation detail).
|
|
Nov 12, 2020 at 19:04 | comment | added | user106860 |
Is it correct to think of l as a function that defines a pure function? (specifically, it looks like l` uses the input f to define a pure function based on f ?)
|
|
Sep 29, 2015 at 17:59 | comment | added | Leonid Shifrin |
@dario [2/2] ... makes it Listable - that is, wraps it in a pure function that has a Listable attribute. Due to the way evaluation sequence works in Mathematica, this leads to threading of the function over lists, before it gets applied to the individual elements. As a result, the construct l[Greater] would automatically work on lists of any dimensionality, compared to a single number - as well as for e.g. comparison of two lists with the same dimensions - like say {1,3,5} ~ l[Greater] ~ {6,4,2} . Thanks for the accept.
|
|
Sep 29, 2015 at 17:56 | comment | added | Leonid Shifrin |
@dario [1/2] The syntax a ~ f ~ b is called infix notation, and is equivalent to f[a,b] , but sometimes looks more natural. Like in this case, where it allows to somewhat make up for the notational convenience of comparison operator symbols. The expression a > b can be equivalently rewritten as Greater[a,b] in Mathematica, and similarly for other operators. So, we could also write a ~ Greater ~ b , which doesn't look bad. Now, from this form, my suggestion is only one step further. The function l I proposed is similar in spirit to Python decorator. It takes another function and ...
|
|
Sep 29, 2015 at 17:08 | comment | added | dario | I don't fully get the sintax (I'm just a beginner) but this function does what I was looking for. Thank you | |
Sep 29, 2015 at 17:07 | vote | accept | dario | ||
Sep 28, 2015 at 12:55 | history | answered | Leonid Shifrin | CC BY-SA 3.0 |