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
(defmacro with-output-to-stream ((var &optional stream &key (element-type 'character)) &body body) | |
(let ((gstream (gensym "STREAM")) | |
(gresult (gensym "RESULT"))) | |
`(let* ((,gstream ,stream) | |
(,var (case ,gstream | |
((t) *standard-output*) | |
((nil) (make-string-output-stream :element-type ',element-type)) | |
(otherwise ,gstream))) | |
(,gresult (multiple-value-list (progn ,@body)))) | |
(if ,gstream |
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
(with-open-file (f "print-args.lisp" :direction :output :if-does-not-exist :create :if-exists :overwrite) | |
(dolist (expr '((defun print-args () | |
(princ (cdr (ext:command-args)))) | |
(print-args) | |
(quit))) | |
(prin1 expr f) | |
(terpri f)) | |
(force-output f)) | |
(defparameter *object-file* (compile-file "print-args.lisp" :system-p t)) |
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
;; See https://tailrecursion.com/jlt/posts/collecting-macro-edition.html | |
;; Shared implementation of collector, providing a standalone collector | |
;; via MAKE-COLLECTOR and an flet-scoped collector via WITH-COLLECTOR | |
(defun %collector-impl (head tail) | |
(let* ((item (gensym "ITEM")) | |
(item-passed (gensym "ITEM-PASSED")) | |
(new-tail (gensym "NEW-TAIL"))) | |
`((&optional (,item nil ,item-passed)) |
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
(ql:quickload :closer-mop) | |
(defclass foo () | |
((bar :initarg :bar :initform nil :reader foo-bar))) | |
(defclass fuu (foo) | |
((baz :initarg :baz :initform nil :reader fuu-baz))) | |
(defmethod print-object ((f foo) stream) | |
(print-unreadable-object (f stream :type t))) |
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
;; This gist licensed GPLv3 | |
(cl-defmacro condition-case+ (var form (&rest handlers/else/finally)) | |
"Like condition-case, only if the last handlers have matching | |
forms of :else or :finally. In that case, the body of an :else | |
handler is evaluated if no exception was thrown. The body of | |
a :finally clause is evaluated always as the last thing before | |
the form is exited whether normally or not. If both :else | |
and :finally appear among the handlers, :else must be second last | |
and :finally must be last." | |
(cl-flet ((maybe-split-last (symbol handlers) |
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
(defgeneric call-with-container-map (container func) | |
(:documentation "Iterate over the contents of CONTAINER, calling | |
FUNC with the current element of CONTAINER, followed by the index or | |
key that corresponds to it.")) | |
(defmethod call-with-container-map ((container array) func) | |
(loop for index from 0 | |
for value across container | |
do (funcall func value index))) |
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
#!/usr/bin/env ruby | |
# Attempt to make a module with methods that default to using state in | |
# a default instance of a class within the module, yet allow for | |
# specific instances of the class to be produced with their own state, | |
# that share these same module methods. It boils down to using the | |
# module method this in place of self. | |
module Moo | |
extend self |
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
(defvar truncated-compilation-line-limit 70) | |
(defvar truncated-compilation-line-trailer "…") | |
;; TODO: convert this from a post filter hook to advice on a | |
;; configured set of filter functions to prevent the insertion of text | |
;; constituting overlong lines in the first place | |
;;;###autoload |
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
(defmacro sq (variable value &optional (documentation nil documentation-p)) | |
"REPL-friendly alternative-to/merger-of setq and defparameter." | |
(assert (and variable (symbolp variable))) | |
(alexandria:once-only (value) | |
`(cond | |
((boundp ',variable) | |
,@(when documentation-p | |
`((setf (documentation ',variable 'variable) ,documentation))) | |
(setf ,variable ,value)) | |
(t |
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
(defpackage :99-bottles | |
(:use :cl) | |
(:export #:print-song)) | |
(in-package :99-bottles) | |
(defun wrap (number) | |
(if (minusp number) | |
(+ number 100) | |
number)) |
NewerOlder