Re: Is this possible?

new topic     » goto parent     » topic index » view thread      » older message » newer message
SDPringle said...

Is the following line CChris be equivalent to a 3.1 function definition since you'll need to supply a fourth argument or can optional arguments really be in the middle and beginning? Does the function foo(3,4) assign to p and r?

function foo(integer n=0,integer p,integer q=2,integer r) 

The error should be foo requires at least 2 but at most 4 arguments.

foo(3,4) is illegal.

However:

?foo(,3,,4) 
-- is the same as 
?foo(0,3,2,4) 

While at first glance it may seem odd to put defaulted parameters in the midle as in the above eample, there are quite a few cases where it makes sense, in matrix or tensor calculations for example.

If the relative positions of your parameters don't critically matter, then you are better off putting mandatory params first, then defaulted. This avoids extra commas. But sometimes the order is critical, so the syntax is available.

I'm not sure he error message you suggest would be right either.

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu