Hello [EMAIL PROTECTED]!
On 17-Ott-99, you wrote:
[...]
j> b: reduce [q arg]
[...]
j> ... at which point (after pressing 'enter') the REBOL shell
j> drops into a black hole! Specifically, the window instantly
j> vanishes, as does the executing interpreter's task. This is
j> happening in version 2.1.2.3.1 running on w95.
j> soooo...
j> 1) What's happening?
Well, that's exactly what the word 'q is supposed to do. ;-)
This is the correct way (notice the use of 'do):
checktypes: func [
arg
] [
foreach [qry typ] types [
print mold do reduce [qry :arg]
]
]
j> 2) How do I do the following: construct a list of
j> function/action
j> pairs, which can be processed against an argument by
j> applying
j> each function to the argument, then performing the
j> corresponding
j> action if the result is 'true?
You have two possibilities: creating a block of words that refer
to the functions you need (like the above), or creating a block of
functions.
Let's use a block of functions:
>> block: compose [
[ (:integer?) (func [] [print "It's an integer"])
[ (:decimal?) (func [] [print "Hey, that's a decimal value!"])
[ (:block?) (func [] [print "That's not fair, you're passing me a block! :-("])
[ ]
== [action func [][print "It's an integer"] action func [][print "Hey, that's a
decimal value!"] action func [][print "That's not f...
Now we can define a function 'check like this:
>> check: func [arg] [
[ foreach [is-it? do-this] block [
[ if is-it? arg [do-this]
[ ]
[ ]
So we can write:
>> check 3
It's an integer
== false
>> check 3.2
Hey, that's a decimal value!
== false
>> check block
That's not fair, you're passing me a block! :-(
In this case it would perhaps be better to do:
>> block: compose [
[ (:integer?) [print "It's an integer"]
[ (:decimal?) [print "Hey, that's a decimal value!"]
[ (:block?) [print "That's not fair, you're passing me a block! :-("]
[ ]
== [action [print "It's an integer"] action [print "Hey, that's a decimal value!"]
action [print "That's not fair, you're passing m...
>> check: func [arg] [
[ foreach [is-it? do-this] block [
[ if is-it? arg do-this
[ ]
[ ]
>> check 3
It's an integer
== false
>> check 3.2
Hey, that's a decimal value!
== false
>> check []
That's not fair, you're passing me a block! :-(
Regards,
Gabriele.
--
o--------------------) .-^-. (----------------------------------o
| Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila |
| GIESSE on IRC \ \-\_/-/ / http://www.amyresource.it/AGI/ |
o--------------------) `-v-' (----------------------------------o