小编Dav*_*vid的帖子

Annonymous functions and foreach usage on event-driven code in julia

I'm currently following Julia for pythonistas notebook by Aurelien Geron (https://github.com/ageron/julia_notebooks) and I'm a bit confused on annonymous functions chapter with the following code:

handlers = []

on_click(handler) = push!(handlers, handler)

click(event) = foreach(handler->handler(event), handlers)

on_click() do event
    println("Mouse clicked at $event")
end

on_click() do event
    println("Beep.")
end

click((x=50, y=20))
click((x=120, y=10))
Run Code Online (Sandbox Code Playgroud)

Mainly I can't see how on_click() gets the event from click(). Can anyone shed some light on it?

julia

3
推荐指数
1
解决办法
43
查看次数

标签 统计

julia ×1