Skip to content

Instantly share code, notes, and snippets.

@dyoo
dyoo / iterate.rkt
Created December 10, 2012 00:21
an implementation of iterate
#lang racket
;; inspired by http://zvon.org/other/haskell/Outputprelude/iterate_f.html
(define (iterate f acc)
(make-do-sequence
(lambda ()
(values
(lambda (x) x)
(lambda (x) (f x))
@dyoo
dyoo / gist:4299589
Created December 15, 2012 21:51
another inspection example
#lang racket
(define child-insp (make-inspector (current-inspector)))
(define parent-insp (current-inspector))
;; Switch to the child inspector. Structures defined next
;; will be under its control.
(current-inspector child-insp)
@dyoo
dyoo / multicast.rkt
Last active December 10, 2015 07:18
multicast
#lang racket/base
(require racket/async-channel)
(provide multicast?
(rename-out (new-multicast multicast))
multicast-put
multicast-get-evt)
@dyoo
dyoo / gist:4411396
Last active December 10, 2015 08:58
Custodian example
#lang racket
(define cust (make-custodian))
(parameterize ([current-custodian cust])
(custodian-shutdown-all cust)
;; The following will fail, since the custodian has shut down:
(open-input-file "/usr/share/dict/words"))
@dyoo
dyoo / gist:4495946
Created January 9, 2013 19:12
ozzloy's example
#! /usr/bin/env racket
#lang racket/base
(require parser-tools/yacc
parser-tools/lex
(prefix-in : parser-tools/lex-sre))
(define-empty-tokens empty-tokens-group
(EOF
TRUE
#lang racket/base
(require (for-syntax racket/base))
(provide swap)
;; taken from:
;;http://docs.racket-lang.org/guide/syntax-case.html
(define-syntax swap
(lambda (stx)
@dyoo
dyoo / gist:4514112
Created January 11, 2013 21:31
examples for ozzloy of syntax-parse and more tests
#lang racket/base
(require (for-syntax racket/base
syntax/parse))
(provide swap)
(define-syntax (swap stx)
(syntax-parse stx
[(_ x:identifier y:identifier)
@dyoo
dyoo / initialize-ns-app.rkt
Created January 13, 2013 21:50
initialize-ns-app should do the necessary work to hook to mac os x application stuff. I ported it from https://github.com/albertz/PySDL/blob/master/SDL/__init__.py, with the hope that this will let SDL bindings work on Mac OS X without provoking the exceptions we were seeing before.
#lang racket/base
;; A small library for setting up a proper evaluation context for SDL and Allegro.
(provide initialize-ns-app)
(require ffi/unsafe
ffi/unsafe/objc)
@dyoo
dyoo / gist:4532270
Created January 14, 2013 18:43
profile from json
Profiling results
-----------------
Total cpu time observed: 53988ms (out of 54129ms)
Number of samples taken: 988 (once every 55ms)
==========================================================
Caller
Idx Total Self Name+src Local%
ms(pct) ms(pct) Callee
==========================================================
@dyoo
dyoo / gist:4533369
Created January 14, 2013 20:56
updated profile of json on large file
bash-3.2$ racket perf.rkt
Profiling results
-----------------
Total cpu time observed: 36182ms (out of 36345ms)
Number of samples taken: 634 (once every 57ms)
============================================================
Caller
Idx Total Self Name+src Local%
ms(pct) ms(pct) Callee