Re: Another EU 2.5 suggestion...
- Posted by "Hayden McKay" <hmck1 at dodo.com.au> Jan 25, 2004
- 506 views
I understand what your sayin but I dont think its necasary. In my opinion the first example is better. In the first example the if statement in produre main() only has to check if x = ERROR, where in the second example it has to call a low_level routine to check if x is assighned. ----- Original Message ----- From: "aku saya" <akusaya at gmx.net> To: <EUforum at topica.com> Sent: Sunday, January 25, 2004 5:06 PM Subject: Re: Another EU 2.5 suggestion... > > > After reading many posts about the eval() function, I want to post my > opinion, that eval() will not be suitable for euphoria, because > euphoria can be translated and compiled, not just interpreted. Eval() > needs interpreter. So I think there will never be an eval() function > in euphoria. > > However I really want a method to set and detect unassigned value in > euphoria. This function > > constant ERROR = -1 > > function generate_random() > -- generate a random number > if (success) then > return the_number > else > return ERROR -- failed to generate > end if > end function > > procedure main() > object x x = generate_random() > if x = ERROR then > puts(1, "error occured") > end if > end procedure > > would be able to be replaced by: > > function generate_random() > -- generate a random number > if (success) then > return the_number > else > return no_value() -- failed to generate > ^^^^^^^^^ > built-in function that returns unassigned > end if > end function > > procedure main() > object x x = generate_random() > if unassigned(x) then > puts(1, "error occured") > end if > end procedure > > For a function that returns all possible value it will be very useful > to differentiate special return value. > > > C> I would like to be able to set the value of a variable like this: > C> integer > C> some_extremly_long_variable_name=82,another_extremly_long_variable_name=45 > > C> Instead of: > C> integer > C> some_extremly_long_variable_name,another_extremly_long_variable_name > C> some_extremly_long_variable_name=82 > C> another_extremly_long_variable_name=45 > > C> This would be much easeyer, especilly with long variable names. > C> This is already used in constants, so why not with regular variables? > > C> And I would also REALLY like my other suggestions included: > > C> "eval()" commands/crash callbacks/ect. for Euphoria 2.5? > > C> Some of the following is missing from Euphoria and would be very > C> helpful to me and many other programmers. I would like to see this in > C> Eu 2.5. Please take these into consideration. > > > C> "eval()" commands: > C> I would really like to see a way to do an "eval()" type command. > C> Many other languages have something like this. > > C> eval(sequence eval_commands,integer global_type,integer crash) > C> eval_commands is a sequence of commands > C> global_type is: > C> 0-No routines/varibles (even global) exist in main program > C> 1-Only routines/varibles declared as global exist in main program > C> 2-All routines/varibles exist in main program > > C> if crash is true, if it encounters an error (like 1/0) than the > C> program dies with (or a crash routine, see below) ex.err, otherwise, it > C> returns an error > C> code(like 5 for divide by 0,see below) > > > C> Example: > C> integer a,global_type > C> sequence eval_commands > > C> eval_commands=" > C> include incl_file.e--should allow including(This could be used > C> --instead of complex "dynamic includeing" libraries) > C> if a then > C> ?a > C> end if" > > C> a=7 > C> var_type=1 > > C> ?eval(eval_commands,global_type,0) > C> Displays: > C> 7(value of a) > C> 0(eval encountered no errors) > > > C> set_crash(integer routine_id) > C> routine_id is the routine id of the function > C> it calls the function with an error code(like 5 for divide by 0), > C> a sequence with info about the error(like a line #, invalid subscript, > C> ect.) > C> and a text string with the complete text error message( > C> "test.ex:3 > C> attempt to divide by 0") > > C> if the function returns -1, ignore the error > > C> Example: > C> function oncrash(integer err_code,sequence info,sequence msg) > C> if err_code=34 then--this error can be ignored in this program > C> return -1 > C> end if > C> save_all_important_data() > C> return 0 > C> end function > C> set_crash(routine_id("oncrash")) > > > C> TOPICA - Start your own email discussion group. FREE! > > > > TOPICA - Start your own email discussion group. FREE! > > > -- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.564 / Virus Database: 356 - Release Date: 20/01/04 > --- --