Re: Variable Arguments?
- Posted by CChris <christian.cuvier at ag?iculture.gouv.f?> Apr 23, 2008
- 668 views
yuku wrote: > > CChris wrote: > > > > Jeremy Cowgar wrote: > > > > > > CChris wrote: > > > > > > > > The change was not trivial because it involves the ability to replay > > > > canned > > > > tokens after recording them. Indeed > > > > procedure foo(integer n=n0) > > > > needs late binding > > > > > > > > > > Even something as simple as: > > > > > > }}} <eucode> > > > procedure foo(opt object n) > > > </eucode> {{{ > > > > > > and if n was not supplied, n defaulting to NULL would be a huge step. > > > > > > }}} <eucode> > > > function round(sequence items, opt object n) > > > if n = NULL then n = 1 end if > > > ... code for round_precision ... > > > end function > > > </eucode> {{{ > > > > > > That's not as good as function round(sequence items, integer precision=1) > > > but, > > > it's a huge step above what we have now and could be maintained later once > > > an > > > assignment would be possible. > > > > > > How hard is something like that? > > > > > What is NULL? > > If we had a nil object, as I have advocated for a long time, then it would > > be > > ok. But adding nil is trickier I think - or not, I haven't tried yet. Moving > > to 3-way logic might break too much code. > > Instead of having a variable arguments or null type, I agree with JCougar, > having default arguments will be easier to understand and easier to implement. > > How about this syntax (as intuitive as possible) > > [global] {function|procedure} <name> ( [<type> <name>]* [<type> <name> = > <def>]* > ) > > where <def> indicates default argument and it must be a constant! > Default arguments also must be the last in the argument list. > > Then, instead of modifying the back end, we can only modify the front end, > to make it act like a preprocessor. e.g. for > }}} <eucode> > global function round(object item, integer prec = 0) > </eucode> {{{ > > , if the call is like round(2.54), the front-end will emit IL that is > exactly the same as if the code were round(2.54, 0). > > > yuku But call_func(routine_id("round"),{2.54}) will need handling at runtime, ie in backend. CChris