Skip to content

Instantly share code, notes, and snippets.

@dharmatech
Created November 29, 2009 06:29
Show Gist options
  • Save dharmatech/244819 to your computer and use it in GitHub Desktop.
Save dharmatech/244819 to your computer and use it in GitHub Desktop.
(import (define-is-type-syntax))
;; Define the pt type:
(define-record-type pt
(fields (mutable x)
(mutable y)))
;; Generate the 'is-pt' macro:
(define-is-type-syntax is-pt
pt
(fields x y)
(methods (neg pt-neg)))
;; Define a "method":
(define (pt-neg p)
(make-pt (- (pt-x p))
(- (pt-y p))))
;; Define a pt:
(define p0 (make-pt 3 4))
;; Declare it to be a pt:
(is-pt p0)
;; Access the x field:
p0.x
;; Set the x field:
(p0.x! 7)
;; Call the 'neg' method:
(p0.neg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment