RE: [S] Can't formal argument name == actual name?

Terry Elrod (Terry.Elrod@UAlberta.ca)
Mon, 15 Jun 1998 09:04:12 -0600


Alan Zaslavsky [zaslavsk@hcp.med.harvard.edu] reminds me that default
arguments are evaluated in the local frame. And come to think of it, the
examples I have seen of formal.argument.name == actual.name are in the calls
to the function, and not in the function definition.

I had thought that, because y is on the search path, its value would be
found from within the function, but apparently not.

Terry Elrod

> -----Original Message-----
> From: owner-s-news@wubios.wustl.edu
> [mailto:owner-s-news@wubios.wustl.edu]On Behalf Of Terry Elrod
> Sent: Monday, June 15, 1998 7:30 AM
> To: s-news@wubios.wustl.edu
> Subject: [S] Can't formal argument name == actual name?
>
>
> > # Perhaps I'm losing my mind, but I swear this has worked, and ought to
> work...
> > y <- 5
> > y
> [1] 5
> > .f
> function(y = y)
> {
> y
> }
> > .f()
> Error in .f(): Recursive occurrence of default argument "y"
> Dumped
> > traceback()
> Message: Error in .f(): Recursive occurrence of default argument "y"
>
> 5: .f()
> 4: eval(expr, local = F)
> 3: .Sapi.build.output(txt = ".f()\n", hints = c("SapiOutput",
> "SapiErrorText", "SapiWarningText",
> 2: .C(NAME = "S_api_get_message",
> 1:
> > # The problem disappears when the actual and formal names do
> not agree, of
> course ...
> > .f2
> function(x = y)
> {
> x
> }
> > .f2()
> [1] 5
> > # The problem has nothing to do with returning an object named y ...
> > .f3
> function(y = y)
> {
> z <- y
> z
> }
> > .f3()
> Error in .f3(): Recursive occurrence of default argument "y"
> Dumped
> > # Using inspect shows that the problem arises in trying to obtain the
> value of y from
> > # within the frame.
> >
> > # I'm running S-Plus 4.5 rel. 1 under Windows 95.
>
> Terry Elrod
> ------------------------------------------------------------------------
> Terry Elrod; Assoc. Prof. of Marketing
> 3-23 Faculty of Business; Univ. of Alberta; Edmonton, AB; Canada T6G 2R6
> phone: 403-492-5884; fax: 403-492-3325; email: Terry.Elrod@UAlberta.ca
> ------------------------------------------------------------------------

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news