Skip to content

Commit

Permalink
fix grammar issues in functions generating functions concept (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
tasxatzial authored Sep 8, 2024
1 parent c42619d commit 7b46e1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions concepts/functions-generating-functions/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About

Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of high-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.
Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of higher-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.

## partial

Expand All @@ -15,7 +15,7 @@ The result is a new function which applies the original one `my-function` by fix
; => equivalent to (my-function v1 v2 ... vM xM+1 xM+2 ... xN)
```

As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such function as follows:
As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such a function as follows:

```clojure
(def inc-by-9 (partial + 9))
Expand All @@ -42,13 +42,13 @@ And use `partial` to always use a specific greetings message:

## comp

`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the ouput of the previous function to the next one. In mathematical notation this is expressed as:
`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the output of the previous function to the next one. In mathematical notation this is expressed as:

```
f1 (f2 (... fN(x)))
```

In clojure, this is equivalent to doing:
In Clojure, this is equivalent to doing:
```clojure
(f1 (f2 (... (fN x))))
```
Expand Down Expand Up @@ -79,7 +79,7 @@ As an example, let's say we want to sum a series of numbers and then multiply th

`memoize` allows to reuse previously computed results associated with a given input. Given the same input, the *memoized* function returns the same result without having to recompute it again. It takes advantage of the fact that `clojure` functions are, by default, *referentially transparent*: given the same input, they always produce the same output, which makes it possible to reuse previous computations with ease.

In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so we can easily compare the *computation time* before and after using `memoize`.
In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so that we can easily compare the *computation time* before and after using `memoize`.

```clojure
(defn my-time-consuming-fn
Expand All @@ -89,7 +89,7 @@ In order to see how this works, let us use a synthetic case where the function s
(* x 2)
)

; We measure the time it takes the original function
; We measure the time it takes for the original function
(time (my-time-consuming-fn 3))
; => "Elapsed time: 2007.785622 msecs"
; => 6
Expand Down
12 changes: 6 additions & 6 deletions concepts/functions-generating-functions/introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of high-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.
Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of higher-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.

## partial

Expand All @@ -15,7 +15,7 @@ The result is a new function which applies the original one `my-function` by fix
; => equivalent to (my-function v1 v2 ... vM xM+1 xM+2 ... xN)
```

As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such function as follows:
As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such a function as follows:

```clojure
(def inc-by-9 (partial + 9))
Expand All @@ -42,13 +42,13 @@ And use `partial` to always use a specific greetings message:

## comp

`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the ouput of the previous function to the next one. In mathematical notation this is expressed as:
`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the output of the previous function to the next one. In mathematical notation this is expressed as:

```
f1 (f2 (... fN(x)))
```

In clojure, this is equivalent to doing:
In Clojure, this is equivalent to doing:
```clojure
(f1 (f2 (... (fN x))))
```
Expand Down Expand Up @@ -79,7 +79,7 @@ As an example, let's say we want to sum a series of numbers and then multiply th

`memoize` allows to reuse previously computed results associated with a given input. Given the same input, the *memoized* function returns the same result without having to recompute it again. It takes advantage of the fact that `clojure` functions are, by default, *referentially transparent*: given the same input, they always produce the same output, which makes it possible to reuse previous computations with ease.

In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so we can easily compare the *computation time* before and after using `memoize`.
In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so that we can easily compare the *computation time* before and after using `memoize`.

```clojure
(defn my-time-consuming-fn
Expand All @@ -89,7 +89,7 @@ In order to see how this works, let us use a synthetic case where the function s
(* x 2)
)

; We measure the time it takes the original function
; We measure the time it takes for the original function
(time (my-time-consuming-fn 3))
; => "Elapsed time: 2007.785622 msecs"
; => 6
Expand Down

0 comments on commit 7b46e1f

Please sign in to comment.