-
Crazy idea
This is probably a crazy idea and to be honest I haven't really thought it
through, but why wouldn't it be possible for a function to return more than
one value. Something like this:
(x ,y) = GetSomePoint ( )
Function GetSomePoint ( ) As Int32, Int32
Return 3, 5
End Function
I know underneath it would be the same as a byref parameter (except the
values could not be modified). I also know that there are other ways to do
this but this could be an option. Its been a convention that functions only
return one parameter, afaik, since computers where invented, but is it a
convention just because it's a convention?
-
Re: Crazy idea
"Michael Culley" <mculley@optushome.com.au> wrote in message
news:3d0ea909@10.1.10.29...
> This is probably a crazy idea and to be honest I haven't really thought it
> through, but why wouldn't it be possible for a function to return more
than
> one value. Something like this:
>
> (x ,y) = GetSomePoint ( )
>
> Function GetSomePoint ( ) As Int32, Int32
> Return 3, 5
> End Function
>
> I know underneath it would be the same as a byref parameter (except the
> values could not be modified). I also know that there are other ways to do
> this but this could be an option. Its been a convention that functions
only
> return one parameter, afaik, since computers where invented, but is it a
> convention just because it's a convention?
You can do this in Perl - you can do anything in Perl!
#!/usr/bin/perl -w
use strict;
my($x) = 0;
my($y) = 0;
($x, $y) = getpoint();
print "\$x=$x, \$y=$y\n";
sub getpoint()
{
return (10, 20);
}
I suppose you could always use Active States Visual Perl - it runs on the
..NET platform.
Tom Shelton
-
Re: Crazy idea
Yep, perl has a very, um, flexible syntax. I didn't know you could return 2
or more values from a function but I like the way you can use anything as a
quotation mark as long as they were in a pair. I can't remember the exact
syntax, something like this (?):
$x = \abc\ ;
$x = |abc| ;
$x = @abc@;
Michael Culley
"Tom Shelton" <tom@mtogden.com> wrote in message news:3d0eadd4@10.1.10.29...
>
> "Michael Culley" <mculley@optushome.com.au> wrote in message
> news:3d0ea909@10.1.10.29...
> > This is probably a crazy idea and to be honest I haven't really thought
it
> > through, but why wouldn't it be possible for a function to return more
> than
> > one value. Something like this:
> >
> > (x ,y) = GetSomePoint ( )
> >
> > Function GetSomePoint ( ) As Int32, Int32
> > Return 3, 5
> > End Function
> >
> > I know underneath it would be the same as a byref parameter (except the
> > values could not be modified). I also know that there are other ways to
do
> > this but this could be an option. Its been a convention that functions
> only
> > return one parameter, afaik, since computers where invented, but is it a
> > convention just because it's a convention?
>
> You can do this in Perl - you can do anything in Perl!
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my($x) = 0;
> my($y) = 0;
>
> ($x, $y) = getpoint();
> print "\$x=$x, \$y=$y\n";
>
> sub getpoint()
> {
> return (10, 20);
> }
>
> I suppose you could always use Active States Visual Perl - it runs on the
> .NET platform.
>
> Tom Shelton
>
>
-
Re: Crazy idea
I think by ref and compound data types made this unnecessary.
Tim
"Michael Culley" <mculley@optushome.com.au> wrote in message
news:3d0ea909@10.1.10.29...
> This is probably a crazy idea and to be honest I haven't really thought it
> through, but why wouldn't it be possible for a function to return more
than
> one value. Something like this:
>
> (x ,y) = GetSomePoint ( )
>
> Function GetSomePoint ( ) As Int32, Int32
> Return 3, 5
> End Function
>
> I know underneath it would be the same as a byref parameter (except the
> values could not be modified). I also know that there are other ways to do
> this but this could be an option. Its been a convention that functions
only
> return one parameter, afaik, since computers where invented, but is it a
> convention just because it's a convention?
>
>
>
>
-
Re: Crazy idea
"Michael Culley" <mculley@optushome.com.au> wrote in message
news:3d0eb68f@10.1.10.29...
> Yep, perl has a very, um, flexible syntax. I didn't know you could return
2
> or more values from a function but I like the way you can use anything as
a
> quotation mark as long as they were in a pair. I can't remember the exact
> syntax, something like this (?):
>
> $x = \abc\ ;
> $x = |abc| ;
> $x = @abc@;
>
> Michael Culley
Yeah, Perl does have some interesting features. One of my favorites are
statement modifiers, unless, until, if, etc. you can do stuff like:
print $x unless $y == 10;
print $x if $x == 2;
somefunc($x) until $x == 10;
somefunc($x) while $x < 10;
makes for some really compact code (wholy unreadable, but hey it's Perl -
the original write only programming language.)
Tom Shelton
-
Re: Crazy idea
But with byref the syntax isn't the best. A few times I've been confused by
components that return byref parameters. I remember once I was using a
component with a function like this:
GetSomePoint (X , Y)
I spent approx 15 minutes thinking 'why do I have to give it the co-ords, I
want it to give them to me'.
With structures you have to dim a structure first and then pull it apart.
Neither of these are big deals but if returning 2 values was available i'd
probably do it that way over these methods.
Michael Culley
"Luhar" <luhar@slipnet.net> wrote in message news:3d0eb6d6@10.1.10.29...
> I think by ref and compound data types made this unnecessary.
>
-
Re: Crazy idea
Michael Culley <mculley@optushome.com.au> wrote:
> Yep, perl has a very, um, flexible syntax. I didn't know you could return 2
> or more values from a function
Technically, you're not. You're returning a list.
--
Dave Rothgery
Picking nits since 1976
drothgery@alum.wpi.edu
http://drothgery.editthispage.com
-
Re: Crazy idea
I'm totally baffled by what you mean by this...
I mean...isn't this the same thing?
Function GetSomePoint() as Point
return new Point(3,5)
End Function
Because your receiver has to have two buckets to receive two answers in it
has to be a formal type of data, in this instance, a point...so you get back
a pointer to the copy created by the function...
What am I missing here?
--
-Robert
Have a cow, man:
http://www.riddleme.com/html/cow.html
"Michael Culley" <mculley@optushome.com.au> wrote in message
news:3d0ea909@10.1.10.29...
> This is probably a crazy idea and to be honest I haven't really thought it
> through, but why wouldn't it be possible for a function to return more
than
> one value. Something like this:
>
> (x ,y) = GetSomePoint ( )
>
> Function GetSomePoint ( ) As Int32, Int32
> Return 3, 5
> End Function
>
> I know underneath it would be the same as a byref parameter (except the
> values could not be modified). I also know that there are other ways to do
> this but this could be an option. Its been a convention that functions
only
> return one parameter, afaik, since computers where invented, but is it a
> convention just because it's a convention?
>
>
>
>
-
Re: Crazy idea
The differences aren't great, it could even work the same underneath, but
the difference is that you don't have to define a structure.
--
Michael Culley
www.vbdotcom.com
"Robert Lantry" <mirth@mirthy.com> wrote in message
news:3d0ecb1e$1@10.1.10.29...
> I'm totally baffled by what you mean by this...
>
> I mean...isn't this the same thing?
>
> Function GetSomePoint() as Point
> return new Point(3,5)
> End Function
>
> Because your receiver has to have two buckets to receive two answers in
it
> has to be a formal type of data, in this instance, a point...so you get
back
> a pointer to the copy created by the function...
>
> What am I missing here?
>
> --
>
> -Robert
>
> Have a cow, man:
> http://www.riddleme.com/html/cow.html
>
>
> "Michael Culley" <mculley@optushome.com.au> wrote in message
> news:3d0ea909@10.1.10.29...
> > This is probably a crazy idea and to be honest I haven't really thought
it
> > through, but why wouldn't it be possible for a function to return more
> than
> > one value. Something like this:
> >
> > (x ,y) = GetSomePoint ( )
> >
> > Function GetSomePoint ( ) As Int32, Int32
> > Return 3, 5
> > End Function
> >
> > I know underneath it would be the same as a byref parameter (except the
> > values could not be modified). I also know that there are other ways to
do
> > this but this could be an option. Its been a convention that functions
> only
> > return one parameter, afaik, since computers where invented, but is it a
> > convention just because it's a convention?
> >
> >
> >
> >
>
>
-
Re: Crazy idea
Michael,
Michael Culley wrote:
> The differences aren't great, it could even work the same
underneath,
> but the difference is that you don't have to define a structure.
Maybe its me but I'd prefer a structure as you know what your getting
back as opposed to the systems interpretation of what you want back.
Eddie
>
> "Robert Lantry" <mirth@mirthy.com> wrote in message
> news:3d0ecb1e$1@10.1.10.29...
>> I'm totally baffled by what you mean by this...
>>
>> I mean...isn't this the same thing?
>>
>> Function GetSomePoint() as Point
>> return new Point(3,5)
>> End Function
>>
>> Because your receiver has to have two buckets to receive two
>> answers in it has to be a formal type of data, in this instance, a
>> point...so you get back a pointer to the copy created by the
>> function...
>>
>> What am I missing here?
>>
>> --
>>
>> -Robert
>>
>> Have a cow, man:
>> http://www.riddleme.com/html/cow.html
>>
>>
>> "Michael Culley" <mculley@optushome.com.au> wrote in message
>> news:3d0ea909@10.1.10.29...
>>> This is probably a crazy idea and to be honest I haven't really
>>> thought it through, but why wouldn't it be possible for a function
>>> to return more than one value. Something like this:
>>>
>>> (x ,y) = GetSomePoint ( )
>>>
>>> Function GetSomePoint ( ) As Int32, Int32
>>> Return 3, 5
>>> End Function
>>>
>>> I know underneath it would be the same as a byref parameter
(except
>>> the values could not be modified). I also know that there are
other
>>> ways to do this but this could be an option. Its been a convention
>>> that functions only return one parameter, afaik, since computers
>>> where invented, but is it a convention just because it's a
>>> convention?
-
Re: Crazy idea
So why don't we pass all parameters into a function as structures? Same
thing, isn't it?
--
Michael Culley
www.vbdotcom.com
"Eddie Burdak" <eburdak@pilatus-aircraft.com> wrote in message
news:3d0edde7@10.1.10.29...
> Michael,
>
> Michael Culley wrote:
>
> > The differences aren't great, it could even work the same
> underneath,
> > but the difference is that you don't have to define a structure.
>
> Maybe its me but I'd prefer a structure as you know what your getting
> back as opposed to the systems interpretation of what you want back.
>
> Eddie
>
>
> >
> > "Robert Lantry" <mirth@mirthy.com> wrote in message
> > news:3d0ecb1e$1@10.1.10.29...
> >> I'm totally baffled by what you mean by this...
> >>
> >> I mean...isn't this the same thing?
> >>
> >> Function GetSomePoint() as Point
> >> return new Point(3,5)
> >> End Function
> >>
> >> Because your receiver has to have two buckets to receive two
> >> answers in it has to be a formal type of data, in this instance, a
> >> point...so you get back a pointer to the copy created by the
> >> function...
> >>
> >> What am I missing here?
> >>
> >> --
> >>
> >> -Robert
> >>
> >> Have a cow, man:
> >> http://www.riddleme.com/html/cow.html
> >>
> >>
> >> "Michael Culley" <mculley@optushome.com.au> wrote in message
> >> news:3d0ea909@10.1.10.29...
> >>> This is probably a crazy idea and to be honest I haven't really
> >>> thought it through, but why wouldn't it be possible for a function
> >>> to return more than one value. Something like this:
> >>>
> >>> (x ,y) = GetSomePoint ( )
> >>>
> >>> Function GetSomePoint ( ) As Int32, Int32
> >>> Return 3, 5
> >>> End Function
> >>>
> >>> I know underneath it would be the same as a byref parameter
> (except
> >>> the values could not be modified). I also know that there are
> other
> >>> ways to do this but this could be an option. Its been a convention
> >>> that functions only return one parameter, afaik, since computers
> >>> where invented, but is it a convention just because it's a
> >>> convention?
>
-
Re: Crazy idea
On Tue, 18 Jun 2002 13:49:20 +1000, "Michael Culley"
<mculley@optushome.com.au> wrote:
>This is probably a crazy idea and to be honest I haven't really thought it
>through, but why wouldn't it be possible for a function to return more than
>one value. Something like this:
>
>(x ,y) = GetSomePoint ( )
>
>Function GetSomePoint ( ) As Int32, Int32
> Return 3, 5
>End Function
How about:
Public Type MyRet
Customer As String
Order As Long
End Type
Function GetThoseValues() As MyRet
Dim r As MyRet
r.Customer = "fred" ' First return value
r.Order = 1234 ' Second return value
GetThoseValues = r
End Function
Private Sub Command1_Click()
Dim r As MyRet
r = GetThoseValues
Debug.Print r.Customer, r.Order
End Sub
Of course, that is VB6 code. I have no way of knowing whether it could
be converted to work in other languages.
MM
-
Re: Crazy idea
Michael,
"Michael Culley" <mculley@optushome.com.au> wrote in message
news:3d0ee02f@10.1.10.29...
> So why don't we pass all parameters into a function as structures?
Same
> thing, isn't it?
(x,z) = GetSomePoint()
but say the point you wish to retrieve is actually represented in 3D
space but you are simply after x and z values for some reason the
system needs to know what you want back - data structure or parameters
and there is no confusion its hard wired. What you propose is
intriguing but somehow it needs to know what you want to get back. The
idea and flexibility I like - its knowing what comes back that bugs me
a little
Eddie
-
Re: Crazy idea
"David A. Rothgery" <drothgery@alum.wpi.edu> wrote in message
news:MPG.17786428782acab198971a@news.devx.com...
> Michael Culley <mculley@optushome.com.au> wrote:
> > Yep, perl has a very, um, flexible syntax. I didn't know you could
return 2
> > or more values from a function
>
> Technically, you're not. You're returning a list.
That's true. It really is returning an anonymous list. But when used in
the way I should, it acts and looks like you are.
Tom Shelton
-
Re: Crazy idea
Michael Culley had this to say:
> This is probably a crazy idea and to be honest I haven't really
> thought it through, but why wouldn't it be possible for a function to
> return more than one value. Something like this:
>
> (x ,y) = GetSomePoint ( )
>
> Function GetSomePoint ( ) As Int32, Int32
> Return 3, 5
> End Function
If you're asking for a point, why shouldn't the function return a point?
More often than not I just want to pass the structure to a routine that
requires a structure. If I need to inspect its individual members, I can do
so at any time.
--
http://www.acadx.com
"If you want to be somebody else change your mind"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|