task 2 - sum and length

This commit is contained in:
2025-09-28 14:57:02 +02:00
parent 76265730fc
commit b54016d5df
2 changed files with 18 additions and 0 deletions

View File

@@ -24,3 +24,10 @@ in
{TestQuad 2.0 1.0 ~1.0}
{TestQuad 2.0 1.0 2.0}
end
% task 2
fun {Sum List}
case List of Head|Tail then Head + {Sum Tail} else 0 end
end

View File

@@ -39,3 +39,14 @@ procedural abstractions (`proc` instead of `fun`) enable side-effects and intera
c) already covers some of the differences. a `fun`ction will have a set signature and have some different syntactic parsing. in some languages, functions don't allow sequential expressions, but oz is weird, so they are allowed. you may also print values to stdout in a function, unlike languages like haskell.
the distinction is in a way pedantic, but a useful one to make. one entails mathematical functions and all their bells and whistles, while the other corresponds more closely to how a computer works. this furthers oz as a general purpose multi-paradigm programming language.
## task 2
a simple recursive sum implementation
```oz
fun {Sum List}
case List of Head|Tail then Head + {Sum Tail} else 0 end
end
```