1. Re: we need official libs : Swap
- Posted by Jason Gade <jgade at PCEZ.COM>
Jul 22, 1999
-
Last edited Jul 23, 1999
Hi, all. I've been lurking for awhile and I've been following this thread.
It seems strangely related to the structures arguments and the object-
oriented arguments. Here is my take:
While I have thought that it would be useful to do something such as
args = command_line()[2]
I realize that it is clearer to me to just assign the whole bunch to a
sequence and check it later.
I believe that the example of
-- with sequences
pt1 = mapToParent( x1, y1 )
pt2 = mapToParent( x2, y2 )
draw_line( color, pt1[1], pt1[2], pt2[1], pt2[2] )
is incorrect, because according to my manual draw_line() is called:
draw_line(color, {pt1, pt2})
But I'm not sure what mapToParent() does . . .
This leads into my point, though, that returning a sequence or an object
is just as good as the multiple assignment and maybe even better. Assuming
that the function has been written correctly. Like in the draw_line()
example
above, like types are combined into a single sequence. Functions should
accept sequences of like types and return sequences of like types.
Here is good example of a bad example:
s = get_position()
...
position( s[1], s[2] )
The position() function should accept a sequence as an argument, instead of
atoms.
That would be more consistent with the way Euphoria works.
I was also thinking that you could have a pseudo-overload by having a
function proto-
typed as:
position(object i1, object i2)
and the function could check whether it received a sequence or an atom. The
second
argument could be zero if the first argument fulfilled the function's needs,
and the function
could return an error if the args were incorrect or inconsistent.
As for swap, I think that I would do it like this:
sequence swap
object a, b
.
.
.
swap = {a, b}
a = swap[2]
b = swap[1]
Jason Gade