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 typed/racket | |
| (define-type T (U String Integer)) | |
| (: fizzbuzz/1 : (Integer -> T)) | |
| (define (fizzbuzz/1 x) | |
| (define mod3 (zero? (modulo x 3))) | |
| (define mod5 (zero? (modulo x 5))) | |
| (cond [(and mod3 mod5) "fizzbuzz"] | |
| [mod3 "fizz"] |
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 syntax/modresolve) | |
| ;; An example of letting Racket tell you where things are defined. | |
| (resolve-module-path-index (first (identifier-binding #'for/hash)) | |
| (current-directory)) |
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-syntax (for/string stx) | |
| (syntax-case stx () | |
| [(_ clauses . defs+exprs) | |
| (with-syntax ([original stx]) | |
| (syntax/loc stx | |
| (apply string-append | |
| (reverse | |
| (for/fold/derived original |
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 (find-duplicates elts) | |
| (define ht (make-hash)) | |
| (for/fold ([dups '()]) ([x (in-list elts)]) | |
| (hash-set! ht x (add1 (hash-ref ht x 0))) | |
| (cond | |
| [(= (hash-ref ht x) 2) | |
| (cons x dups)] |
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 | |
| ;; A str-expr is either: | |
| ;; | |
| ;; 1. a plain string, or | |
| ;; 2. (list '+ str-expr str-expr) | |
| ;; 3. (list '* number str-expr) | |
| ;; evaluate: str-expr -> string |
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 (f x) | |
| (* x x)) | |
| (provide f) | |
| (module* foo racket/base | |
| ;; External test of the function | |
| (require rackunit |
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 | |
| (module foo ragg/sexp/lang | |
| rule-1: "0"+ || rule-2 | |
| rule-2: "1" | |
| ) | |
| (require (prefix-in test: (submod "." foo))) |
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 (for-syntax racket/base syntax/parse)) | |
| (module+ test (require rackunit)) | |
| (define-syntax (test+ stx) | |
| (syntax-parse stx | |
| #:literals (=>) | |
| [(_ (fn arg ...) => v) | |
| (with-syntax ([fn-name (symbol->string (syntax->datum #'fn))]) |
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 syntax/parse) | |
| (syntax-parse #'("foo" "bar") | |
| [((~and "foo" x) y) | |
| (list #'x #'y)]) | |
| (syntax-parse #'("food" "bar") | |
| [((~and "foo" x) y) | |
| (list #'x #'y)]) |
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 ragg/examples/simple-line-drawing/lexer | |
| ragg/examples/simple-line-drawing/grammar | |
| syntax/strip-context | |
| syntax/parse | |
| (for-syntax racket/base)) | |
| (define-syntax (drawing stx) (raise-syntax-error #f "Don't look at me; I'm shy" stx)) |