add at and hibye examples
This commit is contained in:
parent
b1fc1a3715
commit
5c341d7df4
|
@ -0,0 +1,15 @@
|
||||||
|
-- at (indexer) function, for lists and strings
|
||||||
|
|
||||||
|
-- out of values (hey, this isn't the Circus of Values!)
|
||||||
|
at([], _) -> -1.
|
||||||
|
at("", _) -> -1.
|
||||||
|
|
||||||
|
-- we've hit our target item
|
||||||
|
at(x::_, 0) -> x.
|
||||||
|
|
||||||
|
-- we've got more to go, keep iterating
|
||||||
|
at(x::xs, i) -> at(xs, i-1).
|
||||||
|
|
||||||
|
-- test
|
||||||
|
print(at([1, 2, 3, 4], 2)).
|
||||||
|
print(at("hi there", 1)).
|
|
@ -0,0 +1,7 @@
|
||||||
|
-- demonstrates string patterns
|
||||||
|
|
||||||
|
f("hi") -> "hello to you too!".
|
||||||
|
f("bye") -> "goodbye!".
|
||||||
|
|
||||||
|
putstrln(f("hi")).
|
||||||
|
putstrln(f("bye")).
|
Loading…
Reference in New Issue