This file contains 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 <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 |
This file contains 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 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 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
(define (make-palindrome l) | |
(define (loop l suffix) | |
(if (null? (cdr l)) | |
(cons (car l) suffix) | |
(cons (car l) | |
(loop (cdr l) (cons (car l) suffix))))) | |
(if (null? l) | |
#f ; arbitrary choice | |
(loop l '()))) |
This file contains 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
def rindex_func(func, l): | |
for (i,obj) in reversed(list(enumerate(l))): ## Boo! list() | |
if func(obj): | |
return i | |
return None | |
def only_as_suffix(obj, l): | |
try: | |
i = l.index(obj) | |
except ValueError: |
This file contains 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
(setq fib (lambda () | |
(let* ((b (cdddr fib)) | |
(s (apply '+ b))) | |
(setcdr (cddr fib) (list (cadr b) s)) | |
(throw 'result s)) | |
0 1)) | |
(defun fib () (catch 'result (funcall fib))) | |
(fib) |
This file contains 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
;; not tested | |
(defun galex-assoc-string (regexp alist) | |
(catch 'done | |
(while alist | |
(cond ((consp (car alist)) | |
(if (string-match regexp (caar alist)) | |
(throw 'done (car alist)))) | |
((stringp (car alist)) | |
(if (string-match regexp (car alist)) |
This file contains 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 (system repl command)) | |
(define-meta-command ((clear module) repl) | |
"clear | |
Removes all current bindings." | |
(let ((mod (current-module))) | |
(module-for-each (lambda (k v) | |
(module-remove! mod k)) | |
mod))) |
This file contains 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
(defun my-erc-quit (s) | |
(or s (concat "brb " (aref my-erc-quit-reasons (random (length my-erc-quit-reasons)))))) | |
(setq erc-part-reason 'my-erc-quit) | |
(setq erc-quit-reason 'my-erc-quit) | |
(setq my-erc-quit-reasons | |
["proving riemann hypothesis" | |
"cleaning the augean stables" | |
"inventing something better than sliced bread" |
This file contains 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
# a sketch of how Scheme fluids/parameters would work in python | |
obarray = {} | |
class Manager(object): | |
def __init__(self, parameter, value): | |
self.parameter = parameter | |
self.value = value | |
def __enter__(self): |