Paste: valueable to anyone?

Author: randy7
Mode: factor
Date: Sat, 28 Mar 2009 15:41:47
Plain Text |
: nested-ifs ( item quot-seq inner-truth-quot all-false-quot -- ... )
    '[ _ dupd 1&& [ @ ] [ @ ] if ] call ;
    
! Example: { 1 2 } { [ sequence? ] [ first 1 = ] }  [ drop t ] [ drop f ] nested-ifs
    
! ----- 
    \ index { [ sequence? ] [ length 4 >= ] } 
        [ dup length zip >hashtable '[ _ at ] ]
        [ drop f ] nested-ifs 
    1 define-transform
    
    ! is it an improvement over this?:
    
    \ index [
    dup sequence? [
        dup length 4 >= [
            dup length zip >hashtable '[ _ at ]
        ] [ drop f ] if
    ] [ drop f ] if
] 1 define-transform
    
! heh, the connotation may be wrong, I'm not sure what that code does.     
! the idea is that case style is easier to see than nested ifs, but nested ifs may be faster or less repetitive (less checks in inner branches).

New Annotation

Summary:
Author:
Mode:
Body: