USING: io math sequences ;

"Hello world" print
10 [ "Hello, Factor" print ] times
"Hello, " "Factor" append print
----
USING: io kernel sequences
http.client xml xml.data xml.traversal ;

"https://factorcode.org" http-get nip string>xml
"a" deep-tags-named
[ "href" attr ] map
[ print ] each
----
USING: accessors kernel math math.constants
math.functions prettyprint ;

TUPLE: circle radius ;
TUPLE: rectangle width height ;

GENERIC: area ( shape -- area )
M: circle area radius>> sq pi * ;
M: rectangle area [ width>> ] [ height>> ] bi * ;

rectangle new 10 >>width 20 >>height area .
----
USING: accessors smtp ;

<email>
    "john@foobar.com" >>from
    { "jane@foobar.com" } >>to
    "Up for lunch?" >>subject
    "At Tracy's." >>body
send-email
----
USING: io.encodings.utf8 io.files sequences
splitting ;

"table.txt" utf8 [
    [ "|" split ] map flip [ "|" join ] map
] change-file-lines
----
USING: sequences xml.syntax xml.writer ;

{ "three" "blind" "mice" }
[ [XML <li><-></li> XML] ] map
[XML <ul><-></ul> XML]
pprint-xml
----
USING: inspector io.files.info
io.pathnames system tools.files ;

home directory.
home file-system-info free-space>> .
image-path file-info describe
----
USING: io kernel sequences ;

4 <iota> [
    "Happy Birthday " write
    2 = "dear NAME" "to You" ? print
] each
----
USING: dice formatting ;

ROLL: 2d8+4
"You do %s points of damage!" printf
----
USING: kernel rot13 ;

"Hello, world!" rot13
"Uryyb, jbeyq!" assert=
----
USING: ascii tools.test ;

{ "HELLO" } [ "HeLlO" >upper ] unit-test
{ "Hello" } [ "HeLlO" >title ] unit-test
{ "hello" } [ "HeLlO" >lower ] unit-test
----
USING: io io.encodings.ascii io.files
random sequences splitting ;

"/usr/share/games/fortune/fortunes"
ascii file-lines { "%" } split random
[ print ] each
----
USING: combinators io kernel locals
math.functions math.parser ranges
sequences ;

100 [1..b] [| i |
    {
        { [ i 15 divisor? ] [ "FizzBuzz" ] }
        { [ i  3 divisor? ] [ "Fizz" ] }
        { [ i  5 divisor? ] [ "Buzz" ] }
        [ i number>string ]
    } cond print
] each
----
USING: kernel math sequences text-to-speech ;

"factor"

dup [ "aeiou" member? ] find drop [
    [ "way" append ]
    [ cut swap "ay" 3append ] if-zero
] when*

speak-text
----
USING: math.text.english morse sequences ;

{ 4 8 15 16 23 42 } [
    number>text play-as-morse
] each
----
USING: calendar io ;

now
[ "The date is " write timestamp>ymd print ]
[ "The time is " write timestamp>hms print ] bi
----
USING: emojify tools.test ;

{ "I ❤️ Factor! 👍!" } [
    "I :heart: Factor! :+1:!" emojify
] unit-test
----
USING: accessors sequences ;

TUPLE: person name age ;

{
    T{ person f "Jim" 30 }
    T{ person f "Sally" 27 }
    T{ person f "Rebecca" 32 }
    T{ person f "James" 28 }
    T{ person f "Benjamin" 22 }
} [ age>> ] maximum-by
----
USING: accessors io io.encodings.binary
io.encodings.string io.encodings.utf8
io.servers kernel namespaces ;

binary <threaded-server>
    1234 >>insecure
    "echo.server" >>name
    [
        [ 1024 read-partial ]
        [ write flush ] while*
    ] >>handler

start-server wait-for-server
----
"+ + * 😃 - /" dup 0 [
    {
        { CHAR: + [ 1 + ] }
        { CHAR: - [ 1 - ] }
        { CHAR: * [ 2 * ] }
        { CHAR: / [ 2 /i ] }
        { CHAR: 😃 [ sq ] }
        [ drop ]
    } case
] reduce "The program '%s' returns %d\n" sprintf
