Skip to content

Instantly share code, notes, and snippets.

View malisper's full-sized avatar

Michael Malis malisper

View GitHub Profile
(defmacro iter (&body body)
(with-gensyms (iter-block accumulate start)
(handler-case
(macroexpand-dammit:macroexpand-dammit
`(block ,iter-block
(let ((,accumulate nil))
(macrolet ((while (condition)
`(unless ,condition
(return-from ,',iter-block
(nreverse ,',accumulate))))
(defpackage :hardest-problem
(:nicknames :hard)
(:use :clamp :experimental :iter)
(:shadowing-import-from :experimental
:def :mac :fn :defmemo :coerce
:while :until :repeat :summing :with :in))
(in-package :hard)
(def know (possibilities)
@malisper
malisper / gist:fe2cf8158714c196ec03
Last active August 29, 2015 14:22
Trace of functions in CL-WHO
(macroexpand-1 '(with-html-output (*standard-output*)
(:p :align "right" "Here is some text with a part of it "
(:b "bolded."))))
;; The function trace
0: (TREE-TO-TEMPLATE
((:P :ALIGN "right" "Here is some text with a part of it "
(:B "bolded."))))
1: (PROCESS-TAG
@malisper
malisper / gist:610f691e7b3919d6a421
Created September 8, 2015 16:19
Macroexpansion of defasm
(progn
(let* ((#:*opcode-meta*1641 *opcode-meta*))
(let ((#:new1640 '(adc "Add to Accumulator with Carry" 6 2 indirect-x)))
(funcall #'(setf aref) #:new1640 #:*opcode-meta*1641 97)))
(let* ((#:*opcode-meta*1643 *opcode-meta*))
(let ((#:new1642 '(adc "Add to Accumulator with Carry" 3 2 zero-page)))
(funcall #'(setf aref) #:new1642 #:*opcode-meta*1643 101)))
(let* ((#:*opcode-meta*1645 *opcode-meta*))
(let ((#:new1644 '(adc "Add to Accumulator with Carry" 2 2 immediate)))
(funcall #'(setf aref) #:new1644 #:*opcode-meta*1645 105)))
>> (def test (seed)
(flet1 gen () (pop seed)
(ret result (vector 1 2 3)
(up i 0 3
(swap (aref result i) (aref result (gen)))))))
TEST
>> (test)
; Evaluation aborted on #<SB-INT:SIMPLE-PROGRAM-ERROR "invalid number of arguments: ~S" {1004E51A23}>.
>> (test '(0 0 0))
#(3 1 2)
(self-referential-version-of
'(lambda (self)
(format t
"#include <stdio.h>~%int main(){printf(\"%s\",~(~s~));}"
(remove #\newline (prin1-to-string self)))))
=>
>>>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++
(5/2 11/5 3/2 3/17 13/57 13/11 29/247 323/29 23/13 37/23 43/37 31/23 31/53
2773/31 61/3149 61/43 73/4087 3551/73 71/61 83/71 97/83 79/71 79/103 1919/79
7169/101 109/6313 109/97 127/6431 6077/127 113/109 137/113 149/137 131/113
131/157 163/131 173/163 151/131 151/181 179/28841 179/173 197/34189 34571/197
193/179 211/193 227/211 199/193 199/233 54731/199 241/4351 241/227 257/4579
4427/257 251/241 269/251 277/269 263/251 263/283 53671/263 5567/281 307/70027
307/277 313/73373 67637/313 311/307 331/311 347/331 317/311 317/353
349/5206666620054784675760045562843307267 349/347
367/5732260726811103633565476029754934499
5797959990155643503291154838118887903/367 359/349 379/68569 73153/379 373/359
@malisper
malisper / gist:fcd5fda9741220355f6ce36a423c69cc
Last active November 1, 2017 00:48
Lisptran source code
(defun multiple (a b)
"Is A a multiple of B?"
(= (mod a b) 0))
(defun next-fraction (n fractions)
"Returns the next value of F in the Fractran program."
(find-if (lambda (f)
(integerp (* n f)))
fractions))
(defun multiple (a b)
"Is A a multiple of B?"
(= (mod a b) 0))
(defun next-fraction (n fractions)
"Returns the next value of F in the Fractran program."
(find-if (lambda (f)
(integerp (* n f)))
fractions))