Skip to content

Instantly share code, notes, and snippets.

View greghendershott's full-sized avatar

Greg Hendershott greghendershott

View GitHub Profile
#lang racket
;; Let's write an untyped Racket module that works fine when `require`d
;; by untyped Racket. But also, let's try to use it from Typed Racket.
(provide foo
macro-foo)
;; A user may `require/type` this _function_, and it works fine.
(define (foo x)
<html>
<head>
</head>
<body>
<p>Hello, world.</p>
</body>
</html>
@greghendershott
greghendershott / gist:8568360
Last active January 4, 2016 04:28
This rev uses `for/list` instead of `map` and `filter-map`.
#lang racket
(require (for-syntax syntax/parse
(only-in racket/syntax with-syntax*)))
;; Transform (fun a _ c _ e) => (lambda (b d) (fun a b c d))
(define-syntax (myapply stx)
(define (placeholder? stx)
(equal? (syntax-e stx) '_))
(syntax-parse stx
@greghendershott
greghendershott / gist:8553064
Created January 22, 2014 03:31
Wrong srcloc for a definer macro, even though I'm using `syntax/loc`.
#lang racket
;; This is boiled down to single file with module.
;;
;; The issue is more obvious when it's a separate file, and the error
;; message is for the wrong file as well as line number.
(module mod racket
(require (for-syntax racket/syntax
syntax/parse))
raco setup: --- building documentation ---
raco setup: running: <pkgs>/racket-doc/scribblings/reference/reference.scrbl
raco setup: 1 running: <pkgs>/racket-doc/compatibility/scribblings/compatibility.scrbl
raco setup: 2 running: <pkgs>/games/cards/cards.scrbl
raco setup: 0 running: <pkgs>/web-server-doc/web-server/scribblings/tutorial/continue.scrbl
raco setup: 3 running: <pkgs>/drracket/help/bug-report.scrbl
raco setup: 5 running: <pkgs>/algol60/algol60.scrbl
raco setup: 4 running: <pkgs>/drracket/browser/browser.scrbl
raco setup: 6 running: <pkgs>/racket-index/scribblings/main/acks.scrbl
raco setup: 7 running: <pkgs>/racket-doc/scribblings/guide/guide.scrbl
greg@mbp in ~/src/plt/racket on master*
$ make
if [ "" = "" ] ; \
then make plain-in-place PKGS="main-distribution plt-services" ; \
else make cpus-in-place PKGS="main-distribution plt-services" ; fi
make base
mkdir -p build/config
echo '#hash((links-search-files . ()))' > build/config/config.rktd
mkdir -p racket/src/build
make racket/src/build/Makefile
#lang racket
(require rackunit
sexp-diff) ;; raco pkg install sexp-diff
;; check-equal? doesn't even pretty-print the sexprs, which can be
;; very long and hard to compare. Anyway let's do even better and use
;; sexp-diff to highlight to diff.
(define-syntax (check-sexp-equal? stx)
(syntax-case stx ()
(require racket/date)
(match "2012-11-07" ;; <- @|date|
[(pregexp "(\\d{4})-(\\d{2})-(\\d{2})" (list _ y m d))
(date->string (date 0 0 0
(string->number d)
(string->number m)
(string->number y)
0 0 #f 0))])
greg@halo:~/src/shriphani-blog$ racket --version
Welcome to Racket v5.3.6.
greg@halo:~/src/shriphani-blog$ raco pkg show
Installation-wide:
[none]
User-specific, all-version:
[none]
User-specific, version-specific (5.3.6):
Package[*=auto] Checksum Source
aws #f (link /home/greg/src/racket/collects/aws)
~/src/blog$ raco frog -Vb
Frog 0.8
Using configuration /home/greg/src/blog/.frogrc
Very verbose mode
Trying to start pygments process
Reading _src/posts/2013-07-13-fast-dates-parser.md
Reading _src/posts/2013-07-13-new-blog.md
Skipping _src/posts/2013-07-13-new-blog.md~
Not named #px"^(\\d{4}-\\d{2}-\\d{2})-(.+?)\\.(?:md|markdown|scrbl)$"
Reading _src/posts/2013-07-21-accessing-your-kindle-highlights.md