Catamorphism: Difference between revisions
Content added Content deleted
m (→Excel LAMBDA) |
(→Excel LAMBDA: Added a second example) |
||
Line 652: | Line 652: | ||
# leaves the nesting depth unchanged for any other character |
# leaves the nesting depth unchanged for any other character |
||
# updates the accumulator no further if the nesting depth ever becomes negative. |
# updates the accumulator no further if the nesting depth ever becomes negative. |
||
Or for a simple count of bracket characters in a string, ignoring other characters, we could instead use FOLDLROW with an alternative binary operator like: |
|||
<lang lisp>bracketCount |
|||
=LAMBDA(a, |
|||
LAMBDA(c, |
|||
IF(ISNUMBER(FIND(c, "[]", 1)), |
|||
1 + a, |
|||
a |
|||
) |
|||
) |
|||
)</lisp> |
|||
Line 780: | Line 793: | ||
| |
| |
||
| style="text-align:center" | -1 |
| style="text-align:center" | -1 |
||
| ][ [[[ [ ]]] [[[ ]]] [[[ [] ]]] ] |
|||
|} |
|||
Or for a simple count of bracket characters, ignoring other characters: |
|||
{| class="wikitable" |
|||
|- |
|||
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx |
|||
! colspan="3" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=FOLDROW( bracketCount )( 0 )( CHARSROW(C2) ) |
|||
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;" |
|||
| |
|||
| A |
|||
| B |
|||
| C |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1 |
|||
| |
|||
| style="font-weight:bold" | Bracket character count |
|||
| style="font-weight:bold" | Sample string |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2 |
|||
| |
|||
| style="text-align:center; background-color:#cbcefb" | 2 |
|||
| [simply bracketed] |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3 |
|||
| |
|||
| style="text-align:center" | 3 |
|||
| [[ ] |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4 |
|||
| |
|||
| style="text-align:center" | 3 |
|||
| [ ]] |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5 |
|||
| |
|||
| style="text-align:center" | 8 |
|||
| [[[ [] ]]] |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 6 |
|||
| |
|||
| style="text-align:center" | 24 |
|||
| [ [[[ [] ]]] [[[ ]]] [[[ [] ]]] ] |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 7 |
|||
| |
|||
| style="text-align:center" | 23 |
|||
| [ [[[ [ ]]] [[[ ]]] [[[ [] ]]] ] |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 8 |
|||
| |
|||
| style="text-align:center" | 24 |
|||
| ][ [[[ [ ]]] [[[ ]]] [[[ [] ]]] ] |
| ][ [[[ [ ]]] [[[ ]]] [[[ [] ]]] ] |
||
|} |
|} |