Skip to content

Instantly share code, notes, and snippets.

View ijp's full-sized avatar

Ian Price ijp

  • Aberdeen, Scotland
View GitHub Profile
#!r6rs
(library (generalized-set)
(export (rename (set!!! set!))
define-getter/setter)
(import (rnrs)
(rnrs mutable-pairs)
(rnrs mutable-strings))
;; Usage:
;; > (import (generalized-set))
(define (random-permutate lst)
(let* ([len (length lst)]
[i (rand len)]
[j (let loop ((number (rand len)))
(if (= number i)
(loop (rand len))
number))]
[vec (list->vector lst)])
(vector-swap! vec i j)
(vector->list vec)))
(library (tagbody)
(export tagbody go)
(import (rnrs)
(for (tagbody utils) expand)
(for (srfi :8 receive) expand))
(define (go tag)
(tag #f))
(define-syntax tagbody
(library (tagbody utils)
(export plist->alist
shift-left
unzip
syntax->list
)
(import (rnrs))
(define (syntax->list stxobj)
(define (inner stx)
; guile -x ".sls" -x ".ss" -x ".guile.sls" tests.scm
(import (rnrs)
(tagbody)
(wak trc-testing))
(define-syntax inc!
(syntax-rules ()
((inc! x)
(set! x (+ x 1)))
((inc! x n)
(define (s:reify thunk)
(reset-at 'state (s:return (thunk))))
(define (s:reflect m)
(shift-at 'state k (s:>>= m k)))
(define (r:reify thunk)
(reset-at 'reader (return (thunk))))
(define (r:reflect m)
@node Syntax Parameters
@subsection Syntax Parameters
Syntax parameters@footnote{Described in the paper @cite{Keeping it Clean with
Syntax Parameters} by Barzilay, Culpepper and Flatt.} are a mechanism for rebinding a macro
definition within the dynamic extent of a macro expansion. It provides
a convenient solution to one of the most common types of unhygienic
macro: those that introduce a unhygienic binding each time the macro
is used. Examples include a 'lambda' form with a 'return' keyword , or
class macros that introduce a special 'self' binding.
;; general tree fold
(define (traverse traverser nil tree)
(define (left nil)
(traverse traverser nil (node-left tree)))
(define (right nil)
(traverse traverser nil (node-right tree)))
(if (empty? tree)
nil
(traverser (node-key tree)
(node-key value)
@ijp
ijp / traverse.scm
Created January 5, 2012 02:06
traversal for bbtrees
;; bbtree-traverse : (any any (any -> any) (any -> any) any) any bbtree -> any
;; A general tree traversal procedure. Returns the value of applying
;; the traverser procedure to the current node's key, value, a
;; procedure to traverse the left subtree, a procedure to traverse the
;; right subtree, and a base value. The subtree traversal procedures
;; both take a base argument, and call bbtree-traverse recursively on
;; the appropriate subtree. It is mostly useful for implementing
;; other, more specific tree traversal procedures. For example,
;; (define (l-to-r-pre-order cons base bbtree)
;; (bbtree-traverse (lambda (key value left right base)
@node Syntax Parameters
@subsection Syntax Parameters
Syntax parameters@footnote{Described in the paper @cite{Keeping it Clean with
Syntax Parameters} by Barzilay, Culpepper and Flatt.} are a mechanism for rebinding a macro
definition within the dynamic extent of a macro expansion. It provides
a convenient solution to one of the most common types of unhygienic
macro: those that introduce a unhygienic binding each time the macro
is used. Examples include a 'lambda' form with a 'return' keyword , or
class macros that introduce a special 'self' binding.