-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Davi Barreira
committed
Jul 20, 2022
1 parent
cc0844c
commit b545017
Showing
12 changed files
with
11,446 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.ipynb_checkpoints/ | ||
*.CondaPkg/ | ||
*textcat_demo/ | ||
*textcat_docs_issues/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "eb18deb9-c78c-46b0-9eff-746e4c7fd521", | ||
"metadata": {}, | ||
"source": [ | ||
"# Grokking Simplicity\n", | ||
"\n", | ||
"## Chapter 1\n", | ||
"\n", | ||
"### 1.1. Defining Functional Programming\n", | ||
"\n", | ||
"We start with a definition of **Function Programming (FP)**. It is a programming paradigm characterized by\n", | ||
"the use of **pure functions** and the avoidance of **side effects**.\n", | ||
"\n", | ||
"What are **pure functions**? In programming, a pure function is a function that depends *only* on it's arguments,\n", | ||
"such that it always returns the same value if the same same arguments are passed.\n", | ||
"\n", | ||
"What are **side effects**? A side effect is anything that a function does that affects the \"outside\"/\"global scope\". For example,\n", | ||
"consider the following function:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "51a9ed1b-3bc7-471d-ab23-ce9e4dc0113a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"squaring" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"4" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"function squareprint(x::Real)\n", | ||
" print(\"squaring\")\n", | ||
" x^2\n", | ||
"end\n", | ||
"squareprint(2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "469cc91f-8868-4ecb-853e-b38121f2c3ff", | ||
"metadata": {}, | ||
"source": [ | ||
"This function has the side-effect of printing \"squaring\". Another possible side-effect would be sending an email, writing a log, and so on. \n", | ||
"\n", | ||
"From this definition, it might looks like FP is useless in the real world, since we need side-effects for most\n", | ||
"practical programs. The answer is that, *actually*, FP allows side-effects, but in a very controlled manner. Hence one of it's utility.\n", | ||
"By controlling side-effects (when an how they occur), we can better understand when some kind of error is going on." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "083d71a0-3fd5-4c70-843f-c5f997f422d4", | ||
"metadata": {}, | ||
"source": [ | ||
"### 1.2 Data, Calculation and Action \n", | ||
"\n", | ||
"In FP, every chunk of code can be classified in Data, Calculation or Action.\n", | ||
"Actions are usually pieces of code that result in side-effects, and thus, it matters when and how\n", | ||
"many times such piece of code is used. For example, a function `sendemail()` would be an Action,\n", | ||
"since calling this function twice would result in sending two emails. Yet, a function\n", | ||
"such as `sum(x::Vector{Real})` would be a calculation, since calling it several times does\n", | ||
"not alter anything, it just calculates the same sum over and over again.\n", | ||
"\n", | ||
"Hence, Actions are the most \"dangerous\" pieces of code. On the other hand,\n", | ||
"Data is \"inert\", while Calculations can be \"executed\". Thus, there is sort of a hierarchy of\n", | ||
"complixity to simplicity, where Actions are the most complex and Data are the most simple." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Julia (4 threads) 1.7.2", | ||
"language": "julia", | ||
"name": "julia-(4-threads)-1.7" | ||
}, | ||
"language_info": { | ||
"file_extension": ".jl", | ||
"mimetype": "application/julia", | ||
"name": "julia", | ||
"version": "1.7.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Functional Programming with Julia | ||
|
||
These notes are based on the "Grokking Simplicty" book. |
Oops, something went wrong.