Skip to content

Instantly share code, notes, and snippets.

View lispm's full-sized avatar

Rainer Joswig lispm

  • Germany
View GitHub Profile
; https://gigadom.wordpress.com/2012/06/18/working-with-binary-trees-in-lisp/
(defstruct (binary-tree (:conc-name tree-))
"A structure for binary trees.
Creates functions: make-binary-tree, tree-data, tree-left, tree-right, ..."
data left right)
(defun add-item (data tree)
"Add some data to a binary tree. Uses numeric comparisons: =, < and >."
(defun circular-mapc (function list)
(loop for fast = list then (cddr fast)
for slow = list then (cdr slow)
do
(funcall function (car slow))
(when (eq (cddr fast) (cdr slow))
(return-from circular-mapc nil))))
(defun circular (items)
(check-type items cons)
;;; Diamond problem
;;; Solutions by Rainer Joswig, [email protected], 2016
;;; See "Diamond Kata"
; A
; B B
; C C
; B B
; A
; orig
(defun fl-alpha-cuts(lv alpha)
(let ((i) (n) (fset) (sub_list))
(setq i 0)
(setq n (length lv))
(while (< i n)
(progn
(setq fset (eval (nth i lv)))
(defun sieve (n &aux (list (loop for i from 2 to n collect i)))
(flet ((fact-p (i n)
(zerop (mod n i))))
(loop for (head . rest) = list then (remove head rest :test #'fact-p)
while head collect head)))
; an iterative prime sieve, which is not limited by stack size
(defun sieve (n &aux (list (loop for i from 2 to n collect i))) ; helper variable LIST of prime candidates
; this code iterates over a hashmap
; prints a pair to a string
; collects the strings into a list
; prints the list to a string, by using an format iteration command
; then concatenates the string with two other strings
(defun pr-mal-hash-map (hash-map &optional (print-readably t))
(let ((hash-map-value (types:mal-data-value hash-map)))
(concatenate 'string
"{"
Comparing/explaining the screenshots
http://dustycloud.org/tmp/emacs-and-the-lisp-machine.png
* Left: Document Examniner from Symbolics, a system supplied application of the Genera OS
** Application to browse and read documentation on the Symbolics Lisp Machine
* Right: GNU Emacs
; https://github.com/alandipert/dotfiles/blob/master/dotfiles/bash/abbrev_pwd.lisp
; original
; splits string into a vector of strings
(defun split-string (str delim-char)
(let* ((num-delims 2)
(delim-idxs (loop with idxs = (list (length str))
for idx from (1- (length str)) downto 0
when (eq (elt str idx) delim-char)
@lispm
lispm / join.lisp
Last active December 11, 2016 22:02
; a join function using FORMAT
(defun join-aux (stream &rest args)
(declare (ignore args)
(special delim))
(princ delim stream))
(defun join (list delim)
(declare (special delim))
(format nil "~{~a~^~/JOIN-AUX/~:*~}" list))
(defun abbreviate-butlast (path)
(loop for (item . rest) on path
collect (if (and rest (> (length item) 1))
(subseq item 0 1)
item)))