Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: a new switch-like flow-control function

From: lmecir:mbox:vol:cz at: 23-Dec-2003 19:21

Hi Pat,
>What is the meaning of thro? >I have seen it here and there but never quite understood its purpose. > >Regards >Patrick > >----- Original Message ----- >From: "Ladislav Mecir" > >>yes, it is useful. The following improvement uses the [throw] attribute >>to make the behaviour of the function more standard with respect to >> >> >Return: > >>trif: func [ >> {Three case if} >> [throw] >> condition >> iftrue [block!] >> iffalse [block!] >> ifnone [block!] >>] [ >> do either condition [ >> iftrue >> ] [ >> either none? condition [ >> ifnone >> ] [ >> iffalse >> ] >> ] >>] >> >>; example: >> >>f: does [trif request "give an answer" [return "yes"] [return "no"] >> >> >[return "cancel"] "Shoudn't get here"] >
Try to use the version of the above function without the [throw] attribute and you will find out, that the result of F will be: == "Shoudn't get here" , which indicates, that the Return got "consumed" by Trif , while what we intended was to "throw" Return to F. The "throw" attribute does exactly that - throws Return to caller functions. Merry Christmas -Ladislav