Message Boards Message Boards

1
|
3499 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Passing options to function as a list rather than individual arguments?

Anonymous User
Anonymous User
Posted 6 years ago

I see code like this that works:

show3D[graphics_] := Show[graphics, {ImageSize -> localImageSize}]

It works similarly if the list of options contains more than one option; and it works if the list of options contains zero options.

Normally, I see options strung as individual arguments at the end of the list of arguments; not inside any list:

show3D[graphics_] := Show[graphics, ImageSize -> localImageSize]

That's what I've seen in many examples in the documentation, iirc. Does putting them inside a list make any difference? Thank you.

POSTED BY: Anonymous User
3 Replies

That depends a bit on the implementation of these functions. If the option passing is implemented with OptionsPattern[] then providing lists of options should work fine. I think, before OptionsPattern[] was introduced (version 6.0), the usual way was to implement functions with optional arguments by using BlankNullSequence like f[arg1_,opt____]:=.... (Actually I don't know if this has ever been the "official" way of doing that but I have seen something like that in undocumented functions several times when I was spelunking.) So it depended a bit on the developers wether they processed the options with Flatten[List[opt]] or not. So, rather old functions that were coded before OptionsPattern[] was introduced and haven't been touched since then might get problems...

Anonymous User
Anonymous User
Posted 6 years ago

Thank you.

POSTED BY: Anonymous User

You're welcome.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract