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
; 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 >." |
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
(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) |
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
;;; Diamond problem | |
;;; Solutions by Rainer Joswig, [email protected], 2016 | |
;;; See "Diamond Kata" | |
; A | |
; B B | |
; C C | |
; B B | |
; A |
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
; 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))) |
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
(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 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 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 | |
"{" |
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
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 |
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
; 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) |
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
; 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)) |
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
(defun abbreviate-butlast (path) | |
(loop for (item . rest) on path | |
collect (if (and rest (> (length item) 1)) | |
(subseq item 0 1) | |
item))) |