フォーラム: Forum of Decimal BASIC (スレッド #36949)

Passing Parameters by Reference (2015-07-14 02:36 by toml_12953 #76538)

BASIC has an option switch to choose between passing paramters by reference or passing them by value (ISO standard). Does this apply to FUNCTIONs as well as SUBs? If so how do I specify in my program that the parameters are to be passed by reference? I'd really like to be able to modify arrays passed to a function and have the changes visible even after the function has ended. The option doesn't seem to affect the way parameters are passed at all. I see no difference whichever way I set the option.

メッセージ #76538 への返信×

Wiki文法は使えません
ログインしていません。投稿を区別するために投稿者のニックネームをつけてください(ニックネームの一意性は保証されません。全く別の人も同じ名前を利用することが可能ですので本人であることの特定には利用できません。本人であることを保証したい場合にはログインして投稿を行なってください)。 ログインする

Re: Passing Parameters by Reference (2015-07-14 21:20 by Kazuo SHIRAISHI #76544)

[Reply To Message #76538]
Subs can be passed the parameters by values in such a manner
10 SUB s(x)
20 LET x=2
30 END SUB
40 LET n=1
50 CALL s((n))
60 PRINT n
70 END
But FUNCTIONs do not have such an expedient.
DEFs have an option whether parameters shall be passed by reference on Decimal BASIC, but this not legitimate in Full BASIC.
#76538 への返信

メッセージ #76544 への返信×

Wiki文法は使えません
ログインしていません。投稿を区別するために投稿者のニックネームをつけてください(ニックネームの一意性は保証されません。全く別の人も同じ名前を利用することが可能ですので本人であることの特定には利用できません。本人であることを保証したい場合にはログインして投稿を行なってください)。 ログインする

Re: Passing Parameters by Reference (2015-07-14 22:41 by toml_12953 #76545)

[Reply To Message #76544]
> [Reply To Message #76538]
> Subs can be passed the parameters by values in such a manner
> 10 SUB s(x)
> 20 LET x=2
> 30 END SUB
> 40 LET n=1
> 50 CALL s((n))
> 60 PRINT n
> 70 END
> But FUNCTIONs do not have such an expedient.
> DEFs have an option whether parameters shall be passed by reference on Decimal BASIC, but this not legitimate in Full BASIC.
>
I do know about SUBs but the parameter passing option isn't necessary for those. I need the option in the menu to change the way parameters are passed to FUNCTIONs:

DECLARE EXTERNAL FUNCTION f
DIM a(10)
LET a(5)=3
LET b=f(a)
PRINT a(5)
END
EXTERNAL FUNCTION f(x())
LET x(5)=-1
LET f = 0
END FUNCTION

If parameters are passed by reference, this should print -1. It prints 3 no matter which way I set the parameter option.
#76544 への返信

メッセージ #76545 への返信×

Wiki文法は使えません
ログインしていません。投稿を区別するために投稿者のニックネームをつけてください(ニックネームの一意性は保証されません。全く別の人も同じ名前を利用することが可能ですので本人であることの特定には利用できません。本人であることを保証したい場合にはログインして投稿を行なってください)。 ログインする

Re: Passing Parameters by Reference (2015-07-19 11:41 by SHIRAISHI Kazuo #76561)

Full BASIC standard denies functions to have an argument that refers a variabale.
Decimal BASIC's option on DEF statements does not afect FUNCTION ~ END FNCTION, because it is difficult to write a function in a DEF statement which changes the value of the parameter variable, that is, allowing parameters passed by refference in a function defined in a DEF statement seldom harm the Full BASIC standard.


#76545 への返信

メッセージ #76561 への返信×

Wiki文法は使えません
ログインしていません。投稿を区別するために投稿者のニックネームをつけてください(ニックネームの一意性は保証されません。全く別の人も同じ名前を利用することが可能ですので本人であることの特定には利用できません。本人であることを保証したい場合にはログインして投稿を行なってください)。 ログインする

Re: Passing Parameters by Reference (2016-10-29 17:54 by SHIRAISHI Kazuo #78943)

メッセージ #78943 への返信×

Wiki文法は使えません
ログインしていません。投稿を区別するために投稿者のニックネームをつけてください(ニックネームの一意性は保証されません。全く別の人も同じ名前を利用することが可能ですので本人であることの特定には利用できません。本人であることを保証したい場合にはログインして投稿を行なってください)。 ログインする