Hi Franz,
Maybe that is indeed a bug, but I wouldn't care too much. I'd rather say
that your function looks much too complicated for what you want to achieve.
As far as I understand, you'd like to get a stream that returns the nth
element. So I tried the following.
)abbrev package SELBUG SelectBug
SelectBug(R: Ring): with
nth: (Stream R, Integer) -> Stream R
== add
nth(st, n) == delay
s := st
for k in 1..n-1 repeat s := rest s
concat(first s, nth(rest s, n))
(1) -> st: Stream(Integer) := expand [1..]
(1) [1,2,3,4,5,6,7,8,9,10,...]
Type: Stream(Integer)
(2) -> nth(st, 3)
(2) [3,6,9,12,15,18,21,24,27,30,...]
Type: Stream(Integer)
(3) -> nth(st, 4)
(3) [4,8,12,16,20,24,28,32,36,40,...]
Type: Stream(Integer)
(4) -> nth(st, 2)
(4) [2,4,6,8,10,12,14,16,18,20,...]
Compilation of your code shows me.
Semantic Errors:
[1] nth: mk is BOTH a variable and a literal
Warnings:
[1] nth: kk has no value
[2] nth: mk has no value
And in the end
(1) -> st: Stream(Integer) := expand [1..]
(1) [1,2,3,4,5,6,7,8,9,10,...]
Type: Stream(Integer)
(2) -> mth(st, 3)
(2) [1,2,3,4,5,6,7,8,9,10,...]
Type: Stream(Integer)
(3) -> nth(st, 3)
>> System error:
The variable |mkRecord| is unbound.
No idea, whether that helps to find the bug.
Ralf