Reply to topic  [ 4 posts ] 
more_args without named positional args 
Author Message
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post more_args without named positional args
I found a small inconsistency in more_args's behavior when it's used with a function that doesn't have any named positional arguments.

Consider these two example functions:

Code:
func example1(nil, ..) {
write, more_args();
}

func example2(..) {
write, more_args();
}


When called in subroutine form, both work as expected:

Code:
> example1
  0
> example1, 1
  0
> example1, 1, 2
  1
> example2
  0
> example2, 1
  1


When called in functional form, example1 works as expected:

Code:
> example1()
  0
[]
> example1(1)
  0
[]
>  example(1, 2)
  1
[]


However, example2 does not:

Code:
> example2()
1
[]
> example2(1)
1
[]


It appears that more_args erroneously treats "example2()" as equivalent to "example2([])".

I'm guessing I can work around this using wrap_args, but figured it warranted mentioning anyway.


Mon May 10, 2010 1:56 pm
Profile
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post 
Uh, that's a feature, not a bug...

f() is precisely equivalent to f([]), and f(x,,y) is precisely equivalent to f(x,[],y). Unlike C, there is no way to invoke a function with zero arguments in yorick. An omitted argument is []. You can see this happen with the disassemble function -- try

disassemble;example2()
disassemble;example1()

You will see they both are called with one argument. Furthermore,

disassemble;example1(,)

But

disassemble;example1

is called with zero arguments. This is slightly confusing, because yorick will initialize unprovided arguments to [], just as explicitly nil arguments are [].

You can get a little more control with the new wrap_args function, which gives you the full range of identification of arguments available to compiled (builtin) functions.


Mon May 10, 2010 9:58 pm
Profile
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post 
Aha! Perhaps a "gotcha" then instead of a "bug". :) Thanks for the explanation, I'll use wrap_args.


Tue May 11, 2010 5:38 am
Profile
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post 
I hope I was clear that wrap_args does not count arguments any differently than more_args. Mostly it lets you use extra positional arguments (..) as outputs if you want, and also it lets you find the names of any arguments supplied as simple variable references (as opposed to expressions). The latter feature permits you to write interpreted code that imitates functions like save and restore.


Tue May 11, 2010 7:12 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.