Skip to content

Instantly share code, notes, and snippets.

@earl-ducaine
earl-ducaine / declare-special.lisp
Last active May 25, 2020 07:27
Using (declare (special ...))
(defun get-my-value ()
(list val))
(defun my-value ()
(let ((val nil))
(locally
(declare (special val))
(setf val t)
(get-my-value))))
(defun emit-defreplace (name newname)
(let ((form
'(defmacro name (&body body)
`(newname ,@body))))
(setf (cadr form) name)
(setf (car (cadr (cadddr form))) newname)
form))
@earl-ducaine
earl-ducaine / gist:778a2eaf5b7d1cda5c7ea363f76cef44
Created December 21, 2019 14:35
Slime stacktrace, read parameters
(defun parse-file (file-stream)
(let (locations forms)
(do ((form (read file-stream nil :eof )
(read file-stream nil :eof )))
((eq form :eof)
forms)
(push (list :form form
:end-position (file-position file-stream))
forms))))
https://github.com/earl-ducaine/flavor
SLIME debug window
------------------
COMPILE-FILE-ERROR while
compiling #<CL-SOURCE-FILE "flavor" "flavor-main0">
[Condition of type UIOP/LISP-BUILD:COMPILE-FILE-ERROR]
@earl-ducaine
earl-ducaine / example.lisp
Last active August 29, 2018 21:01
Macro Help -- transform arguments
;; A macro that would transform this:
(my-macro my-function (medium pathname options)
(list medium pathname options))
;; Into:
(defun my-function (&rest rest)
(let ((medium (nth 0 rest))
(pathname (nth 1 rest))
(options (nth 1 rest)))
(list medium pathname options)))
(defmacro valid-address? (address)
`(and (numberp ,address) (>= ,address 0) (<= ,address 65535)))
(defclass plane (moving-object graphics-object)
((altitude :initform 0 :accessor plane-altitude)
(speed))
(:default-initargs :engine *jet*))
(ensure-class 'plane
':direct-superclasses '(moving-object graphics-object)
':direct-slots (list (list ':name 'altitude
':initform '0
':initfunction #'(lambda () 0)
@earl-ducaine
earl-ducaine / lisp
Created July 16, 2018 20:56
Create executable CL world: save-lisp-and-die
(defun main ()
(format t "Hello, world!~%"))
(sb-ext:save-lisp-and-die "hello-world.exe"
:executable t
:compression 9
:toplevel 'main)
@earl-ducaine
earl-ducaine / lisp
Created April 8, 2018 02:41
gensym with prefix
CL-USER> *gensym-counter*
78744
CL-USER> (gensym "T")
#:T78744
CL-USER> *gensym-counter*
78745
(defmacro with-foreign-slots ((vars ptr type) &body body)
"Create local symbol macros for each var in VARS to reference
foreign slots in PTR of TYPE. Similar to WITH-SLOTS.
Each var can be of the form: slot-name - in which case slot-name will
be bound to the value of the slot or: (:pointer slot-name) - in which
case slot-name will be bound to the pointer to that slot."
(let ((ptr-var (gensym "PTR")))
`(let ((,ptr-var ,ptr))
(symbol-macrolet
,(loop :for var :in vars