Vocabulary/selectdot
>> << Back to: Vocabulary Thru to: Dictionary
select. selector
case. value do.
fcase. value do.Evaluate selector
Execute if value matches selector
Execute if value matches selector, then fall through to next [f]case.Control
Valid only inside an explicit definition.
Execute one (or one sequence) of a list of blocks whose case.-value includes the value of the select.-selector.
The block following the select. is evaluated. Then the blocks following each subsequent case. or fcase. are evaluated. When a case is found whose value includes the result of the select.-block, the block following its do. is executed.
After a case.-block has been executed, control passes to a single end. statement corresponding to the select., unless the executing case is fcase.--a fallthrough case. Execution of an fcase. is followed by unconditional execution of the next case.-block, which may be another fcase.:
select_trial=: 3 : 0 select. y fcase. 'A' do. case. 'a' do. echo 'select a' fcase. 'B' do. case. 'b' do. echo 'select b' case. do. NB. optional catch-all case echo 'none of these' end. ) select_trial 'a' select a select_trial 'A' select a select_trial 'b' select b select_trial 'B' select b select_trial 'C' none of these select_trial 99 none of these
Details
1. The select.-block is terminated by the first case., not by a do..
2. The block following each case. or fcase., except the last, is terminated by do., not end..
3. If the case.-value is omitted, the case matches any selector.
4. value may be a list of boxed values; the case is executed if the selector matches any of them. If the selector or value is unboxed, it is first boxed before being tested. Thus an unboxed select. selection list would have to be matched by a case.-value list item-by-item, in the same order, to cause execution of that case.
Formally, the test is selector e.&boxopen value where boxopen=:<^:(0&(>: L.)), as defined in the Standard Library.
Related Primitives
Agenda ([x] u@.v y)