Arguments as actual objects

i was wondering if anyone’s thought any more on the idea of making arguments
actual objects in there own right.

i talked about this a bit before in relation to Arrays and Hashes.

i think it would be a powerful tool to be able to pass argument lists around.

for example:

def i_take_args(*args)
puts args.inspect
end

def i_give_args
return [1, 2, 3].to_arg
end

i_take_args(i_give_args) #—> [1,2,3] ( not [[1,2,3]] )

what does this really amount to? you see, this makes for a 100% OO way to do
what we normally do with *.

i_take_args *[1,2,3] # this is a syntatical means (what would you call it?)

i_take_args [1,2,3].to_arg # the OO Way!!!

···


tom sawyer, aka transami
transami@transami.net

                               .''.
   .''.      .        *''*    :_\/_:     .
  :_\/_:   _\(/_  .:.*_\/_*   : /\ :  .'.:.'.

.’’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:’.:::. | ’ ‘’ * ‘.’/.’ (/’.’:’.’
: /\ : ::::: = / -= o =- /)\ ’ *
’…’ ‘:::’ === * /\ * .’/.’. ‘._____
* | : |. |’ .—"|
* | _ .–’| || | _| |
* | .-’| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /"\ | '-."". ‘-’ ‘-.’ '` |.

Hi –

i was wondering if anyone’s thought any more on the idea of making arguments
actual objects in there own right.

i talked about this a bit before in relation to Arrays and Hashes.

i think it would be a powerful tool to be able to pass argument lists around.

for example:

def i_take_args(*args)
puts args.inspect
end

def i_give_args
return [1, 2, 3].to_arg
end

i_take_args(i_give_args) #—> [1,2,3] ( not [[1,2,3]] )

what does this really amount to? you see, this makes for a 100% OO way to do
what we normally do with *.

I don’t think there’s anything wrong with using * . We use operators
in Ruby all the time (like , . , (), etc.). Also, there are lots of
cases where you use * other than in argument lists. As long as it’s
there, it seems fine to use it for argument lists too.

There’s another conundrum here. How would you define to_arg? What
would its return value be? Let’s say you did:

class Array
def to_arg
*self
end
end

This will return an array. Since Ruby uses Arrays as its mechanism
for handling multiple return values, any method called on any object
that returns more than one value (including Array#to_arg) will return
an Array. That’s why you need an operator like * to manipulate arrays
directly.

i_take_args *[1,2,3] # this is a syntatical means (what would you call it?)

I know this is just an example, but don’t forget that you can pass a
literal list: i_take-args(1,2,3)

i_take_args [1,2,3].to_arg # the OO Way!!!

Oh, we can get more OO than that:

send(:i_take_args,Array.new.push(1,2,3).to_arg)

:slight_smile:

David

···

On Mon, 13 Jan 2003, Tom Sawyer wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

I don’t think there’s anything wrong with using * . We use operators
in Ruby all the time (like , . , (), etc.). Also, there are lots of
cases where you use * other than in argument lists. As long as it’s
there, it seems fine to use it for argument lists too.

i’m not really saying that there is anything wrong with it per se. only
pointing out that b/c arguments aren’t objects in their own right we require
a sytatically disperate operator to provide the functionality.

There’s another conundrum here. How would you define to_arg? What
would its return value be? Let’s say you did:

well, that’s the thing. Arguments would need to be a built-in class.

class Array
def to_arg
*self
end
end

This will return an array. Since Ruby uses Arrays as its mechanism
for handling multiple return values, any method called on any object
that returns more than one value (including Array#to_arg) will return
an Array. That’s why you need an operator like * to manipulate arrays
directly.

well, you hit the nail on the head: Arguments are not Arrays. if they were
then this wouldn’t be an issue and * would not be needed. moreover * behavior
is complex. in one instance it converts an Array into “Arguments” and in a
another instance returns an Array (as in your Array#to_arg example above).

Oh, we can get more OO than that:

send(:i_take_args,Array.new.push(1,2,3).to_arg)

silly david :wink:

···

On Monday 13 January 2003 06:28 am, dblack@candle.superlink.net wrote:

**
actually, it quite interesting. what i am thinking of is an object that
dosen’t get passed like normal objects, rather:

arg_obj = (1, 2, 3) # literal contructor for args
somemethod arg_obj

this would not pass a single Argument object as such, but would act as if it
were:

somemethod(1, 2, 3)

an oddity in itself, for then how does one pass an Argument object? to be
clear, my whole desire for this is to be able to do:

i_take_args i_make_args

rather than having to do:

i_take_args *i_make_args

but perhaps that is simply logically impossible?


tom sawyer, aka transami
transami@transami.net

                               .''.
   .''.      .        *''*    :_\/_:     .
  :_\/_:   _\(/_  .:.*_\/_*   : /\ :  .'.:.'.

.‘’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:‘.:::. | ’ ‘’ * ‘.'/.’ (/’.‘:’.’
: /\ : ::::: = / -= o =- /)\ ’ *
‘…’ ‘:::’ === * /\ * .‘/.'. ‘._____
* | : |. |’ .—"|
* | _ .–’| || | _| |
* | .-‘| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /“\ | '-.”". ‘-’ ‘-.’ '` |.