1. Is this possible?

function foo (object arg1, object arg2=0, object arg3=0} 

Now, if you call foo() <- note: fewer than the 'required" # of args, you get an error

foo takes 3 arguments
foo()

Is it possible that the error message could be, instead:

foo requires 1..3 arguments

would make things easier, as you wouldn't have to go back & look up foo to determine if it really requires 3, or if it will be satisfied with 1.

new topic     » topic index » view message » categorize

2. Re: Is this possible?

You'd probably want to look it up anyway to see what KINDS of arguments it takes. But it's still a good idea I guess.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Is this possible?

mic said...

You'd probably want to look it up anyway to see what KINDS of arguments it takes. But it's still a good idea I guess.

Can do, but cannot commit to svn these days sad

CChris

new topic     » goto parent     » topic index » view message » categorize

4. Re: Is this possible?

CChris said...

Can do, but cannot commit to svn these days sad

Chris,

Is this because of your Internet down or are you still suffering from a 403 error since SF.net did their SVN upgrade? If that later is the case, you need to do a

svn switch relocate http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk https://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk

Jeremy

new topic     » goto parent     » topic index » view message » categorize

5. Re: Is this possible?

CChris said...
mic said...

You'd probably want to look it up anyway to see what KINDS of arguments it takes. But it's still a good idea I guess.

Can do, but cannot commit to svn these days sad

CChris

Hmm, not as clear cut as I thought.

The first non defaulted argument # is known, as well as the total number.

However, you could always code

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

I'm not sure what the error message should be then. Perhaps recording the # of the last non defaulted parameter as well would be enough, not too difficult.

CChris

new topic     » goto parent     » topic index » view message » categorize

6. Re: Is this possible?

jeremy said...
CChris said...

Can do, but cannot commit to svn these days sad

Chris,

Is this because of your Internet down or are you still suffering from a 403 error since SF.net did their SVN upgrade? If that later is the case, you need to do a

svn switch relocate http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk https://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk

Jeremy

No, it's the landline, I think I mentioned it in the private email with the zip filme with some files to commit. Hopefully it gets repaired this week.

For the arg # issue: what you can do now is the following:

in parser.e, locate the CompileErr() call in ParseArgs() that is being reached, and change its string parameter to a sprintf() using the values of fda (first defaulted arg #) and n (max number of args).

You nneed to recompile, except if using eu.ex.

CChris

new topic     » goto parent     » topic index » view message » categorize

7. Re: Is this possible?

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.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Is this possible?

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.

Actually, in the example you gave, I think it requires 3 (or 4) arguments, it's just that the first and third can be defaulted with a blank instead of a value: foo(39) (hope I typed that right) the results should be {0,3,2,9}

So the question is really how to word the message to give the most useful info in the least confusing way. Maybe something like "foo requires 4 parameters, (1 and 3 may be defaulted)"

new topic     » goto parent     » topic index » view message » categorize

9. Re: Is this possible?

looks like two commas together don't work, that should have read:

foo(,3,,9) 
new topic     » goto parent     » topic index » view message » categorize

10. Re: Is this possible?

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 message » categorize

11. Re: Is this possible?

murphy said...

foo(39) (hope I typed that right)

The double commas markup is used for subscripting text. You coded foo(,,3,,9) so the '3' got subscripted.

When typing in code fragments, it is better to use the <eucode> </eucode> tags, or the no-wiki tags {{{ }}} to display it inline.

eg.
The defaulted version would be foo(,,3,,9)

or
The defaulted version would be

foo(,,3,,9) 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu