[Python-ideas] Vectorization [was Re: Add list.join() please]

Steven D'Aprano steve at pearwood.info
Sat Feb 2 17:36:18 EST 2019


On Sat, Feb 02, 2019 at 07:58:34PM +0000, Jeff Allen wrote:

[MRAB asked]
> >OK, here's another one: if you use 'list(...)' on a vector, does it 
> >apply to the vector itself or its members?

With the Julia vectorization operator, there is no puzzle there.

list(vector) applies list to the vector itself.

list.(vector) applies list to each component of vector.


> The problem, of course, is that list() now has to understand Vector 
> specially, and so does any function you think of applying to it. 

*The whole point* of the Julia syntax is that no function has to 
understand any sequence. When we write:

for item in vector:
    func(item)

func only has to understand item, not vector. The same applies to the 
Julia syntax

func.(vector)

There's no puzzle here, no tricky cases, because it is completely 
deterministic and explicit: func(x) always calls func with x as 
argument, func.(x) always calls func with each of x's items as 
arguments.



> Operators are easier (even those like [1:]) because Vector can make its 
> own definition of each through (a finite set of) dunder methods. To make 
> a Vector accept an arbitrarily-named method call like my_strings.upper() 
> to mean:

With the Julia syntax, there is no need for vectors (or lists, or 
generators, or tuples, or sets, or any other iterator...) to accept 
arbitrary method calls. So long as vectors can be iterated over, 
func.(vector) will work.



More information about the Python-ideas mailing list