Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
14
Task/Optional-parameters/Ada/optional-parameters-1.adb
Normal file
14
Task/Optional-parameters/Ada/optional-parameters-1.adb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package Tables is
|
||||
|
||||
type Table is private;
|
||||
|
||||
type Ordering is (Lexicographic, Psionic, ...); -- add others
|
||||
|
||||
procedure Sort (It : in out Table;
|
||||
Order_By : in Ordering := Lexicographic;
|
||||
Column : in Positive := 1;
|
||||
Reverse_Ordering : in Boolean := False);
|
||||
|
||||
private
|
||||
... -- implementation specific
|
||||
end Tables;
|
||||
10
Task/Optional-parameters/Ada/optional-parameters-2.adb
Normal file
10
Task/Optional-parameters/Ada/optional-parameters-2.adb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
with Tables;
|
||||
procedure Table_Test is
|
||||
My_Table : Tables.Table;
|
||||
begin
|
||||
... -- insert stuff in table
|
||||
Sort (My_Table); -- use default sorting
|
||||
Sort (My_Table, Psionic, 5, True); -- use psionic sorting by 5th column in reverse order
|
||||
Sort (It => My_Table, Reverse_Ordering => True); -- use default sorting in reverse order
|
||||
... -- other stuff
|
||||
end Table_Test;
|
||||
62
Task/Optional-parameters/REXX/optional-parameters.rexx
Normal file
62
Task/Optional-parameters/REXX/optional-parameters.rexx
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
-- 11 Sep 2025
|
||||
include Setting
|
||||
|
||||
say 'OPTIONAL PARAMETERS'
|
||||
say version
|
||||
say
|
||||
call Stem
|
||||
call Sort1
|
||||
call Sort1 'n',,'yes'
|
||||
call Sort1 ,12,''
|
||||
call Sort1 'n',12,'yes'
|
||||
say
|
||||
call Sort2
|
||||
call Sort2 'order=n rev=yes'
|
||||
call Sort2 'col=12'
|
||||
call Sort2 'order=n col=12 rev=yes'
|
||||
exit
|
||||
|
||||
Stem:
|
||||
-- Populate an array
|
||||
procedure expose stem.
|
||||
-- Your code...
|
||||
return
|
||||
|
||||
Sort1:
|
||||
-- Comma separated positional parameters
|
||||
procedure expose stem.
|
||||
arg order,col,rev
|
||||
call charout ,'Sort1:' 'Order='order 'Column='col 'Reverse='rev
|
||||
if order = '' then
|
||||
order='L'
|
||||
if col = '' then
|
||||
col=1
|
||||
rev=(Left(rev,1)='Y')
|
||||
say ' ---> ' 'Order='order 'Column='col 'Reverse='rev
|
||||
-- Your sort...
|
||||
return
|
||||
|
||||
Sort2:
|
||||
-- Space separated named parameters
|
||||
procedure expose stem.
|
||||
arg xx
|
||||
call charout ,'Sort2:' 'Parms='xx
|
||||
order='L'; col=1; rev=0
|
||||
do n = 1 to Words(xx)
|
||||
w=Word(xx,n); parse var w nam '=' val
|
||||
select
|
||||
when nam = 'ORDER' then
|
||||
order=val
|
||||
when nam = 'COL' then
|
||||
col=val
|
||||
when nam = 'REV' then
|
||||
rev=(Left(val,1) = 'Y')
|
||||
otherwise
|
||||
nop
|
||||
end
|
||||
end
|
||||
say ' ---> ' 'Order='order 'Column='col 'Reverse='rev
|
||||
-- Your sort...
|
||||
return
|
||||
|
||||
include Math
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
@[params]
|
||||
struct Params {
|
||||
a int // default value is 0
|
||||
b int
|
||||
|
|
@ -8,13 +9,24 @@ fn a_fn(p Params) int {
|
|||
return p.a + p.b + p.c
|
||||
}
|
||||
|
||||
fn main() {
|
||||
w := a_fn(Params{a: 1, b: 2, c: 3}) // same order, with new value given to `c`
|
||||
println("w = ${w}")
|
||||
x := a_fn(Params{c: 3, b: 2, a: 1}) // different order
|
||||
println("x = ${x}")
|
||||
y := a_fn(Params{c: 2}) // only one field
|
||||
println("y = ${y}")
|
||||
z := a_fn(Params{}) // no fields, so given value of `c` and default values used
|
||||
println("z = ${z}")
|
||||
fn b_fn(word string, num ?int) (string, int) {
|
||||
val := if num == none {0} else {num} // unwrap option type to assign value
|
||||
return word, val
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// using a struct as a parameter
|
||||
v := a_fn(Params{a: 1, b: 2, c: 3}) // same order, with new value given to `c`
|
||||
println("v = ${v}")
|
||||
w := a_fn(Params{c: 3, b: 2, a: 1}) // different order
|
||||
println("w = ${w}")
|
||||
x := a_fn(Params{c: 2}) // only one field
|
||||
println("x = ${x}")
|
||||
y := a_fn(Params{}) // no fields; given value of `c` and default values used
|
||||
println("y = ${y}")
|
||||
z := a_fn() // no parameters via @[params]; given value of `c` and default values used
|
||||
println("z = ${z}")
|
||||
// using an option type as a parameter
|
||||
println(b_fn('hello', 1000))
|
||||
println(b_fn('hello')) // no second parameter usage possible because option type (`?`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue