Re: RE: pass by reference Karl

new topic     » goto parent     » topic index » view thread      » older message » newer message

-------Phoenix-Boundary-07081998-

Hi Derek Parnell, you wrote on 2/12/02 4:21:17 PM:

>
>kbochert at ix.netcom.com wrote:
>
> In my implementation, pass-by reference is accomplished by
> the caller. That is:
>
>    procedure foo (sequence x)
>       x = x[2..3]
>    end procedure
>
>    sequence s = "test"
>    foo (s)
>    -- s still equals "test"
>
>    foo (!!s)
>    -- s now equals "es"
>
> Library routines can never do something behind your
> back.
>
>I'm not so sure Karl. Lets say that I have a routine like this...
>
>   procedure X(object a)
>      if sequence(a) then
>          a = ConvertToNumber(a)
>      end if
>
>      GlobalX += a
>   end procedure
>
>then I call this using your method...
>
>   s = "23"
>   X(!!s)
>
>this should either crash with an assignment error (assigning an atom to
>seq) or change the
>sequence
>S to now be an atom.
>
>However, calling it normally is quite safe...
>
>   s = "23"
>   X(s)
>
>---------
>Cheers,
>Derek Parnell
>

   I hadn't considered that possibility.
Surprisingly it seems to work reasonably!

   integer q = 1
   sequence t = "hello"

procedure X(object a)
   if sequence(a) then
      a = 5
   end if
   q += a
   ?q        --=> 6
end procedure

   X (!!t)
   ?t       -- => "hello"

The procedure never actually modifies the
sequence, only the identifier. the 'a=5'
line creates a new entity. A bit confusing
perhaps but what can you do? I guess that
PBR only happens when you pass a sequence AND the
subroutine treats it as a sequence.

Karl

-------Phoenix-Boundary-07081998---

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu