Paste: ifte

Author: dharmatech
Mode: factor
Date: Fri, 7 Nov 2008 13:31:13
Plain Text |
USING: kernel sequences macros accessors math fry locals
       generalizations combinators.cleave stack-checker ;

IN: ifte

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

: [nkeep*] ( quot n -- quot )
  >r { [ ] } swap suffix r> [ ncleave ] curry curry ;

MACRO: nkeep* ( quot n -- ) [nkeep*] ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

: [predicating] ( quot -- pred ) [ ] [ infer out>> 1 - ] bi '[ @ _ nnip ] ;

: [keeping*] ( quot -- quot ) [ ] [ infer in>> ] bi '[ _ _ nkeep* ] ;

: [preserving] ( quot -- quot ) [predicating] [keeping*] ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

:: [ifte] ( TEST THEN ELSE -- quot ) TEST [preserving] '[ @ THEN ELSE if ] ;

MACRO: ifte ( test then else -- ) [ifte] ;

Annotation: Tweaked [preserving] to fix simple cases (force a span of 1)

Author: dharmatech
Mode: factor
Date: Fri, 7 Nov 2008 13:59:29
Plain Text |
: [preserving] ( quot -- quot ) '[ dup drop @ ] [predicating] [keeping*] ;

New Annotation

Summary:
Author:
Mode:
Body: