Skip to content

Instantly share code, notes, and snippets.

View ijp's full-sized avatar

Ian Price ijp

  • Aberdeen, Scotland
View GitHub Profile
@ijp
ijp / fraktur
Created September 7, 2014 19:49
#!/usr/local/bin/guile -s
!#
;; Hey emacs this is -*- scheme -*- code
(eval-when (compile load eval)
(set! %load-extensions '(".guile.sls" ".sls" ".ss" ".scm" "")))
(import (ijputils strings)
(only (rnrs) let*-values)
(ice-9 match))
(assert
(equal
'(1 2)
(mbe-destructuring-let
(a b)
(list 1 2)
(list a b))))
(assert
(equal
;;; macro-rules.el --- Macros by Example
;; Copyright (C) 2014 Ian Price
;; Author: Ian Price <ianprice90@googlemail.com>
;; Keywords: tools
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
(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))))
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
(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*
@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}
@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)
;; 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))))))
(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)))