Skip to content

Commit

Permalink
Use OR=
Browse files Browse the repository at this point in the history
  • Loading branch information
shawwn committed Feb 6, 2019
1 parent ac8567d commit 7ed7d12
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 37 deletions.
5 changes: 4 additions & 1 deletion apps/news/blog.arc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
; A blog for news.arc
; For the standalone blog example by PG, see blog.arc from arc3.1

(= postdir* (+ srvdir* "posts/") blog-maxid* 0 posts* (table))
(= postdir* (+ srvdir* "posts/"))

(or= blog-maxid* 0
posts* (table))

(deftem post id nil by nil title nil text nil)

Expand Down
22 changes: 11 additions & 11 deletions apps/news/news.arc
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@
(def author (u i) (is u i!by))


(= stories* nil ranked-stories* nil comments* nil
items* (table) url->story* (table)
maxid* 0 initload* 15000)
(or= stories* nil ranked-stories* nil comments* nil
items* (table) url->story* (table)
maxid* 0 initload* 15000)

; The dir expression yields stories in order of file creation time
; (because arc infile truncates), so could just rev the list instead of
Expand Down Expand Up @@ -233,7 +233,7 @@
(def register-url (i url)
(= (url->story* (canonical-url url)) i!id))

(= stemmable-sites* (table))
(or= stemmable-sites* (table))

(def canonical-url (url)
(if (stemmable-sites* (sitename url))
Expand Down Expand Up @@ -268,7 +268,7 @@
(set i!dead)
(save-item i)))

(= kill-log* nil)
(or= kill-log* nil)

(def log-kill (i how)
(push (list i!id how) kill-log*))
Expand Down Expand Up @@ -416,7 +416,7 @@
background-color: #" (hexrep (main-color user)) ";"
"}"))))

(= pagefns* nil)
(or= pagefns* nil)

; page top

Expand Down Expand Up @@ -573,7 +573,7 @@
(newslog ip user ',name ,@parms)
,@body)))))

(= newsop-names* nil)
(or= newsop-names* nil)

(mac newsop args
`(do (pushnew ',(car args) newsop-names*)
Expand Down Expand Up @@ -1051,7 +1051,7 @@

(= user-changetime* 120 editor-changetime* 1440)

(= everchange* (table) noedit* (table))
(or= everchange* (table) noedit* (table))

(def canedit (user i)
(or (admin user)
Expand Down Expand Up @@ -1685,7 +1685,7 @@
(do (note-baditem user ip)
(pr "No such item.")))))

(= baditemreqs* (table) baditem-threshold* 1/100)
(or= baditemreqs* (table) baditem-threshold* 1/100)

; Something looking at a lot of deleted items is probably the bad sort
; of crawler. Throttle it for this server invocation.
Expand Down Expand Up @@ -1730,7 +1730,7 @@
(mem 'commentable i!keys))))


(= displayfn* (table))
(or= displayfn* (table))

(= (displayfn* 'story) (fn (n i user here inlist)
(display-story n i user here)))
Expand Down Expand Up @@ -1773,7 +1773,7 @@

(def editable-type (i) (fieldfn* i!type))

(= fieldfn* (table))
(or= fieldfn* (table))

(= (fieldfn* 'story)
(fn (user s)
Expand Down
4 changes: 2 additions & 2 deletions arc.arc
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ of 'x' by calling 'self'."
(def write (x (o port (stdout)))
(swrite serialize.x port))

(= hooks* (table))
(or= hooks* (table))

(def hook (name . args)
(aif (hooks* name) (apply it args)))
Expand All @@ -2905,7 +2905,7 @@ Useful in higher-order functions, or to index into lists, strings, tables, etc."
(map get.2 '((a b c) (1 2 3) (p q r)))
(c 3 r))

(= savers* (table))
(or= savers* (table))

(mac fromdisk (var file init load save)
(w/uniq (gf gv)
Expand Down
6 changes: 3 additions & 3 deletions lib/app.arc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

; idea: a bidirectional table, so don't need two vars (and sets)

(= cookie->user* (table) user->cookie* (table) logins* (table))
(or= cookie->user* (table) user->cookie* (table) logins* (table))

(def get-user (req)
"Gets the user id string associated with 'req'.
Expand Down Expand Up @@ -258,7 +258,7 @@ Returns nil if no logged-in user."
(link "Try logging in now." "/")))))
(single-input "New password: " 'p 20 "update" t)))

(= good-logins* (queue) bad-logins* (queue))
(or= good-logins* (queue) bad-logins* (queue))

(def good-login (user pw ip)
(let record (list (seconds) ip user)
Expand All @@ -279,7 +279,7 @@ Returns nil if no logged-in user."
;prepending this (stdin)= for backwards compatibility with previous hashes
(+ "(stdin)= " ($.bytes->hex-string ($.sha512 ($.string->bytes/utf-8 str)))))

(= dc-usernames* (table))
(or= dc-usernames* (table))

(def username-taken (user)
(when (empty dc-usernames*)
Expand Down
3 changes: 1 addition & 2 deletions lib/brackets.arc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; avoid redefinition warning
($ (namespace-undefine-variable! (ac-global-name '%brackets)))

(def -mbf-argsym (e)
(and (begins string.e "_")
Expand All @@ -23,7 +22,7 @@
; treats any symbols starting with '_' as args, ordered alphabetically
; e.g. _1, _2, _3, or _a, _b, _c, etc.
; treats __ as the rest arg
(mac %brackets body
(remac %brackets body
(let args '__
(each arg (dedup:sort > -mbf-argsyms.body)
(pushnew arg args))
Expand Down
2 changes: 1 addition & 1 deletion lib/declare.arc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; by [email protected]

(= declare-fns* (table))
(or= declare-fns* (table))

(defs decl-idfn (old new args) new
decl-bool (old new args) (no:no new))
Expand Down
2 changes: 1 addition & 1 deletion lib/html.arc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
darkblue (color 0 0 120)
)

(= opmeths* (table))
(or= opmeths* (table))

(mac opmeth args
`(opmeths* (list ,@args)))
Expand Down
12 changes: 6 additions & 6 deletions lib/ppr.arc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(= pprsyms* (fill-table (table)
'(quote "'"
quasiquote "`"
unquote ","
unquote-splicing ",@")))
(or= pprsyms* (fill-table (table)
'(quote "'"
quasiquote "`"
unquote ","
unquote-splicing ",@")))

(def sp ((o n 1))
" Print a number of spaces. "
Expand Down Expand Up @@ -143,7 +143,7 @@
(indent-block (nthcdr 2 xs) (+ col (len "(suite "))))
(indent-block (cdr xs) (+ col (len "(suite "))))))

(= indent-rules*
(or= indent-rules*
(fill-table (table)
`(if ,(indent-if (len "if"))
aif ,(indent-if (len "aif"))
Expand Down
2 changes: 1 addition & 1 deletion lib/prompt.arc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
(fn () (map eval exprs)))
(prompt-page user "Error: No application " app " for user " user))))

(wipe repl-history*)
(or= repl-history* nil)

(defop repl req
(if (admin (get-user req))
Expand Down
15 changes: 7 additions & 8 deletions lib/srv.arc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
; To adjust this while running, adjust the req-window* time, not
; req-limit*, because algorithm doesn't enforce decreases in the latter.

req-times* (table)
req-limit* 30
req-window* 10 ;10
dos-window* 2 ;2
)

(or= req-times* (table))

(def serve ((o port 8080))
(wipe quitsrv*)
Expand Down Expand Up @@ -65,8 +64,8 @@
; a thread to handle it. also arrange to kill that thread
; if it has not completed in threadlife* seconds.

(= threadlife* 30 requests* 0 requests/ip* (table)
throttle-ips* (table) ignore-ips* (table) spurned* (table))
(or= threadlife* 30 requests* 0 requests/ip* (table)
throttle-ips* (table) ignore-ips* (table) spurned* (table))

(def accept-request-with-deadline (s)
(with ((in out ip) (socket-accept s)
Expand Down Expand Up @@ -332,7 +331,7 @@

;; extending the server with new ops

(= srvops* (table) redirector* (table) optimes* (table) opcounts* (table))
(or= srvops* (table) redirector* (table) optimes* (table) opcounts* (table))

(def save-optime (name elapsed)
; this is the place to put a/b testing
Expand Down Expand Up @@ -392,7 +391,7 @@ stdout, returns a url to redirect requests to after processing."
it)))
""))

(= fns* (table) fnids* nil timed-fnids* nil)
(or= fns* (table) fnids* nil timed-fnids* nil)

; count on huge (expt 64 10) size of fnid space to avoid clashes

Expand Down Expand Up @@ -600,7 +599,7 @@ stdout, returns a url to redirect requests to after processing."

; only unique per server invocation

(= unique-ids* (table))
(or= unique-ids* (table))

(def unique-id ((o len 8))
(let id (sym (rand-string (max 5 len)))
Expand Down Expand Up @@ -661,7 +660,7 @@ stdout, returns a url to redirect requests to after processing."

; Background Threads

(= bgthreads* (table) pending-bgthreads* nil)
(or= bgthreads* (table) pending-bgthreads* nil)

(def new-bgthread (id f sec)
(aif (bgthreads* id) (break-thread it))
Expand Down
2 changes: 1 addition & 1 deletion lib/tem.arc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
($:require (only-in racket vector-map))

(= templates* (table))
(or= templates* (table))

(mac deftem (tem . fields)
"Defines a _template_, a table with defaults defined for various keys.
Expand Down

0 comments on commit 7ed7d12

Please sign in to comment.