# Writing a counter function

Shlomi Fish shlomif@vipe.technion.ac.il
Sat, 29 Jun 2002 20:40:00 +0300 (IDT)

```On Sat, 29 Jun 2002, Jon Fairbairn wrote:

> Shlomi Fish wrote:
> > No. But I want to generate an irregular series, which I determine the
> > intervals between two consecutive numbers myself. E.g:
> >
> > let (num1, next1) =3D (counter 5)
> >     (num2, next2) =3D (next1 100)
> >     (num3, next3) =3D (next2 50) in
> >     [num1,num2,num3]
> >
> > Will have the numbers [5, 105, 155].
>
> What do you mean by "determine"?
>

_I_ want to determine which step to go to next. I'd like to pass a
parameter the counter each time, and each time get the next number as well
as a new counter.

Regards,

=09Shlomi Fish

> You can write
>
> sequence =3D iterate step_counter 0
>
> if the interval between successive numbers is determined by
> the current number, or
>
> sequence =3D map f [1..]
>
> if it's determined by the index in the sequence.
>
> or
>
> sequence =3D  map snd \$ iterate step_counter (0,-7)
> step_counter (a,b) =3D (a+1, f a b)
>
> if it depends on both.
>
>
>   J=F3n
>

----------------------------------------------------------------------
Shlomi Fish        shlomif@vipe.technion.ac.il
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       shlomif@iglu.org.il

He who re-invents the wheel, understands much better how a wheel works.

```