1 USING: help.markup namespaces peg.ebnf slides typed ;
7 { $url "https://factorcode.org" }
8 "Development started in 2003"
9 "Open source (BSD license)"
10 "Influenced by Forth, Lisp, and Smalltalk"
11 "Blurs the line between language and library"
12 "Interactive development"
13 "Upcoming release: 0.99, then... 0.100?"
26 { $slide "Concatenative"
28 { $code "3 weeks ago noon ." }
29 { $code "\"hello\" rot13 ." }
30 { $code "URL\" https://factorcode.org\" http-get" }
31 { $code "10 [ \"Hello, Factor\" print ] times" }
32 { $code "{ 4 8 15 16 23 42 } [ sum ] [ length ] bi / ." }
36 "Defined at parse time"
37 "Parts: name, stack effect, definition"
38 "Composed of tokens separated by whitespace"
39 { $code ": palindrome? ( string -- ? ) dup reverse = ;" }
41 { $code "{ f } [ \"hello\" palindrome? ] unit-test"
43 "{ t } [ \"racecar\" palindrome? ] unit-test"
48 "Quotation: un-named blocks of code"
49 { $code "[ \"Hello, World\" print ]" }
50 "Combinators: words taking quotations"
51 { $code "10 dup 0 < [ 1 - ] [ 1 + ] if ." }
52 { $code "{ -1 1 -2 0 3 } [ 0 max ] map ." }
55 { $slide "Vocabularies"
56 "Vocabularies: named sets of words"
57 { $link "vocab-index" }
58 { { $link POSTPONE: USING: } " loads dependencies" }
59 "Source, docs, tests in one place"
62 { $slide "Debugging Tools"
63 { "Let's implement the " { $snippet "fortune" } " program" }
65 "\"/usr/local/share/games/fortunes/science\""
67 "{ \"%\" } split random"
73 { $slide "Native Performance"
74 { $snippet "wc -l factor.image" }
75 "Counting lines is reasonably fast..."
77 ": simple-wc ( path -- n )"
78 " binary <file-reader> ["
80 " [ CHAR: \\n = ] count +"
81 " ] each-stream-block-slice"
84 { $code "[ \"factor.image\" simple-wc ] time" }
87 { $slide "Native Performance"
88 "But it can be even faster!"
91 "[ \"factor.image\" wc ] time"
94 { $code "\"tools.wc\" deploy" }
97 { $slide "Visual Tools"
99 "\"Bigger\" { 12 18 24 72 } ["
100 " font-size associate format nl"
106 " swap 10 / 1 over - over 1 <rgba>"
107 " background associate format nl"
112 "\"https://factorcode.org/logo.png\" http-image."
116 "<time-display> gadget."
120 { $slide "Interactive Development"
121 "Programming is hard, let's play tetris"
122 { $vocab-link "tetris" }
123 "Tetris is hard too... let's cheat"
124 { $code "\"tetris.tetromino\" edit" }
125 { "Factor workflow: change code, " { $snippet "F2" } ", test, repeat" }
128 { $slide "Parsing Words"
129 "Extensible syntax, DSLs"
130 "Most parsing words fall in one of two categories"
131 "First category: literal syntax for new data types"
132 "Second category: defining new types of words"
133 "Some parsing words are more complicated"
136 { $slide "Parsing Words - Pairs"
137 "Generic array syntax"
141 { $code "SYNTAX: => dup pop scan-object 2array suffix! ;" }
145 { $slide "Parsing Words - Dice"
146 { $vocab-link "dice" }
147 { $code "ROLL: 2d8+5"
149 "\"You do %s points of damage!\\n\" printf" }
150 { $code "\\ ROLL: see" }
151 { $code "[ ROLL: 2d8+5 ] ." }
154 { $slide "Parsing Words - Regexp"
155 { $vocab-link "regexp" }
156 "Pre-compiles regexp at parse time"
157 "Implemented with library code"
158 { $code "\"ababbc\" \"[ab]+c\" <regexp> matches? ." }
159 { $code "\"ababbc\" R/ [ab]+c/ matches? ." }
162 { $slide "Parsing Words - XML"
163 { $vocab-link "xml" }
164 "Implemented with library code"
165 "Useful syntax forms"
167 "{ \"three\" \"blind\" \"mice\" }"
168 "[ [XML <li><-></li> XML] ] map"
169 "[XML <ul><-></ul> XML]"
174 { $slide "Local Variables"
175 "Sometimes, there's no good stack solution to a problem"
176 "Or, you're porting existing code in a quick-and-dirty way"
177 "Combinator with 5 parameters!"
179 ":: branch ( a b neg zero pos -- )"
180 " a b = zero [ a b < neg pos if ] if ; inline"
182 "Unwieldy with the stack"
185 { $slide "Local Variables"
187 ": check-voting-age ( age -- )"
189 " [ \"You're underage, sorry...\" print ]"
190 " [ \"Yay, register to vote!\" print ]"
191 " [ \"Participate in democracy!\" print ]"
194 "Locals are entirely implemented in Factor"
195 "Example of compile-time meta-programming"
196 "No performance penalty -vs- using the stack"
199 { $slide "Dynamic Variables"
200 "Implemented as a stack of hashtables"
201 { "Useful words are " { $link get } ", " { $link set } }
202 "Input, output, error streams are stored in dynamic variables"
203 "Read from a string..."
204 { $code "\"cat\\ndog\\nfish\" [ readln ] with-string-reader" }
205 "Read from a file..."
206 { $code "\"LICENSE.txt\" utf8 [ readln ] with-file-reader" }
209 { $slide "Destructors"
210 "Deterministic resource disposal"
211 "Any step can fail and we don't want to leak resources"
212 "We want to conditionally clean up sometimes"
213 { $code ": do-stuff ( -- )
217 ... work goes here ...
218 ] with-destructors ;"
226 " [ 1 - fib ] [ 2 - fib ] bi +"
229 { $code "[ 40 fib ] time" }
230 "Very slow! Let's profile it..."
231 { $code "[ 40 fib ] profile" }
236 { $slide "Profiling - Typed"
237 { "Type declarations with " { $link POSTPONE: TYPED: } }
239 "TYPED: fib ( m: fixnum -- n )"
241 " [ 1 - fib ] [ 2 - fib ] bi +"
247 { $slide "Profiling - Memoize"
248 { "Memoization using " { $link POSTPONE: MEMO: } }
250 "MEMO: fib ( m -- n )"
252 " [ 1 - fib ] [ 2 - fib ] bi +"
256 { $code "10,000 fib number>string "
257 "80 group [ print ] each" }
261 "Expand at compile-time"
262 "Return a quotation to be compiled"
263 "Can express non-static stack effects"
264 { $code "MACRO: ndup ( n -- quot )"
265 " [ \\ dup ] [ ] replicate-as ;"
267 { $code "[ 5 ndup ] infer" }
268 { $code "[ 5 ndup ] expand-macros" }
271 { $slide "PEG / EBNF"
272 { { $link POSTPONE: EBNF: } ": a complex parsing word" }
273 "Implements a custom syntax for expressing parsers"
274 { "Example: " { $vocab-link "printf" } }
276 "2003 <year> ago duration>years"
278 "\"%s is %d years old\\n\" printf" }
279 { $code "[ \"%s monkeys\" printf ] expand-macros" }
283 "A tuple is a user-defined class which holds named values."
285 "TUPLE: rectangle width height ;"
287 "TUPLE: circle radius ;"
292 "Constructing instances:"
293 { $code "rectangle new" }
294 { $code "rectangle boa" }
297 ": <rectangle> ( w h -- r ) rectangle boa ;"
299 ": <circle> ( r -- c ) circle boa ;"
303 { $slide "Single Dispatch"
304 ! "Generic words and methods"
305 { $code "GENERIC: area ( shape -- n )" }
309 " [ width>> ] [ height>> ] bi * ;"
311 "M: circle area radius>> sq pi * ;"
313 "We can compute areas now."
314 { $code "100 20 <rectangle> area ." }
315 { $code "3 <circle> area ." }
318 { $slide "Multiple Dispatch"
319 { $code "SINGLETONS: rock paper scissors ;" }
321 { $code "FROM: multi-methods => GENERIC: METHOD: ;"
323 "GENERIC: beats? ( obj1 obj2 -- ? )"
325 "METHOD: beats? { scissors paper } 2drop t ;"
326 "METHOD: beats? { rock scissors } 2drop t ;"
327 "METHOD: beats? { paper rock } 2drop t ;"
328 "METHOD: beats? { object object } 2drop f ;"
332 { $slide "Multiple Dispatch"
333 "Let's play a game..."
334 { $code ": play. ( obj -- )"
335 " { rock paper scissors } random {"
336 " { [ 2dup beats? ] [ \"WIN\" ] }"
337 " { [ 2dup = ] [ \"TIE\" ] }"
339 " } cond \"%s vs. %s: %s\\n\" printf ;"
341 "With a simple interface:"
342 { $code ": rock ( -- ) \\ rock play. ;"
343 ": paper ( -- ) \\ paper play. ;"
344 ": scissors ( -- ) \\ scissors play. ;"
348 { $slide "Object System"
349 "Supports \"duck typing\""
350 "Two tuples can have a slot with the same name"
351 "Code that uses accessors will work on both"
352 "Objects are not hashtables; slot access is very fast"
353 "Tuple slots can be reordered/redefined"
354 "Instances in memory will be updated"
357 { $slide "Object System"
360 "PREDICATE: positive < integer 0 > ;"
361 "PREDICATE: negative < integer 0 < ;"
363 "GENERIC: abs ( m -- n )"
366 "M: negative abs -1 * ;"
370 { $slide "Object System"
371 "And lots more features..."
372 "Inheritance, type declarations, read-only slots, union, intersection, singleton classes, reflection"
373 "Object system is entirely implemented in Factor"
377 "Access the Time Stamp Counter"
379 "HOOK: rdtsc cpu ( -- n )
387 ] alien-assembly ;" }
392 sqrt – square root function
400 { $code "FUNCTION: double sqrt ( double x )" }
404 { "Syntax experiments with " { $vocab-link "infix" } }
405 "Infix word definitions:"
406 { $code "INFIX:: foo ( x y -- z ) sqrt(x)+y**3 ;" }
408 { $code "[let \"hello\" :> seq"
409 " [infix seq[::-1] infix]"
414 { $slide "Implementation"
415 "VM in C++ (12,000 lines of code)"
416 "VM features primitives, garbage collection, etc."
417 "Lines of code: 300,000"
418 "Lines of tests: 80,000"
419 "Lines of docs: 70,000"
420 "One big repository, and we love contributions!"
423 { $slide "Project Infrastructure"
424 { $url "https://factorcode.org" }
425 { $url "https://concatenative.org" }
426 { $url "https://docs.factorcode.org" }
427 { $url "https://planet.factorcode.org" }
428 { $url "https://paste.factorcode.org" }
429 "Uses our HTTP server, SSL, DB, Atom libraries..."
432 { $slide "Project Infrastructure"
433 "Build farm, written in Factor"
434 "Multiple OS and architecture"
435 "Builds Factor and all libraries, runs tests, makes binaries"
436 "Saves us from the burden of making releases by hand"
437 "Maintains stability"
441 "It is hard to cover everything in a single talk"
442 "Factor has many cool things that I didn't talk about"
443 { $code "\"demos\" run" }
444 "Let's look at a real program!"
447 { $slide "Cool Things"
454 "\"programming\" subreddit."
458 { $slide "Cool Things"
459 { $vocab-link "minesweeper" }
460 { $vocab-link "game-of-life" }
461 { $vocab-link "boids" }
462 { $vocab-link "pong" }
465 { $slide "Cool Things"
468 "\"resource:roms\" rom-root set-global"
470 { $vocab-link "roms.space-invaders" }
473 { $slide "Cool Things"
474 { $vocab-link "bloom-filters" }
475 { $vocab-link "cuckoo-filters" }
476 { $vocab-link "persistent" }
477 { $vocab-link "trees" }
478 { $vocab-link "tuple-arrays" }
479 { $vocab-link "specialized-arrays" }
482 { $slide "Cool Things"
484 "USE: text-to-speech"
485 "\"hello\" speak-text"
489 "\"hello\" play-as-morse"
493 "\"hello\" flip-text ."
497 "\"I :heart: Factor! :+1!\" emojify ."
501 { $slide "Cool Things"
504 "\"x = \\\\frac{-b \\\\pm \\\\sqrt {b^2-4ac}}{2a}\""
505 "<formula> 200 >>width 75 >>height chart."
508 "100 [ 100 random ] replicate"
509 "100 [ 100 random ] replicate"
510 "zip <scatter> chart."
513 "\"/usr/share/dict/words\" utf8 file-lines"
514 "[ >lower 1 head ] histogram-by"
516 " COLOR: green >>foreground"
523 { $slide "Cool Things"
536 { $slide "Cool things"
537 { $code "./factor -run=file-server" }
538 { $code "./factor -run=file-monitor" }
539 { $code "./factor -run=tools.dns microsoft.com" }
540 { $code "./factor -run=tools.cal" }
544 : svfig-talk ( -- ) svfig-slides "SVFIG Talk" slides-window ;