Re[2]: Another EU 2.5 suggestion...
- Posted by akusaya at gmx.net Jan 25, 2004
- 378 views
How if the function is a special function which can return ANY possible return values, such as float64_to_atom(sequence x) but modified so that x can be a sequence of 8-element sequences. NAN, inf, {}, -1 or anything can be considered valid return value. So for that we need special additional function to detect the error. Isn't it troublesome? G> Sometimes I need to return an error code, but my function can return any G> value, such in the case of a random generator. In this case I use NAN. NAN G> means Not A Number and is used in C often. It's basically equal to the G> opposite of zero, which is obviously not a real number. G> constant -- taken from another post G> POS_INF = 1.8e+307 * 10, G> NEG_INF = -POS_INF, G> NAN = -(POS_INF+NEG_INF) G> function rand_num() G> -- generate a random number G> if (success) then G> return rand_number G> else G> return NAN G> end if G> end function G> procedure test_rand() G> atom num G> num = rand_num() G> if num = NAN then G> -- ERROR G> end if G> end procedure G> ----- Original Message ----- G> From: "aku saya" <akusaya at gmx.net> G> To: <EUforum at topica.com> G> Sent: Sunday, January 25, 2004 1:06 AM G> 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> G> 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> ____________________________________________________________ >> C> Crash callback >> C> A way to setup a callback function would allow programs to save user >> C> data before exiting >> C> with ex.err >> >> 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> _________________________________________________ >> >> >> C> TOPICA - Start your own email discussion group. FREE! >> >> >> TOPICA - Start your own email discussion group. FREE! >> >> G> TOPICA - Start your own email discussion group. FREE!