# 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

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