Optional parameters in functions

Posted By: fsgi

Optional parameters in functions - 05/11/20 07:44

I wanted to ask wheter (and how) is it possible to code optional parameters in Zorro functions, like in C/C++ something like
Code
void myfunction(int par1, double par2 = 3.14) {...}

where of course par2 is optional (i.e. it has the defatult value 3.14 if the client does not specifies anything else).

It looks like that Zorro clearly uses optional parameters but I have not found any spec about it in the manual.

In addition, always in the manual, it is very (very very) hard to get a clear-cut, immediate understanding of wich parameters are optional. Take for instance the description of the lhour function:

Quote
lhour (int zone, int offset): int
Closing local hour of the given bar in the given time zone (see timeOffset below), considering daylight saving time (see dst below). F.i. lhour(EST) returns the current hour at the New York Stock Exchange.


From the example in the description it is then obvious that int offset is optional (and... obviously = 0). But for more complex functions wouldn't be nicer to include in the reference which are the parameters that can be omitted and how do they get assigned by default (e.g. indicating them with the "= xyz" label, or, I don't know... putting them at least in italic)?

Thank you in advance.
Posted By: jcl

Re: Optional parameters in functions - 05/11/20 08:51

Lite-C has no optional parameters, but supports overriding. That's used for omitting parameters in some Zorro functions.

void myfunction(int par1, double par2) {...}

void myfunction(int par1) { myfunction(par1,3.14); }

The optional parameters in the manual are in italics.
Posted By: danatrader

Re: Optional parameters in functions - 05/11/20 12:24

Nice example of that is in the CCY scripts of Petra on the finacial hacker.
Posted By: fsgi

Re: Optional parameters in functions - 05/11/20 16:28

Thank you so much for the explanation jcl. Meaningful. Please correct the manual, in this case, because lhour offset parameter is NOT italics.
Posted By: fsgi

Re: Optional parameters in functions - 05/12/20 15:59

jcl, just on the same line of overloading and basic C-lite (coming from a C++ background)...

In lite-C isn't there anything like templatized functions?

I'm asking because I would like to write some array-manipulation functions (for an #include) and it would be tedious to re-write all of them one for integers, one for doubles, one for strings... you know... Is there any alternative ?
Posted By: AndrewAMD

Re: Optional parameters in functions - 05/12/20 16:17

Like C, Lite-C has no templates.

You can always use conventional C++ to write strategies:
https://zorro-project.com/manual/en/dlls.htm

In the future, oP group plans on adding "Support for .cpp scripts by directly calling the VC++ compiler and linker." This means you'll be able to do rapid prototyping without having to fire up Visual Studio every time.
https://zorro-project.com/manual/en/new.htm
Posted By: jcl

Re: Optional parameters in functions - 05/15/20 09:31

As to the time offset, it's not in italics because it's not optional in the VC++ version.
© 2024 lite-C Forums