From 9fb1815e0120bc18e261a6760cf3fee9805ab0e2 Mon Sep 17 00:00:00 2001 From: Robert Bendun Date: Wed, 21 Sep 2022 19:52:26 +0200 Subject: [PATCH] [cheatsheet] Argumentless function calls --- doc/musique-vs-languages-cheatsheet.template | 27 ++++++++++++++++++-- scripts/language-cmp-cheatsheet.py | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/doc/musique-vs-languages-cheatsheet.template b/doc/musique-vs-languages-cheatsheet.template index 3ee6d7d..8cabb42 100644 --- a/doc/musique-vs-languages-cheatsheet.template +++ b/doc/musique-vs-languages-cheatsheet.template @@ -65,6 +65,25 @@ r return x + y r end c Musique nie rozróżnia funkcji anonimowych i zadeklarowanych +n Wywoływanie funkcji +m add 1 3 +p add(1, 3) +r add 1, 3 + +n Wywołanie funkcji +n nie przymujących argumentów +m constant := [ say 42; 10 ]; +m say (call foo) +p def constant(): +p print(42) +p return 10 +p print(constant()) +r def constant() +r puts(42) +r return 10 +r end +r puts constant + n Instrukcja warunkowa m if (n == 42) m [ say 1 ] @@ -82,6 +101,7 @@ c Musique nie posiada instrukcji warunkowej, a funkcję if, c która przyjmuje wartość logiczną i dwa bloki (funkcje anonimowe) c - jeden z nich zostanie wykonany jeśli warunek jest prawdziwy, c a drugi jeśli jest fałszywy. + n Wyrażenie warunkowe m x := if (n == 42) [1] [2] p x = 1 if n == 42 else 2 @@ -99,6 +119,8 @@ n Tablice m x = [1; 2; 3; 4] p x = [1, 2, 3, 4] r x = [1, 2, 3, 4] +c W Musique funkcja anonimowa nie przyjmująca argumentów +c jak i tablica są tożsame. n Nty element tablicy m x.n @@ -150,7 +172,6 @@ m xs := sort [1; 5; 3; 3; 2] p xs = sorted([1, 5, 3, 3, 2]) r xs = [1, 5, 3, 3, 2].sort - n Sortowanie wielu tablic w jedną m xs := sort [1; 5; 3; 3; 2] m [3; 4; 5] 1 2 3 @@ -158,8 +179,10 @@ p xs = sorted(itertools.chain( p [1, 5, 3, 3, 2], [3, 4, 5], p [1], [2], [3] p )) +r [[1, 5, 3, 3, 2], [3, 4, 5], +r [1], [2], [3] +r ].flatten.sort c Wiele operacji na tablicach może być wykonywane na dowolnej kombinacji c tablic i pojedyńczych wartości. Tworzy to jedną tablicę wykoniową. - END TABLE diff --git a/scripts/language-cmp-cheatsheet.py b/scripts/language-cmp-cheatsheet.py index b06b016..f26e5e1 100644 --- a/scripts/language-cmp-cheatsheet.py +++ b/scripts/language-cmp-cheatsheet.py @@ -120,7 +120,7 @@ def compile_template(*, template_path: str, target_path: str): sections = parse_table(lines=table_source) for section in sections: - section.ref = section.name.replace(" ", "_") + section.ref = section.name.strip().replace(" ", "_") nav = "" for section in sections: