Introduction to Elm, v2

# Nested Function Expressions

## Richard Feldman

Vendr, Inc.

### Check out a free preview of the full Introduction to Elm, v2 course

The "Nested Function Expressions" Lesson is part of the full, Introduction to Elm, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Richard covers how to write a comment and how functions are called in Elm.

Preview
Close

### Transcript from the "Nested Function Expressions" Lesson

[00:00:00]
>> Richard Feldman: Okay, so here's our complete pluralized function and the way that we would actually use this in an Elm application, instead of console.log, we would probably render it like this. We'd say main = text. (pluralize "leaf" "leaves" 1). And so here you can see, another difference between Elm and JavaScript, and the way that pluralize is being called a syntactic difference.

[00:00:22]
So this is a function call to pluralize passing three arguments. Leaf, leaves, and 1. Notice that there's again, no commas, and where the parentheses are. This is a common thing to mess up when you're just getting into Elm, because the parentheses go in a different place in Elm than they do in JavaScript.

[00:00:38]
So in Elm, functions are called by using whitespace. So just the fact that I have pluralize followed by some whitespace followed by the arguments means I'm calling pluralize. The purpose of this parenthesis here is to ambiguate between this nested function call and the outer function call of test.

[00:00:57]
So this right here, is a function call to text, a function needs test, passing one argument, and that one argument is a result of calling pluralize passing leaf, leaves and one. If we did not have the parenthesis there, this would be a function called to text passing for arguments.

[00:01:12]
The first argument being the pluralized function itself, then leaf, leaves and 1. So that's the difference. The parentheses here essentially work the same way that they do in math. So sort of disambiguate between nested expressions. So we don't have parentheses sort of touching the function like we do in JavaScript.

[00:01:29]
All we need is whitespace to call a function. Okay, one more note, comments. So inline comments work very similarly to how they do in JavaScript, except you use -- instead of //. And multi-line comments you use curly brace- and then- curly brace, rather than /* and */. Otherwise, they essentially work exactly the same way as they do in JavaScript.

### Learn Straight from the Experts Who Shape the Modern Web

• In-depth Courses