REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
Because functions are created dynamically by evaluation, you can determine how you want a function created, based on other information. This is a way to provide conditional code as is found in the macro or preprocessor sub-languages of other programming languages. Within the REBOL language this type of conditional code is done with normal REBOL code.
For instance, you may want to create a debugging version of a function that prints additional information:
test-mode: on timer: either test-mode [ func [delay] [ print "delaying..." wait delay print "resuming" ] ][ func [delay] [wait delay] ]
Here you will create one of two functions, based on the test-mode you are running. This can also be written shorter as:
timer: func [delay] either test-mode [[ print "delaying..." wait delay print "resuming" ]][[wait delay]]
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |