Merge branch 'master' of git://factorcode.org/git/factor
commit
aabeb53753
|
@ -56,19 +56,19 @@ ARTICLE: { "concurrency" "synchronous-sends" } "Synchronous sends"
|
||||||
"USING: concurrency.messaging kernel threads ;"
|
"USING: concurrency.messaging kernel threads ;"
|
||||||
": pong-server ( -- )"
|
": pong-server ( -- )"
|
||||||
" receive >r \"pong\" r> reply-synchronous ;"
|
" receive >r \"pong\" r> reply-synchronous ;"
|
||||||
"[ pong-server t ] spawn-server"
|
"[ pong-server t ] \"pong-server\" spawn-server"
|
||||||
"\"ping\" swap send-synchronous ."
|
"\"ping\" swap send-synchronous ."
|
||||||
"\"pong\""
|
"\"pong\""
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
ARTICLE: { "concurrency" "exceptions" } "Linked exceptions"
|
ARTICLE: { "concurrency" "exceptions" } "Linked exceptions"
|
||||||
"A thread can handle exceptions using the standard Factor exception handling mechanism. If an exception is uncaught the thread will terminate. For example:"
|
"A thread can handle exceptions using the standard Factor exception handling mechanism. If an exception is uncaught the thread will terminate. For example:"
|
||||||
{ $code "[ 1 0 / \"This will not print\" print ] spawn" }
|
{ $code "[ 1 0 / \"This will not print\" print ] \"division-by-zero\" spawn" }
|
||||||
"Processes can be linked so that a parent thread can receive the exception that caused the child thread to terminate. In this way 'supervisor' threades can be created that are notified when child threades terminate and possibly restart them."
|
"Processes can be linked so that a parent thread can receive the exception that caused the child thread to terminate. In this way 'supervisor' threades can be created that are notified when child threades terminate and possibly restart them."
|
||||||
{ $subsection spawn-linked }
|
{ $subsection spawn-linked }
|
||||||
"This will create a unidirectional link, such that if an uncaught exception causes the child to terminate, the parent thread can catch it:"
|
"This will create a unidirectional link, such that if an uncaught exception causes the child to terminate, the parent thread can catch it:"
|
||||||
{ $code "["
|
{ $code "["
|
||||||
" [ 1 0 / \"This will not print\" print ] spawn-linked drop"
|
" [ 1 0 / \"This will not print\" print ] \"linked-division\" spawn-linked drop"
|
||||||
" receive"
|
" receive"
|
||||||
"] [ \"Exception caught.\" print ] recover" }
|
"] [ \"Exception caught.\" print ] recover" }
|
||||||
"Exceptions are only raised in the parent when the parent does a " { $link receive } " or " { $link receive-if } ". This is because the exception is sent from the child to the parent as a message." ;
|
"Exceptions are only raised in the parent when the parent does a " { $link receive } " or " { $link receive-if } ". This is because the exception is sent from the child to the parent as a message." ;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1,63 @@
|
||||||
|
|
||||||
|
USING: namespaces sequences math random-weighted cfdg ;
|
||||||
|
|
||||||
|
IN: cfdg.models.rules08
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: insct ( -- )
|
||||||
|
[ 1.5 5.5 size* -1 brightness triangle ] do
|
||||||
|
10
|
||||||
|
[ [ [ 1 0.9 size* -0.15 y 0.05 brightness ] times 1 5 size* triangle ] do ]
|
||||||
|
each ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
DEFER: line
|
||||||
|
|
||||||
|
: ligne ( -- )
|
||||||
|
{
|
||||||
|
{ 1 [ 1.15 0.8 size* 4.5 y -0.3 b line ] do }
|
||||||
|
{ 0.5 [ ] }
|
||||||
|
}
|
||||||
|
call-random-weighted ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: line ( -- ) [ insct ligne ] recursive ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: sole ( -- )
|
||||||
|
[
|
||||||
|
{
|
||||||
|
{
|
||||||
|
1 [
|
||||||
|
[ 1 brightness 0.5 saturation ligne ] do
|
||||||
|
[ 140 r 1 hue sole ] do
|
||||||
|
]
|
||||||
|
}
|
||||||
|
{ 0.01 [ ] }
|
||||||
|
}
|
||||||
|
call-random-weighted
|
||||||
|
]
|
||||||
|
recursive ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: centre ( -- )
|
||||||
|
[ 1 b 5 s circle ] do
|
||||||
|
[ sole ] do ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: run ( -- )
|
||||||
|
[ -1 b ] >background
|
||||||
|
{ -20 40 -20 40 } viewport set
|
||||||
|
[ centre ] >start-shape
|
||||||
|
0.0001 >threshold
|
||||||
|
cfdg-window ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
MAIN: run
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -0,0 +1 @@
|
||||||
|
demos
|
|
@ -1,8 +1,9 @@
|
||||||
! Copyright (C) 2007 Doug Coleman.
|
! Copyright (C) 2007 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.accessors arrays assocs combinators.lib io kernel
|
USING: accessors alien alien.accessors arrays assocs
|
||||||
macros math namespaces prettyprint quotations sequences
|
combinators.lib io kernel macros math namespaces prettyprint
|
||||||
vectors vocabs words html.elements slots.private tar ;
|
quotations sequences vectors vocabs words html.elements sets
|
||||||
|
slots.private combinators.short-circuit ;
|
||||||
IN: lint
|
IN: lint
|
||||||
|
|
||||||
SYMBOL: def-hash
|
SYMBOL: def-hash
|
||||||
|
@ -18,7 +19,7 @@ SYMBOL: def-hash-keys
|
||||||
2drop
|
2drop
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: more-defs
|
: more-defs ( -- )
|
||||||
{
|
{
|
||||||
{ [ swap >r swap r> ] -rot }
|
{ [ swap >r swap r> ] -rot }
|
||||||
{ [ swap swapd ] -rot }
|
{ [ swap swapd ] -rot }
|
||||||
|
@ -33,6 +34,7 @@ SYMBOL: def-hash-keys
|
||||||
{ [ 0 = ] zero? }
|
{ [ 0 = ] zero? }
|
||||||
{ [ pop drop ] pop* }
|
{ [ pop drop ] pop* }
|
||||||
{ [ [ ] if ] when }
|
{ [ [ ] if ] when }
|
||||||
|
{ [ f = not ] >boolean }
|
||||||
} [ first2 swap add-word-def ] each ;
|
} [ first2 swap add-word-def ] each ;
|
||||||
|
|
||||||
: accessor-words ( -- seq )
|
: accessor-words ( -- seq )
|
||||||
|
@ -51,33 +53,32 @@ SYMBOL: def-hash-keys
|
||||||
{
|
{
|
||||||
[ get ] [ t ] [ { } ] [ . ] [ drop f ]
|
[ get ] [ t ] [ { } ] [ . ] [ drop f ]
|
||||||
[ drop ] [ f ] [ first ] [ second ] [ third ] [ fourth ]
|
[ drop ] [ f ] [ first ] [ second ] [ third ] [ fourth ]
|
||||||
[ ">" write-html ] [ <unimplemented-typeflag> throw ]
|
[ ">" write-html ] [ "/>" write-html ]
|
||||||
[ "/>" write-html ]
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
H{ } clone def-hash set-global
|
H{ } clone def-hash set-global
|
||||||
all-words [ dup word-def add-word-def ] each
|
all-words [ dup def>> add-word-def ] each
|
||||||
more-defs
|
more-defs
|
||||||
|
|
||||||
! Remove empty word defs
|
! Remove empty word defs
|
||||||
def-hash get-global [
|
def-hash get-global [
|
||||||
drop empty? not
|
drop empty? not
|
||||||
] assoc-subset
|
] assoc-filter
|
||||||
|
|
||||||
! Remove constants [ 1 ]
|
! Remove constants [ 1 ]
|
||||||
[
|
[
|
||||||
drop dup length 1 = swap first number? and not
|
drop dup length 1 = swap first number? and not
|
||||||
] assoc-subset
|
] assoc-filter
|
||||||
|
|
||||||
! Remove set-alien-cell, etc.
|
! Remove set-alien-cell, etc.
|
||||||
[
|
[
|
||||||
drop [ accessor-words swap seq-diff ] keep [ length ] bi@ =
|
drop [ accessor-words diff ] keep [ length ] bi@ =
|
||||||
] assoc-subset
|
] assoc-filter
|
||||||
|
|
||||||
! Remove trivial defs
|
! Remove trivial defs
|
||||||
[
|
[
|
||||||
drop trivial-defs member? not
|
drop trivial-defs member? not
|
||||||
] assoc-subset
|
] assoc-filter
|
||||||
|
|
||||||
! Remove n m shift defs
|
! Remove n m shift defs
|
||||||
[
|
[
|
||||||
|
@ -85,19 +86,19 @@ def-hash get-global [
|
||||||
dup first2 [ number? ] both?
|
dup first2 [ number? ] both?
|
||||||
swap third \ shift = and not
|
swap third \ shift = and not
|
||||||
] [ drop t ] if
|
] [ drop t ] if
|
||||||
] assoc-subset
|
] assoc-filter
|
||||||
|
|
||||||
! Remove [ n slot ]
|
! Remove [ n slot ]
|
||||||
[
|
[
|
||||||
drop dup length 2 = [
|
drop dup length 2 = [
|
||||||
first2 \ slot = swap number? and not
|
first2 \ slot = swap number? and not
|
||||||
] [ drop t ] if
|
] [ drop t ] if
|
||||||
] assoc-subset def-hash set-global
|
] assoc-filter def-hash set-global
|
||||||
|
|
||||||
: find-duplicates
|
: find-duplicates ( -- seq )
|
||||||
def-hash get-global [
|
def-hash get-global [
|
||||||
nip length 1 >
|
nip length 1 >
|
||||||
] assoc-subset ;
|
] assoc-filter ;
|
||||||
|
|
||||||
def-hash get-global keys def-hash-keys set-global
|
def-hash get-global keys def-hash-keys set-global
|
||||||
|
|
||||||
|
@ -107,18 +108,18 @@ M: object lint ( obj -- seq )
|
||||||
drop f ;
|
drop f ;
|
||||||
|
|
||||||
: subseq/member? ( subseq/member seq -- ? )
|
: subseq/member? ( subseq/member seq -- ? )
|
||||||
{ [ 2dup start ] [ 2dup member? ] } || 2nip ;
|
{ [ start ] [ member? ] } 2|| ;
|
||||||
|
|
||||||
M: callable lint ( quot -- seq )
|
M: callable lint ( quot -- seq )
|
||||||
def-hash-keys get [
|
def-hash-keys get [
|
||||||
swap subseq/member?
|
swap subseq/member?
|
||||||
] with subset ;
|
] with filter ;
|
||||||
|
|
||||||
M: word lint ( word -- seq )
|
M: word lint ( word -- seq )
|
||||||
word-def dup callable? [ lint ] [ drop f ] if ;
|
def>> dup callable? [ lint ] [ drop f ] if ;
|
||||||
|
|
||||||
: word-path. ( word -- )
|
: word-path. ( word -- )
|
||||||
[ word-vocabulary ":" ] keep unparse 3append write nl ;
|
[ vocabulary>> ":" ] keep unparse 3append write nl ;
|
||||||
|
|
||||||
: (lint.) ( pair -- )
|
: (lint.) ( pair -- )
|
||||||
first2 >r word-path. r> [
|
first2 >r word-path. r> [
|
||||||
|
@ -135,7 +136,7 @@ M: word lint ( word -- seq )
|
||||||
|
|
||||||
GENERIC: run-lint ( obj -- obj )
|
GENERIC: run-lint ( obj -- obj )
|
||||||
|
|
||||||
: (trim-self)
|
: (trim-self) ( val key -- obj ? )
|
||||||
def-hash get-global at* [
|
def-hash get-global at* [
|
||||||
dupd remove empty? not
|
dupd remove empty? not
|
||||||
] [
|
] [
|
||||||
|
@ -143,13 +144,13 @@ GENERIC: run-lint ( obj -- obj )
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: trim-self ( seq -- newseq )
|
: trim-self ( seq -- newseq )
|
||||||
[ [ (trim-self) ] subset ] assoc-map ;
|
[ [ (trim-self) ] filter ] assoc-map ;
|
||||||
|
|
||||||
: filter-symbols ( alist -- alist )
|
: filter-symbols ( alist -- alist )
|
||||||
[
|
[
|
||||||
nip first dup def-hash get at
|
nip first dup def-hash get at
|
||||||
[ first ] bi@ literalize = not
|
[ first ] bi@ literalize = not
|
||||||
] assoc-subset ;
|
] assoc-filter ;
|
||||||
|
|
||||||
M: sequence run-lint ( seq -- seq )
|
M: sequence run-lint ( seq -- seq )
|
||||||
[
|
[
|
||||||
|
@ -157,7 +158,7 @@ M: sequence run-lint ( seq -- seq )
|
||||||
dup lint
|
dup lint
|
||||||
] { } map>assoc
|
] { } map>assoc
|
||||||
trim-self
|
trim-self
|
||||||
[ second empty? not ] subset
|
[ second empty? not ] filter
|
||||||
filter-symbols ;
|
filter-symbols ;
|
||||||
|
|
||||||
M: word run-lint ( word -- seq )
|
M: word run-lint ( word -- seq )
|
||||||
|
|
Loading…
Reference in New Issue