This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; jffmcc's solution | |
| (define (Last2Equal? L) | |
| (cond ((> (length L) 2) (Last2Equal? (cdr L))) | |
| ((= (length L) 2) (equal? (car L) (cadr L))) | |
| (else #f))) | |
| ;;; Alternative Solutions | |
| ;;; Compute length only once | |
| (define (drop n l) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (assert | |
| (equal | |
| '(1 2) | |
| (mbe-destructuring-let | |
| (a b) | |
| (list 1 2) | |
| (list a b)))) | |
| (assert | |
| (equal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; macro-rules.el --- Macros by Example | |
| ;; Copyright (C) 2014 Ian Price | |
| ;; Author: Ian Price <[email protected]> | |
| ;; 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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)))))) |