Re: Workaround to support default parameter values
Henrik Grubbström escribió/skribis/wrote/scrit (2025-03-20T19:59:55+0100):
> In Pike 9.0 (currently in beta) the following syntax is supported:
>
> ```pike
> int typed_number(string prompt = "") {
>// (…)
> }
> ```
Great. That will make things simpler.
The other day I compiled and installed 8.0.1956 on Debian 12.10 (which
includes only 8.0.1738). I have downloaded 9.0.9 to try it soon.
>prompt = prompt || "";
Meanwhile, that's better than checking with `stringp`.
Thanks.
--
Marcos Cruz
http://programandala.net
Re: Workaround to support default parameter values
On Thu, 20 Mar 2025, Marcos Cruz wrote:
Since Pike does not support default parameter values, I use this
workaround:
```pike
int typed_number(string|void prompt) {
if (!stringp(prompt)) {
prompt = "";
}
// (…)
}
```
Is there a better approach?
In Pike 9.0 (currently in beta) the following syntax is supported:
```pike
int typed_number(string prompt = "") {
// (…)
}
```
It will compile to code similar to
```pike
int typed_number(string|void prompt) {
prompt = prompt || "";
// (…)
}
```
Except that the variable `prompt` will have the type
`string` and not `string|void`.
Did this help?
/grubba
--
Henrik Grubbström [email protected]
Roxen Internet Software AB
