Skip to content

Instantly share code, notes, and snippets.

View inconvergent's full-sized avatar
💭
set fire to the cloud

inconvergent inconvergent

💭
set fire to the cloud
View GitHub Profile
#!/usr/local/bin/sbcl --script
; example code described in this blog post:
; https://inconvergent.net/2023/vectors-as-symbols
; GENERIC UTILS
(defun mkstr (&rest args)
(with-output-to-string (s)
(dolist (a args) (princ a s))))
@inconvergent
inconvergent / lets-write-a-dsl.lisp
Last active November 15, 2023 18:17
let's write a dsl code example
#!/usr/local/bin/sbcl --script
; this is the full DSL example described in this blog post:
; https://inconvergent.net/2023/lets-write-a-dsl/
; the code is explained in more detail in the post
(defun mkstr (&rest args)
(with-output-to-string (s)
(dolist (a args) (princ a s))))
#!/usr/bin/sbcl --script
;do something similar to
(load "~/quicklisp/setup.lisp")
(ql:quickload :sdl2)
(ql:quickload :cl-opengl)
(defun debug-log (msg &rest args)
"Output and flush MSG to STDOUT with arguments ARGS"
; script to reproduce:
#!/usr/bin/sbcl --script
(load "~/quicklisp/setup.lisp")
;(asdf:load-system "weir")
(ql:quickload "png")
; fastest solution. based on https://bitbucket.org/vityok/cl-faster-input/src/default/
(defun do-lines-as-buffer (fn fx &key (buffer-width 80))
(declare #.*opt-settings* (function fx) (fixnum buffer-width))
"
fx will receive a stream (named in). use it like this:
(loop for x = (read in nil nil)
while x
do something)
"
(let ((*read-default-float-format* 'double-float)
(defun do-lines-as-floats (fn n fx &key (buffer-width 80))
(declare (optimize (safety #.*sft*) (speed #.*spd*) (debug #.*dbg*))
(function fx) (fixnum n buffer-width))
(let ((buffer (make-array buffer-width :element-type 'character
:initial-element #\space)))
(with-open-file (is fn :direction :input)
(loop with res-values of-type (simple-array double-float) =
(make-array n :adjustable nil :initial-element 0d0
:element-type 'double-float)
for (val pos newl) =
; for every line produced as in run-buffer in
; https://bitbucket.org/vityok/cl-faster-input/src/default/src/benchmark-read-line.lisp
; do this:
(defun proc-line (l)
(with-input-from-string (in l)
(let ((vals (loop for x = (read in nil nil) while x
collect (coerce x 'double-float))))
(values (vec:3vec* (subseq vals 0 3))
#!/bin/bash
here=`pwd`
dir=$1
if [ -z "$dir" ]
then
dir="."
fi
#!/usr/bin/sbcl --script
(declaim (inline rnd))
(defun rnd (a)
(declare (double-float a))
(the double-float (random (the double-float a))))
(declaim (inline sb-kernel::%random-fixnum))
(sb-ext:unlock-package 'sb-kernel)
(defstruct vec2
(x nil :type double-float :read-only t)
(y nil :type double-float :read-only t))
(defstruct (vec3 (:include vec2))
(z nil :type double-float :read-only t))
(declaim (inline make-vec2))
(declaim (inline make-vec3))