factor: rename :> to set:

locals-and-roots
Doug Coleman 2016-06-25 17:43:42 -07:00
parent a0d1316c8d
commit 0efa16c1f1
362 changed files with 1883 additions and 1883 deletions

View File

@ -12,10 +12,10 @@ IN: benchmark.3d-matrix-scalar
location vneg translation-matrix4 m. m. ; location vneg translation-matrix4 m. m. ;
:: 3d-matrix-scalar-benchmark ( -- ) :: 3d-matrix-scalar-benchmark ( -- )
f :> result! f set: result!
100000 [ 100000 [
{ 1024.0 768.0 } 0.7 0.25 1024.0 p-matrix :> p { 1024.0 768.0 } 0.7 0.25 1024.0 p-matrix set: p
3.0 1.0 { 10.0 -0.0 2.0 } mv-matrix :> mv 3.0 1.0 { 10.0 -0.0 2.0 } mv-matrix set: mv
mv p m. result! mv p m. result!
] times ] times
result . ; result . ;

View File

@ -16,10 +16,10 @@ TYPED:: mv-matrix ( pitch: float yaw: float location: float-4 -- matrix: matrix4
location vneg translation-matrix4 m4. m4. ; location vneg translation-matrix4 m4. m4. ;
:: 3d-matrix-vector-benchmark ( -- ) :: 3d-matrix-vector-benchmark ( -- )
f :> result! f set: result!
100000 [ 100000 [
float-4{ 1024.0 768.0 0.0 0.0 } 0.7 0.25 1024.0 p-matrix :> p float-4{ 1024.0 768.0 0.0 0.0 } 0.7 0.25 1024.0 p-matrix set: p
3.0 1.0 float-4{ 10.0 -0.0 2.0 0.0 } mv-matrix :> mv 3.0 1.0 float-4{ 10.0 -0.0 2.0 0.0 } mv-matrix set: mv
mv p m4. result! mv p m4. result!
] times ] times
result . ; result . ;

View File

@ -35,14 +35,14 @@ C: <point> point ;
[ x>> ] [ y>> ] bi [ sum-digits ] bi@ + 25 <= ; inline [ x>> ] [ y>> ] bi [ sum-digits ] bi@ + 25 <= ; inline
:: ant-benchmark ( -- ) :: ant-benchmark ( -- )
200000 <hash-set> :> seen 200000 <hash-set> set: seen
100000 <vector> :> stack 100000 <vector> set: stack
0 :> total! 0 set: total!
1000 1000 <point> stack push 1000 1000 <point> stack push
[ stack empty? ] [ [ stack empty? ] [
stack pop :> p stack pop set: p
p seen ?adjoin [ p seen ?adjoin [
p walkable? [ p walkable? [
total 1 + total! total 1 + total!

View File

@ -7,9 +7,9 @@ IN: benchmark.beust2
:: (count-numbers) ( remaining first value used max listener: ( -- ) -- ? ) :: (count-numbers) ( remaining first value used max listener: ( -- ) -- ? )
10 first - iota |[ i | 10 first - iota |[ i |
i first + :> digit i first + set: digit
digit 2^ :> mask digit 2^ set: mask
i value + :> value' i value + set: value'
used mask bitand zero? [ used mask bitand zero? [
value max > [ t ] [ value max > [ t ] [
remaining 1 <= [ remaining 1 <= [
@ -31,7 +31,7 @@ IN: benchmark.beust2
10 iota [ 1 + 1 1 0 max listener (count-numbers) ] any? drop ; inline 10 iota [ 1 + 1 1 0 max listener (count-numbers) ] any? drop ; inline
:: beust2-benchmark ( -- ) :: beust2-benchmark ( -- )
0 :> i! 0 set: i!
5000000000 [ i 1 + i! ] count-numbers 5000000000 [ i 1 + i! ] count-numbers
i 7063290 assert= ; i 7063290 assert= ;

View File

@ -68,15 +68,15 @@ TYPED: write-random-fasta ( seed: float n: fixnum chars: byte-array floats: doub
$[ _ _ make-random-fasta ] split-lines ; $[ _ _ make-random-fasta ] split-lines ;
TYPED:: make-repeat-fasta ( k: fixnum len: fixnum alu: string -- k': fixnum ) TYPED:: make-repeat-fasta ( k: fixnum len: fixnum alu: string -- k': fixnum )
alu length :> kn alu length set: kn
len iota [ k + kn mod alu nth-unsafe ] "" map-as print len iota [ k + kn mod alu nth-unsafe ] "" map-as print
k len + ; k len + ;
: write-repeat-fasta ( n alu desc id -- ) : write-repeat-fasta ( n alu desc id -- )
write-description write-description
let[ let[
:> alu set: alu
0 :> k! 0 set: k!
|[ len | k len alu make-repeat-fasta k! ] split-lines |[ len | k len alu make-repeat-fasta k! ] split-lines
] ; ] ;
@ -84,8 +84,8 @@ TYPED:: make-repeat-fasta ( k: fixnum len: fixnum alu: string -- k': fixnum )
homo-sapiens make-cumulative homo-sapiens make-cumulative
IUB make-cumulative IUB make-cumulative
let[ let[
:> ( n out IUB-chars IUB-floats homo-sapiens-chars homo-sapiens-floats ) set: ( n out IUB-chars IUB-floats homo-sapiens-chars homo-sapiens-floats )
initial-seed :> seed initial-seed set: seed
out ascii [ out ascii [
n 2 * ALU "Homo sapiens alu" "ONE" write-repeat-fasta n 2 * ALU "Homo sapiens alu" "ONE" write-repeat-fasta

View File

@ -3,8 +3,8 @@ IN: benchmark.fib7
:: matrix-fib ( m -- n ) :: matrix-fib ( m -- n )
m 0 >= [ m throw ] unless m 0 >= [ m throw ] unless
m 2 >base [ char: 1 = ] { } map-as :> bits m 2 >base [ char: 1 = ] { } map-as set: bits
1 :> a! 0 :> b! 1 :> c! 1 set: a! 0 set: b! 1 set: c!
bits [ bits [
[ [
a c + b * a c + b *

View File

@ -14,8 +14,8 @@ IN: benchmark.matrix-exponential-scalar
] each ; ] each ;
:: matrix-exponential-scalar-benchmark ( -- ) :: matrix-exponential-scalar-benchmark ( -- )
f :> result! f set: result!
4 identity-matrix :> i4 4 identity-matrix set: i4
10000 [ 10000 [
i4 20 e^m result! i4 20 e^m result!
] times ] times

View File

@ -9,7 +9,7 @@ TYPED:: e^m4 ( m: matrix4 iterations: fixnum -- e^m: matrix4 )
] each ; ] each ;
:: matrix-exponential-simd-benchmark ( -- ) :: matrix-exponential-simd-benchmark ( -- )
f :> result! f set: result!
10000 [ 10000 [
identity-matrix4 20 e^m4 result! identity-matrix4 20 e^m4 result!
] times ] times

View File

@ -36,7 +36,7 @@ IN: benchmark.pidigits
:: (pidigits) ( k z n row col -- ) :: (pidigits) ( k z n row col -- )
n 0 > [ n 0 > [
z next :> y z next set: y
z y safe? [ z y safe? [
col 10 = [ col 10 = [
row 10 + y "\t:%d\n%d" printf row 10 + y "\t:%d\n%d" printf

View File

@ -3,7 +3,7 @@ sequences ;
IN: benchmark.sieve IN: benchmark.sieve
:: sieve ( n -- #primes ) :: sieve ( n -- #primes )
n dup odd? [ 1 + ] when 2/ <bit-array> :> sieve n dup odd? [ 1 + ] when 2/ <bit-array> set: sieve
t 0 sieve set-nth t 0 sieve set-nth
3 n sqrt 2 <range> |[ i | 3 n sqrt 2 <range> |[ i |

View File

@ -18,10 +18,10 @@ STRUCT: yuv-buffer
{ v void* } ; { v void* } ;
:: fake-data ( -- rgb yuv ) :: fake-data ( -- rgb yuv )
1600 :> w 1600 set: w
1200 :> h 1200 set: h
yuv-buffer <struct> :> buffer yuv-buffer <struct> set: buffer
w h * 3 * <byte-array> :> rgb w h * 3 * <byte-array> set: rgb
rgb buffer rgb buffer
w >>y_width w >>y_width
h >>y_height h >>y_height

View File

@ -109,20 +109,20 @@ ERROR: not-enough-widthed-bits widthed n ;
[ swap bits>> ] B{ } produce-as nip swap ; [ swap bits>> ] B{ } produce-as nip swap ;
:: |widthed ( widthed1 widthed2 -- widthed3 ) :: |widthed ( widthed1 widthed2 -- widthed3 )
widthed1 bits>> :> bits1 widthed1 bits>> set: bits1
widthed1 #bits>> :> #bits1 widthed1 #bits>> set: #bits1
widthed2 bits>> :> bits2 widthed2 bits>> set: bits2
widthed2 #bits>> :> #bits2 widthed2 #bits>> set: #bits2
bits1 #bits2 shift bits2 bitor bits1 #bits2 shift bits2 bitor
#bits1 #bits2 + <widthed> ; #bits1 #bits2 + <widthed> ;
PRIVATE> PRIVATE>
M:: lsb0-bit-writer poke ( value n bs -- ) M:: lsb0-bit-writer poke ( value n bs -- )
value n <widthed> :> widthed value n <widthed> set: widthed
widthed widthed
bs widthed>> #bits>> 8 swap - split-widthed :> ( byte remainder ) bs widthed>> #bits>> 8 swap - split-widthed set: ( byte remainder )
byte bs widthed>> |widthed :> new-byte byte bs widthed>> |widthed set: new-byte
new-byte #bits>> 8 = [ new-byte #bits>> 8 = [
new-byte bits>> bs bytes>> push new-byte bits>> bs bytes>> push
zero-widthed bs widthed<< zero-widthed bs widthed<<
@ -151,7 +151,7 @@ ERROR: not-enough-bits n bit-reader ;
neg shift n bits ; neg shift n bits ;
:: adjust-bits ( n bs -- ) :: adjust-bits ( n bs -- )
n 8 /mod :> ( #bytes #bits ) n 8 /mod set: ( #bytes #bits )
bs [ #bytes + ] change-byte-pos bs [ #bytes + ] change-byte-pos
bit-pos>> #bits + dup 8 >= [ bit-pos>> #bits + dup 8 >= [
8 - bs bit-pos<< 8 - bs bit-pos<<
@ -173,7 +173,7 @@ M: msb0-bit-reader peek ( n bs -- bits )
\ be> \ subseq>bits-be (peek) ; \ be> \ subseq>bits-be (peek) ;
:: bit-writer-bytes ( writer -- bytes ) :: bit-writer-bytes ( writer -- bytes )
writer widthed>> #bits>> :> n writer widthed>> #bits>> set: n
n 0 = [ n 0 = [
writer widthed>> bits>> 8 n - shift writer widthed>> bits>> 8 n - shift
writer bytes>> push writer bytes>> push

View File

@ -28,7 +28,7 @@ PRIVATE>
GENERIC: representative ( a disjoint-set -- p ) ; GENERIC: representative ( a disjoint-set -- p ) ;
M:: disjoint-set representative ( a disjoint-set -- p ) M:: disjoint-set representative ( a disjoint-set -- p )
a disjoint-set parents>> at :> p a disjoint-set parents>> at set: p
a p = [ a ] [ a p = [ a ] [
p disjoint-set representative [ p disjoint-set representative [
a disjoint-set set-parent a disjoint-set set-parent

View File

@ -118,30 +118,30 @@ TUPLE: my-node < dlist-link { obj fixnum } ;
{ V{ } } [ <dlist> 1 <my-node> over push-node-back [ [ back>> ] [ ] bi delete-node ] [ ] bi dlist>sequence ] unit-test { V{ } } [ <dlist> 1 <my-node> over push-node-back [ [ back>> ] [ ] bi delete-node ] [ ] bi dlist>sequence ] unit-test
[ V{ 1 2 } t ] |[ | [ V{ 1 2 } t ] |[ |
<dlist> :> dl <dlist> set: dl
1 <my-node> :> n1 n1 dl push-node-back 1 <my-node> set: n1 n1 dl push-node-back
2 <my-node> :> n2 n2 dl push-node-back 2 <my-node> set: n2 n2 dl push-node-back
3 <my-node> :> n3 n3 dl push-node-back 3 <my-node> set: n3 n3 dl push-node-back
n3 dl delete-node n3 assert-links n3 dl delete-node n3 assert-links
dl dlist>sequence dup >dlist dl = dl dlist>sequence dup >dlist dl =
] unit-test ] unit-test
[ V{ 1 3 } t ] |[ | [ V{ 1 3 } t ] |[ |
<dlist> :> dl <dlist> set: dl
1 <my-node> :> n1 n1 dl push-node-back 1 <my-node> set: n1 n1 dl push-node-back
2 <my-node> :> n2 n2 dl push-node-back 2 <my-node> set: n2 n2 dl push-node-back
3 <my-node> :> n3 n3 dl push-node-back 3 <my-node> set: n3 n3 dl push-node-back
n2 dl delete-node n2 assert-links n2 dl delete-node n2 assert-links
dl dlist>sequence dup >dlist dl = dl dlist>sequence dup >dlist dl =
] unit-test ] unit-test
[ V{ 2 3 } t ] |[ | [ V{ 2 3 } t ] |[ |
<dlist> :> dl <dlist> set: dl
1 <my-node> :> n1 n1 dl push-node-back 1 <my-node> set: n1 n1 dl push-node-back
2 <my-node> :> n2 n2 dl push-node-back 2 <my-node> set: n2 n2 dl push-node-back
3 <my-node> :> n3 n3 dl push-node-back 3 <my-node> set: n3 n3 dl push-node-back
n1 dl delete-node n1 assert-links n1 dl delete-node n1 assert-links
dl dlist>sequence dup >dlist dl = dl dlist>sequence dup >dlist dl =

View File

@ -143,9 +143,9 @@ PRIVATE>
:: set-doc-range ( string from to document -- ) :: set-doc-range ( string from to document -- )
from to = string empty? and [ from to = string empty? and [
string split-lines :> new-lines string split-lines set: new-lines
new-lines from text+loc :> new-to new-lines from text+loc set: new-to
from to document doc-range :> old-string from to document doc-range set: old-string
old-string string from to new-to <edit> document add-undo old-string string from to new-to <edit> document add-undo
new-lines from to document [ (set-doc-range) ] models:change-model new-lines from to document [ (set-doc-range) ] models:change-model
new-to document update-locs new-to document update-locs

View File

@ -93,7 +93,7 @@ M: heap heap-peek ( heap -- value key )
PRIVATE< PRIVATE<
:: sift-down ( heap from to -- ) :: sift-down ( heap from to -- )
to heap data-nth :> tmp to heap data-nth set: tmp
to t [ over from > and ] [ to t [ over from > and ] [
dup up dup up
@ -121,8 +121,8 @@ M: heap heap-push*
PRIVATE< PRIVATE<
:: sift-up ( heap n -- ) :: sift-up ( heap n -- )
heap heap-size :> end heap heap-size set: end
n heap data-nth :> tmp n heap data-nth set: tmp
n dup left [ dup end < ] [ n dup left [ dup end < ] [
dup 1 fixnum+fast dup 1 fixnum+fast

View File

@ -49,8 +49,8 @@ PRIVATE>
:: acl-entry-each ( path quot -- ) :: acl-entry-each ( path quot -- )
[ [
path file-acl &free-acl :> acl path file-acl &free-acl set: acl
f :> acl-entry! f set: acl-entry!
acl [ acl [
acl first-acl-entry void* deref quot call acl first-acl-entry void* deref quot call
[ acl next-acl-entry dup acl-entry! ] [ acl next-acl-entry dup acl-entry! ]
@ -60,7 +60,7 @@ PRIVATE>
:: acl-each ( path quot -- ) :: acl-each ( path quot -- )
[ [
path file-acl &free-acl :> acl path file-acl &free-acl set: acl
acl [ acl [
acl first-acl-entry drop acl first-acl-entry drop
acl quot call acl quot call

View File

@ -17,12 +17,12 @@ PRIVATE>
f [ random zero? [ nip ] [ drop ] if ] each-numbered-line ; f [ random zero? [ nip ] [ drop ] if ] each-numbered-line ;
:: random-lines ( n -- lines ) :: random-lines ( n -- lines )
V{ } clone :> accum V{ } clone set: accum
|[ line line# | |[ line line# |
line# n <= [ line# n <= [
line accum push line accum push
] [ ] [
line# random :> r line# random set: r
r n < [ line r accum set-nth-unsafe ] when r n < [ line r accum set-nth-unsafe ] when
] if ] if
] each-numbered-line accum ; ] each-numbered-line accum ;

View File

@ -17,5 +17,5 @@ IN: io.serial.windows
SetCommState win32-error=0/f ; SetCommState win32-error=0/f ;
:: with-comm-state ( duplex quot: ( dcb -- ) -- ) :: with-comm-state ( duplex quot: ( dcb -- ) -- )
duplex get-comm-state :> dcb duplex get-comm-state set: dcb
dcb clone quot curry [ dcb set-comm-state ] recover ; inline dcb clone quot curry [ dcb set-comm-state ] recover ; inline

View File

@ -36,8 +36,8 @@ M: peek-stream stream-read1
] if-empty ; ] if-empty ;
M:: peek-stream stream-read-unsafe ( n buf stream -- count ) M:: peek-stream stream-read-unsafe ( n buf stream -- count )
stream peeked>> :> peeked stream peeked>> set: peeked
peeked length :> #peeked peeked length set: #peeked
#peeked 0 = [ #peeked 0 = [
n buf stream stream>> stream-read-unsafe n buf stream stream>> stream-read-unsafe
] [ ] [
@ -48,12 +48,12 @@ M:: peek-stream stream-read-unsafe ( n buf stream -- count )
] [ ] [
peeked <reversed> 0 buf copy peeked <reversed> 0 buf copy
0 peeked shorten 0 peeked shorten
n #peeked - :> n' n #peeked - set: n'
stream stream>> input-port? [ stream stream>> input-port? [
#peeked buf <displaced-alien> #peeked buf <displaced-alien>
] [ ] [
buf #peeked tail-slice buf #peeked tail-slice
] if :> buf' ] if set: buf'
n' buf' stream stream-read-unsafe #peeked + n' buf' stream stream-read-unsafe #peeked +
] if ] if
] if ; ] if ;

View File

@ -19,7 +19,7 @@ TUPLE: pool
PRIVATE< PRIVATE<
:: copy-tuple ( from to -- to ) :: copy-tuple ( from to -- to )
from tuple-size :> size from tuple-size set: size
size |[ n | n from array-nth n to set-array-nth ] each-integer size |[ n | n from array-nth n to set-array-nth ] each-integer
to ; inline to ; inline

View File

@ -10,10 +10,10 @@ IN: persistent.hashtables.nodes.bitmap
: index ( bit bitmap -- n ) [ 1 - ] dip bitand bit-count ; inline : index ( bit bitmap -- n ) [ 1 - ] dip bitand bit-count ; inline
M:: bitmap-node (entry-at) ( key hashcode bitmap-node -- entry ) M:: bitmap-node (entry-at) ( key hashcode bitmap-node -- entry )
bitmap-node shift>> :> shift bitmap-node shift>> set: shift
hashcode shift bitpos :> bit hashcode shift bitpos set: bit
bitmap-node bitmap>> :> bitmap bitmap-node bitmap>> set: bitmap
bitmap-node nodes>> :> nodes bitmap-node nodes>> set: nodes
bitmap bit bitand 0 eq? [ f ] [ bitmap bit bitand 0 eq? [ f ] [
key hashcode key hashcode
bit bitmap index nodes nth-unsafe bit bitmap index nodes nth-unsafe
@ -21,22 +21,22 @@ M:: bitmap-node (entry-at) ( key hashcode bitmap-node -- entry )
] if ; ] if ;
M:: bitmap-node (new-at) ( shift value key hashcode bitmap-node -- node' added-leaf ) M:: bitmap-node (new-at) ( shift value key hashcode bitmap-node -- node' added-leaf )
bitmap-node shift>> :> shift bitmap-node shift>> set: shift
hashcode shift bitpos :> bit hashcode shift bitpos set: bit
bitmap-node bitmap>> :> bitmap bitmap-node bitmap>> set: bitmap
bit bitmap index :> idx bit bitmap index set: idx
bitmap-node nodes>> :> nodes bitmap-node nodes>> set: nodes
bitmap bit bitand 0 eq? [ bitmap bit bitand 0 eq? [
value key hashcode <leaf-node> :> new-leaf value key hashcode <leaf-node> set: new-leaf
bitmap bit bitor bitmap bit bitor
new-leaf idx nodes insert-nth new-leaf idx nodes insert-nth
shift shift
<bitmap-node> <bitmap-node>
new-leaf new-leaf
] [ ] [
idx nodes nth :> n idx nodes nth set: n
shift radix-bits + value key hashcode n (new-at) :> ( n' new-leaf ) shift radix-bits + value key hashcode n (new-at) set: ( n' new-leaf )
n n' eq? [ n n' eq? [
bitmap-node bitmap-node
] [ ] [
@ -49,14 +49,14 @@ M:: bitmap-node (new-at) ( shift value key hashcode bitmap-node -- node' added-l
] if ; ] if ;
M:: bitmap-node (pluck-at) ( key hashcode bitmap-node -- node' ) M:: bitmap-node (pluck-at) ( key hashcode bitmap-node -- node' )
hashcode bitmap-node shift>> bitpos :> bit hashcode bitmap-node shift>> bitpos set: bit
bitmap-node bitmap>> :> bitmap bitmap-node bitmap>> set: bitmap
bitmap-node nodes>> :> nodes bitmap-node nodes>> set: nodes
bitmap-node shift>> :> shift bitmap-node shift>> set: shift
bit bitmap bitand 0 eq? [ bitmap-node ] [ bit bitmap bitand 0 eq? [ bitmap-node ] [
bit bitmap index :> idx bit bitmap index set: idx
idx nodes nth-unsafe :> n idx nodes nth-unsafe set: n
key hashcode n (pluck-at) :> n' key hashcode n (pluck-at) set: n'
n n' eq? [ n n' eq? [
bitmap-node bitmap-node
] [ ] [

View File

@ -15,7 +15,7 @@ M:: collision-node (entry-at) ( key hashcode collision-node -- leaf-node )
M:: collision-node (pluck-at) ( key hashcode collision-node -- leaf-node ) M:: collision-node (pluck-at) ( key hashcode collision-node -- leaf-node )
hashcode collision-node hashcode>> eq? [ hashcode collision-node hashcode>> eq? [
key hashcode collision-node find-index drop :> idx key hashcode collision-node find-index drop set: idx
idx [ idx [
idx collision-node leaves>> smash [ idx collision-node leaves>> smash [
collision-node hashcode>> collision-node hashcode>>
@ -26,7 +26,7 @@ M:: collision-node (pluck-at) ( key hashcode collision-node -- leaf-node )
M:: collision-node (new-at) ( shift value key hashcode collision-node -- node' added-leaf ) M:: collision-node (new-at) ( shift value key hashcode collision-node -- node' added-leaf )
hashcode collision-node hashcode>> eq? [ hashcode collision-node hashcode>> eq? [
key hashcode collision-node find-index :> ( idx leaf-node ) key hashcode collision-node find-index set: ( idx leaf-node )
idx [ idx [
value leaf-node value>> = [ value leaf-node value>> = [
collision-node f collision-node f
@ -40,7 +40,7 @@ M:: collision-node (new-at) ( shift value key hashcode collision-node -- node' a
f f
] if ] if
] [ ] [
value key hashcode <leaf-node> :> new-leaf-node value key hashcode <leaf-node> set: new-leaf-node
hashcode hashcode
collision-node leaves>> collision-node leaves>>
new-leaf-node new-leaf-node

View File

@ -8,11 +8,11 @@ persistent.hashtables.nodes ;
IN: persistent.hashtables.nodes.full IN: persistent.hashtables.nodes.full
M:: full-node (new-at) ( shift value key hashcode full-node -- node' added-leaf ) M:: full-node (new-at) ( shift value key hashcode full-node -- node' added-leaf )
full-node nodes>> :> nodes full-node nodes>> set: nodes
hashcode full-node shift>> mask :> idx hashcode full-node shift>> mask set: idx
idx nodes nth-unsafe :> n idx nodes nth-unsafe set: n
shift radix-bits + value key hashcode n (new-at) :> ( n' new-leaf ) shift radix-bits + value key hashcode n (new-at) set: ( n' new-leaf )
n n' eq? [ n n' eq? [
full-node full-node
] [ ] [
@ -21,9 +21,9 @@ M:: full-node (new-at) ( shift value key hashcode full-node -- node' added-leaf
new-leaf ; new-leaf ;
M:: full-node (pluck-at) ( key hashcode full-node -- node' ) M:: full-node (pluck-at) ( key hashcode full-node -- node' )
hashcode full-node shift>> mask :> idx hashcode full-node shift>> mask set: idx
idx full-node nodes>> nth :> n idx full-node nodes>> nth set: n
key hashcode n (pluck-at) :> n' key hashcode n (pluck-at) set: n'
n n' eq? [ n n' eq? [
full-node full-node

View File

@ -19,7 +19,7 @@ M:: leaf-node (new-at) ( shift value key hashcode leaf-node -- node' added-leaf
value leaf-node value>> = value leaf-node value>> =
[ leaf-node f ] [ value key hashcode <leaf-node> f ] if [ leaf-node f ] [ value key hashcode <leaf-node> f ] if
] [ ] [
value key hashcode <leaf-node> :> new-leaf value key hashcode <leaf-node> set: new-leaf
hashcode leaf-node new-leaf 2array <collision-node> hashcode leaf-node new-leaf 2array <collision-node>
new-leaf new-leaf
] if ] if

View File

@ -30,7 +30,7 @@ IN: sequences.extras
[ swap ] 2dip each-from ; inline [ swap ] 2dip each-from ; inline
:: subseq* ( from to seq -- subseq ) :: subseq* ( from to seq -- subseq )
seq length :> len seq length set: len
from [ dup 0 < [ len + ] when ] [ 0 ] if* from [ dup 0 < [ len + ] when ] [ 0 ] if*
to [ dup 0 < [ len + ] when ] [ len ] if* to [ dup 0 < [ len + ] when ] [ len ] if*
[ 0 len clamp ] bi@ dupd max seq subseq ; [ 0 len clamp ] bi@ dupd max seq subseq ;
@ -42,11 +42,11 @@ IN: sequences.extras
dup length [1,b] [ clump ] with map concat ; dup length [1,b] [ clump ] with map concat ;
:: each-subseq ( ... seq quot: ( ... x -- ... ) -- ... ) :: each-subseq ( ... seq quot: ( ... x -- ... ) -- ... )
seq length :> len seq length set: len
len [0,b] [ len [0,b] [
:> from set: from
from len (a,b] [ from len (a,b] [
:> to set: to
from to seq subseq quot call from to seq subseq quot call
] each ] each
] each ; inline ] each ; inline
@ -63,16 +63,16 @@ IN: sequences.extras
[ dup length [1,b] ] dip filter-all-subseqs-range ; inline [ dup length [1,b] ] dip filter-all-subseqs-range ; inline
:: longest-subseq ( seq1 seq2 -- subseq ) :: longest-subseq ( seq1 seq2 -- subseq )
seq1 length :> len1 seq1 length set: len1
seq2 length :> len2 seq2 length set: len2
0 :> n! 0 set: n!
0 :> end! 0 set: end!
len1 1 + [ len2 1 + 0 <array> ] replicate :> table len1 1 + [ len2 1 + 0 <array> ] replicate set: table
len1 [1,b] |[ x | len1 [1,b] |[ x |
len2 [1,b] |[ y | len2 [1,b] |[ y |
x 1 - seq1 nth-unsafe x 1 - seq1 nth-unsafe
y 1 - seq2 nth-unsafe = [ y 1 - seq2 nth-unsafe = [
y 1 - x 1 - table nth-unsafe nth-unsafe 1 + :> len y 1 - x 1 - table nth-unsafe nth-unsafe 1 + set: len
len y x table nth-unsafe set-nth-unsafe len y x table nth-unsafe set-nth-unsafe
len n > [ len n! x end! ] when len n > [ len n! x end! ] when
] [ 0 y x table nth-unsafe set-nth-unsafe ] if ] [ 0 y x table nth-unsafe set-nth-unsafe ] if
@ -139,7 +139,7 @@ PRIVATE>
2tri ; inline 2tri ; inline
:: slice-when ( seq quot: ( elt -- ? ) -- seq' ) :: slice-when ( seq quot: ( elt -- ? ) -- seq' )
seq length :> len seq length set: len
0 [ len dupd < ] [ 0 [ len dupd < ] [
dup seq quot find-from drop dup seq quot find-from drop
[ 2dup = [ 1 + ] when ] [ len ] if* [ 2dup = [ 1 + ] when ] [ len ] if*
@ -211,7 +211,7 @@ ERROR: underlying-mismatch slice1 slice2 ;
2dup and [ span-slices ] [ or ] if ; 2dup and [ span-slices ] [ or ] if ;
:: rotate! ( seq n -- ) :: rotate! ( seq n -- )
seq length :> len seq length set: len
n len mod dup 0 < [ len + ] when seq bounds-check drop 0 over n len mod dup 0 < [ len + ] when seq bounds-check drop 0 over
[ 2dup = ] [ [ 2dup = ] [
[ seq exchange-unsafe ] [ [ 1 + ] bi@ ] 2bi [ seq exchange-unsafe ] [ [ 1 + ] bi@ ] 2bi

View File

@ -28,9 +28,9 @@ C: <appender> appender ;
INSTANCE: appender inserter ; INSTANCE: appender inserter ;
M:: appender new-sequence ( len inserter -- sequence ) M:: appender new-sequence ( len inserter -- sequence )
inserter underlying>> :> underlying inserter underlying>> set: underlying
underlying length :> old-length underlying length set: old-length
old-length len + :> new-length old-length len + set: new-length
new-length underlying set-length new-length underlying set-length
underlying old-length <offset-growable> ; inline underlying old-length <offset-growable> ; inline

View File

@ -13,7 +13,7 @@ TUPLE: sequence-parser sequence n ;
0 >>n ; 0 >>n ;
:: with-sequence-parser ( sequence-parser quot -- seq/f ) :: with-sequence-parser ( sequence-parser quot -- seq/f )
sequence-parser n>> :> n sequence-parser n>> set: n
sequence-parser quot call [ sequence-parser quot call [
n sequence-parser n<< f n sequence-parser n<< f
] unless* ; inline ] unless* ; inline
@ -79,13 +79,13 @@ TUPLE: sequence-parser sequence n ;
take-sequence drop ; take-sequence drop ;
:: take-until-sequence ( sequence-parser sequence -- sequence'/f ) :: take-until-sequence ( sequence-parser sequence -- sequence'/f )
sequence-parser n>> :> saved sequence-parser n>> set: saved
sequence length <growing-circular> :> growing sequence length <growing-circular> set: growing
sequence-parser sequence-parser
[ [
current growing growing-circular-push current growing growing-circular-push
sequence growing sequence= sequence growing sequence=
] take-until :> found ] take-until set: found
growing sequence sequence= [ growing sequence sequence= [
found dup length found dup length
growing length 1 - - head growing length 1 - - head
@ -97,7 +97,7 @@ TUPLE: sequence-parser sequence n ;
] if ; ] if ;
:: take-until-sequence* ( sequence-parser sequence -- sequence'/f ) :: take-until-sequence* ( sequence-parser sequence -- sequence'/f )
sequence-parser sequence take-until-sequence :> out sequence-parser sequence take-until-sequence set: out
out [ out [
sequence-parser [ sequence length + ] change-n drop sequence-parser [ sequence length + ] change-n drop
] when out ; ] when out ;

View File

@ -53,14 +53,14 @@ M: product-sequence nth
product@ nths ; product@ nths ;
:: product-each ( ... sequences quot: ( ... seq -- ... ) -- ... ) :: product-each ( ... sequences quot: ( ... seq -- ... ) -- ... )
sequences start-product-iter :> ( ns lengths ) sequences start-product-iter set: ( ns lengths )
lengths [ 0 = ] any? [ lengths [ 0 = ] any? [
[ ns lengths end-product-iter? ] [ ns lengths end-product-iter? ]
[ ns sequences nths quot call ns lengths product-iter ] until [ ns sequences nths quot call ns lengths product-iter ] until
] unless ; inline ] unless ; inline
:: product-map-as ( ... sequences quot: ( ... seq -- ... value ) exemplar -- ... sequence ) :: product-map-as ( ... sequences quot: ( ... seq -- ... value ) exemplar -- ... sequence )
0 :> i! 0 set: i!
sequences product-length exemplar sequences product-length exemplar
|[ result | |[ result |
sequences [ quot call i result set-nth-unsafe i 1 + i! ] product-each sequences [ quot call i result set-nth-unsafe i 1 + i! ] product-each
@ -71,7 +71,7 @@ M: product-sequence nth
over product-map-as ; inline over product-map-as ; inline
:: product-map>assoc ( ... sequences quot: ( ... seq -- ... key value ) exemplar -- ... assoc ) :: product-map>assoc ( ... sequences quot: ( ... seq -- ... key value ) exemplar -- ... assoc )
0 :> i! 0 set: i!
sequences product-length { } sequences product-length { }
|[ result | |[ result |
sequences [ quot call 2array i result set-nth-unsafe i 1 + i! ] product-each sequences [ quot call 2array i result set-nth-unsafe i 1 + i! ] product-each

View File

@ -20,8 +20,8 @@ IN: sets.extras
intersects? not ; intersects? not ;
:: non-repeating ( seq -- seq' ) :: non-repeating ( seq -- seq' )
HS{ } clone :> visited HS{ } clone set: visited
0 seq new-resizable :> accum 0 seq new-resizable set: accum
seq [ seq [
accum over visited ?adjoin accum over visited ?adjoin
[ push ] [ remove-first! drop ] if [ push ] [ remove-first! drop ] if

View File

@ -7,7 +7,7 @@ IN: splitting.monotonic
PRIVATE< PRIVATE<
:: monotonic-split-impl ( seq quot slice-quot n -- pieces ) :: monotonic-split-impl ( seq quot slice-quot n -- pieces )
V{ 0 } clone :> accum V{ 0 } clone set: accum
0 seq [ ] [ 0 seq [ ] [
[ 1 + ] 2dip [ [ 1 + ] 2dip [

View File

@ -108,7 +108,7 @@ IN: bootstrap.syntax
"SBUF\"" "SBUF\""
"::" "M::" "MEMO:" "MEMO::" "MACRO:" "MACRO::" "IDENTITY-MEMO:" "IDENTITY-MEMO::" "TYPED:" "TYPED::" "::" "M::" "MEMO:" "MEMO::" "MACRO:" "MACRO::" "IDENTITY-MEMO:" "IDENTITY-MEMO::" "TYPED:" "TYPED::"
":>" "|[" "let[" "MEMO[" "set:" "|[" "let[" "MEMO["
"$[" "$["
"_" "_"
"@" "@"

View File

@ -19,10 +19,10 @@ ERROR: local-writer-in-literal-error ;
M: local-writer-in-literal-error summary M: local-writer-in-literal-error summary
drop "Local writer words not permitted inside literals" ; drop "Local writer words not permitted inside literals" ;
ERROR: :>-outside-lambda-error ; ERROR: set:-outside-lambda-error ;
M: :>-outside-lambda-error summary M: set:-outside-lambda-error summary
drop ":> cannot be used outside of let[, |[, or :: forms" ; drop "set: cannot be used outside of let[, |[, or :: forms" ;
ERROR: bad-local args obj ; ERROR: bad-local args obj ;

View File

@ -8,34 +8,34 @@ HELP: \ |[
{ $examples "See " { $link "locals-examples" } "." } ; { $examples "See " { $link "locals-examples" } "." } ;
HELP: \ let[ HELP: \ let[
{ $syntax "let[ code :> var code :> var code... ]" } { $syntax "let[ code set: var code set: var code... ]" }
{ $description "Establishes a new scope for lexical variable bindings. Variables bound with " { $link postpone\ :> } " within the body of the " { $snippet "let[" } " will be lexically scoped to the body of the " { $snippet "let[" } " form." } { $description "Establishes a new scope for lexical variable bindings. Variables bound with " { $link \ set: } " within the body of the " { $snippet "let[" } " will be lexically scoped to the body of the " { $snippet "let[" } " form." }
{ $examples "See " { $link "locals-examples" } "." } ; { $examples "See " { $link "locals-examples" } "." } ;
HELP: \ :> HELP: \ set:
{ $syntax ":> var" ":> var!" ":> ( var-1 var-2 ... )" } { $syntax "set: var" "set: var!" "set: ( var-1 var-2 ... )" }
{ $description "Binds one or more new lexical variables. In the " { $snippet ":> var" } " form, the value on the top of the datastack is bound to a new lexical variable named " { $snippet "var" } " and is scoped to the enclosing quotation, " { $link postpone\ let[ } " form, or " { $link postpone\ :: } " definition." { $description "Binds one or more new lexical variables. In the " { $snippet "set: var" } " form, the value on the top of the datastack is bound to a new lexical variable named " { $snippet "var" } " and is scoped to the enclosing quotation, " { $link \ let[ } " form, or " { $link \ :: } " definition."
$nl $nl
"The " { $snippet ":> ( var-1 ... )" } " form binds multiple variables to the top values of the datastack in right to left order, with the last variable bound to the top of the datastack. These two snippets have the same effect:" "The " { $snippet "set: ( var-1 ... )" } " form binds multiple variables to the top values of the datastack in right to left order, with the last variable bound to the top of the datastack. These two snippets have the same effect:"
{ $code ":> c :> b :> a" } { $code "set: c set: b set: a" }
{ $code ":> ( a b c )" } { $code "set: ( a b c )" }
$nl $nl
"If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), that new variable is mutable. See " { $link "locals-mutable" } " for more information." } "If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), that new variable is mutable. See " { $link "locals-mutable" } " for more information." }
{ $notes { $notes
"This syntax can only be used inside a lexical scope established by a " { $link postpone\ :: } " definition, " { $link postpone\ let[ } " form, or " { $link postpone\ |[ } " quotation. Normal quotations have their own lexical scope only if they are inside an outer scope. Definition forms such as " { $link postpone\ : } " do not establish a lexical scope by themselves unless documented otherwise, nor is there a lexical scope available at the top level of source files or in the listener. " { $link postpone\ let[ } " can be used to create a lexical scope where one is not otherwise available." } "This syntax can only be used inside a lexical scope established by a " { $link \ :: } " definition, " { $link \ let[ } " form, or " { $link \ |[ } " quotation. Normal quotations have their own lexical scope only if they are inside an outer scope. Definition forms such as " { $link \ : } " do not establish a lexical scope by themselves unless documented otherwise, nor is there a lexical scope available at the top level of source files or in the listener. " { $link \ let[ } " can be used to create a lexical scope where one is not otherwise available." }
{ $examples "See " { $link "locals-examples" } "." } ; { $examples "See " { $link "locals-examples" } "." } ;
{ postpone\ let[ postpone\ :> } related-words { \ let[ \ set: } related-words
HELP: \ :: HELP: \ ::
{ $syntax ":: word ( vars... -- outputs... ) body... ;" } { $syntax ":: word ( vars... -- outputs... ) body... ;" }
{ $description "Defines a word with named inputs. The word binds its input values to lexical variables from left to right, then executes the body with those bindings in scope." { $description "Defines a word with named inputs. The word binds its input values to lexical variables from left to right, then executes the body with those bindings in scope."
$nl $nl
"If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), the corresponding new variable is made mutable. See " { $link "locals-mutable" } " for more information." } "If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), the corresponding new variable is made mutable. See " { $link "locals-mutable" } " for more information." }
{ $notes "The names of the " { $snippet "outputs" } " do not affect the word's behavior. However, the compiler verifies that the stack effect accurately represents the number of outputs as with " { $link postpone\ : } " definitions." } { $notes "The names of the " { $snippet "outputs" } " do not affect the word's behavior. However, the compiler verifies that the stack effect accurately represents the number of outputs as with " { $link \ : } " definitions." }
{ $examples "See " { $link "locals-examples" } "." } ; { $examples "See " { $link "locals-examples" } "." } ;
{ postpone\ : postpone\ :: } related-words { \ : \ :: } related-words
HELP: \ MACRO:: HELP: \ MACRO::
{ $syntax "MACRO:: word ( vars... -- outputs... ) body... ;" } { $syntax "MACRO:: word ( vars... -- outputs... ) body... ;" }
@ -45,7 +45,7 @@ $nl
{ $notes "The expansion of a macro cannot reference lexical variables bound in the outer scope. There are also limitations on passing arguments involving lexical variables into macros. See " { $link "locals-limitations" } " for details." } { $notes "The expansion of a macro cannot reference lexical variables bound in the outer scope. There are also limitations on passing arguments involving lexical variables into macros. See " { $link "locals-limitations" } " for details." }
{ $examples "See " { $link "locals-examples" } "." } ; { $examples "See " { $link "locals-examples" } "." } ;
{ postpone\ MACRO: postpone\ MACRO:: } related-words { \ MACRO: \ MACRO:: } related-words
HELP: \ MEMO:: HELP: \ MEMO::
{ $syntax "MEMO:: word ( vars... -- outputs... ) body... ;" } { $syntax "MEMO:: word ( vars... -- outputs... ) body... ;" }
@ -54,35 +54,35 @@ $nl
"If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), the corresponding new variable is made mutable. See " { $link "locals-mutable" } " for more information." } "If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), the corresponding new variable is made mutable. See " { $link "locals-mutable" } " for more information." }
{ $examples "See " { $link "locals-examples" } "." } ; { $examples "See " { $link "locals-examples" } "." } ;
{ postpone\ MEMO: postpone\ MEMO:: } related-words { \ MEMO: \ MEMO:: } related-words
HELP: \ M:: HELP: \ M::
{ $syntax "M:: class generic ( vars... -- outputs... ) body... ;" } { $syntax "M:: class generic ( vars... -- outputs... ) body... ;" }
{ $description "Defines a new method on " { $snippet "generic" } " for " { $snippet "class" } " with named inputs. The method binds its input values to lexical variables from left to right, then executes the body with those bindings in scope." { $description "Defines a new method on " { $snippet "generic" } " for " { $snippet "class" } " with named inputs. The method binds its input values to lexical variables from left to right, then executes the body with those bindings in scope."
$nl $nl
"If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), the corresponding new variable is made mutable. See " { $link "locals-mutable" } " for more information." } "If any " { $snippet "var" } " name is followed by an exclamation point (" { $snippet "!" } "), the corresponding new variable is made mutable. See " { $link "locals-mutable" } " for more information." }
{ $notes "The names of the " { $snippet "outputs" } " do not affect the word's behavior. However, the compiler verifies that the stack effect accurately represents the number of outputs as with " { $link postpone\ M: } " definitions." } { $notes "The names of the " { $snippet "outputs" } " do not affect the word's behavior. However, the compiler verifies that the stack effect accurately represents the number of outputs as with " { $link \ M: } " definitions." }
{ $examples "See " { $link "locals-examples" } "." } ; { $examples "See " { $link "locals-examples" } "." } ;
{ postpone\ M: postpone\ M:: } related-words { \ M: \ M:: } related-words
ARTICLE: "locals-examples" "Examples of lexical variables" ARTICLE: "locals-examples" "Examples of lexical variables"
{ $heading "Definitions with lexical variables" } { $heading "Definitions with lexical variables" }
"The following example demonstrates lexical variable bindings in word definitions. The " { $snippet "quadratic-roots" } " word is defined with " { $link postpone\ :: } ", so it takes its inputs from the top three elements of the datastack and binds them to the variables " { $snippet "a" } ", " { $snippet "b" } ", and " { $snippet "c" } ". In the body, the " { $snippet "disc" } " variable is bound using " { $link postpone\ :> } " and then used in the following line of code." "The following example demonstrates lexical variable bindings in word definitions. The " { $snippet "quadratic-roots" } " word is defined with " { $link \ :: } ", so it takes its inputs from the top three elements of the datastack and binds them to the variables " { $snippet "a" } ", " { $snippet "b" } ", and " { $snippet "c" } ". In the body, the " { $snippet "disc" } " variable is bound using " { $link \ set: } " and then used in the following line of code."
{ $example "USING: locals math math.functions kernel ; { $example "USING: locals math math.functions kernel ;
IN: scratchpad IN: scratchpad
:: quadratic-roots ( a b c -- x y ) :: quadratic-roots ( a b c -- x y )
b sq 4 a c * * - sqrt :> disc b sq 4 a c * * - sqrt set: disc
b neg disc [ + ] [ - ] 2bi [ 2 a * / ] bi@ ; b neg disc [ + ] [ - ] 2bi [ 2 a * / ] bi@ ;
1.0 1.0 -6.0 quadratic-roots [ . ] bi@" 1.0 1.0 -6.0 quadratic-roots [ . ] bi@"
"2.0 "2.0
-3.0" -3.0"
} }
"If you wanted to perform the quadratic formula interactively from the listener, you could use " { $link postpone\ let[ } " to provide a scope for the variables:" "If you wanted to perform the quadratic formula interactively from the listener, you could use " { $link \ let[ } " to provide a scope for the variables:"
{ $example "USING: locals math math.functions kernel ; { $example "USING: locals math math.functions kernel ;
IN: scratchpad IN: scratchpad
let[ 1.0 :> a 1.0 :> b -6.0 :> c let[ 1.0 set: a 1.0 set: b -6.0 set: c
b sq 4 a c * * - sqrt :> disc b sq 4 a c * * - sqrt set: disc
b neg disc [ + ] [ - ] 2bi [ 2 a * / ] bi@ b neg disc [ + ] [ - ] 2bi [ 2 a * / ] bi@
] [ . ] bi@" ] [ . ] bi@"
"2.0 "2.0
@ -92,7 +92,7 @@ let[ 1.0 :> a 1.0 :> b -6.0 :> c
$nl $nl
{ $heading "Quotations with lexical variables, and closures" } { $heading "Quotations with lexical variables, and closures" }
"These next two examples demonstrate lexical variable bindings in quotations defined with " { $link postpone\ |[ } ". In this example, the values " { $snippet "5" } " and " { $snippet "3" } " are put on the datastack. When the quotation is called, it takes those values as inputs and binds them respectively to " { $snippet "m" } " and " { $snippet "n" } " before executing the quotation:" "These next two examples demonstrate lexical variable bindings in quotations defined with " { $link \ |[ } ". In this example, the values " { $snippet "5" } " and " { $snippet "3" } " are put on the datastack. When the quotation is called, it takes those values as inputs and binds them respectively to " { $snippet "m" } " and " { $snippet "n" } " before executing the quotation:"
{ $example { $example
"USING: kernel locals math prettyprint ;" "USING: kernel locals math prettyprint ;"
"IN: scratchpad" "IN: scratchpad"
@ -120,7 +120,7 @@ IN: scratchpad
TUPLE: counter adder subtractor ; TUPLE: counter adder subtractor ;
:: <counter> ( -- counter ) :: <counter> ( -- counter )
0 :> value! 0 set: value!
counter new counter new
[ value 1 + dup value! ] >>adder [ value 1 + dup value! ] >>adder
[ value 1 - dup value! ] >>subtractor ; [ value 1 - dup value! ] >>subtractor ;
@ -138,10 +138,10 @@ TUPLE: counter adder subtractor ;
"USING: kernel locals prettyprint ; "USING: kernel locals prettyprint ;
IN: scratchpad IN: scratchpad
:: rebinding-example ( -- quot1 quot2 ) :: rebinding-example ( -- quot1 quot2 )
5 :> a [ a ] 5 set: a [ a ]
6 :> a [ a ] ; 6 set: a [ a ] ;
:: mutable-example ( -- quot1 quot2 ) :: mutable-example ( -- quot1 quot2 )
5 :> a! [ a ] 5 set: a! [ a ]
6 a! [ a ] ; 6 a! [ a ] ;
rebinding-example [ call . ] bi@ rebinding-example [ call . ] bi@
mutable-example [ call . ] bi@" mutable-example [ call . ] bi@"
@ -199,7 +199,7 @@ $nl
"IN: scratchpad" "IN: scratchpad"
"TUPLE: person first-name last-name ;" "TUPLE: person first-name last-name ;"
":: constructor-test ( -- tuple )" ":: constructor-test ( -- tuple )"
" \"Jane Smith\" \" \" split1 :> last :> first" " \"Jane Smith\" \" \" split1 set: last set: first"
" T{ person { first-name first } { last-name last } } ;" " T{ person { first-name first } { last-name last } } ;"
"constructor-test constructor-test eq? ." "constructor-test constructor-test eq? ."
"f" "f"
@ -207,7 +207,7 @@ $nl
"One exception to the above rule is that array instances containing free lexical variables (that is, immutable lexical variables not referenced in a closure) do retain identity. This allows macros such as " { $link cond } " to expand at compile time even when their arguments reference variables." ; "One exception to the above rule is that array instances containing free lexical variables (that is, immutable lexical variables not referenced in a closure) do retain identity. This allows macros such as " { $link cond } " to expand at compile time even when their arguments reference variables." ;
ARTICLE: "locals-mutable" "Mutable lexical variables" ARTICLE: "locals-mutable" "Mutable lexical variables"
"When a lexical variable is bound using " { $link postpone\ :> } ", " { $link postpone\ :: } ", or " { $link postpone\ |[ } ", the variable may be made mutable by suffixing its name with an exclamation point (" { $snippet "!" } "). A mutable variable's value is read by giving its name without the exclamation point as usual. To write to the variable, use its name with the " { $snippet "!" } " suffix." "When a lexical variable is bound using " { $link \ set: } ", " { $link \ :: } ", or " { $link \ |[ } ", the variable may be made mutable by suffixing its name with an exclamation point (" { $snippet "!" } "). A mutable variable's value is read by giving its name without the exclamation point as usual. To write to the variable, use its name with the " { $snippet "!" } " suffix."
$nl $nl
"Mutable bindings are implemented in a manner similar to that taken by the ML language. Each mutable binding is actually an immutable binding of a mutable cell. Reading the binding automatically unboxes the value from the cell, and writing to the binding stores into it." "Mutable bindings are implemented in a manner similar to that taken by the ML language. Each mutable binding is actually an immutable binding of a mutable cell. Reading the binding automatically unboxes the value from the cell, and writing to the binding stores into it."
$nl $nl
@ -224,7 +224,7 @@ $nl
"Conceptually, " { $link curry } " is defined so that the following two code snippets are equivalent:" "Conceptually, " { $link curry } " is defined so that the following two code snippets are equivalent:"
{ $code "3 [ - ] curry" } { $code "3 [ - ] curry" }
{ $code "[ 3 - ]" } { $code "[ 3 - ]" }
"When quotations take named parameters using " { $link postpone\ |[ } ", " { $link curry } " fills in the variable bindings from right to left. The following two snippets are equivalent:" "When quotations take named parameters using " { $link \ |[ } ", " { $link curry } " fills in the variable bindings from right to left. The following two snippets are equivalent:"
{ $code "3 |[ a b | a b - ] curry" } { $code "3 |[ a b | a b - ] curry" }
{ $code "|[ a | a 3 - ]" } { $code "|[ a | a 3 - ]" }
"Because of this, the behavior of " { $snippet "fry" } " changes when applied to such a quotation to ensure that fry conceptually behaves the same as with normal quotations, placing the fried values “underneath” the variable bindings. Thus, the following snippets are no longer equivalent:" "Because of this, the behavior of " { $snippet "fry" } " changes when applied to such a quotation to ensure that fry conceptually behaves the same as with normal quotations, placing the fried values “underneath” the variable bindings. Thus, the following snippets are no longer equivalent:"
@ -233,7 +233,7 @@ $nl
"Instead, the first line above expands into something like the following:" "Instead, the first line above expands into something like the following:"
{ $code "[ [ swap |[ a | a - ] ] curry call ]" } { $code "[ [ swap |[ a | a - ] ] curry call ]" }
$nl $nl
"The precise behavior is as follows. When frying a " { $link postpone\ |[ } " quotation, a stack shuffle (" { $link mnswap } ") is prepended so that the " { $snippet "m" } " curried values, which start off at the top of the stack, are transposed with the quotation's " { $snippet "n" } " named input bindings." ; "The precise behavior is as follows. When frying a " { $link \ |[ } " quotation, a stack shuffle (" { $link mnswap } ") is prepended so that the " { $snippet "m" } " curried values, which start off at the top of the stack, are transposed with the quotation's " { $snippet "n" } " named input bindings." ;
ARTICLE: "locals-limitations" "Limitations of lexical variables" ARTICLE: "locals-limitations" "Limitations of lexical variables"
"There are two main limitations of the current implementation, and both concern macros." "There are two main limitations of the current implementation, and both concern macros."
@ -282,18 +282,18 @@ ARTICLE: "locals" "Lexical variables"
} }
"Word definitions where the inputs are bound to lexical variables:" "Word definitions where the inputs are bound to lexical variables:"
{ $subsections { $subsections
postpone\ :: \ ::
postpone\ M:: \ M::
postpone\ MEMO:: \ MEMO::
postpone\ MACRO:: \ MACRO::
} }
"Lexical scoping and binding forms:" "Lexical scoping and binding forms:"
{ $subsections { $subsections
postpone\ let[ \ let[
postpone\ :> \ set:
} }
"Quotation literals where the inputs are bound to lexical variables:" "Quotation literals where the inputs are bound to lexical variables:"
{ $subsections postpone\ |[ } { $subsections \ |[ }
"Additional topics:" "Additional topics:"
{ $subsections { $subsections
"locals-literals" "locals-literals"

View File

@ -27,30 +27,30 @@ IN: locals.tests
{ { 5 6 7 } } [ { 1 2 3 } 4 map-test-2 ] unit-test { { 5 6 7 } } [ { 1 2 3 } 4 map-test-2 ] unit-test
:: let-test ( c -- d ) :: let-test ( c -- d )
let[ 1 :> a 2 :> b a b + c + ] ; let[ 1 set: a 2 set: b a b + c + ] ;
{ 7 } [ 4 let-test ] unit-test { 7 } [ 4 let-test ] unit-test
:: let-test-2 ( a -- a ) :: let-test-2 ( a -- a )
a let[ :> a let[ a :> b a ] ] ; a let[ set: a let[ a set: b a ] ] ;
{ 3 } [ 3 let-test-2 ] unit-test { 3 } [ 3 let-test-2 ] unit-test
:: let-test-3 ( a -- a ) :: let-test-3 ( a -- a )
a let[ :> a let[ [ a ] :> b let[ 3 :> a b ] ] ] ; a let[ set: a let[ [ a ] set: b let[ 3 set: a b ] ] ] ;
:: let-test-4 ( a -- b ) :: let-test-4 ( a -- b )
a let[ 1 :> a :> b a b 2array ] ; a let[ 1 set: a set: b a b 2array ] ;
{ { 1 2 } } [ 2 let-test-4 ] unit-test { { 1 2 } } [ 2 let-test-4 ] unit-test
:: let-test-5 ( a b -- b ) :: let-test-5 ( a b -- b )
a b let[ :> a :> b a b 2array ] ; a b let[ set: a set: b a b 2array ] ;
{ { 2 1 } } [ 1 2 let-test-5 ] unit-test { { 2 1 } } [ 1 2 let-test-5 ] unit-test
:: let-test-6 ( a -- b ) :: let-test-6 ( a -- b )
a let[ :> a 1 :> b a b 2array ] ; a let[ set: a 1 set: b a b 2array ] ;
{ { 2 1 } } [ 2 let-test-6 ] unit-test { { 2 1 } } [ 2 let-test-6 ] unit-test
@ -72,7 +72,7 @@ IN: locals.tests
{ 5 } [ 2 "q" get call ] unit-test { 5 } [ 2 "q" get call ] unit-test
:: write-test-2 ( -- q ) :: write-test-2 ( -- q )
let[ 0 :> n! |[ i | n i + dup n! ] ] ; let[ 0 set: n! |[ i | n i + dup n! ] ] ;
write-test-2 "q" set write-test-2 "q" set
@ -93,11 +93,11 @@ write-test-2 "q" set
{ } [ 1 2 write-test-3 call ] unit-test { } [ 1 2 write-test-3 call ] unit-test
:: write-test-4 ( x! -- q ) [ let[ 0 :> y! f x! ] ] ; :: write-test-4 ( x! -- q ) [ let[ 0 set: y! f x! ] ] ;
{ } [ 5 write-test-4 drop ] unit-test { } [ 5 write-test-4 drop ] unit-test
:: let-let-test ( n -- n ) let[ n 3 + :> n n ] ; :: let-let-test ( n -- n ) let[ n 3 + set: n n ] ;
{ 13 } [ 10 let-let-test ] unit-test { 13 } [ 10 let-let-test ] unit-test
@ -135,9 +135,9 @@ M:: string lambda-generic ( a b -- c ) a b lambda-generic-2 ;
{ } [ \ lambda-generic see ] unit-test { } [ \ lambda-generic see ] unit-test
:: unparse-test-1 ( a -- ) let[ 3 :> a! 4 :> b ] ; :: unparse-test-1 ( a -- ) let[ 3 set: a! 4 set: b ] ;
{ "let[ 3 :> a! 4 :> b ]" } [ { "let[ 3 set: a! 4 set: b ]" } [
\ unparse-test-1 "lambda" word-prop body>> first unparse \ unparse-test-1 "lambda" word-prop body>> first unparse
] unit-test ] unit-test
@ -177,11 +177,11 @@ M:: fixnum next-method-test ( a -- b ) a call-next-method 1 + ;
{ 3 0 } |[ a b c | ] must-infer-as { 3 0 } |[ a b c | ] must-infer-as
{ } [ 1 let[ :> a ] ] unit-test { } [ 1 let[ set: a ] ] unit-test
{ 3 } [ 1 let[ :> a 3 ] ] unit-test { 3 } [ 1 let[ set: a 3 ] ] unit-test
{ } [ 1 2 let[ :> a :> b ] ] unit-test { } [ 1 2 let[ set: a set: b ] ] unit-test
:: a-word-with-locals ( a b -- ) ; :: a-word-with-locals ( a b -- ) ;
@ -239,10 +239,10 @@ M:: sequence method-with-locals ( a -- y ) a reverse ;
{ t } [ 12 &&-test ] unit-test { t } [ 12 &&-test ] unit-test
:: let-and-cond-test-1 ( -- a ) :: let-and-cond-test-1 ( -- a )
let[ 10 :> a let[ 10 set: a
let[ 20 :> a let[ 20 set: a
{ {
{ [ t ] [ let[ 30 :> c a ] ] } { [ t ] [ let[ 30 set: c a ] ] }
} cond } cond
] ]
] ; ] ;
@ -252,8 +252,8 @@ M:: sequence method-with-locals ( a -- y ) a reverse ;
{ 20 } [ let-and-cond-test-1 ] unit-test { 20 } [ let-and-cond-test-1 ] unit-test
:: let-and-cond-test-2 ( -- pair ) :: let-and-cond-test-2 ( -- pair )
let[ 10 :> A let[ 10 set: A
let[ 20 :> B let[ 20 set: B
{ { [ t ] [ { A B } ] } } cond { { [ t ] [ { A B } ] } } cond
] ]
] ; ] ;
@ -266,7 +266,7 @@ M:: sequence method-with-locals ( a -- y ) a reverse ;
{ { 10 20 } } [ 10 20 |[ a b | { a b } ] call ] unit-test { { 10 20 } } [ 10 20 |[ a b | { a b } ] call ] unit-test
{ { 10 20 30 } } [ 10 20 30 |[ a b c | { a b c } ] call ] unit-test { { 10 20 30 } } [ 10 20 30 |[ a b c | { a b c } ] call ] unit-test
{ { 10 20 30 } } [ let[ 10 :> a 20 :> b 30 :> c { a b c } ] ] unit-test { { 10 20 30 } } [ let[ 10 set: a 20 set: b 30 set: c { a b c } ] ] unit-test
{ V{ 10 20 30 } } [ 10 20 30 |[ a b c | V{ a b c } ] call ] unit-test { V{ 10 20 30 } } [ 10 20 30 |[ a b c | V{ a b c } ] call ] unit-test
@ -388,7 +388,7 @@ M:: integer lambda-method-forget-test ( a -- b ) a ;
{ 10 } [ 10 |[ A | { [ A ] } ] call first call ] unit-test { 10 } [ 10 |[ A | { [ A ] } ] call first call ] unit-test
[ [
"USING: locals fry math ; 1 $[ let[ 10 :> A A _ + ] ]" "USING: locals fry math ; 1 $[ let[ 10 set: A A _ + ] ]"
eval( -- ) call eval( -- ) call
] [ error>> >r/r>-in-fry-error? ] must-fail-with ] [ error>> >r/r>-in-fry-error? ] must-fail-with
@ -416,28 +416,28 @@ M:: integer lambda-method-forget-test ( a -- b ) a ;
{ 3 } [ 3 |[ a | \ a ] call ] unit-test { 3 } [ 3 |[ a | \ a ] call ] unit-test
[ "USE: locals |[ | { let[ 0 :> a a ] } ]" eval( -- ) ] must-fail [ "USE: locals |[ | { let[ 0 set: a a ] } ]" eval( -- ) ] must-fail
[ "USE: locals |[ | let[ 0 :> a! { a! } ] ]" eval( -- ) ] must-fail [ "USE: locals |[ | let[ 0 set: a! { a! } ] ]" eval( -- ) ] must-fail
[ "USE: locals |[ | { :> a } ]" eval( -- ) ] must-fail [ "USE: locals |[ | { set: a } ]" eval( -- ) ] must-fail
[ "USE: locals 3 :> a" eval( -- ) ] must-fail [ "USE: locals 3 set: a" eval( -- ) ] must-fail
{ 3 } [ 3 |[ | :> a a ] call ] unit-test { 3 } [ 3 |[ | set: a a ] call ] unit-test
{ 3 } [ 3 |[ | :> a! a ] call ] unit-test { 3 } [ 3 |[ | set: a! a ] call ] unit-test
{ 3 } [ 2 |[ | :> a! a 1 + a! a ] call ] unit-test { 3 } [ 2 |[ | set: a! a 1 + a! a ] call ] unit-test
: fry-locals-test-1 ( -- n ) : fry-locals-test-1 ( -- n )
let[ 6 $[ let[ 4 :> A A _ + ] ] call ] ; let[ 6 $[ let[ 4 set: A A _ + ] ] call ] ;
\ fry-locals-test-1 def>> must-infer \ fry-locals-test-1 def>> must-infer
{ 10 } [ fry-locals-test-1 ] unit-test { 10 } [ fry-locals-test-1 ] unit-test
:: fry-locals-test-2 ( -- n ) :: fry-locals-test-2 ( -- n )
let[ 6 $[ let[ 4 :> A A _ + ] ] call ] ; let[ 6 $[ let[ 4 set: A A _ + ] ] call ] ;
\ fry-locals-test-2 def>> must-infer \ fry-locals-test-2 def>> must-infer
{ 10 } [ fry-locals-test-2 ] unit-test { 10 } [ fry-locals-test-2 ] unit-test
@ -455,31 +455,31 @@ M:: integer lambda-method-forget-test ( a -- b ) a ;
] unit-test ] unit-test
{ 10 } [ { 10 } [
|[ | 0 $[ let[ 10 :> A A _ + ] ] call ] call |[ | 0 $[ let[ 10 set: A A _ + ] ] call ] call
] unit-test ] unit-test
! littledan found this problem ! littledan found this problem
{ "bar" } [ let[ let[ "bar" :> foo foo ] :> a a ] ] unit-test { "bar" } [ let[ let[ "bar" set: foo foo ] set: a a ] ] unit-test
{ 10 } [ let[ 10 :> a let[ a :> b b ] ] ] unit-test { 10 } [ let[ 10 set: a let[ a set: b b ] ] ] unit-test
{ { \ + } } [ let[ \ + :> x { \ x } ] ] unit-test { { \ + } } [ let[ \ + set: x { \ x } ] ] unit-test
{ { \ + 3 } } [ let[ 3 :> a { \ + a } ] ] unit-test { { \ + 3 } } [ let[ 3 set: a { \ + a } ] ] unit-test
{ 3 } [ let[ \ + :> a 1 2 [ \ a execute ] ] call ] unit-test { 3 } [ let[ \ + set: a 1 2 [ \ a execute ] ] call ] unit-test
! erg found this problem ! erg found this problem
:: erg's-:>-bug ( n ? -- n ) ? [ n :> n n ] [ n :> b b ] if ; :: erg's-set:-bug ( n ? -- n ) ? [ n set: n n ] [ n set: b b ] if ;
{ 3 } [ 3 f erg's-:>-bug ] unit-test { 3 } [ 3 f erg's-set:-bug ] unit-test
{ 3 } [ 3 t erg's-:>-bug ] unit-test { 3 } [ 3 t erg's-set:-bug ] unit-test
:: erg's-:>-bug-2 ( n ? -- n ) ? n $[ _ :> n n ] [ n :> b b ] if ; :: erg's-set:-bug-2 ( n ? -- n ) ? n $[ _ set: n n ] [ n set: b b ] if ;
{ 3 } [ 3 f erg's-:>-bug-2 ] unit-test { 3 } [ 3 f erg's-set:-bug-2 ] unit-test
{ 3 } [ 3 t erg's-:>-bug-2 ] unit-test { 3 } [ 3 t erg's-set:-bug-2 ] unit-test
! dharmatech found this problem ! dharmatech found this problem
GENERIC: ed's-bug ( a -- b ) ; GENERIC: ed's-bug ( a -- b ) ;
@ -493,7 +493,7 @@ M: integer ed's-bug neg ;
{ t } [ \ ed's-test-case word-optimized? ] unit-test { t } [ \ ed's-test-case word-optimized? ] unit-test
! multiple bind ! multiple bind
{ 3 1 2 } [ let[ 1 2 3 :> ( a b c ) c a b ] ] unit-test { 3 1 2 } [ let[ 1 2 3 set: ( a b c ) c a b ] ] unit-test
! Test smart combinators and locals interaction ! Test smart combinators and locals interaction
:: smart-combinator-locals ( a b c -- seq ) [ a b c ] output>array ; :: smart-combinator-locals ( a b c -- seq ) [ a b c ] output>array ;

View File

@ -10,7 +10,7 @@ HELP: parse-def
{ "name/paren" string } { "name/paren" string }
{ "def" "a " { $link def } " or a " { $link multi-def } } { "def" "a " { $link def } " or a " { $link multi-def } }
} }
{ $description "Parses the lexical variable bindings following a " { $link postpone\ :> } " token." } ; { $description "Parses the lexical variable bindings following a " { $link postpone\ set: } " token." } ;
HELP: with-lambda-scope HELP: with-lambda-scope
{ $values { "assoc" "local variables" } { "reader-quot" quotation } { "quot" quotation } } { $values { "assoc" "local variables" } { "reader-quot" quotation } { "quot" quotation } }

View File

@ -60,11 +60,11 @@ COMPILE>
COMPILE< COMPILE<
{ {
"V{ 99 :> kkk kkk }" "V{ 99 set: kkk kkk }"
} [ } [
[ [
"locals" use-vocab "locals" use-vocab
{ "99 :> kkk kkk ;" } <lexer> [ { "99 set: kkk kkk ;" } <lexer> [
H{ } clone [ \ ; parse-until ] with-lambda-scope H{ } clone [ \ ; parse-until ] with-lambda-scope
] with-lexer ] with-lexer
] with-compilation-unit unparse ] with-compilation-unit unparse

View File

@ -35,7 +35,7 @@ M: def localize
M: object localize 1quotation ; M: object localize 1quotation ;
! We special-case all the :> at the start of a quotation ! We special-case all the set: at the start of a quotation
: load-locals-quot ( args -- quot ) : load-locals-quot ( args -- quot )
[ [ ] ] [ [ [ ] ] [
dup [ local-reader? ] any? [ dup [ local-reader? ] any? [

View File

@ -6,7 +6,7 @@ locals.errors locals.types make quotations sequences vectors
words ; words ;
IN: locals.rewrite.sugar IN: locals.rewrite.sugar
! Step 1: rewrite |[ into :> forms, turn ! Step 1: rewrite |[ into set: forms, turn
! literals with locals in them into code which constructs ! literals with locals in them into code which constructs
! the literal after pushing locals on the stack ! the literal after pushing locals on the stack

View File

@ -43,12 +43,12 @@ ERROR: unexpected-end n string ;
n [ n [
n string $[ tokens member? ] find-from n string $[ tokens member? ] find-from
dup "\s\r\n" member? [ dup "\s\r\n" member? [
:> ( n' ch ) set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
] [ ] [
[ dup [ 1 + ] when ] dip :> ( n' ch ) [ dup [ 1 + ] when ] dip set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
@ -60,12 +60,12 @@ ERROR: unexpected-end n string ;
! ":foo" with partial>> slot broke this ! ":foo" with partial>> slot broke this
:: lex-til-either ( lexer tokens -- n'/f string' slice/f ch/f ) :: lex-til-either ( lexer tokens -- n'/f string' slice/f ch/f )
lexer >lexer< lexer >lexer<
lexer partial>> :> partial lexer partial>> set: partial
partial [ partial [
[ dup [ 1 - ] when ] dip [ dup [ 1 - ] when ] dip
f lexer partial<< f lexer partial<<
] when ] when
tokens slice-til-either :> ( n' string' slice ch ) tokens slice-til-either set: ( n' string' slice ch )
lexer lexer
n' >>n drop n' >>n drop
n' string' n' string'
@ -74,13 +74,13 @@ ERROR: unexpected-end n string ;
:: slice-til-separator-inclusive ( n string tokens -- n' string slice/f ch/f ) :: slice-til-separator-inclusive ( n string tokens -- n' string slice/f ch/f )
n string $[ tokens member? ] find-from [ dup [ 1 + ] when ] dip :> ( n' ch ) n string $[ tokens member? ] find-from [ dup [ 1 + ] when ] dip set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ; inline ch ; inline
:: lex-til-separator-inclusive ( lexer tokens -- n' string' slice/f ch/f ) :: lex-til-separator-inclusive ( lexer tokens -- n' string' slice/f ch/f )
lexer >lexer< tokens slice-til-separator-inclusive :> ( n' string' slice ch ) lexer >lexer< tokens slice-til-separator-inclusive set: ( n' string' slice ch )
lexer lexer
n' >>n drop n' >>n drop
@ -94,7 +94,7 @@ ERROR: unexpected-end n string ;
] when ; ] when ;
:: lex-til-separator-exclusive ( lexer tokens -- n'/f string' slice/f ch/f ) :: lex-til-separator-exclusive ( lexer tokens -- n'/f string' slice/f ch/f )
lexer >lexer< tokens slice-til-separator-exclusive :> ( n' string' slice ch ) lexer >lexer< tokens slice-til-separator-exclusive set: ( n' string' slice ch )
lexer lexer
n' >>n drop n' >>n drop
n' string' slice ch ; n' string' slice ch ;
@ -102,7 +102,7 @@ ERROR: unexpected-end n string ;
! Don't include the whitespace in the slice ! Don't include the whitespace in the slice
:: slice-til-whitespace ( n string -- n'/f string slice/f ch/f ) :: slice-til-whitespace ( n string -- n'/f string slice/f ch/f )
n [ n [
n string [ "\s\r\n" member? ] find-from :> ( n' ch ) n string [ "\s\r\n" member? ] find-from set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
@ -111,14 +111,14 @@ ERROR: unexpected-end n string ;
] if ; inline ] if ; inline
:: lex-til-whitespace ( lexer -- n'/f string slice/f ch/f ) :: lex-til-whitespace ( lexer -- n'/f string slice/f ch/f )
lexer >lexer< slice-til-whitespace :> ( n' string' slice ch ) lexer >lexer< slice-til-whitespace set: ( n' string' slice ch )
lexer lexer
n' >>n drop n' >>n drop
n' string' slice ch ; n' string' slice ch ;
! rollback only n, other state is not rolled back ! rollback only n, other state is not rolled back
:: with-lexer-rollback ( lexer quot -- ) :: with-lexer-rollback ( lexer quot -- )
lexer n>> :> n lexer n>> set: n
lexer quot call lexer n >>n drop ; inline lexer quot call lexer n >>n drop ; inline
@ -130,7 +130,7 @@ ERROR: unexpected-end n string ;
:: slice-til-eol ( n string -- n'/f string slice/f ch/f ) :: slice-til-eol ( n string -- n'/f string slice/f ch/f )
n [ n [
n string $[ "\r\n" member? ] find-from :> ( n' ch ) n string $[ "\r\n" member? ] find-from set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
@ -139,7 +139,7 @@ ERROR: unexpected-end n string ;
] if ; inline ] if ; inline
:: lex-til-eol ( lexer -- n' string' slice/f ch/f ) :: lex-til-eol ( lexer -- n' string' slice/f ch/f )
lexer >lexer< slice-til-eol :> ( n' string' slice ch ) lexer >lexer< slice-til-eol set: ( n' string' slice ch )
lexer lexer
n' >>n drop n' >>n drop
n' string' slice ch ; n' string' slice ch ;
@ -148,14 +148,14 @@ ERROR: unexpected-end n string ;
ERROR: subseq-expected-but-got-eof n string expected ; ERROR: subseq-expected-but-got-eof n string expected ;
:: slice-til-string ( n string search -- n' string payload closing ) :: slice-til-string ( n string search -- n' string payload closing )
search string n start* :> n' search string n start* set: n'
n' [ n string search subseq-expected-but-got-eof ] unless n' [ n string search subseq-expected-but-got-eof ] unless
n' search length + string n' search length + string
n n' string ?<slice> n n' string ?<slice>
n' dup search length + string ?<slice> ; n' dup search length + string ?<slice> ;
:: lex-til-string ( lexer search -- n'/f string' payload closing ) :: lex-til-string ( lexer search -- n'/f string' payload closing )
lexer >lexer< search slice-til-string :> ( n' string' payload closing ) lexer >lexer< search slice-til-string set: ( n' string' payload closing )
lexer lexer
n' >>n drop n' >>n drop
n' string' payload closing ; n' string' payload closing ;
@ -174,14 +174,14 @@ ERROR: subseq-expected-but-got-eof n string expected ;
ERROR: char-expected-but-got-eof n string expected ; ERROR: char-expected-but-got-eof n string expected ;
:: slice-til-not-char ( n string slice char -- n' string found ) :: slice-til-not-char ( n string slice char -- n' string found )
n string [ char = not ] find-from drop :> n' n string [ char = not ] find-from drop set: n'
n' [ n string char char-expected-but-got-eof ] unless n' [ n string char char-expected-but-got-eof ] unless
n' n'
string string
slice from>> n' string ?<slice> ; slice from>> n' string ?<slice> ;
:: lex-til-not-char ( lexer slice char -- n'/f string' found ) :: lex-til-not-char ( lexer slice char -- n'/f string' found )
lexer >lexer< slice char slice-til-not-char :> ( n' string' found ) lexer >lexer< slice char slice-til-not-char set: ( n' string' found )
lexer lexer
n' >>n drop n' >>n drop
n' string' found ; n' string' found ;

View File

@ -261,21 +261,21 @@ MACRO:: read-double-matched ( open-ch -- quot: ( lexer tag ch -- seq ) )
[ drop 2 swap <string> ] [ drop 2 swap <string> ]
[ drop 1string ] [ drop 1string ]
[ nip 2 swap <string> ] [ nip 2 swap <string> ]
} 2cleave :> ( openstr2 openstr1 closestr2 ) } 2cleave set: ( openstr2 openstr1 closestr2 )
|[ lexer tag! ch | |[ lexer tag! ch |
ch { ch {
{ char: = [ { char: = [
lexer openstr1 lex-til-separator-inclusive [ -1 modify-from ] dip :> ( n' string' opening ch ) lexer openstr1 lex-til-separator-inclusive [ -1 modify-from ] dip set: ( n' string' opening ch )
ch open-ch = [ tag openstr2 lexer ch long-opening-mismatch ] unless ch open-ch = [ tag openstr2 lexer ch long-opening-mismatch ] unless
opening matching-delimiter-string :> needle opening matching-delimiter-string set: needle
lexer needle lex-til-string :> ( n'' string'' payload closing ) lexer needle lex-til-string set: ( n'' string'' payload closing )
payload closing tag but-last-slice opening double-matched-literal make-matched-literal payload closing tag but-last-slice opening double-matched-literal make-matched-literal
[ >string ] change-payload [ >string ] change-payload
] } ] }
{ open-ch [ { open-ch [
tag 1 cut-slice* swap tag! 1 modify-to :> opening tag 1 cut-slice* swap tag! 1 modify-to set: opening
lexer [ 1 + ] change-n closestr2 lex-til-string :> ( n' string' payload closing ) lexer [ 1 + ] change-n closestr2 lex-til-string set: ( n' string' payload closing )
payload closing tag opening double-matched-literal make-matched-literal payload closing tag opening double-matched-literal make-matched-literal
[ >string ] change-payload [ >string ] change-payload
] } ] }
@ -317,7 +317,7 @@ MACRO:: read-matched ( ch -- quot: ( lexer tag -- slice' ) )
ch dup matching-delimiter { ch dup matching-delimiter {
[ drop "=" swap prefix ] [ drop "=" swap prefix ]
[ nip 1string ] [ nip 1string ]
} 2cleave :> ( openstreq closestr1 ) ! [= ] } 2cleave set: ( openstreq closestr1 ) ! [= ]
|[ lexer tag | |[ lexer tag |
lexer tag lexer tag
@ -339,7 +339,7 @@ MACRO:: read-matched ( ch -- quot: ( lexer tag -- slice' ) )
:: read-string-payload ( lexer -- n' string slice ) :: read-string-payload ( lexer -- n' string slice )
lexer dup ?lexer-nth [ lexer dup ?lexer-nth [
{ char: \\ char: \" } lex-til-separator-inclusive :> ( n' string' slice ch ) { char: \\ char: \" } lex-til-separator-inclusive set: ( n' string' slice ch )
ch { ch {
{ f [ n' string' slice ] } { f [ n' string' slice ] }
{ char: \" [ n' string' slice ] } { char: \" [ n' string' slice ] }
@ -350,8 +350,8 @@ MACRO:: read-matched ( ch -- quot: ( lexer tag -- slice' ) )
] if ; ] if ;
:: read-string ( lexer tag -- seq ) :: read-string ( lexer tag -- seq )
lexer n>> :> n lexer n>> set: n
lexer read-string-payload :> ( n' string slice ) lexer read-string-payload set: ( n' string slice )
n' [ n string string-expected-got-eof ] unless n' [ n string string-expected-got-eof ] unless
n n' 1 - string <slice> n n' 1 - string <slice>
n' 1 - n' string <slice> n' 1 - n' string <slice>
@ -426,11 +426,11 @@ ERROR: closing-tag-required lexer tag ;
(trim-tail) [ length ] dip - ; inline (trim-tail) [ length ] dip - ; inline
:: read-backtick ( lexer slice -- obj ) :: read-backtick ( lexer slice -- obj )
lexer slice char: \` lex-til-not-char 2nip :> tag-opening lexer slice char: \` lex-til-not-char 2nip set: tag-opening
tag-opening [ char: \` = ] count-tail :> count tag-opening [ char: \` = ] count-tail set: count
tag-opening count cut-slice* :> ( tag opening ) tag-opening count cut-slice* set: ( tag opening )
count 1 > [ count 1 > [
lexer opening lex-til-string :> ( n' string' payload closing ) lexer opening lex-til-string set: ( n' string' payload closing )
payload closing tag opening matched-backtick-literal make-matched-literal payload closing tag opening matched-backtick-literal make-matched-literal
[ >string ] change-payload [ >string ] change-payload
] [ ] [

View File

@ -61,13 +61,13 @@ ERROR: unexpected-end n string ;
! Don't include the whitespace in the slice ! Don't include the whitespace in the slice
:: slice-til-whitespace ( n string -- n' string slice/f ch/f ) :: slice-til-whitespace ( n string -- n' string slice/f ch/f )
n string [ "\s\r\n" member? ] find-from :> ( n' ch ) n string [ "\s\r\n" member? ] find-from set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ; inline ch ; inline
:: (slice-until) ( n string quot -- n' string slice/f ch/f ) :: (slice-until) ( n string quot -- n' string slice/f ch/f )
n string quot find-from :> ( n' ch ) n string quot find-from set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ; inline ch ; inline
@ -76,7 +76,7 @@ ERROR: unexpected-end n string ;
(slice-until) drop ; inline (slice-until) drop ; inline
:: slice-til-not-whitespace ( n string -- n' string slice/f ch/f ) :: slice-til-not-whitespace ( n string -- n' string slice/f ch/f )
n string [ "\s\r\n" member? not ] find-from :> ( n' ch ) n string [ "\s\r\n" member? not ] find-from set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ; inline ch ; inline
@ -92,7 +92,7 @@ ERROR: unexpected-end n string ;
:: slice-til-eol ( n string -- n' string slice/f ch/f ) :: slice-til-eol ( n string -- n' string slice/f ch/f )
n [ n [
n string $[ "\r\n" member? ] find-from :> ( n' ch ) n string $[ "\r\n" member? ] find-from set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
@ -102,7 +102,7 @@ ERROR: unexpected-end n string ;
:: ((merge-slice-til-eol-slash)) ( n string -- n' string slice/f ch/f ) :: ((merge-slice-til-eol-slash)) ( n string -- n' string slice/f ch/f )
n [ n [
n string $[ "\r\n\\" member? ] find-from :> ( n' ch ) n string $[ "\r\n\\" member? ] find-from set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
@ -129,7 +129,7 @@ ERROR: unexpected-end n string ;
over [ ?nth ] [ 2drop f ] if ; over [ ?nth ] [ 2drop f ] if ;
:: (merge-slice-til-eol-slash) ( n string slice -- n' string slice/f ch/f ) :: (merge-slice-til-eol-slash) ( n string slice -- n' string slice/f ch/f )
n string ((merge-slice-til-eol-slash)) :> ( n' string' slice' ch' ) n string ((merge-slice-til-eol-slash)) set: ( n' string' slice' ch' )
ch' char: \ = [ ch' char: \ = [
n' 1 + string' ?nth' "\r\n" member? [ n' 1 + string' ?nth' "\r\n" member? [
n' 2 + string' slice slice' span-slices (merge-slice-til-eol-slash) n' 2 + string' slice slice' span-slices (merge-slice-til-eol-slash)
@ -145,7 +145,7 @@ ERROR: unexpected-end n string ;
2dup empty-slice-from (merge-slice-til-eol-slash) ; 2dup empty-slice-from (merge-slice-til-eol-slash) ;
:: slice-til-separator-inclusive ( n string tokens -- n' string slice/f ch/f ) :: slice-til-separator-inclusive ( n string tokens -- n' string slice/f ch/f )
n string $[ tokens member? ] find-from [ dup [ 1 + ] when ] dip :> ( n' ch ) n string $[ tokens member? ] find-from [ dup [ 1 + ] when ] dip set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ; inline ch ; inline
@ -159,12 +159,12 @@ ERROR: unexpected-end n string ;
n [ n [
n string $[ tokens member? ] find-from n string $[ tokens member? ] find-from
dup "\s\r\n" member? [ dup "\s\r\n" member? [
:> ( n' ch ) set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
] [ ] [
[ dup [ 1 + ] when ] dip :> ( n' ch ) [ dup [ 1 + ] when ] dip set: ( n' ch )
n' string n' string
n n' string ?<slice> n n' string ?<slice>
ch ch
@ -176,7 +176,7 @@ ERROR: unexpected-end n string ;
ERROR: subseq-expected-but-got-eof n string expected ; ERROR: subseq-expected-but-got-eof n string expected ;
:: slice-til-string ( n string search -- n' string payload end-string ) :: slice-til-string ( n string search -- n' string payload end-string )
search string n start* :> n' search string n start* set: n'
n' [ n string search subseq-expected-but-got-eof ] unless n' [ n string search subseq-expected-but-got-eof ] unless
n' search length + string n' search length + string
n n' string ?<slice> n n' string ?<slice>
@ -185,7 +185,7 @@ ERROR: subseq-expected-but-got-eof n string expected ;
ERROR: char-expected-but-got-eof n string expected ; ERROR: char-expected-but-got-eof n string expected ;
:: slice-til-not-char ( n string slice char -- n' string found ) :: slice-til-not-char ( n string slice char -- n' string found )
n string [ char = not ] find-from drop :> n' n string [ char = not ] find-from drop set: n'
n' [ n string char char-expected-but-got-eof ] unless n' [ n string char char-expected-but-got-eof ] unless
B B
n' n'

View File

@ -6,7 +6,7 @@ IN: multiline
PRIVATE< PRIVATE<
:: scan-multiline-string ( i end lexer -- j ) :: scan-multiline-string ( i end lexer -- j )
lexer line-text>> :> text lexer line-text>> set: text
lexer still-parsing? [ lexer still-parsing? [
end text i start* |[ j | end text i start* |[ j |
i j text subseq % j end length + i j text subseq % j end length +

View File

@ -166,19 +166,19 @@ M: object apply-object push-literal ;
dup pair? [ second dup effect? [ drop f ] unless ] [ drop f ] if ; dup pair? [ second dup effect? [ drop f ] unless ] [ drop f ] if ;
:: declare-effect-d ( word effect variables branches n -- ) :: declare-effect-d ( word effect variables branches n -- )
meta-d length :> d-length meta-d length set: d-length
n d-length < [ n d-length < [
d-length 1 - n - :> n' d-length 1 - n - set: n'
n' meta-d nth :> value n' meta-d nth set: value
value known :> known value known set: known
known word effect variables branches <declared-effect> :> known' known word effect variables branches <declared-effect> set: known'
known' value set-known known' value set-known
known' branches push known' branches push
] [ word unknown-macro-input ] if ; ] [ word unknown-macro-input ] if ;
:: declare-input-effects ( word -- ) :: declare-input-effects ( word -- )
H{ } clone :> variables H{ } clone set: variables
V{ } clone :> branches V{ } clone set: branches
word stack-effect in>> <reversed> |[ in n | word stack-effect in>> <reversed> |[ in n |
in ?quotation-effect |[ effect | in ?quotation-effect |[ effect |
word effect variables branches n declare-effect-d word effect variables branches n declare-effect-d

View File

@ -206,10 +206,10 @@ M: object infer-call* \ call bad-macro-input ;
\ load-local [ infer-load-local ] "special" set-word-prop \ load-local [ infer-load-local ] "special" set-word-prop
:: infer-get-local ( -- ) :: infer-get-local ( -- )
pop-literal nip 1 swap - :> n pop-literal nip 1 swap - set: n
n consume-r :> in-r n consume-r set: in-r
in-r first copy-value 1array :> out-d in-r first copy-value 1array set: out-d
in-r copy-values :> out-r in-r copy-values set: out-r
out-d output-d out-d output-d
out-r output-r out-r output-r

View File

@ -410,8 +410,8 @@ IN: bootstrap.syntax
"IDENTITY-MEMO:" [ (:) define-identity-memoized ] define-core-syntax "IDENTITY-MEMO:" [ (:) define-identity-memoized ] define-core-syntax
"IDENTITY-MEMO::" [ (::) define-identity-memoized ] define-core-syntax "IDENTITY-MEMO::" [ (::) define-identity-memoized ] define-core-syntax
":>" [ "set:" [
in-lambda? get [ :>-outside-lambda-error ] unless in-lambda? get [ set:-outside-lambda-error ] unless
scan-token parse-def suffix! scan-token parse-def suffix!
] define-core-syntax ] define-core-syntax

View File

@ -18,7 +18,7 @@ MACRO: declare1 ( type -- quot: ( value -- value ) )
PRIVATE> PRIVATE>
:: (typed-get) ( name type getter: ( name -- value ) -- value ) :: (typed-get) ( name type getter: ( name -- value ) -- value )
name getter call :> value name getter call set: value
value type instance? [ name value type variable-type-error ] unless value type instance? [ name value type variable-type-error ] unless
value type declare1 ; inline value type declare1 ; inline

View File

@ -67,7 +67,7 @@ PRIVATE<
[ (unboxed-types) ] map concat ; [ (unboxed-types) ] map concat ;
:: typed-inputs ( quot word types -- quot' ) :: typed-inputs ( quot word types -- quot' )
types unboxed-types :> unboxed-types types unboxed-types set: unboxed-types
[ input-mismatch-error ] word types make-unboxer [ input-mismatch-error ] word types make-unboxer
unboxed-types quot $[ _ declare @ ] unboxed-types quot $[ _ declare @ ]

View File

@ -137,7 +137,7 @@ M: range-observer model-changed
:: create-gadgets ( -- gadgets ) :: create-gadgets ( -- gadgets )
<shelf> <shelf>
<boids-gadget> :> boids-gadget <boids-gadget> set: boids-gadget
boids-gadget [ start-boids-thread ] keep boids-gadget [ start-boids-thread ] keep
add-gadget add-gadget

View File

@ -65,10 +65,10 @@ GENERIC: force ( neighbors boid behaviour -- force ) ;
:: simulate ( boids behaviours dt -- boids ) :: simulate ( boids behaviours dt -- boids )
boids |[ boid | boids |[ boid |
boid boids behaviours boid boids behaviours
[ [ (force) ] keep weight>> v*n ] 2with map vsum :> a [ [ (force) ] keep weight>> v*n ] 2with map vsum set: a
boid vel>> a dt v*n v+ normalize :> vel boid vel>> a dt v*n v+ normalize set: vel
boid pos>> vel dt v*n v+ wrap-pos :> pos boid pos>> vel dt v*n v+ wrap-pos set: pos
pos vel <boid> pos vel <boid>
] map ; ] map ;
@ -95,6 +95,6 @@ M: alignment force ( neighbors boid behaviour -- force )
2drop [ vel>> ] map vsum normalize ; 2drop [ vel>> ] map vsum normalize ;
M:: separation force ( neighbors boid behaviour -- force ) M:: separation force ( neighbors boid behaviour -- force )
behaviour radius>> :> r behaviour radius>> set: r
boid pos>> neighbors boid pos>> neighbors
[ pos>> v- [ normalize ] [ r v/n ] bi v- ] with map vsum ; [ pos>> v- [ normalize ] [ r v/n ] bi v- ] with map vsum ;

View File

@ -33,7 +33,7 @@ IN: project-euler.073
PRIVATE< PRIVATE<
:: (euler073) ( counter limit lo hi -- counter' ) :: (euler073) ( counter limit lo hi -- counter' )
lo hi mediant :> m lo hi mediant set: m
m denominator limit <= [ m denominator limit <= [
counter 1 + counter 1 +
limit lo m (euler073) limit lo m (euler073)

View File

@ -51,7 +51,7 @@ PRIVATE<
0 1000 [1,b] [ [ next ] replicate partial-sums ] map nip ; inline 0 1000 [1,b] [ [ next ] replicate partial-sums ] map nip ; inline
:: (euler150) ( m -- n ) :: (euler150) ( m -- n )
sums-triangle :> table sums-triangle set: table
m iota |[ x | m iota |[ x |
x 1 + iota |[ y | x 1 + iota |[ y |
m x - iota |[ z | m x - iota |[ z |

View File

@ -22,8 +22,8 @@ IN: rosetta-code.balanced-brackets
! [[][]] OK []][[] NOT OK ! [[][]] OK []][[] NOT OK
:: balanced? ( str -- ? ) :: balanced? ( str -- ? )
0 :> counter! 0 set: counter!
t :> ok! t set: ok!
str [ str [
{ {
{ char: \[ [ 1 ] } { char: \[ [ 1 ] }

View File

@ -11,7 +11,7 @@ IN: rosetta-code.bitmap-bezier
! draw a cubic bezier curves (definition on Wikipedia). ! draw a cubic bezier curves (definition on Wikipedia).
:: (cubic-bezier) ( P0 P1 P2 P3 -- bezier ) :: (cubic-bezier) ( P0 P1 P2 P3 -- bezier )
[ :> x [ set: x
1 x - 3 ^ P0 n*v 1 x - 3 ^ P0 n*v
1 x - sq 3 * x * P1 n*v 1 x - sq 3 * x * P1 n*v
1 x - 3 * x sq * P2 n*v 1 x - 3 * x sq * P2 n*v

View File

@ -12,9 +12,9 @@ IN: rosetta-code.bitmap-line
! algorithm. ! algorithm.
:: line-points ( pt1 pt2 -- points ) :: line-points ( pt1 pt2 -- points )
pt1 first2 :> y0! :> x0! pt1 first2 set: y0! set: x0!
pt2 first2 :> y1! :> x1! pt2 first2 set: y1! set: x1!
y1 y0 - abs x1 x0 - abs > :> steep y1 y0 - abs x1 x0 - abs > set: steep
steep [ steep [
y0 x0 y0! x0! y0 x0 y0! x0!
y1 x1 y1! x1! y1 x1 y1! x1!
@ -23,12 +23,12 @@ IN: rosetta-code.bitmap-line
x0 x1 x0! x1! x0 x1 x0! x1!
y0 y1 y0! y1! y0 y1 y0! y1!
] when ] when
x1 x0 - :> deltax x1 x0 - set: deltax
y1 y0 - abs :> deltay y1 y0 - abs set: deltay
0 :> current-error! 0 set: current-error!
deltay deltax / abs :> deltaerr deltay deltax / abs set: deltaerr
0 :> ystep! 0 set: ystep!
y0 :> y! y0 set: y!
y0 y1 < [ 1 ystep! ] [ -1 ystep! ] if y0 y1 < [ 1 ystep! ] [ -1 ystep! ] if
x0 x1 1 <range> [ x0 x1 1 <range> [
y steep [ swap ] when 2array y steep [ swap ] when 2array

View File

@ -50,7 +50,7 @@ M: pi cfrac-b
:: cfrac-estimate ( cfrac terms -- number ) :: cfrac-estimate ( cfrac terms -- number )
terms cfrac cfrac-a ! top = last a_n terms cfrac cfrac-a ! top = last a_n
terms 1 - 1 [a,b] [ :> n terms 1 - 1 [a,b] [ set: n
n cfrac cfrac-b swap / ! top = b_n / top n cfrac cfrac-b swap / ! top = b_n / top
n cfrac cfrac-a + ! top = top + a_n n cfrac cfrac-a + ! top = top + a_n
] each ; ] each ;
@ -59,7 +59,7 @@ M: pi cfrac-b
rational 1 /mod ! split whole, fractional parts rational 1 /mod ! split whole, fractional parts
prec 10^ * ! multiply fraction by 10 ^ prec prec 10^ * ! multiply fraction by 10 ^ prec
[ >integer unparse ] bi@ ! convert digits to strings [ >integer unparse ] bi@ ! convert digits to strings
:> fraction set: fraction
"." ! push decimal point "." ! push decimal point
prec fraction length - prec fraction length -
dup 0 < [ drop 0 ] when dup 0 < [ drop 0 ] when

View File

@ -29,7 +29,7 @@ IN: rosetta-code.count-the-coins
PRIVATE< PRIVATE<
:: (make-change) ( cents coins -- ways ) :: (make-change) ( cents coins -- ways )
cents 1 + 0 <array> :> ways cents 1 + 0 <array> set: ways
1 ways set-first 1 ways set-first
coins |[ coin | coins |[ coin |
coin cents [a,b] |[ j | coin cents [a,b] |[ j |

View File

@ -70,7 +70,7 @@ IN: rosetta-code.dice7
! deviation from the ideal number of items in each bucket, ! deviation from the ideal number of items in each bucket,
! expressed as a fraction of the total count. ! expressed as a fraction of the total count.
:: test-distribution ( #sides #trials quot error -- ) :: test-distribution ( #sides #trials quot error -- )
#sides #trials quot replicate count-outcomes :> outcomes #sides #trials quot replicate count-outcomes set: outcomes
outcomes . outcomes .
outcomes error fair-counts? outcomes error fair-counts?
"Random enough" "Not random enough" ? . ; inline "Random enough" "Not random enough" ? . ; inline

View File

@ -37,7 +37,7 @@ IN: rosetta-code.gray-code
: gray-encode ( n -- n' ) dup -1 shift bitxor ; : gray-encode ( n -- n' ) dup -1 shift bitxor ;
:: gray-decode ( n! -- n' ) :: gray-decode ( n! -- n' )
n :> p! n set: p!
[ n -1 shift dup n! 0 = not ] [ [ n -1 shift dup n! 0 = not ] [
p n bitxor p! p n bitxor p!
] while ] while

View File

@ -21,8 +21,8 @@ IN: rosetta-code.hamming-lazy
! a convenient library supports arbitrary-precision integers). ! a convenient library supports arbitrary-precision integers).
:: sort-merge ( xs ys -- result ) :: sort-merge ( xs ys -- result )
xs car :> x xs car set: x
ys car :> y ys car set: y
{ {
{ [ x y < ] [ [ x ] [ xs cdr ys sort-merge ] lazy-cons ] } { [ x y < ] [ [ x ] [ xs cdr ys sort-merge ] lazy-cons ] }
{ [ x y > ] [ [ y ] [ ys cdr xs sort-merge ] lazy-cons ] } { [ x y > ] [ [ y ] [ ys cdr xs sort-merge ] lazy-cons ] }
@ -30,7 +30,7 @@ IN: rosetta-code.hamming-lazy
} cond ; } cond ;
:: hamming ( -- hamming ) :: hamming ( -- hamming )
f :> h! f set: h!
[ 1 ] [ [ 1 ] [
h 2 3 5 [ $[ _ * ] lmap-lazy ] tri-curry@ tri h 2 3 5 [ $[ _ * ] lmap-lazy ] tri-curry@ tri
sort-merge sort-merge sort-merge sort-merge

View File

@ -60,9 +60,9 @@ CONSTANT: limit 400 ;
items length 1 + [ limit 1 + 0 <array> ] replicate ; items length 1 + [ limit 1 + 0 <array> ] replicate ;
:: iterate ( item-no table -- ) :: iterate ( item-no table -- )
item-no table nth :> prev item-no table nth set: prev
item-no 1 + table nth :> curr item-no 1 + table nth set: curr
item-no items nth :> item item-no items nth set: item
limit [1,b] |[ weight | limit [1,b] |[ weight |
weight prev nth weight prev nth
weight item weight>> - dup 0 >= weight item weight>> - dup 0 >=
@ -77,10 +77,10 @@ CONSTANT: limit 400 ;
:: extract-packed-items ( table -- items ) :: extract-packed-items ( table -- items )
[ [
limit :> weight! limit set: weight!
items length iota <reversed> |[ item-no | items length iota <reversed> |[ item-no |
item-no table nth :> prev item-no table nth set: prev
item-no 1 + table nth :> curr item-no 1 + table nth set: curr
weight [ curr nth ] [ prev nth ] bi = weight [ curr nth ] [ prev nth ] bi =
[ [
item-no items nth item-no items nth

View File

@ -9,7 +9,7 @@ IN: rosetta-code.n-queens
! solve the puzzle with a board of side NxN. ! solve the puzzle with a board of side NxN.
:: safe? ( board q -- ? ) :: safe? ( board q -- ? )
let[ q board nth :> x let[ q board nth set: x
q iota [ q iota [
x swap x swap
[ board nth ] keep [ board nth ] keep

View File

@ -50,9 +50,9 @@ PRIVATE<
PRIVATE> PRIVATE>
:: read-odd-word ( -- ) :: read-odd-word ( -- )
f :> first-continuation! f set: first-continuation!
f :> last-continuation! f set: last-continuation!
f :> reverse! f set: reverse!
! Read characters. Loop until end of stream. ! Read characters. Loop until end of stream.
[ read1 dup ] [ [ read1 dup ] [
dup Letter? [ dup Letter? [

View File

@ -87,7 +87,7 @@ M: ast-return compile-ast
[ <def> [ f ] swap suffix ] map [ ] join ; [ <def> [ f ] swap suffix ] map [ ] join ;
:: compile-sequence ( lexenv block -- vars quot ) :: compile-sequence ( lexenv block -- vars quot )
lexenv block block-lexenv lexenv-union :> lexenv lexenv block block-lexenv lexenv-union set: lexenv
block arguments>> lexenv lookup-block-vars block arguments>> lexenv lookup-block-vars
lexenv block body>> (compile-sequence) block lexenv make-temporaries prepend ; lexenv block body>> (compile-sequence) block lexenv make-temporaries prepend ;

View File

@ -129,7 +129,7 @@ CONSTANT: otug-slides
"Area of a triangle using Heron's formula" "Area of a triangle using Heron's formula"
{ $code { $code
":: area ( a b c -- x ) ":: area ( a b c -- x )
a b c + + 2 / :> p a b c + + 2 / set: p
p p
p a - * p a - *
p b - * p b - *

View File

@ -12,11 +12,11 @@ IN: cairo-samples
TUPLE: arc-gadget < cairo-gadget ; TUPLE: arc-gadget < cairo-gadget ;
M:: arc-gadget render-cairo* ( gadget -- ) M:: arc-gadget render-cairo* ( gadget -- )
128.0 :> xc 128.0 set: xc
128.0 :> yc 128.0 set: yc
100.0 :> radius 100.0 set: radius
pi 1/4 * :> angle1 pi 1/4 * set: angle1
pi :> angle2 pi set: angle2
cr 10.0 cairo_set_line_width cr 10.0 cairo_set_line_width
cr xc yc radius angle1 angle2 cairo_arc cr xc yc radius angle1 angle2 cairo_arc
cr cairo_stroke cr cairo_stroke
@ -55,9 +55,9 @@ M: clip-gadget render-cairo* ( gadget -- )
TUPLE: clip-image-gadget < cairo-gadget ; TUPLE: clip-image-gadget < cairo-gadget ;
M:: clip-image-gadget render-cairo* ( gadget -- ) M:: clip-image-gadget render-cairo* ( gadget -- )
"resource:misc/icons/Factor_128x128.png" "resource:misc/icons/Factor_128x128.png"
normalize-path cairo_image_surface_create_from_png :> png normalize-path cairo_image_surface_create_from_png set: png
png cairo_image_surface_get_width :> w png cairo_image_surface_get_width set: w
png cairo_image_surface_get_height :> h png cairo_image_surface_get_height set: h
cr 128 128 76.8 0 2 pi * cairo_arc cr 128 128 76.8 0 2 pi * cairo_arc
cr cairo_clip cr cairo_clip
cr cairo_new_path cr cairo_new_path
@ -69,8 +69,8 @@ M:: clip-image-gadget render-cairo* ( gadget -- )
TUPLE: dash-gadget < cairo-gadget ; TUPLE: dash-gadget < cairo-gadget ;
M:: dash-gadget render-cairo* ( gadget -- ) M:: dash-gadget render-cairo* ( gadget -- )
double-array{ 50 10 10 10 } underlying>> :> dashes double-array{ 50 10 10 10 } underlying>> set: dashes
4 :> ndash 4 set: ndash
cr dashes ndash -50 cairo_set_dash cr dashes ndash -50 cairo_set_dash
cr 10 cairo_set_line_width cr 10 cairo_set_line_width
cr 128.0 25.6 cairo_move_to cr 128.0 25.6 cairo_move_to
@ -81,9 +81,9 @@ M:: dash-gadget render-cairo* ( gadget -- )
TUPLE: gradient-gadget < cairo-gadget ; TUPLE: gradient-gadget < cairo-gadget ;
M:: gradient-gadget render-cairo* ( gadget -- ) M:: gradient-gadget render-cairo* ( gadget -- )
0 0 0 256 cairo_pattern_create_linear :> pat 0 0 0 256 cairo_pattern_create_linear set: pat
115.2 102.4 25.6 102.4 102.4 128.0 115.2 102.4 25.6 102.4 102.4 128.0
cairo_pattern_create_radial :> radial cairo_pattern_create_radial set: radial
pat 1 0 0 0 1 cairo_pattern_add_color_stop_rgba pat 1 0 0 0 1 cairo_pattern_add_color_stop_rgba
pat 0 1 1 1 1 cairo_pattern_add_color_stop_rgba pat 0 1 1 1 1 cairo_pattern_add_color_stop_rgba
cr 0 0 256 256 cairo_rectangle cr 0 0 256 256 cairo_rectangle

View File

@ -17,9 +17,9 @@ CONSTANT: NS-EACH-BUFFER-SIZE 16 ;
] with-destructors ; inline ] with-destructors ; inline
:: (NSFastEnumeration-each) ( ... object quot: ( ... elt -- ) state stackbuf count -- ... ) :: (NSFastEnumeration-each) ( ... object quot: ( ... elt -- ) state stackbuf count -- ... )
object state stackbuf count send\ countByEnumeratingWithState:objects:count: :> items-count object state stackbuf count send\ countByEnumeratingWithState:objects:count: set: items-count
items-count 0 = [ items-count 0 = [
state itemsPtr>> [ items-count id <c-direct-array> ] [ stackbuf ] if* :> items state itemsPtr>> [ items-count id <c-direct-array> ] [ stackbuf ] if* set: items
items-count iota [ items nth quot call ] each items-count iota [ items nth quot call ] each
object quot state stackbuf count (NSFastEnumeration-each) object quot state stackbuf count (NSFastEnumeration-each)
] unless ; inline recursive ] unless ; inline recursive

View File

@ -49,7 +49,7 @@ IN: cocoa.subclassing
] with-nested-compilation-unit ; ] with-nested-compilation-unit ;
:: (redefine-objc-method) ( class method -- ) :: (redefine-objc-method) ( class method -- )
method init-method :> ( sel imp types ) method init-method set: ( sel imp types )
class sel class_getInstanceMethod [ class sel class_getInstanceMethod [
imp method_setImplementation drop imp method_setImplementation drop
@ -63,7 +63,7 @@ IN: cocoa.subclassing
] [ 2drop ] if ; ] [ 2drop ] if ;
:: define-objc-class ( name superclass protocols methods -- ) :: define-objc-class ( name superclass protocols methods -- )
methods prepare-methods :> methods methods prepare-methods set: methods
name "cocoa.classes" create-word drop name "cocoa.classes" create-word drop
methods name redefine-objc-methods methods name redefine-objc-methods
name [ methods protocols superclass name (define-objc-class) ] import-objc-class ; name [ methods protocols superclass name (define-objc-class) ] import-objc-class ;

View File

@ -20,8 +20,8 @@ IN: core-text.tests
:: test-typographic-bounds ( string font -- ? ) :: test-typographic-bounds ( string font -- ? )
[ [
font test-font &CFRelease :> ctfont font test-font &CFRelease set: ctfont
string ctfont color: white <CTLine> &CFRelease :> ctline string ctfont color: white <CTLine> &CFRelease set: ctline
ctfont ctline compute-line-metrics { ctfont ctline compute-line-metrics {
[ width>> float? ] [ width>> float? ]
[ ascent>> float? ] [ ascent>> float? ]

View File

@ -116,8 +116,8 @@ render-loc render-dim ;
:: <line> ( font string -- line ) :: <line> ( font string -- line )
[ [
line new-disposable line new-disposable
font retina? get-global [ cache-font@2x ] [ cache-font ] if :> open-font font retina? get-global [ cache-font@2x ] [ cache-font ] if set: open-font
string open-font font foreground>> <CTLine> |CFRelease :> line string open-font font foreground>> <CTLine> |CFRelease set: line
open-font line compute-line-metrics open-font line compute-line-metrics
[ >>metrics ] [ metrics>dim >>dim ] bi [ >>metrics ] [ metrics>dim >>dim ] bi
font >>font font >>font
@ -126,18 +126,18 @@ render-loc render-dim ;
] with-destructors ; ] with-destructors ;
:: render ( line -- line image ) :: render ( line -- line image )
line line>> :> ctline line line>> set: ctline
line string>> :> string line string>> set: string
line font>> :> font line font>> set: font
line render-loc>> [ line render-loc>> [
ctline line-rect :> rect ctline line-rect set: rect
rect origin>> CGPoint>loc :> (loc) rect origin>> CGPoint>loc set: (loc)
rect size>> CGSize>dim :> (dim) rect size>> CGSize>dim set: (dim)
(loc) vfloor :> loc (loc) vfloor set: loc
(loc) (dim) v+ vceiling :> ext (loc) (dim) v+ vceiling set: ext
ext loc [ - >integer 1 max ] 2map :> dim ext loc [ - >integer 1 max ] 2map set: dim
loc line render-loc<< loc line render-loc<<
dim line render-dim<< dim line render-dim<<
@ -146,8 +146,8 @@ render-loc render-dim ;
] unless ] unless
line render-loc>> :> loc line render-loc>> set: loc
line render-dim>> :> dim line render-dim>> set: dim
line dim [ line dim [
{ {

View File

@ -75,10 +75,10 @@ IN: cuda.devices
:: (distribute-jobs) ( job-count per-job-shared max-shared-size max-block-size :: (distribute-jobs) ( job-count per-job-shared max-shared-size max-block-size
-- grid-size block-size per-block-shared ) -- grid-size block-size per-block-shared )
per-job-shared [ max-block-size ] [ max-shared-size swap /i max-block-size min ] if-zero per-job-shared [ max-block-size ] [ max-shared-size swap /i max-block-size min ] if-zero
job-count min :> job-max-block-size job-count min set: job-max-block-size
job-count job-max-block-size up/i :> grid-size job-count job-max-block-size up/i set: grid-size
job-count grid-size up/i :> block-size job-count grid-size up/i set: block-size
block-size per-job-shared * :> per-block-shared block-size per-job-shared * set: per-block-shared
grid-size block-size per-block-shared ; inline grid-size block-size per-block-shared ; inline

View File

@ -23,7 +23,7 @@ M: macosx nvcc-path "/usr/local/cuda/bin/nvcc" ;
ERROR: nvcc-failed n path ; ERROR: nvcc-failed n path ;
:: compile-cu ( path -- path' ) :: compile-cu ( path -- path' )
path normalize-path :> path2 path normalize-path set: path2
path2 parent-directory [ path2 parent-directory [
path2 nvcc-command path2 nvcc-command
run-process wait-for-process [ path2 nvcc-failed ] unless-zero run-process wait-for-process [ path2 nvcc-failed ] unless-zero

View File

@ -290,7 +290,7 @@ PRIVATE<
:: (wcread) ( n encoding window-ptr -- string ) :: (wcread) ( n encoding window-ptr -- string )
[ [
n 1 + malloc &free :> str n 1 + malloc &free set: str
window-ptr str n ffi:wgetnstr curses-error window-ptr str n ffi:wgetnstr curses-error
str encoding alien>string str encoding alien>string
] with-destructors ; inline ] with-destructors ; inline

View File

@ -39,11 +39,11 @@ PRIVATE>
[ &BN_clear_free EC_KEY_set_private_key ssl-error ] with-destructors ; [ &BN_clear_free EC_KEY_set_private_key ssl-error ] with-destructors ;
:: set-public-key ( BIN -- ) :: set-public-key ( BIN -- )
ec-key-handle :> KEY ec-key-handle set: KEY
KEY EC_KEY_get0_group :> GROUP KEY EC_KEY_get0_group set: GROUP
GROUP EC_POINT_new dup ssl-error GROUP EC_POINT_new dup ssl-error
[ [
&EC_POINT_clear_free :> POINT &EC_POINT_clear_free set: POINT
GROUP POINT BIN dup length f EC_POINT_oct2point ssl-error GROUP POINT BIN dup length f EC_POINT_oct2point ssl-error
KEY POINT EC_KEY_set_public_key ssl-error KEY POINT EC_KEY_set_public_key ssl-error
] with-destructors ; ] with-destructors ;
@ -53,21 +53,21 @@ PRIVATE>
dup [ dup BN_num_bits bits>bytes <byte-array> [ BN_bn2bin drop ] keep ] when ; dup [ dup BN_num_bits bits>bytes <byte-array> [ BN_bn2bin drop ] keep ] when ;
:: get-public-key ( -- bin/f ) :: get-public-key ( -- bin/f )
ec-key-handle :> KEY ec-key-handle set: KEY
KEY EC_KEY_get0_public_key dup KEY EC_KEY_get0_public_key dup
|[ PUB | |[ PUB |
KEY EC_KEY_get0_group :> GROUP KEY EC_KEY_get0_group set: GROUP
GROUP EC_GROUP_get_degree bits>bytes 1 + :> LEN GROUP EC_GROUP_get_degree bits>bytes 1 + set: LEN
LEN <byte-array> :> BIN LEN <byte-array> set: BIN
GROUP PUB POINT_CONVERSION_COMPRESSED BIN LEN f GROUP PUB POINT_CONVERSION_COMPRESSED BIN LEN f
EC_POINT_point2oct ssl-error EC_POINT_point2oct ssl-error
BIN BIN
] when ; ] when ;
:: ecdsa-sign ( DGST -- sig ) :: ecdsa-sign ( DGST -- sig )
ec-key-handle :> KEY ec-key-handle set: KEY
KEY ECDSA_size dup ssl-error <byte-array> :> SIG KEY ECDSA_size dup ssl-error <byte-array> set: SIG
0 uint <ref> :> LEN 0 uint <ref> set: LEN
0 DGST dup length SIG LEN KEY ECDSA_sign ssl-error 0 DGST dup length SIG LEN KEY ECDSA_sign ssl-error
LEN uint deref SIG resize ; LEN uint deref SIG resize ;

View File

@ -25,7 +25,7 @@ PRIVATE<
[ first2 rect> ] { } map-as ; [ first2 rect> ] { } map-as ;
:: (fft1d) ( seq sign -- seq' ) :: (fft1d) ( seq sign -- seq' )
seq length :> n seq length set: n
[ [
n n
seq >fftw-array seq >fftw-array

View File

@ -83,7 +83,7 @@ DESTRUCTOR: gdbm-close
:: (setopt) ( value option -- ) :: (setopt) ( value option -- )
[ [
int heap-size dup malloc &free :> ( size ptr ) int heap-size dup malloc &free set: ( size ptr )
value ptr 0 int set-alien-value value ptr 0 int set-alien-value
dbf option ptr size gdbm_setopt check-error dbf option ptr size gdbm_setopt check-error
] with-destructors ; ] with-destructors ;

View File

@ -37,7 +37,7 @@ PRIVATE<
path exists? path exists?
[ path ] [ [ path ] [
current-vocab-dirs custom-gir-dirs system-gir-dirs current-vocab-dirs custom-gir-dirs system-gir-dirs
3append sift :> paths 3append sift set: paths
paths [ path append-path exists? ] find nip paths [ path append-path exists? ] find nip
[ path append-path ] [ path paths gir-not-found ] if* [ path append-path ] [ path paths gir-not-found ] if*
] if ; ] if ;

View File

@ -8,21 +8,21 @@ IN: gtk-samples.hello-world
nip "Hello! :)" utf8 string>alien gtk_label_set_text ; nip "Hello! :)" utf8 string>alien gtk_label_set_text ;
:: hello-world-win ( -- window ) :: hello-world-win ( -- window )
GTK_WINDOW_TOPLEVEL gtk_window_new :> window GTK_WINDOW_TOPLEVEL gtk_window_new set: window
window window
[ "Hello world!" utf8 string>alien gtk_window_set_title ] [ "Hello world!" utf8 string>alien gtk_window_set_title ]
[ 300 200 gtk_window_set_default_size ] [ 300 200 gtk_window_set_default_size ]
[ GTK_WIN_POS_CENTER gtk_window_set_position ] tri [ GTK_WIN_POS_CENTER gtk_window_set_position ] tri
gtk_fixed_new :> frame gtk_fixed_new set: frame
window frame gtk_container_add window frame gtk_container_add
"Say 'Hello!'" utf8 string>alien gtk_button_new_with_label :> button "Say 'Hello!'" utf8 string>alien gtk_button_new_with_label set: button
button 140 30 gtk_widget_set_size_request button 140 30 gtk_widget_set_size_request
frame button 80 60 gtk_fixed_put frame button 80 60 gtk_fixed_put
"" utf8 string>alien gtk_label_new :> label "" utf8 string>alien gtk_label_new set: label
frame label 120 110 gtk_fixed_put frame label 120 110 gtk_fixed_put
button "clicked" utf8 string>alien button "clicked" utf8 string>alien
@ -33,7 +33,7 @@ IN: gtk-samples.hello-world
:: hello-world-main ( -- ) :: hello-world-main ( -- )
f f gtk_init f f gtk_init
hello-world-win :> window hello-world-win set: window
window "destroy" utf8 string>alien window "destroy" utf8 string>alien
[ 2drop gtk_main_quit ] GtkObject:destroy f [ 2drop gtk_main_quit ] GtkObject:destroy f

View File

@ -8,8 +8,8 @@ IN: gtk-samples.opengl
! http://code.valaide.org/content/simple-opengl-sample-using-gtkglext ! http://code.valaide.org/content/simple-opengl-sample-using-gtkglext
:: on-configure ( sender event user-data -- result ) :: on-configure ( sender event user-data -- result )
sender gtk_widget_get_gl_context :> gl-context sender gtk_widget_get_gl_context set: gl-context
sender gtk_widget_get_gl_window :> gl-drawable sender gtk_widget_get_gl_window set: gl-drawable
gl-drawable gl-context gdk_gl_drawable_gl_begin dup gl-drawable gl-context gdk_gl_drawable_gl_begin dup
[ [
@ -18,8 +18,8 @@ IN: gtk-samples.opengl
] when ; ] when ;
:: on-expose ( sender event user-data -- result ) :: on-expose ( sender event user-data -- result )
sender gtk_widget_get_gl_context :> gl-context sender gtk_widget_get_gl_context set: gl-context
sender gtk_widget_get_gl_window :> gl-drawable sender gtk_widget_get_gl_window set: gl-drawable
gl-drawable gl-context gdk_gl_drawable_gl_begin dup gl-drawable gl-context gdk_gl_drawable_gl_begin dup
[ [
@ -42,14 +42,14 @@ IN: gtk-samples.opengl
] when ; ] when ;
:: opengl-win ( -- window ) :: opengl-win ( -- window )
GTK_WINDOW_TOPLEVEL gtk_window_new :> window GTK_WINDOW_TOPLEVEL gtk_window_new set: window
window window
[ "OpenGL" utf8 string>alien gtk_window_set_title ] [ "OpenGL" utf8 string>alien gtk_window_set_title ]
[ 200 200 gtk_window_set_default_size ] [ 200 200 gtk_window_set_default_size ]
[ GTK_WIN_POS_CENTER gtk_window_set_position ] tri [ GTK_WIN_POS_CENTER gtk_window_set_position ] tri
GDK_GL_MODE_RGBA gdk_gl_config_new_by_mode :> gl-config GDK_GL_MODE_RGBA gdk_gl_config_new_by_mode set: gl-config
window gl-config f t GDK_GL_RGBA_TYPE window gl-config f t GDK_GL_RGBA_TYPE
gtk_widget_set_gl_capability drop gtk_widget_set_gl_capability drop
@ -67,7 +67,7 @@ IN: gtk-samples.opengl
:: opengl-main ( -- ) :: opengl-main ( -- )
f f gtk_init f f gtk_init
f f gtk_gl_init f f gtk_gl_init
opengl-win :> window opengl-win set: window
window "destroy" utf8 string>alien window "destroy" utf8 string>alien
[ 2drop gtk_main_quit ] GtkObject:destroy [ 2drop gtk_main_quit ] GtkObject:destroy

View File

@ -943,7 +943,7 @@ TYPED: load-commands ( macho: mach_header_32/64 -- load-commands )
: macho-nm ( path -- ) : macho-nm ( path -- )
|[ macho | |[ macho |
macho load-commands segment-commands sections-array :> sections macho load-commands segment-commands sections-array set: sections
macho load-commands symtab-commands |[ symtab | macho load-commands symtab-commands |[ symtab |
macho symtab symbols [ macho symtab symbols [
[ drop n_value>> "%016x " printf ] [ drop n_value>> "%016x " printf ]

View File

@ -132,11 +132,11 @@ PRIVATE>
:: verify-nodes ( mdb -- ) :: verify-nodes ( mdb -- )
[ [
V{ } clone :> acc V{ } clone set: acc
mdb dup master-node [ check-node ] keep :> node1 mdb dup master-node [ check-node ] keep set: node1
mdb node1 remote>> mdb node1 remote>>
[ [ check-node ] keep ] [ [ check-node ] keep ]
[ drop f ] if* :> node2 [ drop f ] if* set: node2
node1 [ acc push ] when* node1 [ acc push ] when*
node2 [ acc push ] when* node2 [ acc push ] when*
mdb acc nodelist>table >>nodes drop mdb acc nodelist>table >>nodes drop

View File

@ -164,8 +164,8 @@ PRIVATE<
: check-collection ( collection -- fq-collection ) : check-collection ( collection -- fq-collection )
let[ let[
mdb-instance :> instance mdb-instance set: instance
instance name>> :> instance-name instance name>> set: instance-name
dup mdb-collection? [ name>> ] when dup mdb-collection? [ name>> ] when
"." split1 over instance-name = "." split1 over instance-name =
[ nip ] [ drop ] if [ nip ] [ drop ] if

View File

@ -88,7 +88,7 @@ PRIVATE<
] with-output-stream* write flush ; inline ] with-output-stream* write flush ; inline
:: build-query-object ( query -- selector ) :: build-query-object ( query -- selector )
H{ } clone :> selector H{ } clone set: selector
query { query {
[ orderby>> [ "$orderby" selector set-at ] when* ] [ orderby>> [ "$orderby" selector set-at ] when* ]
[ explain>> [ "$explain" selector set-at ] when* ] [ explain>> [ "$explain" selector set-at ] when* ]

View File

@ -24,16 +24,16 @@ ERROR: cl-error err ;
dup CL_SUCCESS = [ drop ] [ cl-error ] if ; dup CL_SUCCESS = [ drop ] [ cl-error ] if ;
:: cl-string-array ( str -- alien ) :: cl-string-array ( str -- alien )
str ascii encode 0 suffix :> str-buffer str ascii encode 0 suffix set: str-buffer
str-buffer length malloc &free :> str-alien str-buffer length malloc &free set: str-alien
str-alien str-buffer dup length memcpy str-alien ; str-alien str-buffer dup length memcpy str-alien ;
:: opencl-square ( in -- out ) :: opencl-square ( in -- out )
0 f 0 uint <ref> [ clGetPlatformIDs cl-success ] keep uint deref 0 f 0 uint <ref> [ clGetPlatformIDs cl-success ] keep uint deref
dup void* <c-array> [ f clGetPlatformIDs cl-success ] keep first dup void* <c-array> [ f clGetPlatformIDs cl-success ] keep first
CL_DEVICE_TYPE_DEFAULT 1 f void* <ref> [ f clGetDeviceIDs cl-success ] keep void* deref :> device-id CL_DEVICE_TYPE_DEFAULT 1 f void* <ref> [ f clGetDeviceIDs cl-success ] keep void* deref set: device-id
f 1 device-id void* <ref> f f 0 int <ref> [ clCreateContext ] keep int deref cl-success :> context f 1 device-id void* <ref> f f 0 int <ref> [ clCreateContext ] keep int deref cl-success set: context
context device-id 0 0 int <ref> [ clCreateCommandQueue ] keep int deref cl-success :> queue context device-id 0 0 int <ref> [ clCreateCommandQueue ] keep int deref cl-success set: queue
[ [
context 1 kernel-source cl-string-array void* <ref> context 1 kernel-source cl-string-array void* <ref>
@ -41,13 +41,13 @@ ERROR: cl-error err ;
[ 0 f f f f clBuildProgram cl-success ] [ 0 f f f f clBuildProgram cl-success ]
[ "square" cl-string-array 0 int <ref> [ clCreateKernel ] keep int deref cl-success ] [ "square" cl-string-array 0 int <ref> [ clCreateKernel ] keep int deref cl-success ]
[ ] tri [ ] tri
] with-destructors :> ( kernel program ) ] with-destructors set: ( kernel program )
context CL_MEM_READ_ONLY in byte-length f context CL_MEM_READ_ONLY in byte-length f
0 int <ref> [ clCreateBuffer ] keep int deref cl-success :> input 0 int <ref> [ clCreateBuffer ] keep int deref cl-success set: input
context CL_MEM_WRITE_ONLY in byte-length f context CL_MEM_WRITE_ONLY in byte-length f
0 int <ref> [ clCreateBuffer ] keep int deref cl-success :> output 0 int <ref> [ clCreateBuffer ] keep int deref cl-success set: output
queue input CL_TRUE 0 in byte-length in 0 f f clEnqueueWriteBuffer cl-success queue input CL_TRUE 0 in byte-length in 0 f f clEnqueueWriteBuffer cl-success

View File

@ -21,16 +21,16 @@ __kernel void square(
:: opencl-square ( in -- out ) :: opencl-square ( in -- out )
[ [
in byte-length :> num-bytes in byte-length set: num-bytes
in length :> num-floats in length set: num-floats
cl-platforms first devices>> first :> device cl-platforms first devices>> first set: device
device 1array <cl-context> &dispose :> context device 1array <cl-context> &dispose set: context
context device f f <cl-queue> &dispose :> queue context device f f <cl-queue> &dispose set: queue
context device queue [ context device queue [
"" kernel-source 1array <cl-program> &dispose "square" <cl-kernel> &dispose :> kernel "" kernel-source 1array <cl-program> &dispose "square" <cl-kernel> &dispose set: kernel
cl-read-access num-bytes in <cl-buffer> &dispose :> in-buffer cl-read-access num-bytes in <cl-buffer> &dispose set: in-buffer
cl-write-access num-bytes f <cl-buffer> &dispose :> out-buffer cl-write-access num-bytes f <cl-buffer> &dispose set: out-buffer
kernel in-buffer out-buffer num-floats uint <ref> 3array kernel in-buffer out-buffer num-floats uint <ref> 3array
{ num-floats } [ ] cl-queue-kernel &dispose drop { num-floats } [ ] cl-queue-kernel &dispose drop

View File

@ -119,8 +119,8 @@ MACRO: all-enabled-client-state ( seq quot -- quot )
! We use GL_LINE_STRIP with a duplicated first vertex ! We use GL_LINE_STRIP with a duplicated first vertex
! instead of GL_LINE_LOOP to work around a bug in Apple's ! instead of GL_LINE_LOOP to work around a bug in Apple's
! X3100 driver. ! X3100 driver.
loc first2 [ 0.3 + ] bi@ :> ( x y ) loc first2 [ 0.3 + ] bi@ set: ( x y )
dim first2 [ 0.6 - ] bi@ :> ( w h ) dim first2 [ 0.6 - ] bi@ set: ( w h )
[ [
x y x y
x w + y x w + y
@ -139,8 +139,8 @@ MACRO: all-enabled-client-state ( seq quot -- quot )
rect-vertices (gl-rect) ; rect-vertices (gl-rect) ;
:: (fill-rect-vertices) ( loc dim -- vertices ) :: (fill-rect-vertices) ( loc dim -- vertices )
loc first2 :> ( x y ) loc first2 set: ( x y )
dim first2 :> ( w h ) dim first2 set: ( w h )
[ [
x y x y
x w + y x w + y

View File

@ -282,7 +282,7 @@ TUPLE: single-texture < disposable image dim loc texture-coords texture display-
] unless ; ] unless ;
:: tex-image ( image bitmap -- ) :: tex-image ( image bitmap -- )
image image-format :> ( internal-format format type ) image image-format set: ( internal-format format type )
GL_TEXTURE_2D 0 internal-format GL_TEXTURE_2D 0 internal-format
image dim>> adjust-texture-dim first2 0 image dim>> adjust-texture-dim first2 0
format type bitmap glTexImage2D ; format type bitmap glTexImage2D ;

View File

@ -41,7 +41,7 @@ SYMBOL: current-context
[ py-import ] dip getattr ; [ py-import ] dip getattr ;
:: add-function ( name effect module prefix? -- ) :: add-function ( name effect module prefix? -- )
module name prefix? make-factor-words :> ( call-word obj-word ) module name prefix? make-factor-words set: ( call-word obj-word )
obj-word module name $[ _ _ import-getattr ] ( -- o ) define-inline obj-word module name $[ _ _ import-getattr ] ( -- o ) define-inline
call-word obj-word def>> effect make-function-quot effect define-inline ; call-word obj-word def>> effect make-function-quot effect define-inline ;

View File

@ -16,10 +16,10 @@ ERROR: unix-system-call-error args errno message word ;
} 1|| ; } 1|| ;
MACRO:: unix-system-call ( quot -- quot ) MACRO:: unix-system-call ( quot -- quot )
quot inputs :> n quot inputs set: n
quot first :> word quot first set: word
0 :> ret! 0 set: ret!
f :> failed! f set: failed!
[ [
[ [
n ndup quot call ret! n ndup quot call ret!
@ -39,9 +39,9 @@ MACRO:: unix-system-call ( quot -- quot )
] ; ] ;
MACRO:: unix-system-call-allow-eintr ( quot -- quot ) MACRO:: unix-system-call-allow-eintr ( quot -- quot )
quot inputs :> n quot inputs set: n
quot first :> word quot first set: word
0 :> ret! 0 set: ret!
[ [
n ndup quot call ret! n ndup quot call ret!
ret unix-call-failed? [ ret unix-call-failed? [

View File

@ -24,7 +24,7 @@ CONSTANT: registry-value-max-length 16384 ;
] keep HKEY deref ; ] keep HKEY deref ;
:: create-key* ( hKey lpSubKey lpClass dwOptions samDesired lpSecurityAttributes -- hkey new? ) :: create-key* ( hKey lpSubKey lpClass dwOptions samDesired lpSecurityAttributes -- hkey new? )
f :> ret! f set: ret!
hKey lpSubKey 0 lpClass dwOptions samDesired lpSecurityAttributes hKey lpSubKey 0 lpClass dwOptions samDesired lpSecurityAttributes
0 HKEY <ref> 0 HKEY <ref>
0 DWORD <ref> 0 DWORD <ref>
@ -50,13 +50,13 @@ CONSTANT: registry-value-max-length 16384 ;
] if ; ] if ;
:: with-open-registry-key ( key subkey mode quot -- ) :: with-open-registry-key ( key subkey mode quot -- )
key subkey mode open-key :> hkey key subkey mode open-key set: hkey
[ hkey quot call ] [ hkey quot call ]
[ hkey close-key ] [ hkey close-key ]
[ ] cleanup ; inline [ ] cleanup ; inline
:: with-create-registry-key ( key subkey quot -- ) :: with-create-registry-key ( key subkey quot -- )
key subkey create-key :> hkey key subkey create-key set: hkey
[ hkey quot call ] [ hkey quot call ]
[ hkey close-key ] [ hkey close-key ]
[ ] cleanup ; inline [ ] cleanup ; inline
@ -67,9 +67,9 @@ PRIVATE<
length 2 * <byte-array> ; length 2 * <byte-array> ;
:: reg-query-value-ex ( key subkey ptr1 ptr2 buffer -- buffer ) :: reg-query-value-ex ( key subkey ptr1 ptr2 buffer -- buffer )
buffer length uint <ref> :> pdword buffer length uint <ref> set: pdword
key subkey ptr1 ptr2 buffer pdword [ RegQueryValueEx ] 2keep key subkey ptr1 ptr2 buffer pdword [ RegQueryValueEx ] 2keep
rot :> ret rot set: ret
ret ERROR_SUCCESS = [ ret ERROR_SUCCESS = [
uint deref head uint deref head
] [ ] [
@ -100,12 +100,12 @@ TUPLE: registry-enum-key ;
:: reg-enum-keys ( registry-info -- seq ) :: reg-enum-keys ( registry-info -- seq )
registry-info sub-keys>> iota [ registry-info sub-keys>> iota [
[ registry-info key>> ] dip [ registry-info key>> ] dip
registry-value-max-length TCHAR <c-array> dup :> registry-value registry-value-max-length TCHAR <c-array> dup set: registry-value
registry-value length dup :> registry-value-length registry-value length dup set: registry-value-length
f f
0 DWORD <ref> dup :> type 0 DWORD <ref> dup set: type
f ! 0 BYTE <ref> dup :> data f ! 0 BYTE <ref> dup set: data
f ! 0 BYTE <ref> dup :> buffer f ! 0 BYTE <ref> dup set: buffer
RegEnumKeyEx dup ERROR_SUCCESS = [ RegEnumKeyEx dup ERROR_SUCCESS = [
] [ ] [
@ -115,18 +115,18 @@ TUPLE: registry-enum-key ;
:: reg-query-info-key ( key -- n ) :: reg-query-info-key ( key -- n )
key key
MAX_PATH MAX_PATH
dup TCHAR <c-array> dup :> class-buffer dup TCHAR <c-array> dup set: class-buffer
swap int <ref> dup :> class-buffer-length swap int <ref> dup set: class-buffer-length
f f
0 DWORD <ref> dup :> sub-keys 0 DWORD <ref> dup set: sub-keys
0 DWORD <ref> dup :> longest-subkey 0 DWORD <ref> dup set: longest-subkey
0 DWORD <ref> dup :> longest-class-string 0 DWORD <ref> dup set: longest-class-string
0 DWORD <ref> dup :> #values 0 DWORD <ref> dup set: #values
0 DWORD <ref> dup :> max-value 0 DWORD <ref> dup set: max-value
0 DWORD <ref> dup :> max-value-data 0 DWORD <ref> dup set: max-value-data
0 DWORD <ref> dup :> security-descriptor 0 DWORD <ref> dup set: security-descriptor
FILETIME <struct> dup :> last-write-time FILETIME <struct> dup set: last-write-time
RegQueryInfoKey :> ret RegQueryInfoKey set: ret
ret ERROR_SUCCESS = [ ret ERROR_SUCCESS = [
key key
class-buffer class-buffer

View File

@ -14,8 +14,8 @@ PRIVATE<
:: IStream-read ( stream pv cb out-read -- hresult ) :: IStream-read ( stream pv cb out-read -- hresult )
[ [
cb stream stream-read :> buf cb stream stream-read set: buf
buf length :> bytes buf length set: bytes
pv buf bytes memcpy pv buf bytes memcpy
out-read [ bytes out-read 0 ULONG set-alien-value ] when out-read [ bytes out-read 0 ULONG set-alien-value ] when
@ -50,8 +50,8 @@ PRIVATE<
:: IStream-copy-to ( stream other-stream cb out-read out-written -- hresult ) :: IStream-copy-to ( stream other-stream cb out-read out-written -- hresult )
[ [
cb stream stream-read :> buf cb stream stream-read set: buf
buf length :> bytes buf length set: bytes
out-read [ bytes out-read 0 ULONG set-alien-value ] when out-read [ bytes out-read 0 ULONG set-alien-value ] when
other-stream buf bytes out-written IStream::Write other-stream buf bytes out-written IStream::Write
@ -70,9 +70,9 @@ PRIVATE<
STG_E_INVALIDFUNCTION ; STG_E_INVALIDFUNCTION ;
:: stream-size ( stream -- size ) :: stream-size ( stream -- size )
stream stream-tell :> old-pos stream stream-tell set: old-pos
0 seek-end stream stream-seek 0 seek-end stream stream-seek
stream stream-tell :> size stream stream-tell set: size
old-pos seek-absolute stream stream-seek old-pos seek-absolute stream stream-seek
size ; size ;

View File

@ -68,7 +68,7 @@ CONSTANT: ssa-dwFlags flags{ SSA_GLYPHS SSA_FALLBACK SSA_TAB } ;
ScriptStringOut check-ole32-error ; ScriptStringOut check-ole32-error ;
:: render-image ( dc ssa script-string -- image ) :: render-image ( dc ssa script-string -- image )
script-string size>> :> size script-string size>> set: size
size dc size dc
[ ssa size script-string draw-script-string ] make-bitmap-image ; [ ssa size script-string draw-script-string ] make-bitmap-image ;

View File

@ -19,17 +19,17 @@ PRIVATE<
PRIVATE> PRIVATE>
:: XISetMask ( mask event -- ) :: XISetMask ( mask event -- )
event mask-index :> index event mask-index set: index
event bitmask index mask nth bitor event bitmask index mask nth bitor
index mask set-nth ; inline index mask set-nth ; inline
:: XIClearMask ( mask event -- ) :: XIClearMask ( mask event -- )
event mask-index :> index event mask-index set: index
event bitmask bitnot index mask nth bitand event bitmask bitnot index mask nth bitand
index mask set-nth ; inline index mask set-nth ; inline
:: XIMaskIsSet ( mask event -- n ) :: XIMaskIsSet ( mask event -- n )
event mask-index :> index event mask-index set: index
event bitmask index mask nth bitand ; event bitmask index mask nth bitand ;
: XIMaskLen ( event -- n ) 7 + -3 shift ; : XIMaskLen ( event -- n ) 7 + -3 shift ;

View File

@ -83,8 +83,8 @@ M: literal-bind sqlite-bind-conversion ( tuple literal-bind -- array )
<sqlite-low-level-binding> ; <sqlite-low-level-binding> ;
M:: generator-bind sqlite-bind-conversion ( tuple generate-bind -- array ) M:: generator-bind sqlite-bind-conversion ( tuple generate-bind -- array )
generate-bind generator-singleton>> eval-generator :> obj generate-bind generator-singleton>> eval-generator set: obj
generate-bind slot-name>> :> name generate-bind slot-name>> set: name
obj name tuple set-slot-named obj name tuple set-slot-named
generate-bind key>> obj generate-bind type>> <sqlite-low-level-binding> ; generate-bind key>> obj generate-bind type>> <sqlite-low-level-binding> ;

View File

@ -23,7 +23,7 @@ GENERIC: new-user ( user provider -- user/f ) ;
! Password recovery support ! Password recovery support
:: issue-ticket ( email username provider -- user/f ) :: issue-ticket ( email username provider -- user/f )
username provider get-user :> user username provider get-user set: user
user [ user [
user email>> length 0 > [ user email>> length 0 > [
user email>> email = [ user email>> email = [
@ -35,7 +35,7 @@ GENERIC: new-user ( user provider -- user/f ) ;
] [ f ] if ; ] [ f ] if ;
:: claim-ticket ( ticket username provider -- user/f ) :: claim-ticket ( ticket username provider -- user/f )
username provider get-user :> user username provider get-user set: user
user [ user [
user ticket>> ticket = [ user ticket>> ticket = [
user f >>ticket dup provider update-user user f >>ticket dup provider update-user

View File

@ -50,8 +50,8 @@ PRIVATE<
"\n" split first2 [ "true" = ] dip ; "\n" split first2 [ "true" = ] dip ;
:: (validate-recaptcha) ( challenge response recaptcha -- valid? error ) :: (validate-recaptcha) ( challenge response recaptcha -- valid? error )
recaptcha private-key>> :> private-key recaptcha private-key>> set: private-key
remote-address get host>> :> remote-ip remote-address get host>> set: remote-ip
H{ H{
{ "challenge" challenge } { "challenge" challenge }
{ "response" response } { "response" response }

View File

@ -105,7 +105,7 @@ CONSTANT: debug-text-texture-parameters
:: screen-quad ( image pt dim -- float-array ) :: screen-quad ( image pt dim -- float-array )
pt dim v/ 2.0 v*n 1.0 v-n pt dim v/ 2.0 v*n 1.0 v-n
dup image dim>> dim v/ 2.0 v*n v+ dup image dim>> dim v/ 2.0 v*n v+
[ first2 ] bi@ :> ( x0 y0 x1 y1 ) [ first2 ] bi@ set: ( x0 y0 x1 y1 )
image upside-down?>> image upside-down?>>
[ { x0 y0 0 0 x1 y0 1 0 x1 y1 1 1 x0 y1 0 1 } ] [ { x0 y0 0 0 x1 y0 1 0 x1 y1 1 1 x0 y1 0 1 } ]
[ { x0 y0 0 1 x1 y0 1 1 x1 y1 1 0 x0 y1 0 0 } ] [ { x0 y0 0 1 x1 y0 1 1 x1 y1 1 0 x0 y1 0 0 } ]

View File

@ -17,7 +17,7 @@ IN: game.debug.tests
180 / pi * ; 180 / pi * ;
:: draw-debug-tests ( world -- ) :: draw-debug-tests ( world -- )
world [ wasd-p-matrix ] [ wasd-mv-matrix ] bi m. :> mvp-matrix world [ wasd-p-matrix ] [ wasd-mv-matrix ] bi m. set: mvp-matrix
{ 0 0 0 } clear-screen { 0 0 0 } clear-screen
[ [

View File

@ -51,7 +51,7 @@ CONSTANT: pov-polygons
[ (xy>loc) ] dip (z>loc) ; [ (xy>loc) ] dip (z>loc) ;
:: move-axis ( gadget x y z -- ) :: move-axis ( gadget x y z -- )
x y z (xyz>loc) :> ( xy z ) x y z (xyz>loc) set: ( xy z )
xy gadget indicator>> loc<< xy gadget indicator>> loc<<
z gadget z-indicator>> loc<< ; z gadget z-indicator>> loc<< ;

View File

@ -281,7 +281,7 @@ M: iokit-game-input-backend reset-mouse
} cond ; } cond ;
:: (device-input-callback) ( context result sender value -- ) :: (device-input-callback) ( context result sender value -- )
sender get-input-device :> device sender get-input-device set: device
{ {
{ [ device mouse-device? ] [ +mouse-state+ get-global value record-mouse ] } { [ device mouse-device? ] [ +mouse-state+ get-global value record-mouse ] }
{ [ device controller-device? ] [ { [ device controller-device? ] [

Some files were not shown because too many files have changed in this diff Show More