vault backup: 2023-09-05 15:07:54
This commit is contained in:
@ -11,20 +11,20 @@ It's a simple language to write.
|
||||
- **;;** is the end of the line
|
||||
|
||||
```Ocaml
|
||||
_: int=3 *That a Caml answer to the previus program*
|
||||
_: int=3 (*That a Caml answer to the previus program*)
|
||||
```
|
||||
|
||||
```Ocaml
|
||||
# 1+2.2;; *That an error*
|
||||
# 1+2.2;; (*That an error*)
|
||||
|
||||
# 1. +. 2.2;; *This is good*
|
||||
# 1. +. 2.2;; (*This is good*)
|
||||
```
|
||||
## 1.2. CAML interaction
|
||||
```Ocaml
|
||||
# 1;; *He can be a simple expression*
|
||||
# 1;; (*He can be a simple expression*)
|
||||
_: int=1
|
||||
|
||||
# "Hello World";; *He can be a string*
|
||||
# "Hello World";; (*He can be a string*)
|
||||
_:string = "Hello World"
|
||||
```
|
||||
|
||||
@ -38,10 +38,10 @@ _: type of the evaluation = result of the evaluation
|
||||
### Global definitions
|
||||
```Ocaml
|
||||
# let x=1+2;;
|
||||
val x:int = 3 *our current env is x -> 3*
|
||||
val x:int = 3 (*our current env is x -> 3*)
|
||||
|
||||
# let y=x/2;;
|
||||
val y:int = 1 *our current env is x -> 3 ; y -> 1*
|
||||
val y:int = 1 (*our current env is x -> 3 ; y -> 1*)
|
||||
|
||||
# let x = 2
|
||||
val x : int = 2
|
||||
@ -61,7 +61,7 @@ _ : float = 6.28
|
||||
_ : float = 30
|
||||
|
||||
# x;;
|
||||
_ : int =2 *see global definition section*
|
||||
_ : int =2 (*see global definition section*)
|
||||
|
||||
# pi;;
|
||||
error: unbound value pi
|
||||
@ -71,15 +71,14 @@ when there is the keyword ``len``and ``in`` that create a local definition. A lo
|
||||
|
||||
### Multiple definitions
|
||||
```Ocaml
|
||||
# let r = 1. and pi : 3.14 in 2 *. pi *. r;; *local version*
|
||||
# let r = 1. and pi : 3.14 in 2 *. pi *. r;; (*local version*)
|
||||
_ : float = 6.28
|
||||
|
||||
# let x = 1.2 and y = "Hello";;
|
||||
val x: float = 1.2 *our current env is x -> 3 ; y -> 1 ; x -> 1.2 *
|
||||
val y: string = "Hello" *our current env is x -> 3 ; y -> 1 ; x -> 1.2 ; y -> "Hello"*
|
||||
|
||||
val x: float = 1.2 (*our current env is x -> 3 ; y -> 1 ; x -> 1.2 *)
|
||||
val y: string = "Hello" (*our current env is x -> 3 ; y -> 1 ; x -> 1.2 ; y -> "Hello"*)
|
||||
# let x = 2 and y = x + 1 in y + 2;;
|
||||
Error *because x is 1.2 in our current evaluation*
|
||||
Error (*because x is 1.2 in our current evaluation*)
|
||||
```
|
||||
> ⚠️ We have only one `let` and one `in` for the multiple definitions methods
|
||||
|
||||
@ -129,7 +128,7 @@ _: bool = false
|
||||
- String: `string`
|
||||
```Ocaml
|
||||
# "ab" < "abc" ;;
|
||||
_: bool = true *because O chars -> 2^24 - 6 chars*
|
||||
_: bool = true (*because O chars -> 2^24 - 6 chars*)
|
||||
|
||||
# "Hello" ^" World"
|
||||
_: string = "Hello World"
|
||||
|
Reference in New Issue
Block a user