Recursion in Šaral programming language

Recursion

In computer science recursion is a function, which calls itself in the functio body. The function call is always conditional to ensure that calculation ends.

Šaral as a problem-oriented programming langugage supports writing recursive procedures and functions.

Specifics of a recursive function in Šaral

The function recursion is different than in other programming languages. The specification states that there should be only one vrac (return) statement always on a last line in the function body.

The showcase of a Fibonacci numbers and a calculation of Greatest Common Divisor will highlight how to resolve the specifics.

Recursive procedure in Šaral

Writing a recursive procedure is easier because no such strict rules apply as for functions.

More examples in Šaral repository.

Conclusion

Every recursive function should be possible to be rewritten in iterative way and vice versa.

I suppose that there always exists a way how to write every recursive function in different programming language Šaral way.

Leave a Reply

Your email address will not be published. Required fields are marked *