How to use anon. func + how to use web irc?

In the manual it has this eg

julia> function (x)
           x^2 + 2x - 1
       end
#3 (generic function with 1 method)

How can I call this function?

PS I tried to ask on IRC by visiting the link on the Julia website IRC but it just gave the message == Cannot send to nick/channel: #julia.

julia> f = function (x)
               x^2 + 2x - 1
           end
#3 (generic function with 1 method)

julia> f(3)
14

I undertand that I could assign. But in the manual the anon. function is not assigned, so I really want to know how to call it by the “internal” name “#3”.

I’m sure it’s possible to do this, but why would you? It’s an anonymous function for a reason…

This example is given in the manual which I’m trying to edit but as it stands the example can’t be used because there’s no explanation of how it can be done. So, either the example should be removed from the manual or the manual needs to explain how to use it. That’s why I want to know.

Can you link to the place in the manual that says this?

Edit: I suppose you mean here: https://docs.julialang.org/en/v1/manual/functions/#man-anonymous-functions-1

In this section: https://docs.julialang.org/en/v1/manual/functions/#man-anonymous-functions-1

Two examples are given, but neither of them can be used as-is. Of course the first one could be passed as an argument to, say, map, but can the second also be passed?

Edit: Oh, it turns out that you really can do say map(function (x) x^2, a), so you don’t need to be able to access the anon. function’s name for this to make sense. I’ll clarify this in the manual.

But how is that different from e.g.

julia> sin(3)
0.1411200080598672

– there’s no global that contains that result (apart from ans, obviously).

2 Likes