- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 208字
- 2021-06-24 14:21:44
Anonymous functions
The function f(x, y) at the end of the Defining functions section can also be written with no name, as an anonymous function: (x, y) -> x^3 - y + x * y. We can, however, bind it to a name, such as f = (x, y) -> x^3 - y + x * y, and then call it, for example, as f(3, 2). Anonymous functions are also often written using the following syntax (note the space before (x)):
function (x) x + 2 end (anonymous function) julia> ans(3) 5
Often, they are also written with a lambda expression as (x) -> x + 2. Before the stab character (->) are the arguments, and after the stab character we have the return value. This can be shortened to x -> x + 2. A function without arguments would be written as () -> println("hello, Julia").
Here is an anonymous function taking three arguments: (x, y, z) -> 3x + 2y - z. When the performance is important, try to use named functions instead, because calling anonymous functions involves a huge overhead. Anonymous functions are mostly used when passing a function as an argument to another function, which is precisely what we will discuss in the next section.
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- LabVIEW2018中文版 虛擬儀器程序設計自學手冊
- Python數據可視化:基于Bokeh的可視化繪圖
- Cassandra Data Modeling and Analysis
- PHP+MySQL網站開發項目式教程
- Highcharts Cookbook
- Learning Python Design Patterns
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- Everyday Data Structures
- 青少年學Python(第2冊)
- Drupal 8 Development Cookbook(Second Edition)
- SQL Server實例教程(2008版)
- 零基礎C語言學習筆記
- JavaScript程序設計實例教程(第2版)
- A/B 測試:創新始于試驗