Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Return outer function in do block

$
0
0

@jamblejoe wrote:

Is it possible to return an outer function from a do block, e.g. the following code

f(x) = map(x) do y; if y==1; return -1; end; x *=2; end
f([1,2])

evaluates to

2-element Array{Int64,1}:
 -1
  4

I guess this is because the do block is creating an anonymous function, in which the return then gets evaluated. Is it possible to return from the enclosing function f and return just
-1
? Maybe that is not useful/possible for map but I would find this very handy for loading files with open or h5open.

Best,
Jamble

Posts: 6

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles