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
0 parents
commit 811a771
Showing
3 changed files
with
44 additions
and
0 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,29 @@ | ||
;; appel de la méthode println sur un objet de type Text | ||
"Hello" println | ||
|
||
;; 2 appels sur la même ligne | ||
"hello" println. "world" println. | ||
|
||
;; création d'une méthode | ||
foo = method("Hello" println) | ||
foo() | ||
|
||
;; une méthode est un objet de type "DefaultMethod" | ||
method() kind println | ||
|
||
;; calcul du factoriel du nombre 10 | ||
fact = method(n, if((0..1) include?(n), 1, n * fact(n-1))) | ||
fact(10) println | ||
|
||
;; création d'un nouveau type | ||
Foo = Origin mimic | ||
Foo kind println | ||
|
||
;; création d'une instance | ||
foo = Foo mimic | ||
foo kind println | ||
|
||
;; obtenir des singletons en surchargeant la méthode de sous-typage | ||
Foo = Origin mimic | ||
Foo mimic = Foo | ||
if(Foo == Foo mimic, "Foo is a singleton", "Foo is a normal type") println |
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,6 @@ | ||
;; Fibonacci de 1 à 15 | ||
fibonacci = method(number, | ||
if((0..1) include?(number), 1, fibonacci(number - 1) + fibonacci(number - 2)) | ||
) | ||
|
||
(1..15) map(n, fibonacci(n)) join("\n") println |
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,9 @@ | ||
;; FizzBuzz de 1 à 23 | ||
|
||
fizzBuzz = method(number, | ||
result = [3, 5] map(n, if(number % n == 0, {3 => "Fizz", 5 => "Buzz"}[n], "")) join | ||
|
||
if(result empty?, number asText, result) | ||
) | ||
|
||
(1..23) map(n, fizzBuzz(n)) join("\n") println |