This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
;; Playing with input-port-append and transplant-input-port, | |
;; with the idea of adding the #lang line for arbitrary text | |
;; without screwing up the original input port's locations. | |
(provide prepend-lang-line) | |
(require racket/port) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(provide dir) | |
(define ns (make-base-namespace)) | |
;; Provides a "dir"-like function on a module. | |
(define (dir module-path) | |
(parameterize ([current-namespace ns]) | |
(dynamic-require module-path (void)) ;; make sure _not_ to cause the module to evaluate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define ns (make-base-namespace)) | |
(define (play module-path) | |
(parameterize ([current-namespace ns]) | |
(dynamic-require module-path #f) | |
(define-values (module-variable-exports module-syntax-exports) | |
(module->exports module-path)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require data/heap | |
data/bit-vector) | |
;; A node is either an interior, or a leaf. | |
;; In either case, they record an item with an associated frequency. | |
(struct node (freq) #:transparent) | |
(struct interior node (left right) #:transparent) | |
(struct leaf node (val) #:transparent) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(syntax-case #'(this is a vector: #(3 4 5)) () | |
[(a b c d #(x y z)) | |
(list #'x #'y #'z)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require racket/port) | |
(require racket/tcp) | |
(define (start-irc #:irc-hostname [irc-hostname "chat.freenode.net"] | |
#:irc-portno [irc-portno 6667] | |
#:irc-nick [irc-nick "nyuracket"] | |
#:irc-user [irc-user "racket"] | |
#:irc-realname [irc-realname "nyuracket"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define ns (make-base-namespace)) | |
(parameterize ([current-namespace ns]) | |
(read-eval-print-loop)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require racket/provide | |
(prefix-in racket: racket)) | |
(define count 'count) | |
(provide (except-out | |
(filtered-out (lambda (name) | |
(and (regexp-match? #rx"^racket:" name) | |
(regexp-replace #rx"^racket:" name ""))) | |
(all-from-out racket)) | |
racket:count) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (my-expand-path-with-env a-path-string) | |
(define (lookup var) | |
(getenv (substring var 1))) | |
(regexp-replace* #px"\\$\\w+" a-path-string lookup)) | |
(my-expand-path-with-env "$HOME/foo/bar") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (parse-date-string str) | |
(match str | |
[(pregexp #px"^(\\d{4})-(\\d{2})-(\\d{2})$" (list _ year month day)) | |
(list (string->number year) | |
(string->number month) | |
(string->number day))])) | |
(parse-date-string "2013-03-10") |