Call a function: Difference between revisions

m
→‎{{header|REXX}}: removed some blank lines. -- ~~~~
m (→‎{{header|REXX}}: removed some blank lines. -- ~~~~)
Line 624:
 
=={{header|REXX}}==
<lang rexx>/*REXX program to demonstrate various methods of calling a REXX function*/
<lang rexx>
/*REXX program to demonstrate various methods of calling a REXX function*/
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Calling a function that REQUIRES no arguments. │
Line 634 ⟶ 632:
│ (or weren't) passed. │
└────────────────────────────────────────────────────────────────────┘*/
 
yr=yearFunc()
say 'year=' yr
Line 642 ⟶ 639:
if arg()\==0 then call sayErr "SomeFunc function won't accept arguments."
return left(date('Sorted'),3)
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Calling a function with a fixed number of arguments. │
Line 652 ⟶ 648:
│ specified (or not). │
└────────────────────────────────────────────────────────────────────┘*/
 
ggg=FourFunc(12,abc,6+q,zz%2,'da 5th disagreement')
say 'ggg squared=' ggg**2
Line 665 ⟶ 660:
end
return a1+a2+a3+a4
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Calling a function with optional arguments. │
Line 672 ⟶ 666:
│ argument (a REXX variable whose value is length zero). │
└────────────────────────────────────────────────────────────────────┘*/
 
x=12; w=x/2; y=x**2; z=x//7 /* z is x modulo seven.*/
say 'sum of w, x, y, & z=' SumIt(w,x,y,,z) /*pass 5 args, 4th is null*/
Line 684 ⟶ 677:
 
return sum
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Calling a function with a variable number of arguments. │
Line 691 ⟶ 683:
│ It's up to the programmer to code how to utilize the arguments. │
└────────────────────────────────────────────────────────────────────┘*/
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Calling a function with named arguments. │
Line 698 ⟶ 689:
│ way this can be accomplished. │
└────────────────────────────────────────────────────────────────────┘*/
 
what=parserFunc('name=Luna',"gravity=.1654",'moon=yes')
say 'name=' common.name
Line 712 ⟶ 702:
end
return arg()
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Calling a function in statement context. │
Line 719 ⟶ 708:
│ example (above) is calling a function in statement context. │
└────────────────────────────────────────────────────────────────────┘*/
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Calling a function in within an expression. │
Line 725 ⟶ 713:
│ This is a variant of the first example. │
└────────────────────────────────────────────────────────────────────┘*/
 
yr=yearFunc()+20
say 'two decades from now, the year will be:' yr
exit
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Obtaining the return value of a function. │
Line 735 ⟶ 721:
│ There are two ways to get the (return) value of a function. │
└────────────────────────────────────────────────────────────────────┘*/
 
currYear=yearFunc()
say 'the current year is' currYear
Line 741 ⟶ 726:
call yearFunc
say 'the current year is' result
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Distinguishing built-in functions and user-defined functions. │
Line 749 ⟶ 733:
│ function with the same name (there isn't a penality for this). │
└────────────────────────────────────────────────────────────────────┘*/
 
qqq=date() /*number of real dates that Bob was on. */
say "Bob's been out" qqq 'times.'
Line 756 ⟶ 739:
 
date: return 4
 
/*┌────────────────────────────────────────────────────────────────────┐
│ Distinguishing subroutines and functions. │
Line 765 ⟶ 747:
│ it were a subroutine. │
└────────────────────────────────────────────────────────────────────┘*/
 
/*┌────────────────────────────────────────────────────────────────────┐
│ In REXX, all arguments are passed by value, never by name, but it │
Line 772 ⟶ 753:
│ to retrieve the variable's value. │
└────────────────────────────────────────────────────────────────────┘*/
 
/*┌────────────────────────────────────────────────────────────────────┐
│ In the REXX language, partial application is possible, depending │
Line 780 ⟶ 760:
│ are: map (f 7 9) [1..9] │
│ or: map(f(7,_,9),{1,...,9}) │
└────────────────────────────────────────────────────────────────────┘*/</lang>
</lang>
 
=={{header|Tcl}}==