World: r3wp
[Core] Discuss core issues
older newer | first last |
Anton 8-Feb-2007 [7036] | ... error handling or "quick exit" flow control. |
Maxim 8-Feb-2007 [7037] | that's what I was wondering... somehow rethrow sounded cooler ;-) |
Volker 9-Feb-2007 [7038] | juggling? |
Robert 10-Feb-2007 [7039x4] | I have question WRT to error handling: |
If I use | |
make error! "problem" | |
Immediatly an error message is printed to console. How can I catch this? I just want to return an error that I can catch an DISARM to get an error-object. Without anything printed to the console. | |
Sunanda 10-Feb-2007 [7043] | Wrap the target code in an attempt: attempt [oops: make error! "problem"] if error? oops [probe disarm oops] |
Robert 10-Feb-2007 [7044x4] | ah, I tried it with TRY etc. |
The MAKE error stuff is return from a function. | |
For example I call: a-function 1 and if this function has an error, it calls an error-function that ends with: make error! ... | |
I can't do: attempt [a: a-function] to getback the error. | |
Sunanda 10-Feb-2007 [7048] | This works for me: a-function: func [] [make error! "problem"] error? a: try [a-function] *** If that's not quite what you have in mind, take a look at 'throw and 'catch -- they may be more suited. |
Robert 10-Feb-2007 [7049x2] | Ok, is this error than gone? It looks like within the error-object/near there is an other error. So I can handle the first one but as soon as I do something, I get the next output... |
Ah, damn, there was an other error in the code... | |
Sunanda 10-Feb-2007 [7051] | Happens to me all the time......:-( |
Ladislav 10-Feb-2007 [7052x5] | Robert: the following approach is better: |
a-function: func [] [return make error! "problem"] | |
error? a-function ; == true | |
or: error? the-error: a-function | |
etc. | |
Graham 10-Feb-2007 [7057x4] | I want to create a little spreadsheet application where users have access to the mathematical functions in rebol and nothing else. |
Is there some way to constrain 'do to work within a specific context of some mathematical functions, and nothing else? | |
Or, do I have to write a little mini parser ? | |
There's a little parser here http://www.rebol.com/docs/core23/rebolcore-15.html | |
Ladislav 10-Feb-2007 [7061x2] | you don't have to write a parser. The approach using my SAFE-EVAL function may be faster: safe-eval: func [ stm-block [block!] /local stm ] [ stm: make block! (length? stm-block) * 2 + 1 insert stm first stm-block while [stm-block: next stm-block not tail? stm-block] [ insert tail stm :first insert/only tail stm stm-block ] first do/next stm ] |
(before using SAFE-EVAL you should test the first element of the STM-BLOCK to find out whether it is one of the functions you are willing to evaluate) | |
Graham 10-Feb-2007 [7063x2] | so, use example? |
Do I have to check each value in the block for safety? | |
Ladislav 10-Feb-2007 [7065x3] | error? try [safe-eval [square-root print "gotcha!"]] ; == true |
...check each value in the block for safety? - no | |
just the first one | |
Graham 10-Feb-2007 [7068x2] | Ok, I'm going to use this example first : 0.56 * sqrt(tender28) + 0.28 * sqrt(swollen28) + 0.70 * ln(ESR) + 0.014 * GH |
turn that into Rebol first ... and then only check the first value? | |
Ladislav 10-Feb-2007 [7070] | it looks, like you want to use any expression, not just function evaluation? |
Graham 10-Feb-2007 [7071] | yes .. |
Ladislav 10-Feb-2007 [7072] | then it is not for you, this was just for a function evaluation |
Graham 10-Feb-2007 [7073] | Ok, so looks like it will have to be a parser |
Ladislav 10-Feb-2007 [7074] | yes |
Graham 10-Feb-2007 [7075] | but it would be nice to be able to use the rebol parser do evaluate words within a mathematical context only |
Ladislav 10-Feb-2007 [7076] | when using a parser, you can even use operator precedence rules and such |
Graham 10-Feb-2007 [7077x6] | A non parse based solution ( ie. parse = too hard! ) |
eval-math: func [ exp [string!] /local t allowed okay ][ allowed: [ + - / square-root log-e * ] t: to block! exp bind t '+ okay: true allowed: [ + - / square-root log-e * ] foreach e t [ switch/default type?/word e [ paren! [ eval-math form e ] word! [ if not find allowed e [ okay: false break ]] decimal! [] integer! [] ][ okay: false break ] ] either okay [ do t ][ none ] ] | |
Hmm. Needs debugging | |
eval-math: func [ exp [string!] /local t allowed ][ allowed: [ + - / square-root log-e * ] t: to block! exp bind t '+ foreach e t [ switch/default type?/word e [ paren! [ if none? eval-math form e [ return none ] ] word! [ if not find allowed e [ print [ "not allowed is : " e ] return none ] ] decimal! [] integer! [] ][ return none ] ] do t ] | |
How does one access the parts of a function? | |
eg; func [face /local var][print face/text] how do I get to the [print face/text ] part? | |
Ladislav 10-Feb-2007 [7083] | second func [face /local var] [print face/text] ; == [print face/text] |
Graham 10-Feb-2007 [7084x2] | oh? and third is the locals ? |
I was thinking it should be after third and not before :( | |
older newer | first last |