This file contains 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 | |
(struct proc/prop (f v) | |
#:property prop:procedure 0) | |
(define (procedure-property p [fail #f]) | |
(if (proc/prop? p) | |
(proc/prop-v p) | |
fail)) |
This file contains 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/generator | |
rackunit | |
rackunit/text-ui) | |
(define/contract (group seq group-size) | |
(sequence? natural-number/c . -> . sequence?) | |
(in-generator | |
(let-values ([(l final-chunk) | |
(for/fold ([l 0] [this-chunk null]) |
This file contains 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
Welcome to Racket v5.1.1.6. | |
> (time (for/first ([i (in-naturals 1)] | |
#:when (regexp-match #rx"^(1|0)*$" | |
(number->string (* i 225)))) | |
(* i 225))) | |
cpu time: 53687 real time: 53692 gc time: 1072 | |
11111111100 | |
> |
This file contains 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 unstable/dict) | |
(provide main) | |
;; Set[String] | |
(define stopwords (list->set (file->lines "./stopwords.txt"))) | |
;; String -> List[String] | |
(define (tokenize raw-text) ;; Lowercases and splits on non-letters, non-numbers. | |
(filter-not (λ (e) (set-member? stopwords e)) |
This file contains 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 at-exp racket | |
(define str | |
@string-append||{ | |
;; giant wall of characters goes here | |
}||) | |
(define (frequencies l) | |
(for/fold ([h (hash)]) ([i l]) (hash-update h i add1 0))) | |
(define h (frequencies str)) | |
(apply string |
This file contains 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 | |
;; translated from an algorithm in C from | |
;; Hyberts SG, Takeuchi K, Wagner G (2010) Poisson-gap sampling and | |
;; forward maximum entropy reconstruction for enhancing the resolution | |
;; and sensitivity of protein NMR Data. J Am Chem Soc 132:2145–2147 | |
;; generate random Poisson-distributed numbers as given | |
;; by Donald E. Knuth (1969). Seminumerical Algorithms. | |
;; The Art of Computer Programming, Volume 2. Addison Wesley |
This file contains 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 | |
(: stx Syntax) | |
(define stx #'bar) | |
(syntax-case stx () | |
[foo (identifier? #'foo) (symbol=? 'bar (syntax-e #'foo))] | |
[_ (error 'whoops)]) |
This file contains 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-syntax (cond* stx) | |
(syntax-case stx () | |
[(_ x clause ...) | |
#`(cond clause ... [else (typecheck-fail #,stx "incomplete coverage" #:covered-id x)])])) | |
(: f : (U String Integer) -> Boolean) | |
(define (f x) | |
(cond* x |
This file contains 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 | |
#reader"read-eval.rkt" | |
(begin | |
#.(begin (define x 30) '(void)) | |
'(1 2 #.x)) |
This file contains 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/define) | |
(define-simple-macro (def (f0:id p0 ...) rhs0:expr (~seq (f:id p ...) rhs:expr) ...) | |
(define f0 (match-lambda** [(p0 ...) rhs0] [(p ...) rhs] ...))) | |
(def (fact 0) 1 (fact 1) 1 (fact n) (* n (fact (- n 1)))) | |
(fact 5) | |
OlderNewer