factor changes. Todo example is currently broken.
: attrs>string ( alist -- string )
#! Convert the attrs alist to a string
#! suitable for embedding in an html tag.
- nreverse <% [ dup car % "='" % cdr % "'" % ] each %> ;
+ reverse <% [ dup car % "='" % cdr % "'" % ] each %> ;
: write-attributes ( n: namespace -- )
#! With the attribute namespace on the stack, get the attributes
USE: logging
USE: url-encoding
USE: unparser
+USE: hashtables
: expiry-timeout ( -- timeout-seconds )
#! Number of seconds to timeout continuations in
#! if they are 'timeout-seconds' old (ie. were added
#! more than 'timeout-seconds' ago.
continuation-items [ cdr dupd expired? not ] subset nip
- alist>namespace "continuation-table" set ;
+ alist>hash "continuation-table" set ;
: register-continuation ( expire? quot -- id )
#! Store a continuation in the table and associate it with
: post-request>namespace ( post-request -- namespace )
#! Return a namespace containing the name/value's from the
#! post data.
- alist>namespace ;
+ alist>hash ;
: cont-post-responder ( id -- )
#! httpd responder that retrieves a continuation for the given
"cont-utils.factor" run-file ;
: l2
"cont-examples.factor" run-file ;
-: l3 "todo.factor" run-file ;
-: l4 "todo-example.factor" run-file ;
+! : l3 "todo.factor" run-file ;
+! : l4 "todo-example.factor" run-file ;
: l5 "live-updater.factor" run-file ;
-: l6 "eval-responder.factor" run-file ;
+! : l6 "eval-responder.factor" run-file ;
: l7 "live-updater-responder.factor" run-file ;
: l8 "browser.factor" run-file ;
: la ;
: la [ 8888 httpd ] [ dup . flush [ la ] when* ] catch ;
-! : lb [ la "httpd thread exited.\n" write flush ] in-thread ;
+: lb [ la "httpd thread exited.\n" write flush ] in-thread ;
: add-todo-item ( <todo> <item> -- )
#! Add the item to the todo list
swap [
- "items" add@
+ "items" get swap unit append "items" set
] bind ;
: namespace>alist ( namespace -- alist )
: (ltake) ( n llist accum -- list )
>r >r pred dup 0 < [
- drop r> drop r> nreverse
+ drop r> drop r> reverse
] [
r> luncons swap r> cons (ltake)
] ifte ;
over [ ] = [
2drop [ ]
] [
- [ luncons ] dip
+ >r luncons r>
dup swapd
[ lmap ] curry2
- [ call ] dip
+ >r call r>
lcons
] ifte ;
over [ ] = [
2drop [ ]
] [
- [ luncons ] dip
+ >r luncons r>
dup swapd
[ lsubset ] curry2
-rot dupd call [
: (list-take) ( n list accum -- list )
>r >r pred dup 0 < [
- drop r> drop r> nreverse
+ drop r> drop r> reverse
] [
r> uncons swap r> cons (list-take)
] ifte ;
: ifte-head= ( string-or-list ch [ quot1 ] [ quot2 ] -- )
#! When the character 'ch' is equal to the head
#! of the string or list, run the quot1 otherwise run quot2.
- [ swap phead = ] 2dip ifte ;
+ r> r> swap phead = r> r> ifte ;
: symbol ( ch -- parser )
#! Return a parser that parses the given symbol.
#! Return a parser that first skips all whitespace before
#! parsing.
[ ( inp parser -- result )
- [ parse-skipwhite ] dip call
+ >r parse-skipwhite r> call
] curry1 ;
: just ( parser -- parser )
#! to the resulting parse tree.
[ ( inp p f -- result )
>r call r> [ ( [ x | xs ] f -- [ fx | xs ] )
- swap uncons [ swap over [ call ] [ drop ] ifte ] dip cons
+ swap uncons r> swap over [ call ] [ drop ] ifte r> cons
] curry1 lmap
] curry2 ;
#! Call quot with start and the first value in the list.
#! quot is then called with the result of quot and the
#! next item in the list until the list is exhausted.
- uncons >r swap dup dip r> dup [
+ uncons >r swap dup swap r> call r> r> dup [
(reduce)
] [
2drop