diff --git a/README.md b/README.md index 6e832fb..643632f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Open `http://localhost:9994/basics/index.html` for the full example index, or go | `http://localhost:9994/data-structures/vektori.html` | Custom class, Euclidean length of [3,4] = 5 | | `http://localhost:9994/strings/merkkijono.html` | String length, concat, trim, split | | `http://localhost:9994/async/nappi.html` | Click handlers, mutable counter | +| `http://localhost:9994/program/kasvutaulukko.html` | Factorial + Fibonacci table, interactive prompt | ## What is Tampio? @@ -55,7 +56,7 @@ See [`docs/cheatsheet.md`](docs/cheatsheet.md) for a map of Finnish grammatical | `examples/data-structures/` | Built-in list operations, custom class | | `examples/strings/` | String length, concat, trim, split | | `examples/async/` | DOM click handlers, mutable state | -| `examples/program/` | A small complete program (coming soon) | +| `examples/program/` | Capstone combining recursion, lists, and click events | ## Local Setup (without Docker) diff --git a/examples/basics/index.itp b/examples/basics/index.itp index eb60002..5f1c782 100644 --- a/examples/basics/index.itp +++ b/examples/basics/index.itp @@ -71,5 +71,9 @@ Kun nykyinen sivu avautuu, nykyinen sivu näyttää tekstin "
Open the page — see string ops applied to 'Hei, Tampio!'.
", nykyinen sivu näyttää tekstin "DOM click handlers. Mutable counter state persists across button clicks.
" -ja nykyinen sivu näyttää tekstin "Open the page — click +1 or +10 and watch the counter update.
". + nykyinen sivu näyttää tekstin "DOM click handlers. Mutable counter state persists across button clicks.
", + nykyinen sivu näyttää tekstin "Open the page — click +1 or +10 and watch the counter update.
", + nykyinen sivu näyttää tekstin "Capstone: recursive functions, list iteration, and a click handler together.
" +ja nykyinen sivu näyttää tekstin "Open the page — see factorial and Fibonacci for n=1..7, then enter any n for both values.
". diff --git a/examples/program/kasvutaulukko.itp b/examples/program/kasvutaulukko.itp new file mode 100644 index 0000000..18205d6 --- /dev/null +++ b/examples/program/kasvutaulukko.itp @@ -0,0 +1,55 @@ +# Kasvutaulukko — Growth Comparison +# +# Combines recursive methods, list iteration, and a click handler +# in a single program. +# +# Page load: computes factorial and Fibonacci for n = 1..7 by +# iterating the same lista twice — once with kertoma, once with kani. +# +# Button: prompts for any n, then shows its factorial and Fibonacci +# as two sequential alerts. +# +# Concepts in use: +# kertoma — recursive factorial (from basics/factorial.itp) +# kani — recursive Fibonacci (from basics/fibonacci.itp) +# lista — built-in list type (from data-structures/lista.itp) +# jokainen alkio — forEach iterator (from data-structures/lista.itp) +# käyköön niin, että — click handler (from async/nappi.itp) + +# --- Recursive definitions --- + +Pienen luvun kertoma on + riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi, + joko yksi + tai pieni luku kerrottuna pienen luvun edeltäjän kertomalla. + +Luvun edeltäjä on se vähennettynä yhdellä. + +Pienen luvun kani on + riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi, + joko pieni luku + tai pienen luvun edeltäjän kani lisättynä pienen luvun edeltäjän edeltäjän kaniin. + +# --- Data --- + +# n = 1 .. 7 +Olkoon kiva lista uusi lista, jonka alkioita ovat yksi, kaksi, kolme, neljä, viisi, kuusi ja seitsemän eikä muuta. + +# Mutable variable for the interactive prompt +Olkoon pieni muuttuja uusi muuttuja, jonka arvo on nolla. + +# --- Page --- + +Kun nykyinen sivu avautuu, + nykyinen sivu näyttää tekstin "", + nykyinen sivu näyttää kivan listan jokaisen alkion kertoman, + nykyinen sivu näyttää tekstin "
", + nykyinen sivu näyttää kivan listan jokaisen alkion kanin, + nykyinen sivu näyttää tekstin "
", + nykyinen sivu etsii elementin nimellä "output" tuloksenaan kiva alue, + kivalle alueelle kirjoitetaan koodi "