vault backup: 2023-09-12 16:13:32
This commit is contained in:
parent
692b0addf2
commit
1b9c17fe27
3
.obsidian/app.json
vendored
3
.obsidian/app.json
vendored
@ -5,5 +5,6 @@
|
|||||||
"landscape": false,
|
"landscape": false,
|
||||||
"margin": "0",
|
"margin": "0",
|
||||||
"downscalePercent": 100
|
"downscalePercent": 100
|
||||||
}
|
},
|
||||||
|
"alwaysUpdateLinks": true
|
||||||
}
|
}
|
18
.obsidian/workspace.json
vendored
18
.obsidian/workspace.json
vendored
@ -13,7 +13,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 4 - A bit of imperative.md",
|
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||||
"mode": "source",
|
"mode": "source",
|
||||||
"source": false
|
"source": false
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "backlink",
|
"type": "backlink",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 4 - A bit of imperative.md",
|
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||||
"collapseAll": false,
|
"collapseAll": false,
|
||||||
"extraContext": false,
|
"extraContext": false,
|
||||||
"sortOrder": "alphabetical",
|
"sortOrder": "alphabetical",
|
||||||
@ -102,7 +102,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outgoing-link",
|
"type": "outgoing-link",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 4 - A bit of imperative.md",
|
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||||
"linksCollapsed": false,
|
"linksCollapsed": false,
|
||||||
"unlinkedCollapsed": true
|
"unlinkedCollapsed": true
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outline",
|
"type": "outline",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 4 - A bit of imperative.md"
|
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -156,10 +156,14 @@
|
|||||||
"command-palette:Open command palette": false
|
"command-palette:Open command palette": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"active": "c82ce15f72f65a11",
|
"active": "c473a791e2b34194",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
"Algo/Chapter 0 - A bit of imperative/0.1 - Print.md",
|
"Algo/Séminaire/assets/fact function response.png",
|
||||||
|
"Algo/Séminaire/assets/recursivite-meme.png",
|
||||||
|
"Pasted image 20230912155138.png",
|
||||||
|
"Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||||
"Algo/Séminaire/Chapter 4 - A bit of imperative.md",
|
"Algo/Séminaire/Chapter 4 - A bit of imperative.md",
|
||||||
|
"Algo/Chapter 0 - A bit of imperative/0.1 - Print.md",
|
||||||
"Algo/Séminaire/Untitled",
|
"Algo/Séminaire/Untitled",
|
||||||
"Algo/Séminaire/Introduction.md",
|
"Algo/Séminaire/Introduction.md",
|
||||||
"Algo/Séminaire/Chapter 1 - CAML basics.md",
|
"Algo/Séminaire/Chapter 1 - CAML basics.md",
|
||||||
@ -183,8 +187,6 @@
|
|||||||
"Mathématiques/Séminaire/Logics/Pasted image 20230904100934.png",
|
"Mathématiques/Séminaire/Logics/Pasted image 20230904100934.png",
|
||||||
"Mathématiques/Séminaire",
|
"Mathématiques/Séminaire",
|
||||||
"Mathématiques/Séminaire/Logics/Pasted image 20230904100125.png",
|
"Mathématiques/Séminaire/Logics/Pasted image 20230904100125.png",
|
||||||
"Mathématiques/Séminaire/Logics/Pasted image 20230904095003.png",
|
|
||||||
"Mathématiques/Séminaire/Logics/Pasted image 20230904094230.png",
|
|
||||||
"2023-09-01.md",
|
"2023-09-01.md",
|
||||||
"Algo",
|
"Algo",
|
||||||
"Mathématiques",
|
"Mathématiques",
|
||||||
|
@ -72,6 +72,12 @@ Error: should have int type (*because of the hidden else*)
|
|||||||
|
|
||||||
# let print_even n =
|
# let print_even n =
|
||||||
if n mod 2 = 0 then
|
if n mod 2 = 0 then
|
||||||
print_int n ;
|
begin
|
||||||
print_newline()
|
print_int n ;
|
||||||
|
print_newline()
|
||||||
|
end;; (*begin and end used to execute more than 1 function into a if*)
|
||||||
|
val print_even : int -> unit = <fun>
|
||||||
|
|
||||||
|
# print_even 4;;
|
||||||
|
4
|
||||||
|
-: unit = ()
|
||||||
|
44
Algo/Séminaire/Chapter 5 - Recursivity.md
Normal file
44
Algo/Séminaire/Chapter 5 - Recursivity.md
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
![[recursivite-meme.png]]
|
||||||
|
### 5.1. Simple functions
|
||||||
|
To create a recursive function we have to use this structure
|
||||||
|
|
||||||
|
```Ocaml
|
||||||
|
(*normal function*)
|
||||||
|
# let f = expr -> 1) evaluate expr ; 2) create & link f to the result
|
||||||
|
|
||||||
|
(*recursiv function*)
|
||||||
|
# let rec f = expr -> 1) create f ; 2) evaluate expr ; 3) link f to the result
|
||||||
|
```
|
||||||
|
|
||||||
|
**Exmple with factorial function**
|
||||||
|
```Ocaml
|
||||||
|
# let rec fact = function
|
||||||
|
| 0 -> 1
|
||||||
|
| n -> n * fact(n-1)
|
||||||
|
|
||||||
|
# fact 4;;
|
||||||
|
-: int = 24
|
||||||
|
```
|
||||||
|
![[fact function response.png]]
|
||||||
|
> ⚠️ CAML have a call stack limite (it will block with stack overflow if the limit is reach)
|
||||||
|
|
||||||
|
**Basic expression**
|
||||||
|
```Ocaml
|
||||||
|
let rec f params =
|
||||||
|
if stop condition then
|
||||||
|
stop expression
|
||||||
|
else
|
||||||
|
recursive expression
|
||||||
|
```
|
||||||
|
|
||||||
|
To write a recurvise function we need two things
|
||||||
|
1) There always is a stop case
|
||||||
|
2) The parameters of a recursive call are different then its parent call, and go towards the stop condition
|
||||||
|
|
||||||
|
### 5.2. Down
|
||||||
|
```Ocaml
|
||||||
|
# let rec countdown n =
|
||||||
|
if n = 0 then
|
||||||
|
print_int(0)
|
||||||
|
else
|
||||||
|
print_int(countdown (n-1));;
|
BIN
Algo/Séminaire/assets/fact function response.png
Normal file
BIN
Algo/Séminaire/assets/fact function response.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
BIN
Algo/Séminaire/assets/recursivite-meme.png
Normal file
BIN
Algo/Séminaire/assets/recursivite-meme.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 867 KiB |
Loading…
x
Reference in New Issue
Block a user