Oxygen Basic
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Latest OxygenBasic.zip at GitHub
(Click on the Wizard)
Home
Help
Search
Login
Register
Oxygen Basic
»
Programming
»
Bugs & Feature Requests
»
optional parameter does not kick in
« previous
next »
Print
Pages: [
1
]
Author
Topic: optional parameter does not kick in (Read 3249 times)
0 Members and 1 Guest are viewing this topic.
kryton9
Guest
optional parameter does not kick in
«
on:
July 10, 2011, 12:06:04 PM »
I have noticed before, but many times by enclosing in () solved it. But here is an example where it doesn't kick in Charles.
Code: OxygenBasic
'optional parameters behaviour
function
power(
sys
number, optional
sys
exponent = 2 )
return
pow
( number, exponent )
end
function
print
str
( power 2 )
'the optional parameter does not kick in
print
str
(
pow
( 2, 4) )
print
str
( power 2, 4 )
print
str
( 2^4 )
Logged
Peter
Guest
Re: optional parameter does not kick in
«
Reply #1 on:
July 10, 2011, 01:29:26 PM »
Hi Kent,
There is no OPTIONAL!
Logged
Charles Pegge
Guest
Re: optional parameter does not kick in
«
Reply #2 on:
July 10, 2011, 02:40:24 PM »
Optional parameters and named parameters are two different paradigms
These use named params
Code: OxygenBasic
'named parameters behaviour
function
power(
sys
number=2,
sys
exponent = 2 )
as
double
return
pow
( number, exponent )
end
function
print
str
power ()
print
str
power (4, 2)
print
str
power (exponent=5)
and these use optional params (which always default to null)
Code: OxygenBasic
'optional parameters behaviour
function
power( optional
sys
number, exponent )
as
double
if
number=0
then
number=1
if
exponent=0
then
exponent=1
return
pow
( number, exponent )
end
function
print
str
power ()
print
str
power (4)
print
str
power (4,3)
Charles
«
Last Edit: July 10, 2011, 02:48:38 PM by Charles Pegge
»
Logged
Charles Pegge
Guest
Re: optional parameter does not kick in
«
Reply #3 on:
July 10, 2011, 03:46:34 PM »
Another Oxygen.dll fix.
print
was giving chinese characters instead of numbers under certain conditions. No need for str ..
Code: OxygenBasic
'optional parameters behaviour
function
power( optional
sys
number, exponent )
as
double
if
number=0
then
number=1
if
exponent=0
then
exponent=1
return
pow
( number, exponent )
end
function
print
power ()
print
power (4)
print
power (4,3)
Charles
[attachment deleted by admin]
Logged
kryton9
Guest
Re: optional parameter does not kick in
«
Reply #4 on:
July 10, 2011, 06:10:34 PM »
That is very helpful Charles. Thanks for the nice explanation. I like using optional parameters a lot, now it makes sense that it would check against NULL or 0 then assign what it is needed.
Logged
Charles Pegge
Guest
Re: optional parameter does not kick in
«
Reply #5 on:
July 10, 2011, 09:46:32 PM »
Here is another example Kent. Using optional parameters passed by reference. In these cases you need to check each address for null.
if
@number
=0 then n=2 else n=number
Code: OxygenBasic
'optional parameters behaviour
'USING OPTIONAL PARAMETERS BY REFERENCE
function
power( optional
sys
*number, *exponent )
as
double
sys
n,e
if
@number=0
then
n=2
else
n=number
if
@exponent=0
then
e=2
else
e=exponent
return
pow
( n, e )
end
function
print
power ()
print
power (4)
print
power (4,3)
Charles
«
Last Edit: July 10, 2011, 09:48:41 PM by Charles Pegge
»
Logged
kryton9
Guest
Re: optional parameter does not kick in
«
Reply #6 on:
July 10, 2011, 10:26:40 PM »
Thanks Charles. Very handy information. As I go back through my class files I will update all of them as I have ConsoleC.inc to work correctly with optional parameters.
Logged
Print
Pages: [
1
]
« previous
next »
Oxygen Basic
»
Programming
»
Bugs & Feature Requests
»
optional parameter does not kick in