|
From: | Louis de Forcrand |
Subject: | Re: [Bug-apl] Recursive Lambda |
Date: | Thu, 7 Jul 2016 04:49:10 +0200 |
The clearest and most versatile idiom for me would be ⍎ ('case1' 'case2' 'case3' ...)[tests] This acts exactly like a case statement (and by extension like an if/else). For example: '/' {⍎ ('+-×÷')['+-*/' ⍳ ⍺] , '/⍵'} 2 .5 yields 4. If you want to select the corresponding case from a list of tests, you can either append the boolean results of the tests and search them with iota 1, or compress nested list of cases. ack←{⍎('⍵+1' '(''(⍺-1)ack 1'' ''(⍺-1)ack ⍺ ack ⍵-1'')[⍵>0]')[⍺>0]} That's the Ackermann function in a lambda. The double quotes start to get hard to read when several switches are nested. Maybe some clever cropping of the result of quad CR could allow one to write and test multiple nested switches. Cheers, Louis Fun fact about the first example: If multiple characters are given as left argument, all but the last will be executed monadically on the result of the last. This behaviour closely resembles the dyadic one described here:
|
[Prev in Thread] | Current Thread | [Next in Thread] |