the use of 'out' in a parameter list / situation

This forum is meant for anything you would like to share with other visitors
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the use of 'out' in a parameter list / situation

Post by Phil Hepburn »

Hi guys,

Can anyone please suggest some X# syntax to show how to use the 'out' option in a parameter list.

I had a quick fumble around but with no good results.

End of day, brain hurts, nee my Forum colleagues ;-0)

Apparently Tuples can happily replace the use of 'OUT'.

HELP !!!

TIA,
Phil.
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

the use of 'out' in a parameter list / situation

Post by lumberjack »

Phil,
Is that not REF?

Code: Select all

METHOD SyMethod(in AS STRING, out REF STRING)
Johan
______________________
Johan Nel
Boshof, South Africa
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the use of 'out' in a parameter list / situation

Post by Phil Hepburn »

Hi again,

Having had another end of day fumble, I think I have a start, you know, my foot in the door!

Here are a couple of small images :-
Out_01.jpg
Out_01.jpg (23.68 KiB) Viewed 596 times
Out_02.jpg
Out_02.jpg (30.3 KiB) Viewed 596 times
I got success once I stopped trying to include 'as'.

Have a nice weekend,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the use of 'out' in a parameter list / situation

Post by Phil Hepburn »

Hi Johan,

I am not sure, I thought the REF idea was out of fashion a while back. These sorts of things are no much in my experience.

However, I do like the Tuple (sexy way) I will need to experiment.

I will feed back here if I get anything useful.

Regards,
Phil.
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

the use of 'out' in a parameter list / situation

Post by robert »

Johan,

See https://www.xsharp.eu/help/parameters.html

Code: Select all


parameterList      : LPAREN (parameter (COMMA parameter)*)? RPAREN
                   ;
 
parameter          : (attributes)? SELF? identifier (ASSIGN_OP expression)? (parameterDeclMods datatype)?
                      | ELLIPSIS
                   ;
 
parameterDeclMods   : (AS | REF | OUT | IS | PARAMS) CONST?
                   ;
So AS, REF, OUT, IS and PARAMS are mutually exclusive.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

the use of 'out' in a parameter list / situation

Post by lumberjack »

Thanks Robert,

Sorry for any confusion, responded and then only checked the manual and did see OUT is recognized.

The same effect can be "simulated" with REF, provided you initialize the parameter before passing, which the OUT does not require. Both have its place.

REF: The parameter might be changed by the called method.
OUT: The parameter has to be set by the called method.

Regards,

Johan
______________________
Johan Nel
Boshof, South Africa
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the use of 'out' in a parameter list / situation

Post by Phil Hepburn »

An interesting short post Johan,

Thanks, I will now give these ideas a go in a test 'rig'.

Speak soon,
Phil.
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

the use of 'out' in a parameter list / situation

Post by Frank Maraite »

Hi Johan,
this
Johan Nel wrote:
REF: The parameter might be changed by the called method.
OUT: The parameter has to be set by the called method.
wasn't clear to me. Thanks!

Does this mean OUT parameters are always NULL at the beginning and should be tested !NULL before return?

Frank
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

the use of 'out' in a parameter list / situation

Post by lumberjack »

Hi Frank,
Frank Maraite wrote: this wasn't clear to me. Thanks!
Does this mean OUT parameters are always NULL at the beginning and should be tested !NULL before return?
No, it will raise an error during compilation that the parameter is not set.

Code: Select all

FUNCTION TestOut(h AS STRING, w OUT STRING) AS STRING
RETURN h + " " + w
error XS0177: The out parameter 'w' must be assigned to before control leaves the current method
Regards Johan
______________________
Johan Nel
Boshof, South Africa
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the use of 'out' in a parameter list / situation

Post by Phil Hepburn »

Hi guys - Johan, Frank, and any others interested,

Attached are a couple of small images to help show the functionality etc.

OUT must change in the method code, and REF can change but does not have to. That's how it seems to me.

I suggest you try these out carefully for yourself before you use them, any guy who is not familiar with their use. Just so you know what is going on - check below :-
REfOut_01.jpg
REfOut_01.jpg (26.59 KiB) Viewed 598 times
REfOut_02.jpg
REfOut_02.jpg (42.4 KiB) Viewed 598 times
REfOut_03.jpg
REfOut_03.jpg (36.63 KiB) Viewed 598 times
RefOut_04.jpg
RefOut_04.jpg (42.49 KiB) Viewed 598 times
RefOut_05.jpg
RefOut_05.jpg (40.91 KiB) Viewed 598 times
Hope this interests a few of you ;-0)

Cheers,
Phil.
Post Reply