Well they aren't necessary I could always write the function like I did,
but it is a common template. Just do some initialization and return the
anonymous function in order to get the scoping right. Is a simple
constructor function like below the right way?
function Closure(initvalue, lambda)
let variable = initvalue
return lambda
end
Maybe I don't understand functional programming well enough. Can one just
make anonymous functions like `(y) -> x = y+x` ? How does it know what to
initialize x to, or the type of x?
On Friday, January 17, 2014 11:25:23 AM UTC-5, Stefan Karpinski wrote:
>
> I'm confused about where the need for macros comes in...
>
> On Friday, January 17, 2014, James Fairbanks
> <[email protected]<javascript:>>
> wrote:
>
>> So we can implement closures in Julia with a function definition that
>> returns a function. And we can use macros to simplify repetitive tasks. How
>> would one combine these to make a macro that defined a closure? My most
>> common use case is a closure that needs an initialized variable and then
>> behaves as a 1 argument function. Such as an accumulator:
>>
>> https://gist.github.com/jpfairbanks/8475467#file-closure-jl
>>
>> I suppose their are other|generalized ways to do this and I would like to
>> know those too.
>>
>> -James
>>
>