Skip to content

Instantly share code, notes, and snippets.

View ijp's full-sized avatar

Ian Price ijp

  • Aberdeen, Scotland
View GitHub Profile
;; extending the y combinator to handle mutual recursion, for zacts
(define (y . funcs)
((lambda (x) (x x))
(lambda (x)
(map (lambda (g)
(lambda args
(apply (apply g (x x)) args)))
funcs))))
(save-module-excursion
(lambda ()
(set-current-module (resolve-module '(web client)))
(eval '(define (extend-request r k v . additional)
(let ((r (build-request (request-uri r)
#:method (request-method r)
#:version (request-version r)
#:headers
(assoc-set! (copy-tree (request-headers r))
k v)
(defun raellear-lgrep (regexp &optional files confirm)
(interactive
(progn
(grep-compute-defaults)
(cond
((and grep-command (equal current-prefix-arg '(16)))
(list (read-from-minibuffer "Run: " grep-command
nil nil 'grep-history)))
((not grep-template)
(error "grep.el: No `grep-template' available"))
(define-module (angels-and-devils)
#:export (milestone devil angel))
;; See the paper "call-with-current-continuation patterns"
(define future '())
(define past '())
(define-syntax-rule (push var val)
(set! var (cons val var)))
;; Vectorish syntactic parameterize for jcowan using only syntax rules
(define-syntax define-syntax-rule
(syntax-rules ()
((_ (name . patterns) template)
(define-syntax name
(syntax-rules ()
((_ . patterns)
template))))))
@ijp
ijp / try.scm
Last active August 29, 2015 14:04
;; Scheme version of try ... in ... unless ... from the paper
;; Exceptional Syntax by Benton and Kennedy
(define-syntax try
(syntax-rules (in unless)
((try (var val) body ... ((tag handler ...) ...))
((catch #t
(lambda () (let ((v val))
(lambda (k) (k v))))
(lambda (t . args)
@ijp
ijp / cc.scm
Last active August 29, 2015 14:04
;; First of all, notice that
(call/cc (lambda (k) e)) = (call/cc (lambda (k) (k e))) ; -- {1}
;; the type of call/cc a.k.a peirces law gives you the free theorem
(f (call/cc g)) = (call/cc (lambda (k) (f (g (compose k f))))) ;; -- {Free}
;; Continuations don't compose
(compose k k2) = k2 ;; {No Compose}
;; If a continuation is not used, we lose the form
If k not in e, then
(call/cc (lambda (k) (k e))) = (call/cc (lambda (k) e)) [k not in e] = e ;; -- {no-op}
(use-modules (sxml transform))
(define (subst var val exp)
(cond ((pair? exp)
(cons (subst var val (car exp))
(subst var val (cdr exp))))
((eqv? var exp) val)
(else exp)))
(define *env*
import Data.List (tails)
import Data.Map (Map)
import qualified Data.Map as Map
-- <Fuco> heh, this is a nice problem: Given a string A, figure out if string B
-- contains any anagram of A as substring. Example: A = abc, B = de[cab]fh
-- -> true
xs `hasAnagramSubsequence` ys = any (check initialMap) (tails xs)
where initialMap = tabulate ys
(defmacro kingpatzer/log-cmd (&rest rest)
"This wraps the body in error checking and prints start and stop information to the message buffer. This requires a variable named 'output' be defined in context that tells us what to print."
`(progn
(message "**** Starting %s ****" (concat output))
(with-demoted-errors ,@rest)
(message "*** Finishing %s ****\n" (concat output))))