Hi,
Disclaimer: Title of posting is provocative on purpose :-).
In EPLI we have the OPTIONAL keyword for proc-parameters. Using OPTIONAL one can hand over a parameter to a proc or not.
Example:
// procedure:
do_something: proc(a, b, c);
dcl a dec fixed(5);
dcl b dec fixed(5);
dcl c dec fixed(5) optional;
if present(c) then .....
// user
call do_something(2,3,4);
// or
call do_something(2,3,*);
I repeatedly stumbled accross code where one wrote
if c_contains_info
then call do_something(a, b, c);
else call do_something(a, b, *);
Imho the better approach would be to write (in some way)
call do_something(a, b, c, c_contains_info);
My example is as simple as possible, imagine a proc with 2 or 3 OPTIONALs.
And for those situations where there is a real optional parameter a generic is imho the better approach as i can completely omit the parameter and not "hide" it behind a "*".
x = format_currency(value);
x = format_currency(value, format_string);
I'm aware that it's not the fault of the language but of the user, but more and more i get the impression that OPTIONAL has more cons than pros.
Am i missing something?
br Johann
Hi,
Disclaimer: Title of posting is provocative on purpose :-).
In EPLI we have the OPTIONAL keyword for proc-parameters. Using OPTIONAL one can hand over a parameter to a proc or not.
Example:
// procedure:
do_something: proc(a, b, c);
dcl a dec fixed(5);
dcl b dec fixed(5);
dcl c dec fixed(5) optional;
if present(c) then .....
// user
call do_something(2,3,4);
// or
call do_something(2,3,*);
I repeatedly stumbled accross code where one wrote
if c_contains_info
then call do_something(a, b, c);
else call do_something(a, b, *);
Imho the better approach would be to write (in some way)
call do_something(a, b, c, c_contains_info);
My example is as simple as possible, imagine a proc with 2 or 3 OPTIONALs.
And for those situations where there is a real optional parameter a generic is imho the better approach as i can completely omit the parameter and not "hide" it behind a "*".
x = format_currency(value);
x = format_currency(value, format_string);
I'm aware that it's not the fault of the language but of the user, but more and more i get the impression that OPTIONAL has more cons than pros.
Am i missing something?
br Johann
On 7/14/21 7:07 AM, johann woeckinger wrote:.
Hi,
Disclaimer: Title of posting is provocative on purpose :-).
In EPLI we have the OPTIONAL keyword for proc-parameters. Using OPTIONAL one can hand over a parameter to a proc or not.
Example:
// procedure:
do_something: proc(a, b, c);
dcl a dec fixed(5);
dcl b dec fixed(5);
dcl c dec fixed(5) optional;
if present(c) then .....
// user
call do_something(2,3,4);
// or
call do_something(2,3,*);
I repeatedly stumbled accross code where one wrote
if c_contains_info
then call do_something(a, b, c);
else call do_something(a, b, *);
Imho the better approach would be to write (in some way)
call do_something(a, b, c, c_contains_info);
My example is as simple as possible, imagine a proc with 2 or 3 OPTIONALs.
And for those situations where there is a real optional parameter a generic is imho the better approach as i can completely omit the parameter and not "hide" it behind a "*".
x = format_currency(value);
x = format_currency(value, format_string);
I'm aware that it's not the fault of the language but of the user, but more and more i get the impression that OPTIONAL has more cons than pros.
Am i missing something?
This is a late addition to a language that started out with no such.
facility at all, apart from the awkward GENERIC keyword.
Most new
languages have a feature along these lines, but not the same. There are keyword parameters with default values, for example. There is
overloading, and there is the feature that Ada calls “generic” and C++ calls “templates”. Or you can simply use pointers/locators that may have the value null/nil. Swift has all of these, but also allows ordinary parameters, not merely locators, to have the value nil. For example:
func doSomething(a: Int, b: Int, c: Int = 4) {
...
}
or:
func doSomething(a: Int, b: Int) {
/* 2-argument version */
}
func doSomething(a: Int, b: Int, c: Int) {
/* 3-argument version */
}
or:
func doSomething(a: Int, b: Int, c: Int?) {
if let c_verified = c {
realDoSomething(a, b, c_verified)
} else {
realDoSomething(a, b, 4)
}
}
On Wednesday, July 14, 2021 at 1:07:42 PM UTC+2, johann woeckinger wrote:
Hi,
Disclaimer: Title of posting is provocative on purpose :-).
In EPLI we have the OPTIONAL keyword for proc-parameters. Using OPTIONAL
one can hand over a parameter to a proc or not.
Example:
// procedure:
do_something: proc(a, b, c);
dcl a dec fixed(5);
dcl b dec fixed(5);
dcl c dec fixed(5) optional;
if present(c) then .....
// user
call do_something(2,3,4);
// or
call do_something(2,3,*);
I repeatedly stumbled accross code where one wrote
if c_contains_info
then call do_something(a, b, c);
else call do_something(a, b, *);
Imho the better approach would be to write (in some way)
call do_something(a, b, c, c_contains_info);
My example is as simple as possible, imagine a proc with 2 or 3 OPTIONALs. >>
And for those situations where there is a real optional parameter a
generic is imho the better approach as i can completely omit the
parameter and not "hide" it behind a "*".
x = format_currency(value);
x = format_currency(value, format_string);
I'm aware that it's not the fault of the language but of the user, but
more and more i get the impression that OPTIONAL has more cons than pros.
Am i missing something?
br Johann
One correction and one additional question:
1) Correction:
EPLI allows to omit the "*" if the trailing parameter is not provided, so there's no need for generic in that case, one can write "...call do_something(a, b);" without providing a generic
2) additional question:
Is there a "more elegant" solution than implementing a separate
"indicator variable" (in my sample "c_contains_info")?
Setting "c" to "null" seems a bit dirty. Implementing a defined struct
that couples "c" and "c_contains_info" seems pretty excessive. Any solutions/ideas out there?
br johann
johann woeckinger <woe...@gmail.com> wrote:
On Wednesday, July 14, 2021 at 1:07:42 PM UTC+2, johann woeckinger wrote:
Hi,
Disclaimer: Title of posting is provocative on purpose :-).
In EPLI we have the OPTIONAL keyword for proc-parameters. Using OPTIONAL >> one can hand over a parameter to a proc or not.
Example:
// procedure:
do_something: proc(a, b, c);
dcl a dec fixed(5);
dcl b dec fixed(5);
dcl c dec fixed(5) optional;
if present(c) then .....
// user
call do_something(2,3,4);
// or
call do_something(2,3,*);
I repeatedly stumbled accross code where one wrote
if c_contains_info
then call do_something(a, b, c);
else call do_something(a, b, *);
Imho the better approach would be to write (in some way)
call do_something(a, b, c, c_contains_info);
My example is as simple as possible, imagine a proc with 2 or 3 OPTIONALs.
And for those situations where there is a real optional parameter a
generic is imho the better approach as i can completely omit the
parameter and not "hide" it behind a "*".
x = format_currency(value);
x = format_currency(value, format_string);
I'm aware that it's not the fault of the language but of the user, but
more and more i get the impression that OPTIONAL has more cons than pros. >>
Am i missing something?
br Johann
One correction and one additional question:
1) Correction:
EPLI allows to omit the "*" if the trailing parameter is not provided, so there's no need for generic in that case, one can write "...call do_something(a, b);" without providing a generic
2) additional question:
Is there a "more elegant" solution than implementing a separate
"indicator variable" (in my sample "c_contains_info")?
Setting "c" to "null" seems a bit dirty. Implementing a defined struct that couples "c" and "c_contains_info" seems pretty excessive. Any solutions/ideas out there?
br johann
Why would the indicator variable be better? The current syntax provides a “hidden” variable automatically generated by the compiler that the PRESENT
BIF tests.
--
Pete
Just a word about GENERIC:.
Be aware that this is a language element already being present in PL/I(F)
of the late 60's . And it took some decades to discover , that you can
define a procedure, or function identity by the combination of it's name,
the number of parameters, and the data types of the parameters.
PL/I was far ahead of the time it was invented. The only changes since.
then was adding functionality. But it's concept is still the same. A small syntactical add on lies in adding empty parentheses expected behind
procedure and function (incl. BUILTIN ) names not having any parameters,
in order to make it visible in the source code, that it is not the name of a simple variable.
On Thursday, August 12, 2021 at 7:34:23 PM UTC+10, archives.in...@gmail.com wrote:
Just a word about GENERIC:.
Be aware that this is a language element already being present in PL/I(F)
of the late 60's . And it took some decades to discover , that you can
define a procedure, or function identity by the combination of it's name,
the number of parameters, and the data types of the parameters.
IIRC, user-written generic procedures in PL/I were available in 1966.
.
PL/I was far ahead of the time it was invented. The only changes since.
then was adding functionality. But it's concept is still the same. A small >> syntactical add on lies in adding empty parentheses expected behind
procedure and function (incl. BUILTIN ) names not having any parameters,
in order to make it visible in the source code, that it is not the name of a >> simple variable.
Yes, a considerable advance compared to FORTRAN, a language in
which is was necessary to spell out the individual function names,
such as SQRT and DSQRT, according to the type of the argument.
PL/I-F was introduced by 1966.
Sorry ! groups.google.com has destroyed the formatting of my programme code :-(
I do not know, how you see my message in your mail box.
Thank you Pete, for the information! I have created a groups.io PL/I(F) an MVS 3.8j group,Markus,
Maybe it is interesting for you. As I do not have your mail address, I cannot send an invitation to you.
You are very welcome to apply for membership at groups.io/g/pl1f-and-mvs38j/. As I moderate the group, I can immediately take measures, if an inappropriate messaging, as to
be seen here, appears.
Best regards Markus Loew,
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 251 |
Nodes: | 16 (2 / 14) |
Uptime: | 25:19:44 |
Calls: | 5,544 |
Calls today: | 3 |
Files: | 11,676 |
Messages: | 5,109,451 |