On 11/13/07 10:52 AM, in article 1194975018.877.1194971684@[EMAIL PROTECTED]
"David Williams" <david.williams@[EMAIL PROTECTED]
> wrote:
> -> > If Twiddle changes the value of its input parameter, the value of X
in
> -> > the calling routine will *not* be changed.
> -> >
> -> > But how easy is it to do the other way around? If the language is
set
> -> > up to call by value, can we write simple code that effectively
calls by
> -> > reference? I can't think of an easy way to do it.
> -> >
> -> > Of course, the language may have specific commands to switch from
one
> -> > method of calling to the other, but without them, a dialect that
calls
> -> > by value can't easily be made to call by reference.
>
> -> Passing a pointer using VARPTR should work, shouldn't it?
>
> Hmmm... Maybe. I'd have to think about that.
>
> What I'm concerned about is the ability to pass numbers back from a SUB
> to the calling routine. For example, in the program SUNALIGN, which I
> posted here a couple of days ago, some three-dimensional trigonometry is
> done by using two methods of representing a direction in space - e.g.
> the direction of the sun in the sky, as seen by an observer on the
> ground. One method is to state the azimuth (compass bearing) and angle
> of elevation. The other is to state the X, Y, Z co-ordinates of the
> endpoint of a unit vector pointing to the sun, with the observer at the
> origin. A lot of 3D trig can be done very easily by switching to and
> fro between these methods, with small operations on the arguments along
> the way. To do this, the program has two SUBs, D2P and P2D. Each has
> five arguments, X, Y, Z, AZ, and EL. D2P takes X, Y, and Z as inputs,
> calculates AZ and EL and p***** them back to the calling routine. P2D
> does the conversion in the opposite direction. So, basically, each SUB
> puts values into the variables in its parameter list that it uses as
> outputs, and expects the calling routine to be able to receive them and
> use them in later calculations.
>
> Could this be done with VARPTR? Certainly, not as easily.
Well, the thought that you have a pointer, it can certainly be modified
within the sub.
I think, though, we might be drifting toward something non-Basic here,
pointers and such.
I do remember VARPTR and address-of operators being used in the older
compilers for such things, though.
Certainly a BYREF qualifier would be more BASIC-like.
But I prefer reference, simply because "()" are so easy to place around a
parameter to specify BYVAL. And I usually like to be able to alter a
variable. Useful in BASICs where FUNCTIONs don't exist, or you need to
pass
back more than one value.


|