Skip to content

Instantly share code, notes, and snippets.

#lang racket
(require racket/pretty)
(define list-with-elts
(range 100))
(pretty-print-columns 'infinity)
(print list-with-elts)
@dyoo
dyoo / pretty-print-example.rkt
Created April 13, 2013 21:31
pretty printing example for eg0
#lang racket
(require racket/pretty)
(define list-with-elts
(range 100))
(pretty-print list-with-elts)
@dyoo
dyoo / wescheme-module-resolver.rkt
Created April 9, 2013 22:30
Requiring WeScheme code for Racket. Preliminary.
#lang racket/base
(require net/url
net/uri-codec
json)
;; Experiments with module-name-resolvers.
(define old-module-name-resolver (current-module-name-resolver))
@dyoo
dyoo / annotation-example.rkt
Last active December 15, 2015 19:49
An example of using namespaces and modules to communicate between annotated, expanded syntax, and some external evaluator. We do it without 3d syntax, which avoids the sort of silly problems that can happen otherwise. (e.g. we can actually compile the code.)
#lang racket
;; Experiment: interaction between compiled code and a tool.
;;
;; Typically, 3d syntax is often used here. But let's say we don't
;; want 3d syntax. Is there another way?
;;
;; Idea: when evaluating code, attach a module to the evaluating
;; namespace that the code and the tool share.
;;
@dyoo
dyoo / gist:5304560
Last active December 15, 2015 18:30
#lang racket
(require (for-syntax syntax/boundmap
syntax/parse))
(begin-for-syntax
(define const-table (make-free-identifier-mapping)))
(define-syntax (define-int-constant stx)
(syntax-parse stx
@dyoo
dyoo / drawing-example.rkt
Created April 2, 2013 21:10
Bitmap drawing example; submitted to Rosetta Code.
#lang racket
;; The racket/draw libraries provide imperative drawing functions.
;; http://docs.racket-lang.org/draw/index.html
(require racket/draw)
;; To create an image with width and height, use the make-bitmap
;; function.
;; For example, let's make a small image here:
@dyoo
dyoo / flood-fill.rkt
Created April 2, 2013 21:09
Flood fill example; submitted to Rosetta Code
#lang racket
(require racket/draw)
;; flood-fill: bitmap<%> number number color color -> void
;; An example of flood filling a bitmap.
;;
;; We'll use a raw, byte-oriented interface here for demonstration
;; purposes. Racket does provide get-pixel and set-pixel functions
;; which work on color% structures rather than bytes, but it's useful
#lang racket
(require parser-tools/lex)
(require (prefix-in : parser-tools/lex-sre))
(require racket/port)
(define a-lexer
(lexer ("a" `(A ,lexeme))
((eof) eof)))
;; produce a list of pairs for all the A tokens in the string "aa"
@dyoo
dyoo / gist:5286702
Last active December 15, 2015 16:09
#lang racket
(require racket/draw)
(define bm (make-bitmap 640 480))
(define dc (send bm make-dc))
(define pixs (make-hash))
(define black (make-object color% 0 0 0))
(define (plot row col)
(hash-set! pixs (list col row) 1)
@dyoo
dyoo / modularize-input-port.rkt
Last active December 15, 2015 14:19
Modularize an input port; we may want to preserve source location even though there's no lang line.
#lang racket/base
(require racket/port
racket/contract)
(provide (contract-out [modularize-input-port (->
#:name symbol?
#:ip input-port?
#:lang symbol?
input-port?)]))