generalizations and delegate no longer uses >r/r>
parent
fc5d53327d
commit
30f93f547f
|
@ -2,7 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors parser generic kernel classes classes.tuple
|
||||
words slots assocs sequences arrays vectors definitions
|
||||
prettyprint math hashtables sets macros namespaces make ;
|
||||
prettyprint math hashtables sets generalizations namespaces make ;
|
||||
IN: delegate
|
||||
|
||||
: protocol-words ( protocol -- words )
|
||||
|
@ -25,15 +25,7 @@ M: tuple-class group-words
|
|||
|
||||
: consult-method ( word class quot -- )
|
||||
[ drop swap first create-method ]
|
||||
[
|
||||
nip
|
||||
[
|
||||
over second saver %
|
||||
%
|
||||
dup second restorer %
|
||||
first ,
|
||||
] [ ] make
|
||||
] 3bi
|
||||
[ nip [ , dup second , \ ndip , first , ] [ ] make ] 3bi
|
||||
define ;
|
||||
|
||||
: change-word-prop ( word prop quot -- )
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
! Copyright (C) 2007, 2008 Chris Double, Doug Coleman, Eduardo
|
||||
! Cavazos, Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel sequences sequences.private namespaces math
|
||||
math.ranges combinators macros quotations fry arrays ;
|
||||
USING: kernel sequences sequences.private math math.ranges
|
||||
combinators macros quotations fry ;
|
||||
IN: generalizations
|
||||
|
||||
<<
|
||||
|
||||
: n*quot ( n seq -- seq' ) <repetition> concat >quotation ;
|
||||
|
||||
: repeat ( n obj quot -- ) swapd times ; inline
|
||||
|
||||
>>
|
||||
|
||||
MACRO: nsequence ( n seq -- quot )
|
||||
[
|
||||
[ drop <reversed> ] [ '[ _ _ new-sequence ] ] 2bi
|
||||
|
@ -22,44 +30,38 @@ MACRO: firstn ( n -- )
|
|||
bi prefix '[ _ cleave ]
|
||||
] if ;
|
||||
|
||||
: npick-wrap ( quot n -- quot )
|
||||
dup 1 >
|
||||
[ swap '[ _ dip swap ] swap 1 - npick-wrap ]
|
||||
[ drop ]
|
||||
if ;
|
||||
|
||||
MACRO: npick ( n -- quot ) [ dup ] swap npick-wrap ;
|
||||
MACRO: npick ( n -- quot )
|
||||
1- [ dup ] [ '[ _ dip swap ] ] repeat ;
|
||||
|
||||
MACRO: ndup ( n -- )
|
||||
dup '[ _ npick ] n*quot ;
|
||||
|
||||
MACRO: nrot ( n -- )
|
||||
1- dup saver swap [ r> swap ] n*quot append ;
|
||||
1- [ ] [ '[ _ dip swap ] ] repeat ;
|
||||
|
||||
MACRO: -nrot ( n -- )
|
||||
1- dup [ swap >r ] n*quot swap restorer append ;
|
||||
1- [ ] [ '[ swap _ dip ] ] repeat ;
|
||||
|
||||
MACRO: ndrop ( n -- )
|
||||
[ drop ] n*quot ;
|
||||
|
||||
: nnip ( n -- )
|
||||
swap >r ndrop r> ; inline
|
||||
MACRO: nnip ( n -- )
|
||||
'[ [ _ ndrop ] dip ] ;
|
||||
|
||||
MACRO: ntuck ( n -- )
|
||||
2 + [ dupd -nrot ] curry ;
|
||||
2 + '[ dup _ -nrot ] ;
|
||||
|
||||
MACRO: nrev ( n -- quot )
|
||||
1 [a,b] [ ] [ '[ @ _ -nrot ] ] reduce ;
|
||||
|
||||
MACRO: ndip ( quot n -- )
|
||||
dup saver -rot restorer 3append ;
|
||||
[ '[ _ dip ] ] times ;
|
||||
|
||||
MACRO: nslip ( n -- )
|
||||
dup saver [ call ] rot restorer 3append ;
|
||||
'[ [ call ] _ ndip ] ;
|
||||
|
||||
MACRO: nkeep ( n -- )
|
||||
[ ] [ 1+ ] [ ] tri
|
||||
'[ [ _ ndup ] dip _ -nrot _ nslip ] ;
|
||||
MACRO: nkeep ( quot n -- )
|
||||
tuck '[ _ ndup _ _ ndip ] ;
|
||||
|
||||
MACRO: ncurry ( n -- )
|
||||
[ curry ] n*quot ;
|
||||
|
@ -69,5 +71,5 @@ MACRO: nwith ( n -- )
|
|||
|
||||
MACRO: napply ( n -- )
|
||||
2 [a,b]
|
||||
[ [ 1- ] keep '[ _ ntuck _ nslip ] ]
|
||||
[ [ 1- ] [ ] bi '[ _ ntuck _ nslip ] ]
|
||||
map concat >quotation [ call ] append ;
|
||||
|
|
Loading…
Reference in New Issue