Skip to content

Instantly share code, notes, and snippets.

View nikodemus's full-sized avatar
🚀
ssh! it's a secret! foolang.org

Nikodemus Siivola nikodemus

🚀
ssh! it's a secret! foolang.org
View GitHub Profile
@nikodemus
nikodemus / split_closures.foo
Last active July 19, 2021 16:01
Splitting a file in Foolang
---
First 'scripting' excursion in Foolang!
Input is file containing stuff like this:
CLOSURE 1:
args: ["out"]
body:
(self
displayOn: out)
@nikodemus
nikodemus / bt.lisp
Last active July 14, 2022 05:46
Showing why conditions are a bad match for doing backtracking -- all you need is CATCH/THROW and a special variable.
;;;; In response to:
;;;;
;;;; http://www.reddit.com/r/lisp/comments/3710zq/directed_procrastination_backtracking_with_the/
;;;; http://directed-procrastination.blogspot.se/2011/05/backtracking-with-common-lisp-condition.html
;;;;
;;;; Demonstrating why one should not use conditions for this kind of stuff,
;;;; instead using the dynamic binding and unwinding facilities on which the
;;;; condition system is built. The author's backtracking system doesn't compare
;;;; badly to Screamer because his is simple: it compares badly because using
;;;; conditions is a bad match for the task.
;;;; By Nikodemus Siivola <nikodemus@random-state.net>, 2012.
;;;;
;;;; Permission is hereby granted, free of charge, to any person
;;;; obtaining a copy of this software and associated documentation files
;;;; (the "Software"), to deal in the Software without restriction,
;;;; including without limitation the rights to use, copy, modify, merge,
;;;; publish, distribute, sublicense, and/or sell copies of the Software,
;;;; and to permit persons to whom the Software is furnished to do so,
;;;; subject to the following conditions:
;;;;
@nikodemus
nikodemus / foo-duplicates.lisp
Created April 19, 2012 19:01
this was what i had in mind
(defconstant +foo-count+ (ash (sb-int:power-of-two-ceiling
(* 8 sb-vm::*backend-page-bytes*))
-1))
(defconstant +foo-mask+ (1- +foo-count+))
(defun foo-duplicates (list)
(let ((bitmap (make-array +foo-count+ :element-type 'bit))
(results nil))
(declare (dynamic-extent bitmap))
@nikodemus
nikodemus / gist:2331850
Created April 7, 2012 20:17
Recompiling stale fasls
;;; If a fasl was stale, try to recompile and load (once).
(defmethod asdf:perform :around ((o asdf:load-op)
(c asdf:cl-source-file))
(handler-case (call-next-method o c)
(sb-ext:invalid-fasl ()
(asdf:perform (make-instance 'asdf:compile-op) c)
(call-next-method))))
@nikodemus
nikodemus / broken-weight.lisp
Created November 30, 2011 22:22
The Broken Weight Problem
;;;; Inspired by http://directed-procrastination.blogspot.com/2011/11/broken-weight-problem.html
;;;;
;;;; An example of using a generator to make your nondeterminism read nice.
(in-package :screamer-user)
(defun a-subset (set)
"Non-deterministically returns all the subsets of SET, including the empty set NIL."
(when set
(either
@nikodemus
nikodemus / condition-wait-gotcha.lisp
Created August 16, 2011 13:10
CONDITION-WAIT gotcha
(with-lock (*lock*)
(unwind-protect
;; Calls CONDITION-WAIT on the lock
(foo)
;; If FOO unwinds, the lock it might not be held here!
(bar)))
@nikodemus
nikodemus / condition-wait-sketch.lisp
Created August 16, 2011 12:49
user-space CONDITION-WAIT sketch
(defun condition-wait (waitqueue lock &key timeout)
(release-lock lock)
(let ((self *current-thread*))
(unwind-protect
(progn
(enqueue self waitqueue)
(when (wait-for (eq self (queue-first waitqueue))
:timeout timeout)
(grab-lock lock :timeout timeout)))
(delete-from-queue self))))
@nikodemus
nikodemus / irc.txt
Created November 2, 2010 11:19
Notes re. debugging Common Lisp with SBCL and Slime
Context from IRC logs for future reference.
[12:36] <kushal> nikodemus, can you point me to some tutorial on debugging on sbcl ?
[12:37] * andreer (andreer@flode.pvv.ntnu.no) has joined #quicklisp
[12:38] <nikodemus> kushal: no really good ones actually exist at the moment. i'm planning on writing one before the year is out, but... in the meanwhile, i can give some pointers
[12:38] <nikodemus> a couple of questions: is this a general question, or do you have a specific issue you need to debug?
[12:39] <kushal> right now , general, managed to debug the specific issue somehow :)
[12:39] <nikodemus> ok. are you using slime?
[12:39] <kushal> nikodemus, yes and no both
[12:40] <nikodemus> good. :)