Ah, I see what you mean. I'm not sure if it's possible, though.

You'd have to determine whether f() do ... meant "function with do block"
or "iterator with do block", which isn't possible in general. So at least
you'd need special syntax for it, and by that point it's probably easier to
stick with map.


On 15 May 2014 22:33, Cameron McBride <cameron.mcbr...@gmail.com> wrote:

> Sure, Mike.  But the idea is to have this for all iterator objects
> intrinsically rather than defining it for each function that returns an
> iterator.
>
> There is likely a way to do this automagically for all iterators, but my
> julia-fu isn't strong enough that it jumped out at me when I looked over
> some source in base/.  I expect it's simple, but I don't have time to
> figure it out today.
>
> Cameron
>
>
>
> On Thu, May 15, 2014 at 4:51 PM, Mike Innes <mike.j.in...@gmail.com>wrote:
>
>> Well, if you want the first syntax you can easily define
>>
>> Base.enumerate(f::Function, args...) = map(t->f(t...), enumerate(args
>> ...))
>>
>> You could always open a pull request if you wanted to see this in Base,
>> too.
>>
>>
>> On Thursday, 15 May 2014 21:18:31 UTC+1, Cameron McBride wrote:
>>
>>> I missed enumerate() for a while,  and was happy I found it.  I find it
>>> amusing how satisfying a few missing keystrokes can be.
>>>
>>> On a related but different note, from a similar influence, I keep
>>> wanting to pass blocks to iterators.  Any chance that will ever happen?
>>>
>>> I realize that do..end blocks are used currently as syntactic sugar for
>>> methods that take a function as the first arg (e.g. open(), map()), and the
>>> same functionality can be achieved with three letters and two braces (map),
>>> but it still seems somewhat cleaner to write:
>>>
>>> enumerate(a) do i,x
>>> ...
>>> end
>>>
>>> over
>>>
>>> map(enumerate(a)) do i,x
>>> ...
>>> end
>>>
>>> which are really just equivalent, as we know, to
>>>
>>> for i,x, in enumerate(a)
>>> ...
>>> end
>>>
>>> Are there technical reasons this is a bad idea to assume?
>>>
>>> Cameron
>>>
>>> On Thu, May 15, 2014 at 1:01 PM, John Myles White 
>>> <johnmyl...@gmail.com>wrote:
>>>
>>>> I kind of suspect Stefan, like me, would instinctively call this
>>>> operation `each_with_index`.
>>>>
>>>>  -- John
>>>>
>>>> On May 15, 2014, at 6:33 AM, Kevin Squire <kevin....@gmail.com> wrote:
>>>>
>>>> One nice thing about Julia is that she borrows many (though not all) good
>>>> ideas from other languages. In this case, enumerate came from Python
>>>> (although it likely has other incarnations).
>>>>
>>>> Cheers!
>>>>    Kevin
>>>>
>>>>
>>>> On Thursday, May 15, 2014, Billou Bielour <jonatha...@epfl.ch> wrote:
>>>>
>>>>> I was thinking the same thing the other day, when using *for x in xs* I
>>>>> often find myself needing an index at some point and then I have to change
>>>>> the for loop, or write an index manually.
>>>>>
>>>>> Enumerate is exactly what I need in this case.
>>>>>
>>>>> +1 for Julia
>>>>>
>>>>>
>>>>
>>>
>

Reply via email to