Skip to content

Instantly share code, notes, and snippets.

@takikawa
takikawa / gist:2597330
Last active October 4, 2015 06:58
Simple debugger-like thing
View gist:2597330
#lang racket
(require racket/control
gui-debugger/annotator)
(provide debug step! set-breakpoint!)
;; original and annotated syntax objects
(define orig-stx #f)
(define ann-stx #f)
View gist:2669212
(define a -1)
(define b 1)
;; original
(define x ((λ ()
(let ([l '()])
(define (loop i)
(if (< i b)
(begin (append (loop (+ i 1/100)) (list i)))
(append l (list i))))
@takikawa
takikawa / gist:2784657
Created May 24, 2012 22:41
Inits are weird
View gist:2784657
Welcome to Racket v5.3.0.8.
-> (define c (class object% (init [x 0]) (super-new)))
-> (define d (class c (init [x 0] [y 0]) (super-instantiate () [x x])))
-> (make-object d 1)
(object:d ...)
-> (make-object d 1 2)
(object:d ...)
-> (make-object d 1 2 4)
; instantiate: unused initialization arguments: (x 4) for instantiated class: d
; [,bt for context]
@takikawa
takikawa / gist:2830805
Created May 29, 2012 21:25
Inits are weird #2
View gist:2830805
;; What should happen here?
(define c% (class object% (super-new) (init a)))
(define d% (class c% (super-new) (init #:a)))
(new d% #:a 5) ; which `a` does it instantiate?
(new d% #:a 5 #:a 6) ; presumably this is not allowed
; (if it is, then it's not like keywords)
; (if it's not, the above leaves an init un-initialized)
@takikawa
takikawa / gist:2927751
Created June 14, 2012 02:36
GUI switching panels
View gist:2927751
#lang racket/gui
(define frame (make-object frame% "top"))
(define parent-panel (make-object panel% frame))
(define panel1 (make-object panel% parent-panel))
(define panel2 (make-object panel% parent-panel))
(send parent-panel delete-child panel2)
(new button%
[label "Switch to 2"]
@takikawa
takikawa / gist:2936908
Created June 15, 2012 15:05
racket/gui widgets -> scribble
View gist:2936908
#lang scribble/base
@(module widgets racket/gui
(require ffi/unsafe
mred/private/wx/gtk/types
mred/private/wx/gtk/utils
racket/draw/unsafe/cairo
slideshow/pict)
(provide screenshots)
@takikawa
takikawa / gist:2950727
Created June 18, 2012 21:07
inits are weird #3
View gist:2950727
(make-object (class (class object%
(super-new)
(init a b c))
(super-new [a 0] [b 0] [c 0])
(init [d 0]))
1 2)
;; => ; instantiate: unused initialization arguments
;; unused arguments:
;; [a 2]
@takikawa
takikawa / gist:2955868
Created June 19, 2012 18:52
contracted shift/reset
View gist:2955868
#lang racket
(require racket/control)
(define/contract pt
(prompt/c (-> (-> integer? integer?)))
(make-continuation-prompt-tag))
(define f
(reset0-at pt
@takikawa
takikawa / gist:2955928
Created June 19, 2012 19:04
expansion of reset0/shift0
View gist:2955928
#lang racket
(define pt (make-continuation-prompt-tag))
(call-with-continuation-prompt
(lambda ()
(+ 1
(call-with-composable-continuation
(lambda (k)
(abort-current-continuation
@takikawa
takikawa / gist:2968823
Created June 21, 2012 21:59
Cake pattern?
View gist:2968823
#lang racket
;; ref: http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/
(define-signature on-off-device^
(on
off))
(define-signature sensor-device^
(is-coffee-present?))