Skip to content

Commit

Permalink
The initial contents of arc0.tar.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Feb 1, 2008
0 parents commit a2abf3b
Show file tree
Hide file tree
Showing 14 changed files with 4,609 additions and 0 deletions.
1,093 changes: 1,093 additions & 0 deletions ac.scm

Large diffs are not rendered by default.

535 changes: 535 additions & 0 deletions app.arc

Large diffs are not rendered by default.

1,496 changes: 1,496 additions & 0 deletions arc.arc

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions as.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; mzscheme -m -f as.scm
; (tl)
; (asv)
; http://localhost:8080

(require mzscheme) ; promise we won't redefine mzscheme bindings

(load "ac.scm")
(require "brackets.scm")
(use-bracket-readtable)

(aload "arc.arc")
(aload "libs.arc")

(tl)

107 changes: 107 additions & 0 deletions blog.arc
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
; Blog tool example. 20 Jan 08.

; To run:
; arc> (load "blog.arc")
; arc> (bsv)
; go to http://localhost:8080/blog

(= postdir* "arc/posts/" maxid* 0 posts* (table))

(= blogtitle* "A Blog")

(deftem post
id nil
title nil
text nil)

(def load-posts ()
(each id (map [coerce _ 'int] (dir postdir*))
(= maxid* (max maxid* id)
(posts* id) (temload 'post (string postdir* id)))))

(def save-post (p)
(save-table p (string postdir* (p 'id))))

(def post (id) (posts* (errsafe (coerce id 'int))))

(mac blogpage body
`(whitepage
(center
(widtable 600
(tag b (link blogtitle* "blog"))
(br 3)
,@body
(br 3)
(w/bars (link "archive")
(link "new post" "newpost"))))))

(defop viewpost req
(aif (post (arg req "id"))
(post-page (get-user req) it)
(notfound)))

(def permalink (p) (string "viewpost?id=" (p 'id)))

(def post-page (user p) (blogpage (display-post user p)))

(def display-post (user p)
(tag b (link (p 'title) (permalink p)))
(when user
(sp)
(link "[edit]" (string "editpost?id=" (p 'id))))
(br2)
(pr (p 'text)))

(def notfound ()
(blogpage (pr "No such post.")))

(defopl newpost req
(whitepage
(aform (fn (req)
(let user (get-user req)
(post-page user
(addpost user (arg req "t") (arg req "b")))))
(tab
(row "title" (input "t" "" 60))
(row "text" (textarea "b" 10 80))
(row "" (submit))))))

(def addpost (user title text)
(let p (inst 'post 'id (++ maxid*) 'title title 'text text)
(save-post p)
(= (posts* (p 'id)) p)))

(defopl editpost req
(aif (post (arg req "id"))
(edit-page (get-user req) it)
(notfound)))

(def edit-page (user p)
(whitepage
(vars-form user
`((string title ,(p 'title) t t)
(text text ,(p 'text) t t))
(fn (name val) (= (p name) val))
(fn () (save-post p)
(post-page user p)))))

(defop archive req
(blogpage
(tag ul
(each p (map post (rev (range 1 maxid*)))
(tag li (link (p 'title) (permalink p)))))))

(defop blog req
(let user (get-user req)
(blogpage
(for i 0 4
(awhen (posts* (- maxid* i))
(display-post user it)
(br 3))))))

(def bsv ()
(ensure-dir postdir*)
(load-posts)
(asv))


48 changes: 48 additions & 0 deletions brackets.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
; From Eli Barzilay, eli@barzilay.org

;> (require "brackets.scm")
;> (use-bracket-readtable)
;> ([+ _ 1] 10)
;11

(module brackets mzscheme

; main reader function for []s
; recursive read starts with default readtable's [ parser,
; but nested reads still use the curent readtable:

(define (read-square-brackets ch port src line col pos)
`(fn (_)
,(read/recursive port #\[ #f)))

; a readtable that is just like the builtin except for []s

(define bracket-readtable
(make-readtable #f #\[ 'terminating-macro read-square-brackets))

; call this to set the global readtable

(provide use-bracket-readtable)

(define (use-bracket-readtable)
(current-readtable bracket-readtable))

; these two implement the required functionality for #reader

;(define (*read inp)
; (parameterize ((current-readtable bracket-readtable))
; (read inp)))

(define (*read . args)
(parameterize ((current-readtable bracket-readtable))
(read (if (null? args) (current-input-port) (car args)))))

(define (*read-syntax src port)
(parameterize ((current-readtable bracket-readtable))
(read-syntax src port)))

; and the need to be provided as `read' and `read-syntax'

(provide (rename *read read) (rename *read-syntax read-syntax))

)
61 changes: 61 additions & 0 deletions code.arc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
; Code analysis. Spun off 21 Dec 07.

; Ought to do more of this in Arc. One of the biggest advantages
; of Lisp is messing with code.

(def codelines (file)
(w/infile in file
(summing test
(whilet line (readline in)
(test (aand (pos nonwhite line) (isnt it #\;)))))))

(def codeflat (file)
(len (flat (readall (infile file)))))

(def codetree (file)
(trav + (fn (x) 1) (readall (infile file))))

(def code-density (file)
(/ (codetree file) (codelines file)))

(def tokcount (files)
(let counts (table)
(each f files
(each token (flat (readall (infile f)))
(= (counts token)
(+ 1 (or (counts token) 0)))))
counts))

(def common-tokens (files)
(let counts (tokcount files)
(let ranking nil
(maptable (fn (k v)
(unless (nonop k)
(insort (compare > cadr) (list k v) ranking)))
counts)
ranking)))

(def nonop (x)
(in x 'quote 'unquote 'quasiquote 'unquote-splicing))

(def common-operators (files)
(keep [and (isa (car _) 'sym) (bound (car _))] (common-tokens files)))

(def top40 (xs)
(map prn (firstn 40 xs))
t)

(def space-eaters (files)
(let counts (tokcount files)
(let ranking nil
(maptable (fn (k v)
(when (and (isa k 'sym) (bound k))
(insort (compare > [* (len (coerce (car _) 'string))
(cadr _)])
(list k v (* (len (string k)) v))
ranking)))
counts)
ranking)))

;(top40 (space-eaters allfiles*))

2 changes: 2 additions & 0 deletions copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This software is copyright (c) Paul Graham and Robert Morris. Permission
to use it is granted under the Perl Foundations's Artistic License 2.0.
Loading

0 comments on commit a2abf3b

Please sign in to comment.