[Coco] Sharing a value with the calling routine in Basic09

James Jones jejones3141 at gmail.com
Sat Aug 15 19:51:49 EDT 2020


Honest, BASIC09 does call by reference (with some care taken to avoid the
infamous old FORTRAN "subroutine changes the value of the constant 2"
problem).  When you pass a parameter, its address (and size) are passed. If
you want to prevent it, you get to pass a copy (for numerics and strings,
x + 0 and x + "" respectively; TYPEs require an honest-to-goodness copy).

BASIC09 doesn't have user-defined functions, alas. Changing a call by
reference parameter is the closest you can get. If you have an example
where it fails, please post it and show what you get that makes you think
it is failing.

On Sat, Aug 15, 2020 at 3:19 PM <coco at jechar.ca> wrote:

> I don't think what you are saying is correct because
> say my programs were called x and y
>
> in x I set p=SOME-VALUE
> then I print p and get
> SOME-VALUE
> then I call y passing p to y
> then I  set p=some-OTHER-value
> then I print p and get
> some-OTHER-value
> but when back in the calling program x
> when I print p and get
> SOME-VALUE
> so basic09 did not remember what module y did.
>
>
>
> On 2020-08-15 15:49, Wayne Campbell wrote:
> > Pass by reference is the default. This means that just passing the
> > variable
> > name is enough. If you update that variable and the procedure you
> > called
> > the variable in the procedure that called it will reflect that change.
> > To
> > pass by value, you use the variable name plus zero in the parameter
> > list.
> >
> > Example:
> >
> > RUN myProc(myVar+0)
> >
> > Passes myVar by it's value.
> >
> > RUN myProc(myVar)
> >
> > Passes myVar by reference.
> >
> >
> > On Sat, Aug 15, 2020, 11:21 AM <coco at jechar.ca> wrote:
> >
> >>
> >> On 2020-08-15 14:17, coco at jechar.ca wrote:
> >> > Would like to know if there is a standard way to pass back the
> >> > value from a called routine to the caller. Cannot use GOSUB the
> >> > routines need to be separate modules although a merged module file
> >> > could be created by OS9 afterwards to make sure that if one module
> >> > is loaded the other is too.
> >> >
> >> > I have an Idea involving ADDR PEEK and POKE of course if I am wrong
> >> > this could go very wrong.
> >> >
> >> > Charlie
> >>
> >> PS: I think what I am trying to do is called pass by reference
> >> in C++
> >>
> >> --
> >> Coco mailing list
> >> Coco at maltedmedia.com
> >> https://pairlist5.pair.net/mailman/listinfo/coco
> >>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list