[Prev][Next][Index][Thread]

Re: small Q





oodl@my-deja.com wrote:
> 
> In article <Gsyj5.3194$pu4.263441@typhoon.ne.mediaone.net>,
>   "Scott McKay" <swm@mediaone.net> wrote:
> >  Multiple return values
> > is one of those things that, once you use them, you can't imagine why
> > all languages don't have them.
> 
> Yes, imagine if functions in programming languages could only *take* one
> parameter.  That would be lame.  Being able to return only one value
> from a function is no different:  It forces one to resort to structures,
> collections, or global variables.... all of which have a negative
> influence on organization and/or clarity of ones source code.

Well, perhaps. Single value parameters and return values are quite
reasonable if they may be aggregate structures. They might be clumsy,
but they aren't actually limiting to use.
Consider a non-constant identifier v. Used on the LHS or RHS of an
expression, it means different things. (going to be pascally in places):

	p := v;
	// versus
	v := 3; 

if the same symbol can represent different things in different contexts
then maybe I can claim that a variable could be a slightly more extended
thing:

	#[a, b] 

if a and b are variables, why can't I consider "#[a, b]" as a whole to
be a variable?

	#[a, b] := #[3, 4]

I say this is valid if you wish to interpret it as valid, AND it cleanly
maps to the underlying machinery.
Okay, suppose there isn't a clean map. I just choose instead to
interpret the above purely as parallel assignments, breaking down into

	a := 3;
	b := 4;

(with a bit extra to manage cycles if req'd). If that was acceptable to
you then the idea of a single return value is quite reasonable and
non-clumsy.

	define method sample()
		#[20, 30];		
	end;

	#[p, q] := sample();

indeed a single parameter may be aggregate:

	define method rotate(v)
		#[second(v), third(v), first(v)];
	end;

is valid but more tidily expressed as
	
	define method rotate(#[s, t, u])
		#[t, u, s];
	end;

and invoked:

	temp := #[a, b, c]
	temp := rotate(temp);
	// or similarly
	#[a, b, c] := rotate(#[a, b, c]);

The value of this is that it doesn't invoke a separate mechanism for
passing multiple params, or returning multiples, unlike values() which
seems[*] to be added on. I accept that different underlying mechanisms
like these mysterious continuations can give rise neatly to different
solutions to different problems, one of which being their own way of
returning multiple values. 
You get the picture. I've inherited a bit of baggage from prolog and
from my very declarative VDM background, as you can tell.

This is certainly not to criticise dylan or to ask for these things,
just to say an alternative ways of dealing with multiple return values
simply seemed obvious to me. I also appreciate that these ways lead into
other things like problems with method invocation and probably much
more, and it just ain't the dylan way of doing things. No problem.

And BTW I have no argument at all with the view that multiple return
values are extremely handy.

[*] don't misinterpret it; it 'seems' because I'm used to other things.

thanks

jt



References: