Add lista and vektori examples
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
# Vektori — Custom Data Structure in Tampio
|
||||
#
|
||||
# Defines a "vektori" (vector) class with fields and computed methods.
|
||||
# This example shows Tampio's OOP model:
|
||||
# class declaration → "[name/adessive] on [fields]"
|
||||
# field access → "[object/genitive] [field]" (same syntax as function call)
|
||||
# recursive methods → ternary base case + recursive step
|
||||
#
|
||||
# Using vector [3, 4] — its Euclidean length is exactly 5 (3-4-5 right triangle).
|
||||
|
||||
# Class declaration: adessive case marks the class name
|
||||
# "komponentit" is plural → stored as an array
|
||||
|
||||
Vektorilla on komponentit.
|
||||
|
||||
# "dimensio" = number of components
|
||||
# "sen" = genitive of "se" (the unnamed parameter = self)
|
||||
# "komponenttien määrä" = count of the elements array
|
||||
|
||||
Vektorin dimensio on sen komponenttien määrä.
|
||||
|
||||
# "pää" = head (first element)
|
||||
# "häntä" = tail (new vektori from index 2 onward)
|
||||
# "toisesta alkaen" = slice starting from the second element
|
||||
|
||||
Vektorin pää on sen ensimmäinen komponentti.
|
||||
Vektorin häntä on uusi vektori, jonka komponentit ovat sen komponentit toisesta alkaen.
|
||||
|
||||
# Recursive sum: base case 0 when empty, otherwise head + tail's sum
|
||||
# "lisättynä ... summaan" = added to ... sum (illative case)
|
||||
|
||||
Vektorin summa on
|
||||
riippuen siitä, onko sen dimensio nolla,
|
||||
joko nolla
|
||||
tai sen pää lisättynä sen hännän summaan.
|
||||
|
||||
# Euclidean length: sqrt(x1^2 + x2^2 + ...)
|
||||
# "toinen potenssi" = squared (array subscript syntax: potenssi[2])
|
||||
# Operator chain without separator = innermost grouping:
|
||||
# (head^2 + tail.length^2).sqrt()
|
||||
|
||||
Vektorin pituus on
|
||||
riippuen siitä, onko sen dimensio nolla,
|
||||
joko nolla
|
||||
tai sen pään toisen potenssin
|
||||
lisättynä sen hännän pituuden toiseen potenssiin
|
||||
neliöjuuri.
|
||||
|
||||
# Vector [3, 4]: sum = 7, length = sqrt(9+16) = 5
|
||||
|
||||
Olkoon kiva vektori uusi vektori, jonka komponentteja ovat kolme ja neljä eikä muuta.
|
||||
|
||||
Kun nykyinen sivu avautuu,
|
||||
nykyinen sivu näyttää tekstin "<p>Dimensio: ",
|
||||
nykyinen sivu näyttää kivan vektorin dimension,
|
||||
nykyinen sivu näyttää tekstin "</p><p>Summa: ",
|
||||
nykyinen sivu näyttää kivan vektorin summan,
|
||||
nykyinen sivu näyttää tekstin "</p><p>Pituus (3-4-5 kolmio → 5): ",
|
||||
nykyinen sivu näyttää kivan vektorin pituuden
|
||||
ja nykyinen sivu näyttää tekstin "</p>".
|
||||
Reference in New Issue
Block a user