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 random-text (string &key (n 300) (color-filter nil)) | |
(flet ((one-of (list) | |
(elt list (random (length list)))) | |
(filter-colors (colors string) | |
(loop for color in colors | |
when (search string (symbol-name color) :test #'equalp) | |
collect color))) | |
(let* ((s (make-instance 'capi:output-pane)) | |
(colors (color:get-all-color-names))) | |
(capi:contain s :width 2000 :height 1400) |
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
; http://stackoverflow.com/questions/12345647/rewrite-this-script-by-designing-an-intepreter-in-racket | |
(defmacro verti (n &body body) | |
`(progn | |
(loop repeat ,n | |
do ,@body | |
(terpri)))) | |
(defun hori (n s) | |
(loop repeat n do (princ s))) |
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 average (list) | |
(/ (tree-reduce #'+ list) | |
(tree-reduce #'+ list :key (constantly 1)))) | |
(defun tree-reduce (fn tree &key (key #'identity)) | |
(reduce fn tree | |
:key (lambda (item) | |
(if (consp item) | |
(tree-reduce fn item :key key) | |
(funcall key item))))) |
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 factors (n) | |
(iterate | |
(with limit = (isqrt n)) | |
(for factor from 1 below limit) | |
(for (values q r) = (floor n factor)) | |
(when (zerop r) | |
(collect factor into lows) | |
(collect q into highs)) | |
(finally (setf highs (reverse highs)) | |
(when (= n (* limit limit)) |
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
(setf (logical-pathname-translations "LIB") | |
`(("**;*" ,(make-pathname | |
:name :wild | |
:directory (append (pathname-directory | |
(sys:lisp-library-directory)) | |
(list :wild-inferiors)) | |
:defaults (sys:lisp-library-directory))))) | |
; now you can use the logical pathname LIB to refer to LispWorks files: | |
; (compile-file-if-needed "lib:examples;editor;commands;space-show-arglist.lisp" :load t) |
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 find-query (query descriptions) | |
(find query descriptions | |
:test (lambda (q b) | |
(interpret-query q b)) | |
:key #'second)) | |
(defun lookup (v bindings) | |
(let ((result (assoc v bindings))) | |
(if result | |
(second result) |
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
; http://tapestryjava.blogspot.se/2013/02/crafting-code-in-clojure.html | |
; | |
; Extract all the keys from both maps | |
; Remove any duplicates | |
; Convert the keys to strings | |
; Sort the strings into ascending order | |
; Build and return one big string, by concatenating all the key strings, using ", " as a separator | |
; Return "<none>" if both maps are empty | |
(defun hash-table-keys (hash-table) |
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
(defmacro -> (form &rest forms) | |
(loop with result = form | |
with next-form = nil | |
while forms | |
do (setf next-form (pop forms)) | |
(if (consp next-form) | |
(setf result (destructuring-bind (function . args) next-form | |
`(,function ,result ,@args))) | |
(setf result `(,next-form ,result))) | |
finally (return result))) |
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 concat (type &rest items) | |
(let* ((len (loop for e in items | |
if (typep e 'sequence) | |
sum (length e) | |
else sum 1)) | |
(seq (make-sequence type len))) | |
(loop with pos = 0 | |
for e in items | |
if (typep e 'sequence) | |
do (progn |
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 example (&rest maps) | |
(format nil "~:[<none>~;~:*~{~A~^, ~}~]" | |
(sort (remove-duplicates | |
(loop for map in maps nconc | |
(loop for key being the hash-key of map collect key)) | |
:test 'equal) | |
'string<))) |
OlderNewer