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 (replace expr from to) | |
; in the expression e replace f with t | |
(define (rep e) | |
(cond | |
[(list? e) | |
(define tail (map rep (rest e))) | |
(define head (first e)) | |
(cond |
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/draw) | |
(define a-font | |
(make-font #:size 72 | |
#:face "Times Roman")) | |
(define bm (make-object bitmap% 200 200)) | |
(define bm-dc (new bitmap-dc% [bitmap bm])) |
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 (for-syntax racket/generic syntax/parse)) | |
; Normal Racket numbers are represented as (num x #f). | |
; Integers modulo p are represented as (num x p). | |
(module ring racket | |
(provide $ (rename-out [new+ +] [new- -] [new* *] [newexpt expt])) | |
(require math racket/generic (for-syntax racket/generic syntax/parse)) | |
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 (for-syntax syntax/parse) | |
(only-in srfi/1 car+cdr) | |
rackunit) | |
; This file implements an extension of cond that | |
; supports variable bindings | |
; A "#let-clause" of the form | |
; #:let ([var/vars expr] ...), |
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/control) | |
(define (make-fringe-getter tree) | |
(λ () | |
(let loop ([tree tree]) | |
(match tree | |
[(cons a d) (loop a) | |
(loop d)] | |
['() (void)] |
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 | |
(begin-for-syntax | |
(displayln "Hello world")) |
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 (fact n) | |
(mult 1 n 1)) | |
(define (mult m n k) | |
; m*(m+k)*(m+2k)*... | |
; last factor <= n | |
(if (< (- n m) k) | |
m | |
(* (mult m n (* 2 k)) |
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 (ε i j k) | |
(* (- i j) (- j k) (- k i) 1/2)) | |
(define (cross-product v w) | |
(define ref vector-ref) | |
(for/vector ([i 3]) | |
(for*/sum ([j 3] [k 3]) | |
(* (ε i j k) (ref v j) (ref w k))))) |
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
'(("JavaScript" ()) | |
("Ruby" (2)) | |
("Java" (3)) | |
("Shell" (4)) | |
("Python" (5)) | |
("PHP" (6)) | |
("C" (7)) | |
("C++" (8)) | |
("Perl" (9)) | |
("CoffeeScript" (10)) |
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 (for-syntax racket/list)) | |
(define-syntax (foo stx) | |
(define (quote-it stx) (list 'quote stx)) | |
(define name+xs (syntax->list stx)) | |
(define name (first name+xs)) ; unused (is foo) | |
(define xs (rest name+xs)) | |
(define result-as-list (cons 'vector (map quote-it xs))) | |
(datum->syntax stx result-as-list)) |