Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2009-08-07 17:45:09 -05:00
commit b85d842ca6
6 changed files with 33 additions and 60 deletions

View File

@ -11,15 +11,13 @@ $nl
{ $code "USE: tools.scaffold" }
"Then, ask the scaffold tool to create a new vocabulary named " { $snippet "palindrome" } ":"
{ $code "\"resource:work\" \"palindrome\" scaffold-vocab" }
"If you look at the output, you will see that a few files were created in your “work” directory. The following phrase will print the full path of your work directory:"
"If you look at the output, you will see that a few files were created in your “work” directory, and that the new source file was loaded."
$nl
"The following phrase will print the full path of your work directory:"
{ $code "\"work\" resource-path ." }
"The work directory is one of several " { $link "vocabs.roots" } " where Factor searches for vocabularies. It is possible to define new vocabulary roots; see " { $link "add-vocab-roots" } ". To keep things simple in this tutorial, we'll just use the work directory, though."
$nl
"Open the work directory in your file manager, and open the subdirectory named " { $snippet "palindrome" } ". Inside this subdirectory you will see a file named " { $snippet "palindrome.factor" } ". We will be editing this file."
$nl
"Notice that the file ends with an " { $link POSTPONE: IN: } " form telling Factor that all definitions in this source file should go into the " { $snippet "palindrome" } " vocabulary using the " { $link POSTPONE: IN: } " word:"
{ $code "IN: palindrome" }
"We will add new definitions after the " { $link POSTPONE: IN: } " form."
"Open the work directory in your file manager, and open the subdirectory named " { $snippet "palindrome" } ". Inside this subdirectory you will see a file named " { $snippet "palindrome.factor" } ". Open this file in your text editor."
$nl
"You are now ready to go on to the next section: " { $link "first-program-logic" } "." ;
@ -30,6 +28,12 @@ ARTICLE: "first-program-logic" "Writing some logic in your first program"
"! See http://factorcode.org/license.txt for BSD license."
"IN: palindrome"
}
"Notice that the file ends with an " { $link POSTPONE: IN: } " form telling Factor that all definitions in this source file should go into the " { $snippet "palindrome" } " vocabulary using the " { $link POSTPONE: IN: } " word. We will add new definitions after the " { $link POSTPONE: IN: } " form."
$nl
"In order to be able to call the words defined in the " { $snippet "palindrome" } " vocabulary, you need to issue the following command in the listener:"
{ $code "USE: palindrome" }
"Now, wee will be making some additions to the file. Since the file was loaded by the scaffold tool in the previous step, you need to tell Factor to reload it if it changes. Factor has a handy feature for this; pressing " { $command tool "common" refresh-all } " in the listener window will reload any changed source files. You can also force a single vocabulary to reload:"
{ $code "\"palindrome\" reload" }
"We will now write our first word using " { $link POSTPONE: : } ". This word will test if a string is a palindrome; it will take a string as input, and give back a boolean as output. We will call this word " { $snippet "palindrome?" } ", following a naming convention that words returning booleans have names ending with " { $snippet "?" } "."
$nl
"Recall that a string is a palindrome if it is spelled the same forwards or backwards; that is, if the string is equal to its reverse. We can express this in Factor as follows:"

View File

@ -277,7 +277,7 @@ PRIVATE>
<PRIVATE
: set-table-model ( model value multiple? -- )
[ multiple>single drop ] unless swap set-model ;
[ values ] [ multiple>single drop ] if swap set-model ;
: update-selected ( table -- )
[

View File

@ -1,4 +0,0 @@
USING: kernel file-trees ;
IN: file-trees.tests
{ "/sample/1" "/sample/2" "/killer/1" "/killer/2/3"
"/killer/2/4" "/killer/2/4/6" "/megakiller" } create-tree drop

View File

@ -1,49 +0,0 @@
USING: accessors arrays delegate delegate.protocols
io.pathnames kernel locals sequences
vectors make strings models.combinators ui.gadgets.controls
sequences.extras ;
IN: file-trees
TUPLE: walkable-vector vector father ;
CONSULT: sequence-protocol walkable-vector vector>> ;
M: walkable-vector set-nth [ vector>> set-nth ] 3keep nip
father>> swap children>> vector>> push ;
TUPLE: tree node comment children ;
CONSULT: sequence-protocol tree children>> ;
: file? ( tree -- ? ) children>> [ node>> ".." = not ] filter empty? ;
: <dir-tree> ( {start,comment} -- tree ) first2 walkable-vector new vector new >>vector
[ tree boa dup children>> ] [ ".." -rot tree boa ] 2bi swap (>>father) ;
DEFER: (tree-insert)
: tree-insert ( path tree -- ) [ unclip <dir-tree> ] [ children>> ] bi* (tree-insert) ;
:: (tree-insert) ( path-rest path-head tree-children -- )
tree-children [ node>> path-head node>> = ] find nip
[ path-rest swap tree-insert ]
[
path-head tree-children push
path-rest [ path-head tree-insert ] unless-empty
] if* ;
: add-paths ( pathseq -- {{name,path}} )
"" [ [ "/" glue dup ] keep swap 2array , ] [ reduce drop ] f make ;
: go-to-path ( path tree -- tree' ) over empty? [ nip ]
[ [ unclip ] [ children>> ] bi* swap [ swap node>> = ] curry find nip go-to-path ] if ;
: find-root ( pathseq -- root ) dup flip
[ [ dupd = [ ] [ drop f ] if ] reduce1 ] find-last drop
[ first ] dip head-slice >string path-components ;
: create-tree ( file-list -- tree ) [ find-root ]
[ [ path-components add-paths ] map { "/" "/" } <dir-tree> [ [ tree-insert ] curry each ] keep ] bi
go-to-path ;
: <dir-table> ( tree-model -- table )
<list*> [ node>> 1array ] >>quot
[ selected-value>> [ file? not ] filter-model swap switch-models ]
[ swap >>model ] bi ;

View File

@ -0,0 +1 @@
Sam Anklesaria

View File

@ -0,0 +1,21 @@
! Copyright (C) 2009 Sam Anklesaria.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays accessors kernel models threads calendar ;
IN: models.conditional
TUPLE: conditional < model condition thread ;
M: conditional model-changed
[
[ dup
[ condition>> call( -- ? ) ]
[ thread>> self = not ] bi or
[ [ value>> ] dip set-model f ]
[ 2drop t ] if 100 milliseconds sleep
] 2curry "models.conditional" spawn-server
] keep (>>thread) ;
: <conditional> ( condition -- model )
f conditional new-model swap >>condition ;
M: conditional model-activated [ model>> ] keep model-changed ;