How to write Spad functions that don't return anything?

5 views
Skip to first unread message

Neven Sajko

unread,
Aug 6, 2021, 5:55:51 PM8/6/21
to fricas-devel
Hello again,

I'm writing some functions in Spad, where the functions only effect
after returning is that they stored some values to some package-level
variables. The function shouldn't return anything. How do I declare
and define functions like these?

Is there some special syntax for no return type, or should I use a
return type like None, Void or Union()?

Furthermore, what is the recommended way to exit such a function, that
is, what should the last statement be?


Thanks,
Neven

Ralf Hemmecke

unread,
Aug 7, 2021, 3:03:29 AM8/7/21
to fricas...@googlegroups.com
To see an example where domain variables are set, see here.

https://github.com/fricas/fricas/blob/master/src/algebra/fmt.spad#L1596
https://github.com/fricas/fricas/blob/master/src/algebra/fmt.spad#L1678

You should decide on the return type according to your wishes. Sometimes
it is interesting if the set-function returns the value that was in the
variable before it is overridden by the new value.

If you are not interested in any value then declare the function like this

foo: A -> Void

and write

foo(a: A): Void ==
...
void()

Knowing that the "digits" function changes the behaviour of Float, you
could have found out yourself yourself how to work with domain variables.

https://github.com/fricas/fricas/blob/master/src/algebra/float.spad#L137
https://github.com/fricas/fricas/blob/master/src/algebra/float.spad#L542
https://github.com/fricas/fricas/blob/master/src/algebra/float.spad#L542

Actually, I would strongly recomment agains such domain variables unless
you have a very good reason to have it, because then your domain behaves
differently to a user depending on a hidden variable.

Ralf
Reply all
Reply to author
Forward
0 new messages