2008-02-11 14:50:29 -05:00
|
|
|
! Copyright (C) 2006, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: arrays sequences sequences.private
|
2008-02-11 14:50:29 -05:00
|
|
|
kernel kernel.private math assocs quotations.private
|
|
|
|
slots.private ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: quotations
|
|
|
|
|
2008-02-11 14:50:29 -05:00
|
|
|
M: quotation call (call) ;
|
|
|
|
|
2008-03-26 04:57:48 -04:00
|
|
|
M: curry call dup 3 slot swap 4 slot call ;
|
2008-02-11 14:50:29 -05:00
|
|
|
|
2008-03-26 04:57:48 -04:00
|
|
|
M: compose call dup 3 slot swap 4 slot slip call ;
|
2008-02-11 14:50:29 -05:00
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
M: wrapper equal?
|
2008-03-29 21:36:58 -04:00
|
|
|
over wrapper? [ [ wrapped ] bi@ = ] [ 2drop f ] if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-11 14:50:29 -05:00
|
|
|
UNION: callable quotation curry compose ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: callable equal?
|
|
|
|
over callable? [ sequence= ] [ 2drop f ] if ;
|
|
|
|
|
|
|
|
M: quotation length quotation-array length ;
|
|
|
|
|
|
|
|
M: quotation nth-unsafe quotation-array nth-unsafe ;
|
|
|
|
|
|
|
|
: >quotation ( seq -- quot )
|
|
|
|
>array array>quotation ; inline
|
|
|
|
|
2008-02-11 14:50:29 -05:00
|
|
|
M: callable like drop dup quotation? [ >quotation ] unless ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
INSTANCE: quotation immutable-sequence
|
|
|
|
|
|
|
|
: 1quotation ( obj -- quot ) 1array >quotation ;
|
|
|
|
|
|
|
|
GENERIC: literalize ( obj -- wrapped )
|
|
|
|
|
|
|
|
M: object literalize ;
|
|
|
|
|
|
|
|
M: wrapper literalize <wrapper> ;
|
|
|
|
|
|
|
|
M: curry length curry-quot length 1+ ;
|
|
|
|
|
|
|
|
M: curry nth
|
|
|
|
over zero? [
|
|
|
|
nip curry-obj literalize
|
|
|
|
] [
|
|
|
|
>r 1- r> curry-quot nth
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
INSTANCE: curry immutable-sequence
|
2008-02-11 14:50:29 -05:00
|
|
|
|
|
|
|
M: compose length
|
2008-04-26 00:12:44 -04:00
|
|
|
[ compose-first length ]
|
|
|
|
[ compose-second length ] bi + ;
|
2008-02-11 14:50:29 -05:00
|
|
|
|
2008-06-09 03:14:14 -04:00
|
|
|
M: compose virtual-seq compose-first ;
|
|
|
|
|
|
|
|
M: compose virtual@
|
2008-02-11 14:50:29 -05:00
|
|
|
2dup compose-first length < [
|
|
|
|
compose-first
|
|
|
|
] [
|
2008-04-26 00:12:44 -04:00
|
|
|
[ compose-first length - ] [ compose-second ] bi
|
2008-06-09 03:14:14 -04:00
|
|
|
] if ;
|
2008-02-11 14:50:29 -05:00
|
|
|
|
2008-06-09 03:14:14 -04:00
|
|
|
INSTANCE: compose virtual-sequence
|