M: timestamp year. ( timestamp -- )
timestamp-year year. ;
-: pad-00 number>string 2 CHAR: 0 pad-left write ;
+: pad-00 number>string 2 CHAR: 0 pad-left ;
+
+: write-00 pad-00 write ;
: (timestamp>string) ( timestamp -- )
dup day-of-week day-abbreviations3 nth write ", " write
dup timestamp-day number>string write bl
dup timestamp-month month-abbreviations nth write bl
dup timestamp-year number>string write bl
- dup timestamp-hour pad-00 ":" write
- dup timestamp-minute pad-00 ":" write
- timestamp-second >fixnum pad-00 ;
+ dup timestamp-hour write-00 ":" write
+ dup timestamp-minute write-00 ":" write
+ timestamp-second >fixnum write-00 ;
: timestamp>string ( timestamp -- str )
[ (timestamp>string) ] string-out ;
: (timestamp>rfc3339) ( timestamp -- )
dup timestamp-year number>string write CHAR: - write1
- dup timestamp-month pad-00 CHAR: - write1
- dup timestamp-day pad-00 CHAR: T write1
- dup timestamp-hour pad-00 CHAR: : write1
- dup timestamp-minute pad-00 CHAR: : write1
- timestamp-second >fixnum pad-00 CHAR: Z write1 ;
+ dup timestamp-month write-00 CHAR: - write1
+ dup timestamp-day write-00 CHAR: T write1
+ dup timestamp-hour write-00 CHAR: : write1
+ dup timestamp-minute write-00 CHAR: : write1
+ timestamp-second >fixnum write-00 CHAR: Z write1 ;
: timestamp>rfc3339 ( timestamp -- str )
>gmt [ (timestamp>rfc3339) ] string-out ;
[ timestamp-month month-abbreviations nth write ] keep bl
[ timestamp-day number>string 2 32 pad-left write ] keep bl
dup now [ timestamp-year ] 2apply = [
- [ timestamp-hour pad-00 ] keep ":" write
- timestamp-minute pad-00
+ [ timestamp-hour write-00 ] keep ":" write
+ timestamp-minute write-00
] [
timestamp-year number>string 5 32 pad-left write
] if
--- /dev/null
+! Copyright (C) 2008 Slava Pestov\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: calendar namespaces models threads ;\r
+IN: calendar.model\r
+\r
+SYMBOL: time\r
+\r
+: (time-thread) ( -- )\r
+ now time get set-model\r
+ 1000 sleep (time-thread) ;\r
+\r
+: time-thread ( -- ) [ (time-thread) ] in-thread ;\r
+\r
+f <model> time set-global\r
+time-thread\r
+++ /dev/null
-Slava Pestov
+++ /dev/null
-USING: slides help.markup math arrays hashtables namespaces
-sequences kernel sequences parser ;
-IN: catalyst-talk
-
-: catalyst-slides
-{
- { $slide "What is Factor?"
- "Originally scripting for a Java game"
- "Language dev more fun than game dev"
- "Start with ideas which were mostly dead"
- "Throw in features from crazy languages"
- "Develop practical libraries and tools"
- }
- { $slide "Factor: a stack language"
- "Implicit parameter passing"
- { "Each " { $emphasis "word" } " is a function call" }
- { $code ": sq dup * ;" }
- { $code "2 3 + sq ." }
- "Minimal syntax and semantics = easy meta-programming"
- { "Related languages: Forth, Joy, PostScript" }
- }
- { $slide "Factor: a functional language"
- { { $emphasis "Quotations" } " can be passed around, constructed..." }
- { $code "[ sq 3 + ]" }
- { { $emphasis "Combinators" } " are words which take quotations, eg " { $link if } }
- { "For FP buffs: " { $link each } ", " { $link map } ", " { $link reduce } ", " { $link accumulate } ", " { $link interleave } ", " { $link subset } }
- { $code "{ 42 69 666 } [ sq 3 + ] map ." }
- }
- { $slide "Factor: an object-oriented language"
- { "Everything is an " { $emphasis "object" } }
- { "An object is an instance of a " { $emphasis "class" } }
- "Methods"
- "Generic words"
- "For CLOS buffs: we allow custom method combination, classes are objects too, there's a MOP"
- }
-
- STRIP-TEASE:
- $slide "Primary school geometry recap"
- { $code
- "GENERIC: area ( shape -- meters^2 )"
- "TUPLE: square dimension ;"
- "M: square area square-dimension sq ;"
- "TUPLE: circle radius ;"
- "M: circle area circle-radius sq pi * ;"
- "TUPLE: rectangle width height ;"
- "M: rectangle area"
- " dup rectangle-width"
- " swap rectangle-height"
- " * ;"
- }
- ;
-
- { $slide "Geometry example"
- { $code "10 <square> area ." }
- { $code "18 <circle> area ." }
- { $code "20 40 <rectangle> area ." }
- }
-! { $slide "Factor: a meta language"
-! "Writing code which writes code"
-! "Extensible parser: define new syntax"
-! "Compiler transforms"
-! "Here's an inefficient word:"
-! { $code
-! ": fib ( x -- y )"
-! " dup 1 > ["
-! " 1 - dup fib swap 1 - fib +"
-! " ] when ;"
-! }
-! }
-! { $slide "Memoization"
-! { { $link POSTPONE: : } " is just another word" }
-! "What if we could define a word which caches its results?"
-! { "The " { $vocab-link "memoize" } " library provides such a feature" }
-! { "Just change " { $link POSTPONE: : } " to " { $link POSTPONE: MEMO: } }
-! { $code
-! "MEMO: fib ( x -- y )"
-! " dup 1 > ["
-! " 1 - dup fib swap 1 - fib +"
-! " ] when ;"
-! }
-! }
- { $slide "Factor: a tool-building language"
- "Tools are not monolithic, but are themselves just sets of words"
- "Examples: parser, compiler, etc"
- "Parser: turns strings into objects"
- { $code "\"1\" <file-reader> contents parse" }
- "Prettyprinter: turns objects into strings"
- { $code "\"2\" <file-writer> [ . ] with-stream" }
- }
- { $slide "Factor: an interactive language"
- { "Let's hack " { $vocab-link "tetris" } }
- "Editor integration"
- { $code "\\ tetrominoes edit" }
- "Inspector"
- { $code "\\ tetrominoes get inspect" }
- }
- { $slide "C library interface"
- "No need to write C glue code!"
- "Callbacks from C to Factor"
- "Factor can be embedded in C apps"
- { "Example: " { $vocab-link "ogg.vorbis" } }
- { "Other bindings: OpenGL, OpenAL, X11, Win32, Cocoa, OpenSSL, memory mapped files, ..." }
- }
- { $slide "Native libraries"
- "XML, HTTP, SMTP, Unicode, calendar, ..."
- "Lazy lists, pattern matching, packed arrays, ..."
- }
- { $slide "Factor: a fun language"
- { "Let's play "
- { $vocab-link "space-invaders" }
- }
- { $url "http://factorcode.org" }
- { $url "http://factor-language.blogspot.com" }
- "irc.freenode.net #concatenative"
- "Have fun!"
- }
-} ;
-
-: catalyst-talk catalyst-slides slides-window ;
-
-MAIN: catalyst-talk
+++ /dev/null
-USING: tools.deploy.config ;
-V{
- { deploy-ui? t }
- { deploy-io 1 }
- { deploy-reflection 1 }
- { deploy-compiler? t }
- { deploy-math? t }
- { deploy-word-props? f }
- { deploy-c-types? f }
- { "stop-after-last-window?" t }
- { deploy-name "Catalyst Talk" }
-}
+++ /dev/null
-Slides for a talk at Catalyst IT NZ, July 2007
USING: sequences kernel math io ;
IN: lcd
-: lcd-digit ( digit row -- str )
- {
- " _ _ _ _ _ _ _ _ "
- " | | | _| _| |_| |_ |_ | |_| |_| "
- " |_| | |_ _| | _| |_| | |_| | "
+: lcd-digit ( row digit -- str )
+ dup CHAR: : = [ drop 10 ] [ CHAR: 0 - ] if swap {
+ " _ _ _ _ _ _ _ _ "
+ " | | | _| _| |_| |_ |_ | |_| |_| * "
+ " |_| | |_ _| | _| |_| | |_| | * "
} nth >r 4 * dup 4 + r> subseq ;
-: lcd-row ( num row -- )
- swap [ CHAR: 0 - swap lcd-digit write ] with each ;
+: lcd-row ( num row -- string )
+ [ swap lcd-digit ] curry { } map-as concat ;
-: lcd ( digit-str -- )
- 3 [ lcd-row nl ] with each ;
+: lcd ( digit-str -- string )
+ 3 [ lcd-row ] with map "\n" join ;
-: lcd-demo ( -- ) "31337" lcd ;
+: lcd-demo ( -- ) "31337" lcd print ;
MAIN: lcd-demo
--- /dev/null
+Slava Pestov
--- /dev/null
+USING: tools.deploy.config ;
+V{
+ { deploy-ui? t }
+ { deploy-io 1 }
+ { deploy-reflection 1 }
+ { deploy-compiler? t }
+ { deploy-math? t }
+ { deploy-word-props? f }
+ { deploy-c-types? f }
+ { "stop-after-last-window?" t }
+ { deploy-name "Catalyst Talk" }
+}
--- /dev/null
+USING: slides help.markup math arrays hashtables namespaces
+sequences kernel sequences parser ;
+IN: minneapolis-talk
+
+: minneapolis-slides
+{
+ { $slide "What is Factor?"
+ "Dynamically typed, stack language"
+ "Have our cake and eat it too"
+ "Research -vs- production"
+ "High level -vs- performance"
+ "Interactive -vs- stand-alone apps"
+ }
+ { $slide "The view from 10,000 feet"
+ "Influenced by Forth, Lisp, Joy, Smalltalk, even Java..."
+ "Vocabularies: modules"
+ "Words: named functions, classes, variables"
+ "Combinators: higher-order functions"
+ "Quotations: anonymous functions"
+ "Other concepts are familiar: classes, objects, etc"
+ }
+ { $slide "Stack-based programming"
+ { "Most languages are " { $emphasis "applicative" } }
+ "Words pop inputs from the stack and push outputs on the stack"
+ "Literals are pushed on the stack"
+ { $code "{ 1 2 } { 7 } append reverse sum ." }
+ "With the stack you can omit unnecessary names"
+ "You can still name things: lexical/dynamic variables, sequences, associations, objects, ..."
+ }
+ { $slide "Functional programming"
+ "A quotation is a sequence of literals and words"
+ "Combinators replace imperative-style loops"
+ "A simple example:"
+ { $code "10 [ \"Hello world\" print ] times" }
+ { "Partial application: " { $link curry } }
+ { $code "{ 3 1 3 3 7 } [ 5 + ] map ." }
+ { $code "{ 3 1 3 3 7 } 5 [ + ] curry map ." }
+ }
+ { $slide "Word definitions"
+ { $code ": name ( inputs -- outputs ) definition ;" }
+ "Stack effect comments document stack inputs and outputs."
+ "Example from previous slide:"
+ { $code ": add-each ( seq n -- newseq ) [ + ] curry map ;" }
+ { $code "{ 3 1 3 3 7 } add-each ." }
+ "Copy and paste factoring"
+ }
+ { $slide "Object-oriented programming"
+ "Define a tuple class and a constructor:"
+ { $code
+ "TUPLE: person name address ;"
+ "C: <person> person"
+ }
+ "Create an instance:"
+ { $code "\"Cosmo Kramer\" \"100 Blah blah St, New York\" <person>" }
+ "We can inspect it and edit it"
+ "We can reshape the class:"
+ { $code "TUPLE: person name address age phone-number ;" }
+ { $code "TUPLE: person name address phone-number age ;" }
+ }
+ STRIP-TEASE:
+ $slide "Primary school geometry recap"
+ { $code
+ "TUPLE: square dimension ;"
+ "TUPLE: circle radius ;"
+ "TUPLE: rectangle width height ;"
+ ""
+ "GENERIC: area ( shape -- meters^2 )"
+ "M: square area square-dimension sq ;"
+ "M: circle area circle-radius sq pi * ;"
+ "M: rectangle area"
+ " { rectangle-width rectangle-height } get-slots * ;"
+ }
+ ;
+
+ { $slide "Geometry example"
+ { $code "10 <square> area ." }
+ { $code "18 <circle> area ." }
+ { $code "20 40 <rectangle> area ." }
+ }
+ { $slide "Factor: a meta language"
+ "Here's fibonacci:"
+ { $code
+ ": fib ( x -- y )"
+ " dup 1 > ["
+ " 1 - dup fib swap 1 - fib +"
+ " ] when ;"
+ }
+ "It is slow:"
+ { $code
+ "20 [ fib ] map ."
+ }
+ "Let's profile it!"
+ }
+ { $slide "Memoization"
+ { { $link POSTPONE: : } " is just another word" }
+ "What if we could define a word which caches its results?"
+ { "The " { $vocab-link "memoize" } " library provides such a feature" }
+ { "Just change " { $link POSTPONE: : } " to " { $link POSTPONE: MEMO: } }
+ { $code
+ "MEMO: fib ( x -- y )"
+ " dup 1 > ["
+ " 1 - dup fib swap 1 - fib +"
+ " ] when ;"
+ }
+ "It is faster:"
+ { $code
+ "20 [ fib ] map ."
+ }
+ }
+ { $slide "The Factor UI"
+ "Written in Factor"
+ "Renders with OpenGL"
+ "Backends for Windows, X11, Cocoa"
+ "You can call Windows, X11, Cocoa APIs directly too"
+ "OpenGL 2.1 shaders, OpenAL 3D audio..."
+ }
+ { $slide "Implementation"
+ "Very small C core"
+ "Non-optimizing compiler"
+ "Optimizing compiler"
+ "Generational garbage collector"
+ "Non-blocking I/O"
+ }
+ { $slide "Live coding demo"
+
+ }
+ { $slide "C library interface"
+ "Efficient"
+ "No need to write C code"
+ "Supports floats, structs, unions, ..."
+ "Function pointers, callbacks"
+ }
+ { $slide "Live coding demo"
+
+ }
+ { $slide "Community"
+ "Factor development began in 2003"
+ "About a dozen contributors"
+ "Handful of \"core contributors\""
+ { "Web site: " { $url "http://factorcode.org" } }
+ "IRC: #concatenative on irc.freenode.net"
+ "Mailing list: factor-talk@lists.sf.net"
+ { "Let's play " { $vocab-link "space-invaders" } }
+ }
+} ;
+
+: minneapolis-talk minneapolis-slides slides-window ;
+
+MAIN: minneapolis-talk
--- /dev/null
+- how to create a small module\r
+- editor integration\r
+- presentations\r
+- module system\r
+- copy and paste factoring, inverse\r
+- help system\r
+- tetris\r
+- memoization\r
+- editing inspector demo\r
+- dynamic scope, lexical scope\r
+\r
+Factor: contradictions?\r
+-----------------------\r
+\r
+Have our cake and eat it too\r
+\r
+Research -vs- practical\r
+High level -vs- fast\r
+Interactive -vs- deployment\r
+\r
+Factor from 10,000 feet\r
+-----------------------\r
+\r
+word: named function\r
+vocabulary: module\r
+quotation: anonymous function\r
+classes, objects, etc.\r
+\r
+The stack\r
+---------\r
+\r
+- Stack -vs- applicative\r
+- Pass by reference, dynamically typed\r
+- Stack languages: you can omit names where they're not needed\r
+- More compositional style\r
+- If you need to name things for clarity, you can:\r
+ lexical vars, dynamic vars, sequences, assocs, objects...\r
+\r
+Functional programming\r
+----------------------\r
+\r
+Quotations\r
+Curry\r
+Continuations\r
+\r
+Object-oriented programming\r
+---------------------------\r
+\r
+Generic words: sort of like open classes\r
+Tuple reshaping\r
+Editing inspector\r
+\r
+Meta programming\r
+----------------\r
+\r
+Simple, orthogonal core\r
+\r
+Why use a stack at all?\r
+-----------------------\r
+\r
+Nice idioms: 10 days ago\r
+Copy and paste factoring\r
+Easy meta-programming\r
+Sequence operations correspond to functional operations:\r
+- curry is adding at the front\r
+- compose is append\r
+\r
+UI\r
+--\r
+\r
+Written in Factor\r
+renders with OpenGL\r
+Windows, X11, Cocoa backends\r
+You can call Windows, X11, Cocoa APIs directly\r
+OpenGL 2.1 shaders, OpenAL 3D audio...\r
+\r
+Tools\r
+-----\r
+\r
+Edit\r
+Usages\r
+Profiler\r
+Easy to make your own tools\r
+\r
+Implementation\r
+--------------\r
+\r
+Two compilers\r
+Generational garbage collector\r
+Non-blocking I/O\r
+\r
+Hands on\r
+--------\r
+\r
+Community\r
+---------\r
+\r
+Factor started in 2003\r
+About a dozen contributors\r
+Handful of "core contributors"\r
+Web site: http://factorcode.org\r
+IRC: #concatenative on irc.freenode.net\r
+Mailing list: factor-talk@lists.sf.net\r
+\r
+C library interface\r
+-------------------\r
+\r
+Efficient\r
+No need to write C code\r
+Supports floats, structs, unions, ...\r
+Function pointers, callbacks\r
+Here is an example\r
+\r
+TerminateProcess\r
+\r
+process-handle TerminateProcess\r
--- /dev/null
+Slides for a talk at Catalyst IT NZ, July 2007
TUPLE: label-control ;
M: label-control model-changed
- swap model-value over set-label-text relayout ;
+ swap model-value over set-label-string relayout ;
: <label-control> ( model -- gadget )
"" <label> label-control construct-control ;