Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Julia 1.0 Programming

You're reading from   Julia 1.0 Programming Dynamic and high-performance programming to build fast scientific applications

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher
ISBN-13 9781788999090
Length 196 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ivo Balbaert Ivo Balbaert
Author Profile Icon Ivo Balbaert
Ivo Balbaert
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Installing the Julia Platform FREE CHAPTER 2. Variables, Types, and Operations 3. Functions 4. Control Flow 5. Collection Types 6. More on Types, Methods, and Modules 7. Metaprogramming in Julia 8. I/O, Networking, and Parallel Computing 9. Running External Programs 10. The Standard Library and Packages 11. Other Books You May Enjoy

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image