Soya has bean (pun intended) created for JPP course @ MIM UW as statically typed language with static binding, with syntax inspired by Python and C++.
-
Fun and intuitive declarations
It makes Soya easy to digest
y = int; # declaration of new variable y = 3; # assignment! x = "hej"; # assignment without declaration? No problem :) now x is declared
-
Default function arguments
Soya is cool with that by default.
def multiply(a = int, b = 2) -> int { return a * b; } print(multiply(4)); # 8
-
Pass by value or reference
# note the ref keyword def modify_some_stuff(ref stuff = int, value = 3) { stuff = value; } a = 5; modify_some_stuff(a); print(a); # 3
-
Handling None and no arguments passed 👻
Because sometimes you just don't have energy for another argument 🙄
uninitialized = int; print(uninitialized); # None def weird_func(a = int, b = int) -> [int]{ return [a, b]; } print(weird_func()); # [None, None]
-
Static type List:
it was just too hard to implement a dynamic list tbh
a = [1, 2, 3]; # 3 element list of ints a[1] = 5; # assignment on list b = [str]; # empty list of strings # more dimensions! c = [[int]]; c = [[6, 7], [3, 4, 5]]; grow (c[0], 8); # add 8 to the first list print(c); # [[6, 7, 8], [3, 4, 5]]
-
Soya doesn't float!
print(5 / 3); # 1
-
Static type-checking 😎
def f(a = int) -> int { return a * 2; } f("arg"); # oh hell naw # [TYPE ERROR at Just (5,1)]: Wrong types of arguments in f: [Str] instead of [Int]
For more fun, jump to examples/good
On students
run make
And test examples with ./check_examples.sh
Na 15 punktów:
1. Co najmniej trzy typy wartości: int, bool i string (to znaczy if 2+2 then _ parsuje się, ale wyrażenie ma niepoprawny typ).
2. Literały, arytmetyka, porównania
3. Zmienne, operacja przypisania
4. Jawne wypisywanie wartości na wyjście (print)
5. while, if, else
6. Funkcje lub procedury bez zagnieżdżania, rekurencja
7. Co najmniej dwa sposoby przekazywania parametrów (wartość/zmienna)
8. Zmienne read-only w pętli for
Na 20 punktów:
9. Przesłananie identyfikatorów ze statycznym ich wiązaniem, zagnieżdżone procedury / funkcje
10. Obsługa błędów wykonania
11. Funkcje przyjmujące i zwracające wartość dowolnych obsługiwanych typów
Do 30 punktów:
12. Statyczne typowanie - typechecker (4pkt)
13. Dowolnie zagnieżdżone definicje funkcji/procedur z zachowaniem statycznego wiązania identyfikatorów (2pkt)
14. Listy (1pkt)
16. Przerywanie pętli: break i continue (1pkt)
Ekstra:
20. Domyślne argumenty funkcji
21. Tworzenie zmiennej podczas przypisania jeśli jeszcze nie istnieje
22. Operacje na listach: grow oraz cut
Łącznie:
20 + 4 + 2 + 1 + 1 + EKSTRA = 28 + EKSTRA to około 30 pkt