Hi Joel,
You wrote:
> checktypes: func [
> arg
> ][
> foreach [qry typ] types [
> b: reduce [q arg]
> print mold b
> ]
> ]
Don't you mean b: reduce [qry arg]
The reason REBOL shell drops into a black hole is because Q is assigned the
function for quitting the shell.
>2) How do I do the following: construct a list of function/action
> pairs, which can be processed against an argument by applying
> each function to the argument, then performing the corresponding
> action if the result is 'true?
I've had a lot of trouble doing similar things in REBOL because when I get
an action in the form of a block as an argument to a function, the words in
the block don't want to be bound to local variables within the function. The
best way seems to be to "compile" the block into a function. So, is this
something like what you had in mind?
do-if: func [
{conditionally do actions}
condition-action [block!]
value [any-type!]
/local f
][
foreach [condition action] condition-action [
if all [
any-function? condition: get condition
condition get/any 'value
][
do make function! [value [any-type!]] action get/any 'value
]
]
exit
]
ca: [
string? [print ["doubled string:" rejoin [value value]]]
number? [print ["doubled number:" value + value]]
unset? [print ["nothing doubled is still nothing!"]]
error? [print ["why would anybody want to double their errors?"]]
]
>> do-if ca 6
doubled number: 12
>> do-if ca "string"
doubled string: stringstring
>> do-if ca
nothing doubled is still nothing!
>> do-if ca try [length?]
why would anybody want to double their errors?
BTW, there're a number of hoops you have to jump through to write functions
that will behave like the datatype test functions (STRING? and forth). Those
functions will not produce an error, no matter what type of value they're
fed. Here's an example, and there are a couple more in %huh.r on rebol.org.
not?: func [
{returns TRUE for NONE and FALSE - returns FALSE for all other values}
value [any-type!]
][
either any [
not value? 'value
error? :value
:value
][false][true]
]
You have to refer to VALUE with the tick ' until you've checked that it has a
value, and with the get-word form :value until you've checked that it is not
holding an ANY-FUNCTION! PAREN! or PATH! , and have to check that it doesn't
hold an error value before you do anything with its value except show it to
another datatype test function. If you do all that, you can have a function
that is guaranteed (I hope!) not to generate an error and interrupt the
processing of DO-IF.
Hope this is of some use,
Eric