what about hyphens?

main
Matthew Butterick 7 years ago
parent 2f698e6cc9
commit e5de445c5c

@ -25,7 +25,10 @@
(define (offset q [signal #f]) (hash-ref (attrs q) 'offset '(0 0)))
(define (origin q) (hash-ref (attrs q) 'origin '(0 0)))
(define (set-origin! q val) (set-$quad-attrs! q (hash-set (attrs q) 'origin val)))
(define (draw q [surface #f] [origin #f]) ((hash-ref (attrs q) 'draw (λ () (λ () (println "<no draw routine>"))))))])
(define (draw q [surface #f])
(define (default-draw-proc q surface)
(for-each (λ (e) (draw e surface)) (elems q)))
((hash-ref (attrs q) 'draw (const default-draw-proc)) q surface))])
(define (quad-attrs? x) (and (hash? x) (hash-eq? x)))
(define (quad-elem? x) (or (char? x) (string? x) ($quad? x)))
@ -59,5 +62,5 @@
'exit 10+10i
'inner 5+5i
'size 8+8i
'draw (λ () (println "foo"))) '(#\H #\e #\l #\o)))
'draw (λ (q doc) (println "foo"))) '(#\H #\e #\l #\o)))
(draw x))

@ -2,26 +2,4 @@
To get started with Racket, download it from the web page and install it. If you are a beginner or would like to use a graphical environment to run programs, run the DrRacket executable. Otherwise, the racket executable will run a command-line Read-Eval-Print-Loop (REPL).
On Windows, you can start DrRacket from the Racket entry in the Start menu. In Windows Vista or newer, you can just type DrRacket. You can also run it from its folder, which you can find in Program Files Racket DrRacket.
On Mac OS, double click on the DrRacket icon. It is probably in a Racket folder that you dragged into your Applications folder. If you want to use command-line tools, instead, Racket executables are in the "bin" directory of the Racket folder (and if you want to set your PATH environment variable, youll need to do that manually).
On Unix (including Linux), the drracket executable can be run directly from the command-line if it is in your path, which is probably the case if you chose a Unix-style distribution when installing. Otherwise, navigate to the directory where the Racket distribution is installed, and the drracket executable will be in the "bin" subdirectory.
If you are new to programming or if you have the patience to work through a textbook:
How to Design Programs is the best place to start. Whenever the book says “Scheme, you can read it as “Racket.”
Continue: Web Applications in Racket introduces you to modules and building web applications.
The Racket Guide describes the rest of the Racket language, which is much bigger than the learning-oriented languages of the textbook. Since you learned functional programming from the textbook, youll be able to skim chapters 1 and 2 of the Guide.
If youre already a programmer and youre in more of a hurry:
Quick: An Introduction to Racket with Pictures gives you a taste of Racket.
More: Systems Programming with Racket dives much deeper and much faster. If its too much, just skip to the Guide.
The Racket Guide starts with a tutorial on Racket basics, and then it describes the rest of the Racket language.
Of course, you should feel free to mix and match the above two tracks, since there is information in each that is not in the other.
@(number->string (current-seconds))

@ -1,17 +1,13 @@
#lang debug br/quicklang
(require racket/promise racket/list sugar/list sugar/debug "quad.rkt" "atomize.rkt" "wrap.rkt" "qexpr.rkt" "generic.rkt" "position.rkt")
(require pitfall/document)
(provide (rename-out [mb #%module-begin]))
(provide (rename-out [mb #%module-begin]) (except-out (all-from-out br/quicklang) #%module-begin))
(define optional-break? (λ (q) (and (quad? q) (memv (car (elems q)) '(#\space)))))
(define optional-break? (λ (q) (and (quad? q) (memv (car (elems q)) '(#\space #\-)))))
(struct $shim $quad () #:transparent)
(struct $char $quad () #:transparent)
(define (charify q) ($char (hash-set (attrs q) 'size '(7.2 12)) (elems q)))
(define (shimify xs) (add-between (map charify xs)
(list ($shim (hasheq) null))
#:splice? #t
#:before-first (list ($shim (hasheq) null))
#:after-last (list ($shim (hasheq) null))))
(define (charify q) ($char (hash-set* (attrs q) 'size (const '(7.2 12))
'draw (λ (q doc) (send/apply doc text (apply string (elems q)) (origin q)))) (elems q)))
(struct $line $quad () #:transparent)
(struct $page $quad () #:transparent)
(struct $doc $quad () #:transparent)
@ -19,23 +15,23 @@
(define (break . xs) ($break (hasheq 'size '(0 0)) xs))
(define line-height 16)
(define (lbs xs size [debug #f])
(define (line-wrap xs size [debug #f])
(wrap xs size debug
#:break-val (break #\newline)
#:optional-break-proc optional-break?
#:finish-segment-proc (λ (pcs) (list ($line (hasheq 'size (list +inf.0 line-height) 'out 'sw) pcs)))))
(define (pbs xs size [debug #f])
(define (page-wrap xs size [debug #f])
(wrap xs size debug
#:break-val (break #\page)
#:optional-break-proc $break?
#:finish-segment-proc (λ (pcs) (list ($page (hasheq) (filter-not $break? pcs))))))
(define (typeset args)
(define chars 60)
(define chars 33)
(define line-width (* 7.2 chars))
(define lines-per-page (* 40 line-height))
(position ($doc (hasheq 'origin '(72 72)) (filter-not $break? (pbs (lbs (map charify (atomize (apply quad #f args))) line-width) lines-per-page)))))
(position ($doc (hasheq 'origin '(36 36)) (page-wrap (line-wrap (map charify (atomize (apply quad #f args))) line-width) lines-per-page))))
(define-macro (mb . ARGS)
@ -43,18 +39,16 @@
#'(#%module-begin
(define q (typeset (list . ARGS)))
;q
(let ()
(define doc (make-object PDFDocument (hasheq 'compress #f)))
(send doc pipe (open-output-file PS #:exists 'replace))
(send doc font "Courier")
(send doc fontSize 12)
(let loop ([q q])
(cond
[($char? q)
(send/apply doc text (apply string (elems q)) (origin q))]
[(quad? q) (map loop (elems q))]))
(send doc end)
(void)))))
(let ([doc (make-object PDFDocument
(hasheq 'compress #f
'size '(300 400)))])
(send* doc
[pipe (open-output-file PS #:exists 'replace)]
[font "Courier"]
[fontSize 12])
(draw q doc)
(send doc end))
(void))))
(module reader syntax/module-reader
quad/typewriter

Loading…
Cancel
Save