Re: ideas from CCC 1.
- Posted by Robert Craig <rds at RapidEuphoria.com> Feb 16, 2004
- 461 views
Guest wrote: > I am working on creating a function library which will be made public, > from the best CCC functions, Great. > but there are ones that I cannot make. > ... > 1. The if() function > > the if() function is something like: > > -- code start > function if(atom condition, object truevalue, object falsevalue) > object retval > if condition then > return truevalue > end if > return falsevalue > end function > -- code end > > and it could be used the following way, for example: > > atom lgt > object something > > lgt=if(sequence(something),length(something),0) > > It would greatly reduce coding time, and would promote > a very good programming style, I think. > > The problem is: > > The parameters are evaluated "too early". In the above example, > if something is an atom, then you have an error. > But the goal of if() is to evaluate the parameters only > when the condition if true or false - so in the example, it should > evaluate length(something) if the sequence(something) > condition is true. > > Can it be made in EU or could I ask Rob to incorporate it in the > interpreter? I think it can be incorporated in the interpreter > easily if one can code in C (I myself cannot) because > it's just a different parsing route: > > 1) evaluate param1 to 0 or non-0 > > 2) if param1 is non-0 then evaluate and return param2 > > 3) if param1 is 0 then evaluate and return param2. > > It can't be complicated, can it?
> > It would really be useful - in a CCC program, almost every 20. line > contains an if() and it really quickens up coding. > > Best Regards, > > Miklos Hollender Thanks for the suggestion. In C they have conditional expressions using ? and : for example: max = (a > b) ? a : b I've sometimes felt that something like this would be convenient, but you can always do it as if a > b then max = a else max = b end if which is longer but just as readable. My basic philosophy favors minimalism over having lots of minor conveniences. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com