id int64 0 45.1k | file_name stringlengths 4 68 | file_path stringlengths 14 193 | content stringlengths 32 9.62M | size int64 32 9.62M | language stringclasses 1
value | extension stringclasses 6
values | total_lines int64 1 136k | avg_line_length float64 3 903k | max_line_length int64 3 4.51M | alphanum_fraction float64 0 1 | repo_name stringclasses 779
values | repo_stars int64 0 882 | repo_forks int64 0 108 | repo_open_issues int64 0 90 | repo_license stringclasses 8
values | repo_extraction_date stringclasses 146
values | sha stringlengths 64 64 | __index_level_0__ int64 0 45.1k | exdup_ids_cmlisp_stkv2 listlengths 1 47 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
22,485 | neoplastic.pde | rheaplex_like-that-generator/source/appearance/neoplastic.pde | class Appearance
{
color colour;
Appearance ()
{
switch (int (random (3)))
{
case 0:
colour = color (255, 0, 0, 240);
break;
case 1:
colour = color (255, 255, 0, 200);
break;
case 2:
colour = color (0, 0, 255, 210);
break;
case 3:
colour = color (0, 0, 0, 245);
break;
}
}
void draw (Form f)
{
fill (colour);
f.draw ();
}
}
| 440 | Common Lisp | .l | 27 | 11 | 42 | 0.476886 | rheaplex/like-that-generator | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | b0382f522260b3ab34beda553f6c1a9f86973791de38b8c514ecf3b182a172a6 | 22,485 | [
-1
] |
22,486 | black.pde | rheaplex_like-that-generator/source/appearance/black.pde | class Appearance
{
void draw (Form f)
{
fill (33);
f.draw ();
}
}
| 73 | Common Lisp | .l | 8 | 7.25 | 19 | 0.6 | rheaplex/like-that-generator | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | a5c387cab8e96cbc545a0af447777bf2ed06058af5bef3d6c928fd2d766ca8db | 22,486 | [
-1
] |
22,489 | rhizomebb.lisp | rheaplex_rhizomebb/rhizomebb.lisp | ;; rhizomebb.lisp - Functions to generate bbcode aestheticized text for Rhizome.
;; Copyright (c) 2008 Rob Myers <rob@robmyers.org>
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Notes
;;
;; map into vector is used to make functions composable/chainable.
;; e.g. (random-colour (random-size "hello" 6 18) 100 200)
;; Todo: random caps, misused unicode replace, image replace from flickr ;-)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun random-range (min max)
"Generate a number between min & max, assumes max is greater than min."
(+ min
(random (- max min))))
(defun random-sign (val)
"Return the value with its sign reversed 50% of the time."
(if (< 0.5 (random 1.0))
val
(* val -1.0)))
(defun next-value (current min-val max-val min-delta max-delta)
"Generate a value between min and max varying from current by the delta."
(let* ((delta (random-sign (random-range min-delta max-delta)))
(next (+ current delta)))
;; Constrain to range min-val..max-val
(max min-val (min next max-val))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BBCode wrapper functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun random-size (text min-val max-val)
"Print the string with each character wrapped in a bbcode size block."
(map 'vector
#'(lambda (char)
(format nil "[size=~d]~a[/size]"
(floor (random-range min-val max-val))
char))
text))
(defun random-colour (text min-val max-val)
"Print the string with each character wrapped in a bbcode color block."
(map 'vector
#'(lambda (char)
(format nil "[color=#~2,'0x~2,'0x~2,'0x]~a[/color]"
(random-range min-val max-val)
(random-range min-val max-val)
(random-range min-val max-val)
char))
text))
(defun random-walk-size (text min-val max-val min-delta max-delta)
"Print the string with each character wrapped in a bbcode size block."
(let ((siz (random-range min-val max-val)))
(map 'vector
#'(lambda (char)
(setf siz (next-value siz min-val max-val min-delta max-delta))
(format nil "[size=~d]~a[/size]" (floor siz) char))
text)))
(defun random-walk-colour (text min-val max-val min-delta max-delta)
"Print the string with each character wrapped in a bbcode color block."
(let ((r (random-range min-val max-val))
(g (random-range min-val max-val))
(b (random-range min-val max-val)))
(map 'vector
#'(lambda (char)
(setf r (next-value r min-val max-val min-delta max-delta))
(setf g (next-value g min-val max-val min-delta max-delta))
(setf b (next-value b min-val max-val min-delta max-delta))
(format nil "[color=#~2,'0x~2,'0x~2,'0x]~a[/color]"
(floor r) (floor g) (floor b) char))
text)))
(defun random-walk-brightness (text min-val max-val min-delta max-delta)
"Print the string with each character wrapped in a bbcode color block."
;; Needs improving
(let ((r (random-range min-val max-val))
(g (random-range min-val max-val))
(b (random-range min-val max-val))
(level (random-range min-val max-val)))
(map 'vector
#'(lambda (char)
(setf level (next-value level min-val max-val min-delta max-delta))
(format nil "[color=#~2,'0x~2,'0x~2,'0x]~a[/color]"
(floor (* r level))
(floor (* g level))
(floor (* b level))
char))
text)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Interface
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun demo ()
"Print the string with each character wrapped in a bbcode size & color block."
(format t "Enter text to encode and press return:~%")
(map nil
#'(lambda (char) (princ char))
(random-colour (random-size (read-line) 8 18) 0 200))
(format t "~%"))
| 4,786 | Common Lisp | .lisp | 107 | 40.925234 | 80 | 0.583441 | rheaplex/rhizomebb | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 12e428c016489a75b43f405130c89ad7704eed06dc5a6144354bbdfdb063de3d | 22,489 | [
-1
] |
22,506 | app-utils.lisp | fade_cl-wikidata/app-utils.lisp | (defpackage :cl-wikidata.app-utils
(:use :cl)
(:export :internal-disable-debugger)
(:export :internal-quit))
(in-package :cl-wikidata.app-utils)
(defun internal-disable-debugger ()
(labels
((internal-exit (c h)
(declare (ignore h))
(format t "~a~%" c)
(internal-quit)))
(setf *debugger-hook* #'internal-exit)))
(defun internal-quit (&optional code)
"Taken from the cliki"
;; This group from "clocc-port/ext.lisp"
#+allegro (excl:exit code)
#+clisp (#+lisp=cl ext:quit #-lisp=cl lisp:quit code)
#+cmu (ext:quit code)
#+cormanlisp (win32:exitprocess code)
#+gcl (lisp:bye code) ; XXX Or is it LISP::QUIT?
#+lispworks (lw:quit :status code)
#+lucid (lcl:quit code)
#+sbcl (sb-ext:exit :code code)
;; This group from Maxima
#+kcl (lisp::bye) ; XXX Does this take an arg?
#+scl (ext:quit code) ; XXX Pretty sure this *does*.
#+(or openmcl mcl) (ccl::quit)
#+abcl (cl-user::quit)
#+ecl (si:quit)
;; This group from <hebi...@math.uni.wroc.pl>
#+poplog (poplog::bye) ; XXX Does this take an arg?
#-(or allegro clisp cmu cormanlisp gcl lispworks lucid sbcl
kcl scl openmcl mcl abcl ecl)
(error 'not-implemented :proc (list 'quit code)))
| 1,309 | Common Lisp | .lisp | 34 | 34.617647 | 74 | 0.615264 | fade/cl-wikidata | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 89380dd0fbd9c74eab81fcad87ab528b909f0da4c1bf8d59ff682e4ec1ffa8fa | 22,506 | [
-1
] |
22,507 | cl-wikidata.asd | fade_cl-wikidata/cl-wikidata.asd | ;;;; cl-wikidata.asd
(asdf:defsystem #:cl-wikidata
:description "Common Lisp interface to the Wikidata SPARQL endpoint."
:author "Brian O'Reilly <fade@deepsky.com>"
:license "GNU General Public License v3 or later."
:serial t
:depends-on (#:ALEXANDRIA
#:RUTILS
#:DEXADOR
#:CL-PPCRE
#:CL-SPARQL
;; #:VELLUM
#:JSOWN
#:CL-JSON-POINTER
#:FLEXI-STREAMS)
:pathname "./"
:components ((:file "app-utils")
(:file "cl-wikidata")))
| 587 | Common Lisp | .asd | 18 | 22.388889 | 71 | 0.525573 | fade/cl-wikidata | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 8322ef13e7bbd6d53ea9b49fcd1c257ed4a100516ab72424d608c91b7371c32f | 22,507 | [
-1
] |
22,508 | wikidata-rest-client | fade_cl-wikidata/wikidata-rest-client | # -*- restclient -*-
# interrogate the wikidata SPARQL endpoint
GET https://query.wikidata.org/sparql
Accept: application/json
User-Agent: Emacs Restclient
"query":"SELECT DISTINCT ?airport ?airportLabel ?icaocode
WHERE
{
?airport wdt:P31 wd:Q1248784 ;
wdt:P239 ?icaocode .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?airportLabel",
"format":"json"
#"query":"SELECT%0A%20%20%3Fitem%20%3FitemLabel%0A%20%20%3Fvalue%20%3FvalueLabel%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP1800%20%3Fvalue%0A%20%20%23%20change%20P1800%20to%20another%20property%20%20%20%20%20%20%20%20%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D%0ALIMIT%2010","format":"json"
# Just do it manually. :(
GET https://query.wikidata.org/sparql?format=json&query=%0A%23Airports+on+earth%0ASELECT+DISTINCT+%3Fairport+%3FairportLabel+%3Ficaocode%0AWHERE%0A%7B%0A++%3Fairport+wdt%3AP31+wd%3AQ1248784+%3B%0A+++++++++++wdt%3AP239+%3Ficaocode+.%0A++SERVICE+wikibase%3Alabel+%7B%0A++++bd%3AserviceParam+wikibase%3Alanguage+%22en%22+.%0A++%7D%0A%7D%0AORDER+BY+%3FairportLabel%0A
Accept: application/json
User-Agent: Emacs Restclient | 1,233 | Common Lisp | .cl | 21 | 56.428571 | 376 | 0.769677 | fade/cl-wikidata | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | cbd926415179aa709c39473f844573baec911c2651c0b550ac24e852eecb2aae | 22,508 | [
-1
] |
22,510 | wikidata-queries.sparql | fade_cl-wikidata/wikidata-queries.sparql | # Demonstrates filtering for "unknown value"
SELECT ?human ?humanLabel
WHERE
{
?human wdt:P21 ?gender .
FILTER wikibase:isSomeValue(?gender)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
| 231 | Common Lisp | .l | 8 | 27.125 | 83 | 0.780269 | fade/cl-wikidata | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | e960503d851a23d4a4cf3e21e495cc16f85d3469d6fce05f050568c741f2c36c | 22,510 | [
-1
] |
22,511 | Makefile | fade_cl-wikidata/Makefile | ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PACKAGE=cl-wikidata
PACKAGEUTILS=cl-wikidata.app-utils
OUT=wikidata
ENTRY=-main
$(OUT): buildapp *.lisp quicklisp-manifest.txt
./buildapp --manifest-file quicklisp-manifest.txt \
--load-system asdf \
--eval '(push "$(ROOT_DIR)/" asdf:*central-registry*)' \
--load-system $(PACKAGE) \
--eval '($(PACKAGEUTILS)::internal-disable-debugger)' \
--output $(OUT) --entry $(PACKAGE):$(ENTRY) \
--compress-core
quicklisp-manifest.txt: *.asd
sbcl --non-interactive \
--eval '(push #P"$(ROOT_DIR)/" asdf:*central-registry*)'\
--eval '(ql:quickload "$(PACKAGE)")'\
--eval '(ql:write-asdf-manifest-file "quicklisp-manifest.txt")'
buildapp:
sbcl --eval '(ql:quickload "buildapp")' --eval '(buildapp:build-buildapp)' --non-interactive
clean:
rm -f *.fasl $(OUT) buildapp quicklisp-manifest.txt
| 886 | Common Lisp | .l | 22 | 37.545455 | 93 | 0.689535 | fade/cl-wikidata | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | bb819b6dd273cdaa91d8cd62c9f341735e2bb8f6e209d17dce686e03a759d5c0 | 22,511 | [
-1
] |
22,529 | package.lisp | kisp_ompw/package.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :cl-user)
(defpackage :ompw
(:use :cl)
(:export #:define-menu #:in-menu #:menu-separator #:menu-add-symbol #:install-menu
#:define-box #:pprint-define-box
#:choose-file-dialog #:choose-new-file-dialog))
| 1,031 | Common Lisp | .lisp | 19 | 52.263158 | 84 | 0.730348 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | c93df37d1194ab09dadc1ab4d59887f0a7ef0d02d89211b86a33033e3cda3550 | 22,529 | [
-1
] |
22,530 | ompw.lisp | kisp_ompw/ompw.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(flet ((load-compile (path)
(if (member :om-deliver *features*)
(om::compile&load (make-pathname :type nil :defaults path))
(load (compile-file path)))))
(let ((*default-pathname-defaults* *load-truename*))
(load-compile "package.lisp")
(load-compile "menu.lisp")
(load-compile "define-box.lisp")
(load-compile "file-dialog.lisp")
(load-compile "pprint-define-box.lisp")))
| 1,212 | Common Lisp | .lisp | 23 | 49.869565 | 73 | 0.715976 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | bb691079e06c658729d74aa4849b9e99e19585c62c88607e26bb9fd4f7852b31 | 22,530 | [
-1
] |
22,531 | menu.lisp | kisp_ompw/menu.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :ompw)
(defvar *library-name* nil)
(defun nconc1 (list obj)
(nconc list (list obj)))
(define-modify-macro nconc1f (obj) nconc1)
#+pwgl
(defun menu-spec2native (menu-spec)
(labels ((collect-until-change (menu-items)
(destructuring-bind (first . rest)
menu-items
(cond
((eq :menu-separator first)
(values :menu-separator rest))
((listp first)
(values first rest))
;; okay its a normal symbol
(t (loop
for items-tail on menu-items
for item = (car items-tail)
while (and (atom item)
(not (eq :menu-separator item)))
collect item into items
finally (return (values items items-tail)))))))
(split-menu-items (menu-items)
(multiple-value-bind (first rest)
(collect-until-change menu-items)
(cond
((null rest) (list first))
(t (cons first (split-menu-items rest))))))
(convert (menu-spec)
(labels ((rec (items)
(cond
((null items) nil)
((eq :menu-separator (first items))
(destructuring-bind (next . rest)
(rec (rest items))
`((:menu-component ,next)
,@rest)))
((stringp (caar items))
(destructuring-bind (first . rest)
items
`(,(convert first) ,@(rec rest))))
(t (cons (car items) (rec (cdr items)))))))
(destructuring-bind (name . items)
menu-spec
(cons name (rec (split-menu-items items)))))))
`(:menu-component ,(convert menu-spec))))
#+om
(defun menu-spec2native (menu-spec)
(labels ((symbols+sub-menus (items)
(loop for item in items
if (listp item)
collect (rec item) into sub-menus
else collect (cond
((eql item :menu-separator)
'-)
(t item))
into symbols
finally (return (values symbols sub-menus))))
(rec (menu-spec)
(destructuring-bind (name . items)
menu-spec
(multiple-value-bind (symbols sub-menus)
(symbols+sub-menus items)
`(,name ,sub-menus nil ,symbols nil)))))
(let ((rec (rec menu-spec)))
(if (fourth rec)
;; we have some functions directly on the first level
(list rec)
;; we have only submenus on the first level
(second rec)))))
#-(or pwgl om)
(defun menu-spec2native (menu-spec)
menu-spec)
#+pwgl
(defun %install-menu (native-menu-spec menu)
(declare (ignore menu))
(ccl::add-PWGL-user-menu native-menu-spec))
#+om
(defun %install-menu (native-menu-spec menu)
(let ((om::*current-lib* (om::find-library (string-downcase (string menu)))))
(unless om::*current-lib*
(cerror "ok - go on" "Sorry, cannot find omlib from name ~s.
You should give your menu the same name as your library."
(string-downcase (string menu))))
(om::fill-library native-menu-spec)))
#-(or pwgl om)
(defun %install-menu (native-menu-spec menu)
)
(defstruct menu
name print-name container items)
(defvar *menus* (make-hash-table))
(defvar *menu* nil)
(defmacro get-menu (name &optional errorp)
(if errorp
(let ((=name= (gensym "NAME")))
`(let* ((,=name= ,name)
(menu (gethash ,=name= *menus*)))
(assert menu nil "The menu of name ~S does not exist.~
~%Maybe you have forgotten to add a DEFINE-MENU~
~%and an IN-MENU before your first DEFINE-BOX." ,=name=)
menu))
`(gethash ,name *menus*)))
(defun menu-add-item (menu item)
(when (symbolp menu)
(setq menu (get-menu menu t)))
(nconc1f (menu-items menu) item))
(defmacro define-menu (name &key print-name in)
(check-type name symbol)
(check-type in symbol)
(when (keywordp name) (warn "It is not recommended to use a keyword for a menu name.
Better use a normal symbol instead."))
(unless print-name (setq print-name (string-capitalize (string name))))
`(eval-when (:load-toplevel :execute)
,@(when in `((assert (get-menu ',in))))
(let ((new-menu (setf (get-menu ',name) (make-menu :name ',name :print-name ,print-name :container ',in))))
(declare (ignorable new-menu))
,@(when in `((menu-add-item (get-menu ',in) new-menu)))
',name)))
(defmacro in-menu (name)
(check-type name symbol)
`(eval-when (:load-toplevel :execute)
(setq *menu* (get-menu ',name t))))
(defmacro menu-separator (&key in)
(check-type in symbol)
`(eval-when (:load-toplevel :execute)
(menu-add-item
,(if in `(get-menu ',in t) '*menu*)
:menu-separator)))
(defgeneric menu-spec (menu)
(:method ((menu menu))
(cons (menu-print-name menu)
(mapcar #'menu-spec (menu-items menu))))
(:method (obj) obj))
(defun install-menu* (menu)
(assert (symbolp menu))
(%install-menu (menu-spec2native (menu-spec (get-menu menu t)))
menu))
(defmacro install-menu (name)
(check-type name symbol)
`(eval-when (:load-toplevel :execute)
(install-menu* ',name)))
(defmacro menu-add-symbol (symbol)
(check-type symbol symbol)
`(eval-when (:load-toplevel :execute)
(export ',symbol)
(menu-add-item *menu* ',symbol)))
| 5,748 | Common Lisp | .lisp | 160 | 31.53125 | 112 | 0.656419 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f7a65e97e931ebccfcd1e7dd7e7b4204a4ce44d9ebbb86db2e0ef7a25575ac81 | 22,531 | [
-1
] |
22,532 | file-dialog.lisp | kisp_ompw/file-dialog.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :ompw)
(define-menu ompw :print-name "ompw")
(define-menu file-dialogs :in ompw :print-name "File-Dialogs")
(in-menu file-dialogs)
;;; choose-new-file-dialog
#-(or pwgl om)
(define-box choose-new-file-dialog (&key (prompt "Enter the path for a new file:")
button-string)
:non-generic t
(declare (ignore button-string))
(format *query-io* "~&~a~%[please enter a path like /tmp/test.txt]~%" prompt)
(force-output *query-io*)
(parse-namestring (read-line *query-io*)))
#+ (or pwgl om)
(define-box choose-new-file-dialog (&key (prompt "Enter the path for a new file:")
button-string)
:non-generic t
(capi:prompt-for-file prompt :operation :save))
;;; choose-file-dialog
#-(or pwgl om)
(define-box choose-file-dialog (&key (prompt "Enter the path for an existing file:")
button-string)
:non-generic t
(format *query-io* "~&~a~%[please enter a path like /tmp/test.txt]~%" prompt)
(force-output *query-io*)
(let ((path (parse-namestring (read-line *query-io*))))
(if (probe-file path)
path
(progn
(format *query-io* "~&ERROR: ~A does not exist.~%" path)
(choose-file-dialog :prompt prompt :button-string button-string)))))
#+ (or pwgl om)
(define-box choose-file-dialog (&key (prompt "Enter the path for an existing file:")
button-string)
:non-generic t
(capi:prompt-for-file prompt))
(install-menu ompw)
| 2,187 | Common Lisp | .lisp | 50 | 41.14 | 84 | 0.707765 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | ab48f31b0ad64f01d104788e4cfc9f0a14a33aeebb5c602c2980576043249325 | 22,532 | [
-1
] |
22,533 | load.lisp | kisp_ompw/load.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :cl-user)
;; this file was intended to be a load file for people
;; that do not use ASDF
;; for the unlikely case, you can comment out the code below
;; for now, let's just call ASDF to do the job
(asdf:oos 'asdf:load-op :ompw)
;; (let ((ompw-base-directory
;; (make-pathname :name nil :type nil :version nil
;; :defaults (parse-namestring *load-truename*)))
;; must-compile)
;; (with-compilation-unit ()
;; (dolist (file '("package"
;; "define-box"
;; "pprint-define-box"
;; ))
;; (let ((pathname (make-pathname :name file :type "lisp" :version nil
;; :defaults ompw-base-directory)))
;; (let ((compiled-pathname (compile-file-pathname pathname)))
;; (unless (and (not must-compile)
;; (probe-file compiled-pathname)
;; (< (file-write-date pathname)
;; (file-write-date compiled-pathname)))
;; (setq must-compile t)
;; (compile-file pathname))
;; (setq pathname compiled-pathname))
;; (load pathname)))))
| 1,989 | Common Lisp | .lisp | 39 | 49.74359 | 76 | 0.62268 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 67af679ec3e93dd4f98fbf14ede2518a0a66effd9ccebe3907c2ff1512192f95 | 22,533 | [
-1
] |
22,534 | pprint-define-box.lisp | kisp_ompw/pprint-define-box.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :ompw)
;;; (set-pprint-dispatch '(cons (eql ompw:define-box)) #'ompw:pprint-define-box)
;;; this could probably be more pretty
(defun pprint-define-box (stream obj)
(destructuring-bind (name lambda-list &rest body) (cdr obj)
(let ((*standard-output* stream))
(write-char #\()
(prin1 'ompw:define-box)
(write-char #\space)
(prin1 name)
(write-char #\space)
(prin1 lambda-list)
;; TODO we assume that a doc string will always be before options
(when (stringp (car body))
(terpri)
(prin1 (pop body)))
(loop for opt-tail = body
for opt = (car opt-tail)
for keywordp = (keywordp opt)
for i upfrom 0
until (and (not keywordp) (evenp i))
do (when (evenp i) (terpri))
do (prin1 opt)
do (when (evenp i)
(write-char #\space))
do (pop body))
(mapc #'pprint body)
(write-char #\))
(terpri))))
| 1,701 | Common Lisp | .lisp | 42 | 36.857143 | 80 | 0.682617 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 0dfc6767266a649d0c439a9798a9c03b40dec4ead7cbb24d8b246ec2298ed870 | 22,534 | [
-1
] |
22,535 | menu-tests.lisp | kisp_ompw/menu-tests.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :ompw)
(rtest:deftest menu1
(menu-spec2native '("ks"
("file1" cl:+ cl:-)
("file2" * + / :menu-separator +)
("file3" ("first" * + /) ("second" +))
("file4" * + / ("second" +))))
#+pwgl
(:menu-component
("ks"
("file1" (+ -))
("file2" (* + /) (:menu-component (+)))
("file3" ("first" (* + /)) ("second" (+)))
("file4" (* + /) ("second" (+)))))
#-(or pwgl)
#.(error "do not know how to test this"))
(rtest:deftest menu2
(menu-spec2native '("KS"
("file1" cl:+ cl:-)
("file2" * + /)))
#+pwgl
(:menu-component
("KS"
("file1"
(+ -))
("file2"
(* + /))))
#-(or pwgl)
#.(error "do not know how to test this"))
(rtest:deftest menu3
(menu-spec2native '("Esquisse"
("Intervals"
("Generation" + - +)
("Treatment" subseq append)
("Analysis" list))
("Freq harmony"
("Harm Series" subseq)
("Modulations" list)
("Treatment" + - +)
("Analysis" subseq append :menu-separator +))
("Utilities"
subseq append
:menu-separator
+ - +
:menu-separator
list)))
#+pwgl
(:menu-component
("Esquisse"
("Intervals"
("Generation" (cl:+ cl:- cl:+))
("Treatment" (cl:subseq cl:append))
("Analysis" (cl:list)))
("Freq harmony"
("Harm Series" (cl:subseq))
("Modulations" (cl:list))
("Treatment" (cl:+ cl:- cl:+))
("Analysis" (cl:subseq cl:append)
(:menu-component (cl:+))))
("Utilities" (cl:subseq cl:append)
(:menu-component (cl:+ cl:- cl:+))
(:menu-component (cl:list))
)))
#-(or pwgl)
#.(error "do not know how to test this"))
| 2,520 | Common Lisp | .lisp | 78 | 27.192308 | 73 | 0.578298 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 1d8c9ebf25e9c23dfadfc9a214c8a47615b6081fd92f8f265d3d9760cdc0925b | 22,535 | [
-1
] |
22,536 | define-box.lisp | kisp_ompw/define-box.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :ompw)
;; TODO allow only one docstring
;; TODO pw menu with association string is currently not possible
;; TODO icon option for OM
(defun ensure-list (thing)
(if (listp thing) thing (list thing)))
(defun atom-or-first (thing)
(or (atom thing) (first thing)))
(defun second-or-nil (thing)
(if (listp thing) (second thing) nil))
(defvar *lambda-list-keywords*
'(&key &aux &rest &body &whole &optional &environment &allow-other-keys))
(defun lambda-list-keywordp (obj)
(member obj *lambda-list-keywords*))
(defun args-after-take-default-value (lambda-list-keyword)
(case lambda-list-keyword
((&key &aux &optional) t)
(otherwise nil)))
;; TODO check these definitions against each other
;; probably make this a normal pure lisp functions
(defun self-evaluating-p (obj)
#+sbcl (sb-int:self-evaluating-p obj)
#-sbcl (and (atom obj) (or (null obj) (not (symbolp obj)) (eq obj t) (keywordp obj))))
(defun canonicalize-menu (menu)
(destructuring-bind (arg &rest values) menu
(cons arg
(loop for value in values
if (consp value)
collect value
else collect (list value (prin1-to-string value))))))
(defun parse-body (body)
"Returns a plist, where values (of possibly multiply
occuring keys in BODY) are collected into lists.
If a documentation string is present, it will get the key :doc.
The actual forms of BODY are available by the key :forms."
(labels ((rec (body)
(cond
((keywordp (car body))
(let ((key (car body))
(rest (rec (cddr body))))
(if (getf rest key)
(progn
(setf (getf rest key) (nconc (list (second body)) (getf rest key)))
rest)
(list* (first body) (list (second body)) rest))))
((stringp (car body))
(rec (cons :doc body)))
((and (listp (car body))
(eql 'declare (caar body)))
(rec `(:declarations ,(car body) ,@(cdr body))))
(t `(:forms ,body)))))
(let ((parsed-body (rec body)))
(setf (getf parsed-body :menu) (mapcar #'canonicalize-menu (getf parsed-body :menu)))
parsed-body)))
(defun canonicalize-lambda-list (lambda-list &optional (default-value t)) ; req args take default
(cond
((null lambda-list)
nil)
((lambda-list-keywordp (car lambda-list))
(cons (car lambda-list)
(canonicalize-lambda-list (cdr lambda-list)
(args-after-take-default-value (car lambda-list)))))
(t
(cons (typecase (car lambda-list)
(symbol (if default-value
(list (car lambda-list) nil)
(car lambda-list)))
(list (car lambda-list)))
(canonicalize-lambda-list (cdr lambda-list) default-value)))))
(defun required-strip-initvals (lambda-list)
(loop
for arg-tail on lambda-list
for arg = (car arg-tail)
do (when (lambda-list-keywordp arg)
(return (nconc required-args arg-tail)))
collect (first arg) into required-args
finally (return required-args)))
(defun strip-initvals (lambda-list)
(mapcar #'(lambda (arg) (if (listp arg) (first arg) arg)) lambda-list))
(defun lambda-list-only-args (lambda-list)
(remove-if #'lambda-list-keywordp lambda-list))
(defun quote-initvals (lambda-list)
"Will quote all initvals (second arg) in LAMBDA-LIST,
if there are not self-evaluating-p."
(loop for arg in lambda-list
if (or (atom arg) (self-evaluating-p (second arg)))
collect arg
else collect (list (first arg) (list 'quote (second arg)))))
;;; its a good time to remember here that PARSED-BODY
;;; is not really a plist
(defun export-option-present (parsed-body)
(car (getf parsed-body :export '(t))))
;;; TODO maybe we dont need this option
(defun main-menu-option-present (parsed-body)
(car (getf parsed-body :main-menu '(t))))
(defun export-and-menu-forms (name parsed-body)
(when (export-option-present parsed-body)
`((export ',name)
,@(when (main-menu-option-present parsed-body)
`((eval-when (:load-toplevel :execute)
(menu-add-item *menu* ',name)))))))
;;; TODO doc should be for the defgeneric, not the defmethod
#-(or pwgl om)
(defmacro define-box (name lambda-list &body body)
(let* ((parsed-body (parse-body body))
(lambda-list (canonicalize-lambda-list lambda-list))
(lambda-list-only-args (lambda-list-only-args lambda-list))
(lambda-list-arg-names (mapcar #'atom-or-first lambda-list-only-args))
(lambda-list-arg-values (mapcar #'second-or-nil lambda-list-only-args)))
`(progn
,@(export-and-menu-forms name parsed-body)
,@(unless (getf parsed-body :non-generic)
`((defgeneric ,name ,(strip-initvals lambda-list))))
(,(if (getf parsed-body :non-generic)
'defun
'defmethod)
,name
,(quote-initvals (required-strip-initvals lambda-list))
,@(getf parsed-body :doc)
,@(getf parsed-body :declarations)
,@(loop for (arg . vals) in (getf parsed-body :menu)
for arg-ind = (position arg lambda-list-arg-names)
for def-val = (nth arg-ind lambda-list-arg-values)
do (unless (member def-val vals :key #'first :test #'equal)
(cerror "Okay - we ignore this."
"Sorry, default-value '~S' of arg '~S' is not part of its menu ~S."
def-val arg (cons arg vals)))
collect `(assert (member ,arg ',(mapcar #'first vals))))
,@(getf parsed-body :forms)))))
#+om
(defmacro define-box (name lambda-list &body body)
(labels ((quote-for-5.1 (obj)
#+(or ccl-5.1 lispworks) (list 'quote obj)
#-(or ccl-5.1 lispworks) obj)
(omify-symbols (tree)
(cond
((null tree)
nil)
((consp tree)
(cons (omify-symbols (car tree))
(omify-symbols (cdr tree))))
((and (symbolp tree) (not (keywordp tree)))
(intern (symbol-name tree) #.(find-package "OM")))
(t tree))))
(let* ((parsed-body (parse-body body))
(lambda-list (canonicalize-lambda-list lambda-list))
(lambda-list-only-args (lambda-list-only-args lambda-list))
(lambda-list-arg-names (mapcar #'atom-or-first lambda-list-only-args))
(lambda-list-arg-values (mapcar #'omify-symbols (mapcar #'second-or-nil lambda-list-only-args))))
`(progn
,@(export-and-menu-forms name parsed-body)
(om::defmethod! ,name ,(quote-initvals (required-strip-initvals lambda-list))
,@(when (getf parsed-body :doc) '(:doc))
,@(getf parsed-body :doc)
:initvals ',lambda-list-arg-values
:icon ,(car (getf parsed-body :icon '(176)))
:numouts ,(car (getf parsed-body :outputs '(1)))
,@(when (getf parsed-body :menu)
(list :menuins
(quote-for-5.1
(loop for (arg . vals) in (getf parsed-body :menu)
for arg-ind = (position arg lambda-list-arg-names)
for def-val = (nth arg-ind lambda-list-arg-values)
do (unless (member def-val vals :key #'first :test #'equal)
(cerror "Okay - we ignore this."
"Sorry, default-value '~S' of arg '~S' is not part of its menu ~S."
def-val arg (cons arg vals)))
collect `(,arg-ind ,(loop for (value title) in vals
collect (if (eql value def-val)
(list title value t)
(list title value))))))))
,@(getf parsed-body :declarations)
,@(getf parsed-body :forms))))))
#+pwgl
;;; use :r :g :b between 0 and 1 for color
;;; look tutorial -> basic -> box-creation
(defmacro define-box (name lambda-list &body body)
(labels ((lambda-list-quoted-values (lambda-list)
(loop
for elt in lambda-list
collect (if (consp elt)
(list (first elt) (list 'quote (second elt)))
elt)))
(lambda-list-ensure-defaults (lambda-list)
(loop for arg in lambda-list
if (lambda-list-keywordp arg)
collect arg
else if (atom arg)
collect (list arg nil)
else collect arg))
(menu-form (menu-spec def-value)
(destructuring-bind (arg &rest items) menu-spec
;; the string is first :menu-list (("eins" 1) ("zwei" 2))
`(ccl::mk-menu-subview :menu-list ',(mapcar #'reverse items) :value ,(position def-value items :key #'first :test #'equal)))))
(let* ((parsed-body (parse-body body))
(lambda-list (lambda-list-quoted-values (canonicalize-lambda-list lambda-list)))
(lambda-list (lambda-list-ensure-defaults lambda-list))
(lambda-list (macrolet ((collect (obj)
`(push ,obj res)))
(loop with res
with menu-specs = (getf parsed-body :menu)
for arg in lambda-list
do (if (lambda-list-keywordp arg)
(collect arg)
(let ((menu-spec (find (car (ensure-list arg)) menu-specs :key #'first)))
(cond
((null menu-spec)
(collect arg))
(t
;; second second because the def-val is quoted
(collect (list (first arg) (second arg) (menu-form menu-spec (second (second arg)))))))))
finally (return (nreverse res)))))
(outputs (getf parsed-body :outputs (list 1))))
(when (and (> (first outputs) 1) (getf parsed-body :class))
(error "In define-box ~s: Currently, you cannot specify a :class together with more than one :outputs." name))
(when (getf parsed-body :class) (assert (= 1 (length (getf parsed-body :class)))))
`(progn
,@(export-and-menu-forms name parsed-body)
(ccl::pwgldef ,name ,lambda-list
,(if (getf parsed-body :doc)
(first (getf parsed-body :doc))
"no doc")
(,@(when (not (= 1 (first outputs)))
`(:class 'ccl::PWGL-values-box :outputs ,(first outputs)))
,@(when (getf parsed-body :class) `(:class ',(first (getf parsed-body :class)))))
,@(getf parsed-body :declarations)
,@(getf parsed-body :forms))))))
| 10,290 | Common Lisp | .lisp | 240 | 38.029167 | 134 | 0.660247 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 603f9e9eff2ed2a0db6accb4cde73c6cf7f607b104cb790fa4837055509020c7 | 22,536 | [
-1
] |
22,537 | examples.lisp | kisp_ompw/examples.lisp | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(defpackage :mylibrary-package
(:use :cl :ompw))
(in-package :mylibrary-package)
(define-ompw myadd ((a 1) (b 1))
"Add A + B."
(+ a b))
(defmethod myadd ((a list) (b list))
(mapcar #'+ a b))
(define-ompw myadd-non-gf ((a 1) (b 1))
:non-generic t
"Add A + B."
(+ a b))
(define-ompw myposition ((elt 3) (list (1 2 3 4 3 2 1)) &optional (from-end nil))
"Return position of ELT in LIST."
:menu (from-end t nil)
(position elt list :from-end from-end))
(define-ompw myadd2 ((a 3) (b 200))
:menu (a 1 2 3 4 5)
:menu (b (100 "einhundert") (200 "zweihundert"))
"Add A + B."
(+ a b))
(define-ompw myadd3 (&optional (a 1) (b 1))
"Add A + B."
(+ a b))
(define-ompw ks ()
(progn
"ks"))
(define-ompw mymember ((elt (2)) (list ((1) (2) 3 4 5 6)) &optional (test equal))
(member elt list :test test))
(define-ompw menu-test ((dyn :mf))
:menu (dyn :p :mf :f)
(if (eql dyn :mf) "its mf" "another dyn"))
(define-ompw menu-test2 ((dyn mf))
:menu (dyn p mf f)
(if (eql dyn 'mf) "its mf" "another dyn"))
(define-ompw outputs-test ((a 1) (b 1))
:outputs 2
(values a b))
| 1,914 | Common Lisp | .lisp | 51 | 35.156863 | 81 | 0.660705 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 25d34d2f60cb9dfe813927e7bfd076728b060a9037fd0c8cb973be7810f74389 | 22,537 | [
-1
] |
22,538 | ompw.asd | kisp_ompw/ompw.asd | ;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; This file is part of ompw.
;;; Copyright (c) 2007 - 2011, Kilian Sprotte. All rights reserved.
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package #:asdf)
(defsystem :ompw
:author "Kilian Sprotte"
:version "0.3.2"
:serial t
:components
((:static-file "README")
(:static-file "TODO")
(:static-file "ompw.asd")
(:static-file "ompw.lisp")
(:static-file "load.lisp")
(:file "package")
(:file "menu")
(:static-file "menu-tests.lisp")
(:file "define-box")
(:file "file-dialog")
(:file "pprint-define-box")))
| 1,211 | Common Lisp | .asd | 30 | 37.8 | 73 | 0.702726 | kisp/ompw | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f3f46b7867d98de8ca03da30aa4a23af4057e5c9818eb4dd4b3c1fcddd63eb19 | 22,538 | [
-1
] |
22,563 | mandelpnm.lisp | lvecsey_mandel-pnm/mandelpnm.lisp | (defpackage :mandelpnm (:use :cl))
(in-package :mandelpnm)
; mandelpnm will stream a set of .pnm images to stdout. You can pipe this
; to an mpeg4 image encoder, or to encodedv first and then another encoder.
; You can also render a single .pnm image directly to a file. Usually this
; is done with the 'nomem' code path for very large desktop backgrounds.
; CLISP
; (setf (long-float-digits) 128)
; (long-float-digits)
; These image frame description resemble the XFRACTINT info <tab> page.
(defstruct frame
(topleft-x -2.5L0 :type long-float)
(topleft-y 1.5L0 :type long-float)
(bottomright-x 1.5L0 :type long-float)
(bottomright-y -1.5L0 :type long-float)
(center-x -0.5L0 :type long-float)
(center-y 0.0L0 :type long-float)
(mag 0.666666667L0 :type long-float)
(x-mag-factor 1.0L0 :type long-float)
(rotation 0.0L0 :type long-float)
(skew 0.0L0 :type long-float)
(iteration-max 150 :type integer))
(defun make-image-data (w h)
(make-array (list (* w h 3)) :initial-element 0 :element-type '(unsigned-byte 8)))
(defun make-image(w h)
(list w h (make-image-data w h)))
(defun flatten-coordinate(x y)
(+ x (* y (* x 3))))
(defun make-displaced-array(flat-array x y)
(make-array 3 :element-type '(unsigned-byte 8) :displaced-to flat-array :displaced-index-offset (flatten-coordinate x y)))
(defun image-width (image)
(first image))
(defun image-height (image)
(second image))
(defun image-data (image)
(third image))
; Some of the next few functions including the core inner loop are based on
; http://uint32t.blogspot.com/2008/04/mandelbrot-generator-in-common-lisp.html
(defun palette-map (iterations-taken max-iterations)
(let (depth)
(if (= iterations-taken max-iterations)
(setf depth 0)
(progn
(setf depth (truncate (* 255 (/ iterations-taken 1000))))))
(list (min 180 (* 1 depth))
(min 180 (* 5 depth))
(min 180 (* 20 depth)))))
(defun set-image-color (stride data x y iterations-taken max-iterations)
(let ((rgb-colors (palette-map iterations-taken max-iterations)))
(setf (aref data (+ (* 3 x) (* stride y))) (first rgb-colors))
(setf (aref data (+ 1 (* 3 x) (* stride y))) (second rgb-colors))
(setf (aref data (+ 2 (* 3 x) (* stride y))) (third rgb-colors))))
(defun set-image-color-write (file rgb-triplet iterations-taken max-iterations)
(let ((rgb-colors (palette-map iterations-taken max-iterations)))
(setf (aref rgb-triplet 0) (first rgb-colors))
(setf (aref rgb-triplet 1) (second rgb-colors))
(setf (aref rgb-triplet 2) (third rgb-colors))
(ext:write-byte-sequence rgb-triplet file :start 0 :end 3 :no-hang NIL :interactive NIL)))
(defun gen-setcolor-image-func (stride data)
(lambda (x y iterations-taken max-iterations)
(set-image-color stride data x y iterations-taken max-iterations)))
(defun gen-setcolor-directwrite-func (file)
(let ((rgb-triplet (make-array '3 :initial-element 0 :element-type '(unsigned-byte 8))))
(lambda (x y iterations-taken max-iterations)
(declare (ignore x y))
(set-image-color-write file rgb-triplet iterations-taken max-iterations))))
(defun within-radius (z)
(let ((r (realpart z))
(i (imagpart z)))
(<= (+ (* r r) (* i i))
4)))
(defun calculate-mandelbrot-image (width height &key (max-iterations 1000)
(real '(-2.5L0 1.5L0))
(imag '(1.5L0 -1.5L0))
(pixel-result-func NIL)
(compute-layout :mem-work))
(let* ((low-real (first real))
(high-real (second real))
(low-imag (first imag))
(high-imag (second imag))
(real-length (- high-real low-real))
(imag-length (- high-imag low-imag))
(real-by (/ real-length width))
(imag-by (/ imag-length height)))
(flet ((do-it (start-x end-x start-cr)
(loop
for y below height
for ci from low-imag by imag-by
do
(loop
for x from start-x to end-x
for cr from start-cr by real-by
do
(let* ((c (complex cr ci))
(iterations-taken
(loop
for z = c then (+ (* z z) c)
for iteration from 0 below max-iterations
while (within-radius z)
count iteration)))
(cond ((not (null pixel-result-func)) (funcall pixel-result-func (truncate x) (truncate y) iterations-taken max-iterations))))))))
(defun mem-work ()
(let* ((end-x (truncate (/ width 2))))
(progn
(do-it 0 end-x low-real)
(do-it (1+ end-x) (1- width) (+ (* end-x real-by) low-real)))))
(defun linear-work()
(do-it 0 (1- width) low-real))
(cond ((eq compute-layout :mem-work) (mem-work))
(t (linear-work))))))
(defparameter +PC_width+ 640)
(defparameter +PC_height+ 480)
(defparameter +SD480p_width+ 720)
(defparameter +SD480p_height+ 480)
(defparameter +HD720p_width+ 1280)
(defparameter +HD720p_height+ 720)
(defun render-frame(width height step pixel-result-func &key (compute-layout :mem-work))
(with-slots ((topleft-x topleft-x) (topleft-y topleft-y) (bottomright-x bottomright-x) (bottomright-y bottomright-y) (iteration-max iteration-max)) step
(calculate-mandelbrot-image width height :real (list topleft-x bottomright-x) :imag (list topleft-y bottomright-y) :max-iterations iteration-max :pixel-result-func pixel-result-func :compute-layout compute-layout)))
(defun spit-header(width height stream)
(let ((header (make-array '(0) :element-type 'base-char
:fill-pointer 0 :adjustable t)))
(with-output-to-string (s header)
(format s "P6~%#generated by mandelpnm~%~a ~a~%255~%" width height)
(let ((header-bytes (ext:convert-string-to-bytes header CHARSET:UTF-8)))
(ext:write-byte-sequence header-bytes stream :start 0 :end (length header) :no-hang NIL :interactive NIL)))))
(defun spit-data(image stream)
(let ((width (first image)) (height (second image)))
(ext:write-byte-sequence (third image) stream :start 0 :end (* width height 3) :no-hang NIL :interactive NIL)))
(defparameter +keyframes+ (list
(make-frame :topleft-x -2.5L0 :topleft-y 1.5L0 :bottomright-x 1.5L0 :bottomright-y -1.5L0
:center-x -0.5L0 :center-y -1.5L0 :mag 6.66666667L0
:x-mag-factor 1.0L0 :iteration-max 150)
(make-frame :topleft-x -0.6784037558685445L0 :topleft-y -0.4665970772442588L0
:bottomright-x -0.1212832550860719L0 :bottomright-y -0.8844374528311133L0
:center-x -0.3998435054773082L0 :center-y -0.6755172650376861L0 :mag 4.78651685L0
:x-mag-factor 1.0L0 :iteration-max 750)
(make-frame :topleft-x -0.7429072735545574L0 :topleft-y -0.2743642010254950L0
:bottomright-x -0.6568507047634542L0 :bottomright-y -0.3389066276188224L0
:center-x -0.6998789891590058L0 :center-y -0.3066354143221587L0 :mag 30.9873692L0
:x-mag-factor 1.0L0 :iteration-max 1000)
(make-frame :topleft-x -0.7167696736957242L0 :topleft-y -0.2980598065419851L0
:bottomright-x -0.7167497132590027L0 :bottomright-y -0.2980747768695262L0
:center-x -0.7167596934773635L0 :center-y -0.2980672917057556L0 :mag 133597.611L0
:x-mag-factor 1.0L0 :iteration-max 2000)
))
(defun coordset-from-frames(keyframes)
(loop for step in keyframes
for i from 0 upto (length keyframes)
collecting (with-slots ((x topleft-x) (y topleft-y)) step
(list (coerce x 'float) (coerce y 'float)))))
(defun zeroensure/ (quot divisor)
(cond ((or (> quot 0) (< quot 0)) (/ quot divisor))
(t 0)))
(defun interpolate-value (start-value end-value divisions count)
(cond ((eq count 0) start-value)
((eq count (- divisions 1)) end-value)
((or (< count 0) (>= count divisions)) (error "count must be in the range 0 <= count < divisions"))
(T (+ start-value (* (- end-value start-value) (zeroensure/ count (coerce divisions 'long-float)))))))
(defun interpolate-value2 (start-value end-value divisions count)
(cond ((eq count 0) start-value)
((eq count (- divisions 1)) end-value)
((or (< count 0) (>= count divisions)) (error "count must be in the range 0 <= count < divisions"))
(T (+ start-value (zeroensure/ (- (* end-value count) (* start-value count)) (coerce divisions 'long-float))))))
(defun interpolate-integervalue2 (start-value end-value divisions count)
(cond ((eq count 0) start-value)
((eq count (- divisions 1)) end-value)
((or (< count 0) (>= count divisions)) (error "count must be in the range 0 <= count < divisions"))
(T (floor (+ start-value (zeroensure/ (- (* end-value count) (* start-value count)) divisions))))))
(defun interpolated-frame (start-frame end-frame divisions count interpolate-func)
(with-slots ((stopleft-x topleft-x) (stopleft-y topleft-y) (sbottomright-x bottomright-x) (sbottomright-y bottomright-y)
(scenter-x center-x) (scenter-y center-y) (smag mag) (sx-mag-factor x-mag-factor) (srotation rotation)
(sskew skew) (siteration-max iteration-max)) start-frame
(with-slots ((etopleft-x topleft-x) (etopleft-y topleft-y) (ebottomright-x bottomright-x) (ebottomright-y bottomright-y)
(ecenter-x center-x) (ecenter-y center-y) (emag mag) (ex-mag-factor x-mag-factor) (erotation rotation)
(eskew skew) (eiteration-max iteration-max)) end-frame
(make-frame :topleft-x (funcall interpolate-func stopleft-x etopleft-x divisions count)
:topleft-y (funcall interpolate-func stopleft-y etopleft-y divisions count)
:bottomright-x (funcall interpolate-func sbottomright-x ebottomright-x divisions count)
:bottomright-y (funcall interpolate-func sbottomright-y ebottomright-y divisions count)
:center-x (funcall interpolate-func scenter-x ecenter-x divisions count)
:center-y (funcall interpolate-func scenter-y ecenter-y divisions count)
:mag (funcall interpolate-func smag emag divisions count)
:x-mag-factor (funcall interpolate-func sx-mag-factor ex-mag-factor divisions count)
:rotation (funcall interpolate-func srotation erotation divisions count)
:skew (funcall interpolate-func sskew eskew divisions count)
:iteration-max (funcall #'interpolate-integervalue2 siteration-max eiteration-max divisions count)
))))
; keyframes are a raw set of frame info into the mandelbrot
; mapped-keyframes is a list of tuples consisting of a frame number and an associated keyframe into the mandelbrot.
(defun write-image-core(image stream)
(progn
(spit-header (image-width image) (image-height image) stream)
(spit-data image stream)))
(defun write-image-file(image)
(with-open-file (file "image0.pnm" :direction :output :if-exists :supersede :if-does-not-exist :create :element-type '(unsigned-byte 8))
(write-image-core image file)))
(defun write-image-stdout(image)
(write-image-core image *STANDARD-OUTPUT*))
(defun write-image-dev_stdout(image)
(with-open-file (file "/dev/stdout" :direction :output :if-exists :supersede :if-does-not-exist :create :element-type '(unsigned-byte 8))
(write-image-core image file)))
(defun keyframe-mapping (keyframes frames)
"Return the frame numbers that contain keyframes"
(let ((keyframe-location 0) (num-middle-keyframes (- (length keyframes) 2)))
(let ((keyframe-spacing (/ frames (length keyframes))) (result-list NIL))
(cond ((null keyframes) NIL)
((eq (length keyframes) 2) (list (list 0 (first keyframes)) (list (- frames 1) (second keyframes))))
(t (progn
(setq result-list (list (cons 0 (first keyframes))))
(loop for step in (cdr keyframes)
for i from 0 below num-middle-keyframes
do (push (cons (floor (setq keyframe-location (+ keyframe-location keyframe-spacing))) step) result-list))
(push (cons (- frames 1) (car (last keyframes))) result-list)
(nreverse result-list)))))))
(defun keyframe-expansions (keyframes frames)
(let ((mapped-keyframes (keyframe-mapping keyframes frames)))
(let ((keyinfo (first mapped-keyframes)) (keyinfo-next (first (cdr mapped-keyframes))))
(loop for x from 0 below frames
collecting (progn
(cond ((>= x (car keyinfo-next)) (progn
(setq mapped-keyframes (cdr mapped-keyframes))
(setq keyinfo (first mapped-keyframes))
(setq keyinfo-next (first (cdr mapped-keyframes))))))
(cond ((not (eq keyinfo-next NIL))
(interpolated-frame (cdr keyinfo) (cdr keyinfo-next) (- (car keyinfo-next) (car keyinfo)) (- x (car keyinfo)) #'interpolate-value))))))))
(defun writerender-dev_stdout-simulation-expanded-frames(width height frame-steps)
(with-open-file (file "/dev/stdout" :direction :output :if-exists :supersede :if-does-not-exist :create :element-type '(unsigned-byte 8))
(loop for step in frame-steps
do (let ((image (make-image width height)))
(let ((pixel-result-func (gen-setcolor-image-func (* 3 width) (image-data image))))
(progn
(render-frame width height step pixel-result-func)
(write-image-core image file)))))))
(defun writerender-dev_stdout-simulation-expansions(x y keyframes frames)
(writerender-dev_stdout-simulation-expanded-frames x y (keyframe-expansions keyframes frames)))
(defun frames-ntsc(minutes)
(* 29.97 60 minutes))
(defun combined-file(width height step)
(let ((image (make-image width height)))
(let ((pixel-result-func (gen-setcolor-image-func (* 3 width) (image-data image))))
(progn
(render-frame width height step pixel-result-func)
(write-image-file image)))))
(defun combined-file-nomem(width height step)
(with-open-file (file "image0.pnm" :direction :output :if-exists :supersede :if-does-not-exist :create :element-type '(unsigned-byte 8))
(let ((pixel-result-func (gen-setcolor-directwrite-func file)))
(progn
(spit-header width height file)
(render-frame width height step pixel-result-func :compute-layout :linear-work)))))
(defun check()
(format t "mandelpnm: PASS OK~%"))
(defun work()
(keyframe-mapping +keyframes+ (frames-ntsc 26)))
| 14,003 | Common Lisp | .lisp | 254 | 50.051181 | 219 | 0.690516 | lvecsey/mandel-pnm | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 11ac173e6ffa8ec7abc2a7e22f1ccd46ceb45a53d162d36a5096286344b0d773 | 22,563 | [
-1
] |
22,564 | mandelpnm.asd | lvecsey_mandel-pnm/mandelpnm.asd | (defsystem "mandelpnm"
:description "Mandelbrot movies via streaming .pnm file output"
:version "0.94"
:author "Lester Vecsey"
:licence "GPL"
:components ((:file "mandelpnm")))
| 197 | Common Lisp | .asd | 6 | 28.5 | 67 | 0.685864 | lvecsey/mandel-pnm | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 09c7e7e1a31808c46664161c78bd6419e12de2d05ca61be02fa17d0c2f041758 | 22,564 | [
-1
] |
22,566 | mandelpnm.sh | lvecsey_mandel-pnm/mandelpnm.sh | #!/usr/bin/clisp -ansi -Kfull -E iso-8859-1
(load "mandelpnm.lisp")
(in-package "MANDELPNM")
;(defparameter +width+ 1280)
;(defparameter +height+ 1024)
(defparameter +width+ 720)
(defparameter +height+ 480)
;(defparameter +width+ 1280)
;(defparameter +height+ 720)
(defun movie-render-short ()
(writerender-dev_stdout-simulation-expansions +width+ +height+ +keyframes+ (/ (frames-ntsc 26) 1000)))
(defun movie-render-full ()
(writerender-dev_stdout-simulation-expansions +width+ +height+ +keyframes+ (frames-ntsc 26)))
(defun movie-render-end (width height keyframes)
(let ((frames (/ (frames-ntsc 26) 10)))
(writerender-dev_stdout-simulation-expanded-frames width height (nthcdr (floor (- frames 1000)) (keyframe-expansions keyframes frames)))))
;(movie-render-end 720 480 +keyframes+)
;(movie-render-short)
(movie-render-full)
| 844 | Common Lisp | .l | 19 | 42.631579 | 142 | 0.743902 | lvecsey/mandel-pnm | 2 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 0935ed0ed4eaae043d14c3eefae9b34961281bb120389e3ac586924dfffdaf66 | 22,566 | [
-1
] |
22,583 | user-example.lisp | persidastricl_persidastricl/user-example.lisp | ;; -----
;;
;; -*- mode: Lisp; -*-
;;
;; user-example.lisp
;;
;; load up the persidastricl library
(ql:quickload :persidastricl)
;; there is a :user package that has already set things up for you if you want to just explore
(in-package #:user)
;; turn on the syntactic sugar
(named-readtables:in-readtable persidastricl:syntax)
;; do something (same code from example.lisp)
(def m (with-meta {:A 0 :a 1 :b 2 :c 3 :d {:e #{1 2 3 4 5} :f [1 2 3 4 5] :g '(9 8 7 6 5)}} {:data {:start 100 :end 200}}))
(meta m)
;; some convenience hacks (not sure this is a good idea or not)
;; in maps you can use keywords as functions IF they are already part of the maps keys"
(:d m)
;; keywords that are NOT in the map already won't work
(:z m) ;; :z is undefined
;; BUT once a keyword fn has been defined then it can be used (see also below with keywords in sequence fns)
(map :z [])
;; should work after running above code
(:z m)
;; dlet is a destructuring let (hasn't been tested nearly enough (yet) and may need to be re-written at some point; impl is a bit hackish imo))
(dlet (({:keys [A a b] {:keys [f]} :d :as my-map} m)
([_ _ third] (get-in m [:d :f])))
[A a b f third])
;; metadata can be added to any clos object (with-meta, meta, vary-meta))
(defclass foo (metadata)
((data :initarg :data :accessor data)))
;; can add a hash-table or any hamt hash-map [persistent or transient] to
;; a CLOS object as metadata when the CLOS object is derived from the
;; metadata class as above
(def obj (with-meta (make-instance 'foo :data "some data") %{:c 3 :d 4})) ;; hash-table as meta
(meta obj)
;; transient data structures (CLOS, hamt, or bpvt) can have transient or persistent meta hash-maps OR a lisp hash-table
;;
;; ex. this is a transient hash map, with a native lisp hash-table as the meta object.
;; also note that the lisp hash-table contains a persistent vector and a persistent set
(def tm (with-meta @{:a 1 :b 2} %{:d [1 2 3] :e #{'a 'b 'c}}))
(:d (meta tm))
;; persistent data structures are restricted to persistent hash map meta data
;; wont work--> (def pm (with-meta {:a 1 :b 2} @{:d 4 :e 5}))
;; will work
(def pm (with-meta {:a 1 :b 2} {:d 4 :e 5}))
(def ps (with-meta #{:a :b :c} {:keywords 3}))
(meta pm)
(meta ps)
(def my-vec (map #'persistent-hash-map (repeat :a) (range 100)))
;; in sequence functions you can use keywords as functions
(map :a my-vec)
;; even if the map doesn't have that keyword as a key
(map :b my-vec)
;; more examples and docs to come (hopefully)
| 2,518 | Common Lisp | .lisp | 55 | 44.163636 | 143 | 0.681967 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 6ed4bed3dbd635d85b8ff141b9730ba32b8e7e86cc00f3c27d6a7dd6f5a93e5f | 22,583 | [
-1
] |
22,584 | example.lisp | persidastricl_persidastricl/example.lisp | ;; -----
;;
;; -*- mode: Lisp; -*-
;;
;; example.lisp
;;
;; load up the persidastricl library
(ql:quickload :persidastricl)
;;
;; now define the package where my code will go and use persidastricl there
;; NOTE: you have to shadow those things that are re-written from CL
;;
(defpackage #:example
(:use #:cl #:persidastricl)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:get
#:keyword
#:last
#:length
#:map
#:merge
#:nth
#:pop
#:reduce
#:remove
#:replace
#:rest
#:second
#:set
#:some
#:third
#:vector))
;; get into the package to write our code
(in-package #:example)
;; turn on the syntax in the example package
(named-readtables:in-readtable persidastricl:syntax)
;; now write some code (all this below is very contrived and just pointless besides for demo!!)
(def m {:A 0 :a 1 :b 2 :c 3 :d {:e #{1 2 3 4 5} :f [1 2 3 4 5] :g '(9 8 7 6 5)}})
;; BEWARE: notice that in the persidastricl world things are case-sensitive
;;
;; WARNING: you will get evaluation warnings here about unused vars ... the '_ and the 'my-map vars (for this example, nbd)
;;
(defun doit ()
(dlet (({:keys [A a b] {:keys [f]} :d :as my-map} m)
([_ _ third] (get-in m [:d :f])))
[A a b f third]))
(doit)
| 1,919 | Common Lisp | .lisp | 55 | 21.563636 | 124 | 0.438814 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | d6f0a5a09bae3887f8fffc134b62826d3664cd3d2275af7a3596a16e8fc5adc0 | 22,584 | [
-1
] |
22,585 | combinatorics.lisp | persidastricl_persidastricl/test/combinatorics.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/combinatorics.lisp
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :combinatorics-tests
:description "testing the combinatorcis library/functions"
:in master-suite)
(in-suite :combinatorics-tests)
(test t-combinations
(is (== (c:combinations (range 3) 2) '((0 1) (0 2) (1 2))))
(is (== (c:combinations [1 2 3] 2) '((1 2) (1 3) (2 3))))
(is (== (c:combinations '(:a :b :c) 2) '((:a :b) (:a :c) (:b :c)))))
(test t-simple-subsets
(is (== (c:subsets []) '(())))
(is (== (c:subsets [1 2 3]) '(() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3))))
(is (== (c:subsets [3 2 1]) '(() (3) (2) (1) (3 2) (3 1) (2 1) (3 2 1))))
(is (== (c:subsets [1 2 3 4]) '(() (1) (2) (3) (4) (1 2) (1 3) (1 4) (2 3) (2 4) (3 4) (1 2 3) (1 2 4) (1 3 4) (2 3 4) (1 2 3 4))))
(is (== (c:subsets [1 1 2]) (c:subsets [1 2 1])))
(is (== (c:subsets [1 3 2 3]) (c:subsets [1 3 3 2])))
(is (== (c:subsets [:a :b :c]) '(() (:a) (:b) (:c) (:a :b) (:a :c) (:b :c) (:a :b :c))))
(is (== (c:subsets [:c :b :a]) '(() (:c) (:b) (:a) (:c :b) (:c :a) (:b :a) (:c :b :a))))
(is (== (c:subsets [:a :b :c :d])
'(() (:a) (:b) (:c) (:d) (:a :b) (:a :c) (:a :d) (:b :c) (:b :d) (:c :d) (:a :b :c) (:a :b :d) (:a :c :d) (:b :c :d) (:a :b :c :d))))
(is (== (c:subsets [:a :a :b]) (c:subsets [:a :b :a])))
(is (== (c:subsets [:a :c :b :c]) (c:subsets [:a :c :c :b]))))
(test t-cartesian-product
(is (== (c:cartesian-product [1 2] [3 4]) '((1 3) (1 4) (2 3) (2 4))))
(is (== (c:cartesian-product [:a :b] [:c :d]) '((:a :c) (:a :d) (:b :c) (:b :d)))))
(test t-selections
(is (== (c:selections [1 2] 3) '((1 1 1) (1 1 2) (1 2 1) (1 2 2) (2 1 1) (2 1 2) (2 2 1) (2 2 2))))
(is (== (c:selections [:a :b] 3) '((:a :a :a) (:a :a :b) (:a :b :a) (:a :b :b) (:b :a :a) (:b :a :b) (:b :b :a) (:b :b :b)))))
(test t-permutations
(is (== (c:permutations [1 2 3]) '((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1))))
(is (== (c:permutations [2 3 1]) '((2 3 1) (2 1 3) (3 2 1) (3 1 2) (1 2 3) (1 3 2))))
(is (== (c:permutations [1 1 2]) (c::lex-permutations [1 1 2])))
(is (== (c:permutations [:a :b]) [[:a :b] [:b :a]]))
(is (== (c:permutations [2 1 1]) [[2 1 1] [1 2 1] [1 1 2]])))
(test t-lex-permutations
(is (== (c::lex-permutations [1 1 2]) [[1 1 2] [1 2 1] [2 1 1]])))
(test t-permuted-combinations
(is (== (c:permuted-combinations [1 2 3] 2) [[1 2] [2 1] [1 3] [3 1] [2 3] [3 2]]))
(is (== (c:permuted-combinations [1 2 2] 2) [[1 2] [2 1] [2 2]])))
(test t-sorted-numbers?
(is-true (c::sorted-numbers? [1 2 3]))
(is-true (c::sorted-numbers? [1 1 2]))
(is-true (c::sorted-numbers? []))
(is-false (c::sorted-numbers? [1 4 2]))
(is-false (c::sorted-numbers? [1 :a 2])))
(test t-factorial-numbers
(is (== (c::factorial-numbers 463) '(3 4 1 0 1 0)))
(is (== (c::factorial-numbers 0) '()))
(is (== (c::factorial-numbers 1) '(1 0)))
(is (== (c::factorial-numbers 2) '(1 0 0))))
(test t-nth-permutation-distinct
(let ((perms (c:permutations (range 4))))
(mapv
(lambda (i)
(is (== (nth perms i) (c::nth-permutation-distinct (range 4) i))))
(range 24))))
(test t-nth-permutation-duplicates
(let ((perms (c:permutations [1 1 2 2 2 3])))
(mapv
(lambda (i)
(is (== (nth perms i) (c::nth-permutation-duplicates [1 1 2 2 2 3] i))))
(range 60))))
(test t-count-permutations
(is (== (c:count-permutations (range 4)) (count (c:permutations (range 4)))))
(is (== (c:count-permutations [1 1 2]) (count (c:permutations [1 1 2]))))
(is (== (c:count-permutations [1 1 2 2]) (count (c:permutations [1 1 2 2]))))
(is (== (c:count-permutations [1 1 1 2 2 3]) (count (c:permutations [1 1 1 2 2 3])))))
(test t-nth-permutation
(let ((sortedDistinctNumbers (range 4))
(sortedDuplicateNumbers [1 1 1 2 3 3])
(distinctChars [#\a #\b #\c #\d])
(duplicates [#\a #\a #\b #\c #\c])
(duplicates2 [1 3 1 2 1 2]))
(mapv
(lambda (collection)
(let* ((perms (c:permutations collection))
(c (count perms)))
(mapv
(lambda (i)
(is (== (nth perms i) (c:nth-permutation collection i)))
(is (== c (c:count-permutations collection))))
(range c))))
[sortedDistinctNumbers
sortedDuplicateNumbers
distinctChars
duplicates
duplicates2])))
(test t-drop-permutations
(mapv
(lambda (items)
(let ((c (c:count-permutations items)))
(mapv
(lambda (i)
(is (== (c:drop-permutations items i) (drop i (c:permutations items)))))
(range c))))
[[1 2 3]
[1 1 2]
[#\a #\b #\c]
[#\a #\a #\b #\c #\c]
[1 3 1 2 1 2]]))
(test t-permutation-index
(let ((sortedDistinctNumbers (range 4))
(sortedDuplicateNumbers [1 1 1 2 3 3])
(distinctChars [#\a #\b #\c #\d])
(duplicates [#\a #\a #\b #\c #\c])
(duplicates2 [1 3 1 2 1 2]))
(mapv
(lambda (collection)
(let ((perms (c:permutations collection)))
(mapv
(lambda (perm)
(is (== (c:nth-permutation (sort (->list collection) #'c::less-than) (c:permutation-index perm)) perm)))
perms)))
[sortedDistinctNumbers
sortedDuplicateNumbers
distinctChars
duplicates
duplicates2])))
;;(5am:run! :combinatorics-tests)
| 5,732 | Common Lisp | .lisp | 137 | 37.284672 | 143 | 0.518479 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 96c98441d8cc35d45dc0c8a87267d09838e2ca51335242cfa5be74f4a516343d | 22,585 | [
-1
] |
22,586 | syntax.lisp | persidastricl_persidastricl/test/syntax.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/syntax.lisp
;;;
;;; testing syntax issues
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :syntax-tests
:description "testing bit operations"
:in master-suite)
(in-suite :syntax-tests)
(test reading-nil-test
:description "test syntax with nil elements"
(is #{nil})
(is @#{nil})
(is {:a nil})
(is @{:a nil})
(is {nil :a})
(is @{nil :a})
(is [nil])
(is @[nil])
(is %{:a nil})
(is %{nil :a}))
;; (5am:run! :syntax-tests)
(comment
(identity #{nil})
(identity @#{nil})
(identity {:a nil})
(identity @{:a nil})
(identity {nil :a})
(identity @{nil :a})
(identity [nil])
(identity @[nil])
(identity %{:a nil})
(identity %{nil :a}))
| 1,111 | Common Lisp | .lisp | 49 | 20.571429 | 65 | 0.617647 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 9cec6bd28c6cb4c033e96e9ac80e203559e6001c380aef076cef698848093e38 | 22,586 | [
-1
] |
22,587 | bits.lisp | persidastricl_persidastricl/test/bits.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/bitop.lisp
;;;
;;; common bit operations testing
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :bits-tests
:description "testing bit operations"
:in master-suite)
(in-suite :bits-tests)
(test set?-tests
:description "test the checking of set bit positions in a bitmap"
(is-true (b:set? 0 #b01))
(is-false (b:set? 0 #b10)))
(test set-tests
:description "test the setting of bit positions in a bitmap"
(is (= #b1000 (b:set 3 #b0000)))
(is (= #b0011 (b:set 1 #b0001)))
(is (= #b0001 (b:set 0 #b0001))))
(test clear-tests
:description "test the clearing of bit positions in a bitmap"
(is (= #b0000 (b:clear 3 #b1000)))
(is (= #b0001 (b:clear 1 #b0011)))
(is (= #b0010 (b:clear 0 #b0010))))
(test below-tests
:description "test the clearing of bits above a bit position (return bits below)"
(is (= #b00000000000000001111111111111111 (b:below 16 #b11111111111111111111111111111111))))
(test index-tests
:description "given a bitmap return the number of 'on' bits below the bit-position"
(is (= 0 (b:index 16 #b11111111111111110000000000000000)))
(is (= 5 (b:index 31 #b11000000110000000000000000000011))))
;; (5am:run! :bits-tests)
| 1,555 | Common Lisp | .lisp | 46 | 31.804348 | 94 | 0.679119 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | c5e25635d84e9a7c25f4a6ff9354ebb5764e91cea97edc7b494b369a1f9a6a52 | 22,587 | [
-1
] |
22,588 | hash.lisp | persidastricl_persidastricl/test/hash.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/hash.lisp
;;;
;;; testing hashing
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :hash-tests
:description "testing bit operations"
:in master-suite)
(in-suite :hash-tests)
(test :hashing-things-tests
:description "test hashing various things doesn't explode"
(is (= 3399008174 (h:hash :keywords)))
(is (= 3502813208 (h:hash "strings")))
(is (= 2896334811 (h:hash 'symbols)))
(is (= 2800891659 (h:hash 12345)))
(is (= 240748949 (h:hash '(l i s t))))
#+sbcl
(is (= 1311568101 (h:hash #(1 2)))))
;; (5am:run! :hash-tests)
| 926 | Common Lisp | .lisp | 34 | 25.470588 | 65 | 0.641084 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f482907ff0f8784be6d19efb5d3c3d4eac83238843a71b4aff520ee933b283bc | 22,588 | [
-1
] |
22,589 | immutable-class.lisp | persidastricl_persidastricl/test/immutable-class.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/immutable.lisp
;;;
;;; testing immutability in CLOS objects
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :immutable-class-tests
:description "testing using the immutable-class as a metaclass for immutable objects used in persistent data structures"
:in master-suite)
(in-suite :immutable-class-tests)
(define-immutable-class foo ()
((data :initarg :data :accessor :data)))
(test :using-setf-to-change-slot-values
:description ""
(let ((my-foo (make-instance 'foo :data 1)))
(is (= 1 (:data my-foo)))
(signals invalid-access-to-immutable-object (setf (:data my-foo) 2))
(is (= 1 (:data my-foo)))
(signals invalid-access-to-immutable-object (setf (slot-value my-foo 'data) 3))
(is (= 1 (:data my-foo)))
(with-slots (data) my-foo
(signals invalid-access-to-immutable-object (setf data 4)))
(is (= 1 (:data my-foo)))))
(defclass a-mixin ()
((other :initarg :other :accessor :other)))
(defclass baz (a-mixin) ())
(define-immutable-class bar (foo a-mixin)
((count :initarg :count :reader :count)))
(defmethod mixin-fn ((c a-mixin))
(identity (:other c)))
(test :mixins-work-as-expected
:description "using a mixin default to immutable with mixed into a mutable class; remains mutable otherwise"
(let ((my-bar (make-instance 'bar :data 1 :other 1))
(my-baz (make-instance 'baz :other 2)))
(setf (:other my-baz) 10)
(is (= 10 (mixin-fn my-baz)))
(signals invalid-access-to-immutable-object (setf (:other my-bar) 10))))
;; (5am:run! :immutable-class-tests)
| 1,918 | Common Lisp | .lisp | 52 | 34.211538 | 122 | 0.670264 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 3b8c191a6f8eb3dff23965250c3d5af7de686c46bd0c226761d7cee1292c2509 | 22,589 | [
-1
] |
22,590 | lazy-sequence.lisp | persidastricl_persidastricl/test/lazy-sequence.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/lazy-sequence.lisp
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :lazy-sequence-tests
:description "testing lazy sequences"
:in master-suite)
(in-suite :lazy-sequence-tests)
(test create-lazy-sequence-with-lseq
:description "test making a lazy sequence via the lseq macro"
(let* ((l (lseq 1 (inc 1))))
(is (= 1 (:head l)))
(is (instance? 'thunk (:tail l)))))
(test lazy-execution
:description "test that the tail of a lazy-sequence is not evaluated until needed"
(let ((a (atom 10)))
(labels ((next* (v)
(declare (ignore v))
(let ((i (deref a)))
(when (pos? i)
(lseq i (next* (swap! a #'dec)))))))
(let ((l (next* a)))
(is (= 10 (head l)))
(is (= 10 (deref a)))
(tail l)
(is (= 9 (deref a)))
(drop 2 l)
(is (= 8 (deref a)))
(drop 3 l)
(is (= 7 (deref a)))
(drop 4 l)
(is (= 6 (deref a)))
(drop 5 l)
(is (= 5 (deref a)))
(drop 6 l)
(is (= 4 (deref a)))
(drop 7 l)
(is (= 3 (deref a)))
(drop 8 l)
(is (= 2 (deref a)))
(drop 9 l)
(is (= 1 (deref a)))
(let ((v (into [] l)))
(is (== v [10 9 8 7 6 5 4 3 2 1]))
(is (= 0 (deref a))))))))
(test bounded-count-test
:description "check a bounded count on an infinite sequence"
(is (= 100 (bounded-count 100 (integers)))))
(test empty-lazy-sequence
(let ((l (lseq 1 nil)))
(is (= 1 (head l)))
(is (eq nil (head (tail l))))
(is (empty? (tail l)))))
;; (5am:run! :lazy-sequence-tests)
| 2,069 | Common Lisp | .lisp | 69 | 24.463768 | 84 | 0.530653 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 9ba9039e7545b2cea1def0c1ac97bc17e643c46d93ce62a9237009666f58fab3 | 22,590 | [
-1
] |
22,591 | data.lisp | persidastricl_persidastricl/test/data.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/data.lisp
;;;
;;; testing data:diff
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :data-tests
:description "testing data:diff with various data structures/data"
:in master-suite)
(in-suite :data-tests)
(test diff-test
(is (== [nil nil nil] (data:diff nil nil)))
(is (== [1 2 nil] (data:diff 1 2)))
(is (== [nil nil [1 2 3]] (data:diff [1 2 3] '(1 2 3))))
(is (== [1 [:a :b] nil] (data:diff 1 [:a :b])))
(is (== [{:a 1} :b nil] (data:diff {:a 1} :b)))
(is (== [:team #{:p1 :p2} nil] (data:diff :team #{:p1 :p2})))
(is (== [{0 :a} [:a] nil] (data:diff {0 :a} [:a])))
(is (== [nil [nil 2] [1]] (data:diff [1] [1 2])))
(is (== [nil nil [1 2]] (data:diff [1 2] (into #() [1 2]))))
(is (== [#{:a} #{:b} #{:c :d}] (data:diff #{:a :c :d} #{:b :c :d})))
(is (== [nil nil {:a 1}] (data:diff {:a 1} {:a 1})))
(is (== [{:a #{2}} {:a #{4}} {:a #{3}}] (data:diff {:a #{2 3}} {:a #{3 4}})))
(is (== [#{1} #{3} #{2}] (data:diff (set [1 2]) (set [2 3]))))
(is (== [nil nil [1 2]] (data:diff (into #() [1 2]) [1 2])))
(is (== [{:a {:c [1]}} {:a {:c [0]}} {:a {:c [nil 2] :b 1}}] (data:diff {:a {:b 1 :c [1 2]}} {:a {:b 1 :c [0 2]}})))
(is (== [{:a nil} {:a 'false} {:b nil :c 'false}] (data:diff {:a nil :b nil :c 'false} {:a 'false :b nil :c 'false}))))
;; (5am:run! :data-tests)
| 1,752 | Common Lisp | .lisp | 43 | 38.744186 | 122 | 0.5 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 92dbc608dcf473bc0e4bfdaa7d0ce23e4946c342b5f443e266b4be3a5b3ec9b7 | 22,591 | [
-1
] |
22,592 | vector.lisp | persidastricl_persidastricl/test/vector.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/vector.lisp
;;;
;;; testing adding/updating/removing items from a 'persistent' vector
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :vector-tests
:description "testing immutable vector operations"
:in master-suite)
(in-suite :vector-tests)
(test insert-prepend-test
:description "test prepending an item onto a vector (returns a new vector; original unchanged)"
(let* ((original #(0 1 2 3))
(new (v:insert original 0 :a :b :c)))
(is (equalp original #(0 1 2 3)))
(is (equalp new #(:a :b :c 0 1 2 3)))))
(test insert-within-test
:description "test inserting an item within a vector (returns a new vector; original unchanged)"
(let* ((original #(0 1 2 3))
(new (v:insert original 2 :a :b :c)))
(is (equalp original #(0 1 2 3)))
(is (equalp new #(0 1 :a :b :c 2 3)))))
(test insert-append-test
:description "test appending an item onto vector (returns a new vector; original unchanged)"
(let* ((original #(0 1 2 3))
(new (v:insert original 4 :a :b :c)))
(is (equalp original #(0 1 2 3)))
(is (equalp new #(0 1 2 3 :a :b :c)))))
(test insert-out-of-bounds-test
:description "test inserting an item with invalid position (out-of-bounds) (signals error)"
(signals error (v:insert #(0 1 2 3) 5 :a :b :c)))
(test update-test
:description "test updating various positions (original unchanged)"
(let* ((original #(0 1 2 3 4)))
(is (equalp #(:a :b :c 3 4) (v:update original 0 :a :b :c)))
(is (equalp #(0 1 2 3 :a :b :c) (v:update original 4 :a :b :c)))
(is (equalp #(0 1 :a :b :c) (v:update original 2 :a :b :c)))
(signals error (v:update original 5 :a :b :c))
(is (equalp #(0 1 2 3 4) original))))
(test delete-test
:description "test deleting various positions (original unchanged)"
(let* ((original #(0 1 2 3 4)))
(is (equalp #(1 2 3 4) (v:delete original 0)))
(is (equalp #(0 1 2 3) (v:delete original 4)))
(is (equalp #(0 1 3 4) (v:delete original 2)))
(is (equalp #(0 1 4) (v:delete original 2 2)))
(signals error (v:delete original 5))
(is (equalp #(0 1 2 3 4) original))))
;; (5am:run! :vector-tests)
| 2,517 | Common Lisp | .lisp | 63 | 36.793651 | 98 | 0.631299 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 31c81194f32f878374b472797c092ca8aef4043ad1177695e00d97c331d1bdae | 22,592 | [
-1
] |
22,593 | walk.lisp | persidastricl_persidastricl/test/walk.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/walk.lisp
;;;
;;; testing walk functions
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :walk-tests
:description "testing walk package functions"
:in master-suite)
(in-suite :walk-tests)
(test prewalk-replace-test
(is (== (walk:prewalk-replace {:a :b} [:a {:a :a} '(3 :c :a)])
[:b {:b :b} '(3 :c :b)])))
(test postwalk-replace-test
(is (== (walk:postwalk-replace {:a :b} [:a {:a :a} '(3 :c :a)])
[:b {:b :b} '(3 :c :b)])))
(test stringify-keys-test
(is (== (walk:stringify-keys {:a 1 nil {:b 2 :c 3} :d 4})
{"a" 1 nil {"b" 2 "c" 3} "d" 4})))
(test keywordize-keys-test
(is (== (walk:keywordize-keys {"a" 1 nil {"b" 2 "c" 3} "d" 4})
{:a 1 nil {:b 2 :c 3} :d 4})))
(test prewalk-order-test
(let ((a (atom [])))
(walk:prewalk (lambda (form) (swap! a #'conj form) form)
[1 2 {:a 3} (list 4 [5])])
(is (== (deref a)
[[1 2 {:a 3} (list 4 [5])]
1 2 {:a 3} (p::map-entry :a 3) :a 3
(list 4 [5]) 4 [5] 5]))))
(test postwalk-order-test
(is (== (let ((a (atom [])))
(walk:postwalk (lambda (form) (swap! a #'conj form) form)
[1 2 {:a 3} (list 4 [5])])
(deref a))
[1 2
:a 3 (p::map-entry :a 3) {:a 3}
4 5 [5] (list 4 [5])
[1 2 {:a 3} (list 4 [5])]])))
(test walk-mapentry-test
(labels ((map-entry? (x) (instance? 'p::entry x))
(f (e)
(if (and (vector? e) (not (map-entry? e))) (->list e) e)))
(let ( (coll [:html {:a ["b" 1]} ""]))
(is (== (list :html {:a (list "b" 1)} "") (walk:postwalk #'f coll))))))
(test walk-maps
(named-readtables:in-readtable persidastricl:syntax)
(is (== {":a" "1"}
(walk:walk (lambda (e)
(apply #'p::map-entry (->list (map #'str e))))
(lambda (form)
form)
{:a 1}))))
;; (5am:run! :walk-tests)
| 2,422 | Common Lisp | .lisp | 69 | 28.623188 | 77 | 0.49059 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 53452023f526a5bef3431fc69ca7ed408f701d6f3cb8c856bab88f63b6b10716 | 22,593 | [
-1
] |
22,594 | entry.lisp | persidastricl_persidastricl/test/entry.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/entry.lisp
;;;
;;; testing making/using map entries (vector tuples)
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :entry-tests
:description "testing map entries"
:in master-suite)
(in-suite :entry-tests)
(defun proper-entry-p (entry k v)
(is (equalp k (key entry)))
(is (equalp v (value entry))))
(test entry-creation-tests
:description "test the making of a map entry 'tuple'"
(is (proper-entry-p (map-entry :k :v) :k :v))
(is (proper-entry-p (map-entry "k" "v") "k" "v"))
(is (proper-entry-p (map-entry 'k 'v) 'k 'v))
(is (proper-entry-p (map-entry 1 2) 1 2)))
(test key-tests
:description "test pulling they key out of map entries"
(is (eq :k (key (map-entry :k :v)))))
(test value-tests
:description "test pulling the value out of map entries"
(is (eq :v (value (map-entry :k :v)))))
;; (5am:run! :entry-tests)
| 1,245 | Common Lisp | .lisp | 40 | 29.25 | 65 | 0.640468 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | c123997821b9a284db2161dd8e85d9c111633184ff97a85902c618bff48481e5 | 22,594 | [
-1
] |
22,595 | atom.lisp | persidastricl_persidastricl/test/atom.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/atom.lisp
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :atom-tests
:description "testing atom operations"
:in master-suite)
(in-suite :atom-tests)
(test reset-test
:description "test resetting an atom"
(let ((a (atom {:a 1})))
(is (= 1 (get (deref a) :a)))
(reset! a {:a 2})
(is (= 2 (get (deref a) :a)))))
(test swap-test
:description "test swapping an atom's value"
(let* ((a (atom {:a 1}))
(prev (deref a)))
(is (= 1 (get (deref a) :a)))
(swap! a (fn (a) (update a :a #'inc)))
(is (= 2 (get (deref a) :a)))
(is (== prev {:a 1}))))
;; (5am:run! :atom-tests)
| 1,052 | Common Lisp | .lisp | 38 | 25.184211 | 65 | 0.595427 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 4c118f85188632e1fd675050d6619ee198d87440ccc5594b5291611dd3bb1c88 | 22,595 | [
-1
] |
22,596 | node.lisp | persidastricl_persidastricl/test/node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/node.lisp
;;;
;;; testing various nodes
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :node-tests
:description ""
:in master-suite)
(in-suite :node-tests)
(test simple-node-tests
:description ""
(is (= 1 1)))
;; (5am:run! :node-tests)
| 631 | Common Lisp | .lisp | 28 | 21.035714 | 65 | 0.634841 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | fec4db087335bcc7810e8ff5a9a868bbd849a017cf5ef63329d12dfa083bc0f9 | 22,596 | [
-1
] |
22,597 | master.lisp | persidastricl_persidastricl/test/master.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/persidastricl.lisp
;;;
;;; master test suite
;;;
;;; -----
(in-package #:persidastricl)
(5am:def-suite master-suite)
(5am:in-suite master-suite)
(shadowing-import '(5am:def-suite
5am:in-suite
5am:test
5am:is-true
5am:is-false
5am:is
5am:signals))
| 748 | Common Lisp | .lisp | 29 | 20.413793 | 65 | 0.558989 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 386a95a11e124357c008e35e6a8d2513edbc012bfbacca724e623772c363e28f | 22,597 | [
-1
] |
22,598 | equality.lisp | persidastricl_persidastricl/test/equality.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/equality.lisp
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :equality-tests
:description "testing scalar/object equality with `==`"
:in master-suite)
(in-suite :equality-tests)
(test :scalars
:description "test equality of atomic/scalar values"
(is (== 1 1))
(is (not (== 1 2)))
(is (== #\a #\a))
(is (not (== #\a #\b)))
(is (== 1.0 1.000))
(is (not (== 1.00 1.00001)))
(is (== :a :a))
(is (not (== :a :b)))
(is (== 'a 'a))
(is (not (== 'a 'b)))
(is (== #'identity #'identity))
(is (not (== #'identity #'expt))))
(test :strings
:description "test equality of string values"
(is (equalp "test" "Test")) ;; by default lisp is case insensitive!
(is (== "test" "test"))
(is (not (== "test" "Test"))))
(test :maps-and-tables
:description "test equality of various types of maps and tables"
(is (== {:a 1 :b 2 :c {:d 4}} {:a 1 :b 2 :c {:d 4}}))
(is (== @{:a 1 :b 2 :c {:d 4}} @{:a 1 :b 2 :c {:d 4}}))
(is (== %{:a 1 :b 2 :c {:d 4}} %{:a 1 :b 2 :c {:d 4}}))
(is (== {:a 1 :b 2 :c {:d 4}} @{:a 1 :b 2 :c {:d 4}}))
(is (== {:a 1 :b 2 :c {:d 4}} %{:a 1 :b 2 :c {:d 4}}))
(is (== @{:a 1 :b 2 :c {:d 4}} %{:a 1 :b 2 :c {:d 4}}))
(is (not (== {:a 1 :b 2 :c {:d 4}} {:a 1 :b 2 :c {:d 3}})))
(is (not (== @{:a 1 :b 2 :c {:d 4}} @{:a 1 :b 2 :c {:d 3}})))
(is (not (== %{:a 1 :b 2 :c {:d 4}} %{:a 1 :b 2 :c {:d 3}})))
(is (not (== {:a 1 :b 2 :c {:d 4}} @{:a 1 :b 2 :c {:d 3}})))
(is (not (== {:a 1 :b 2 :c {:d 4}} %{:a 1 :b 2 :c {:d 3}})))
(is (not (== @{:a 1 :b 2 :c {:d 4}} %{:a 1 :b 2 :c {:d 3}}))))
(test :sequences-vectors-and-subvecs
:description "test equality of various sequences, vectors, and subvecs"
(is (== [1 2 3] [1 2 3]))
(is (== [1 2 3] @[1 2 3]))
(is (== [1 2 3] '(1 2 3)))
(is (== [1 2 3] #(1 2 3)))
(is (== @[1 2 3] '(1 2 3)))
(is (== @[1 2 3] #(1 2 3)))
(is (== (subvec [0 1 2 3 4] 1 4) [1 2 3]))
(is (== (subvec [0 1 2 3 4] 1 4) @[1 2 3]))
(is (== (subvec [0 1 2 3 4] 1 4) '(1 2 3)))
(is (== (subvec [0 1 2 3 4] 1 4) #(1 2 3)))
(is (== '(1 2 3) #(1 2 3)))
(is (== #(1 2 3) '(1 2 3)))
(is (== @[1 2 3] [1 2 3]))
(is (== '(1 2 3) [1 2 3]))
(is (== #(1 2 3) [1 2 3]))
(is (== '(1 2 3) @[1 2 3]))
(is (== #(1 2 3) @[1 2 3]))
(is (== [1 2 3] (subvec [0 1 2 3 4] 1 4)))
(is (== @[1 2 3] (subvec [0 1 2 3 4] 1 4)))
(is (== '(1 2 3) (subvec [0 1 2 3 4] 1 4)))
(is (== #(1 2 3) (subvec [0 1 2 3 4] 1 4))))
(test :equality-of-seqs
:description "test equality of seqs of various sources"
(is (== (range 9) '(0 1 2 3 4 5 6 7 8)))
(is (== '(0 1 2 3 4 5 6 7 8) (range 9)))
(is (== (range 9) [0 1 2 3 4 5 6 7 8]))
(is (== [0 1 2 3 4 5 6 7 8] (range 9)))
(is (not (== (range 9) '(0 2 3 4 5 6 7 8))))
(is (not (== '(0 2 3 4 5 6 7 8) (range 9)))))
(test :equality-with-empty-vectors-arrays-and-lists
:description "test equality of empty/nil data structurs with vectors and nil"
(is (== #() []))
(is (== [] #()))
(is (not (== [] '())))
(is (not (== [] nil)))
(is (not (== #() '())))
(is (not (== #() nil)))
(is (not (== '() [])))
(is (not (== nil [])))
(is (not (== '() #())))
(is (not (== nil #()))))
;; (5am:run! :sequences-vectors-and-subvecs)
| 3,651 | Common Lisp | .lisp | 100 | 33.95 | 79 | 0.465668 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 4817fa55be0540c066bc7f162e759520b9ebf961c27f0ba63a529c9ea7978f6b | 22,598 | [
-1
] |
22,599 | set.lisp | persidastricl_persidastricl/test/set.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/set.lisp
;;;
;;; testing set functions
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :set-tests
:description "testing set package operations"
:in master-suite)
(in-suite :set-tests)
(test union-test
(is (== (set:union) #{}))
(is (== (set:union #{}) #{}))
(is (== (set:union #{1}) #{1}))
(is (== (set:union #{1 2 3}) #{1 2 3}))
(is (== (set:union #{} #{}) #{}))
(is (== (set:union #{} #{1}) #{1}))
(is (== (set:union #{} #{1 2 3}) #{1 2 3}))
(is (== (set:union #{1} #{}) #{1}))
(is (== (set:union #{1 2 3} #{}) #{1 2 3}))
(is (== (set:union #{1} #{2}) #{1 2}))
(is (== (set:union #{1} #{1 2}) #{1 2}))
(is (== (set:union #{2} #{1 2}) #{1 2}))
(is (== (set:union #{1 2} #{3}) #{1 2 3}))
(is (== (set:union #{1 2} #{2 3}) #{1 2 3}))
(is (== (set:union #{} #{} #{}) #{}))
(is (== (set:union #{1} #{} #{}) #{1}))
(is (== (set:union #{} #{1} #{}) #{1}))
(is (== (set:union #{} #{} #{1}) #{1}))
(is (== (set:union #{1 2} #{2 3} #{}) #{1 2 3}))
(is (== (set:union #{1 2} #{3 4} #{5 6}) #{1 2 3 4 5 6}))
(is (== (set:union #{1 2} #{2 3} #{1 3 4}) #{1 2 3 4}))
(is (== (set:union #{1 2}
#{:a :b}
#{nil}
#{nil t}
#{'false 'true}
#{#\c "abc"}
#{[] [1 2]}
#{{} {:a 1}}
#{#{} #{1 2}})
#{1 2 :a :b nil t 'false 'true #\c "abc" [] [1 2] {} {:a 1} #{} #{1 2}})))
(test intersection-test
(signals simple-error (set:intersection))
(is (== (set:intersection #{}) #{}))
(is (== (set:intersection #{1}) #{1}))
(is (== (set:intersection #{1 2 3}) #{1 2 3}))
(is (== (set:intersection #{} #{}) #{}))
(is (== (set:intersection #{} #{1}) #{}))
(is (== (set:intersection #{} #{1 2 3}) #{}))
(is (== (set:intersection #{1} #{}) #{}))
(is (== (set:intersection #{1 2 3} #{}) #{}))
(is (== (set:intersection #{1 2} #{1 2}) #{1 2}))
(is (== (set:intersection #{1 2} #{3 4}) #{}))
(is (== (set:intersection #{1 2} #{1}) #{1}))
(is (== (set:intersection #{1 2} #{2}) #{2}))
(is (== (set:intersection #{1 2 4} #{2 3 4 5}) #{2 4}))
(is (== (set:intersection #{} #{} #{}) #{}))
(is (== (set:intersection #{1} #{} #{}) #{}))
(is (== (set:intersection #{1} #{1} #{}) #{}))
(is (== (set:intersection #{1} #{} #{1}) #{}))
(is (== (set:intersection #{1 2} #{2 3} #{}) #{}))
(is (== (set:intersection #{1 2} #{2 3} #{5 2}) #{2}))
(is (== (set:intersection #{1 2 3} #{1 3 4} #{1 3}) #{1 3}))
(is (== (set:intersection #{1 2 3} #{3 4 5} #{8 2 3}) #{3})))
(test difference-test
(is (== (set:difference #{}) #{}))
(is (== (set:difference #{1}) #{1}))
(is (== (set:difference #{1 2 3}) #{1 2 3}))
(is (== (set:difference #{1 2} #{1 2}) #{}))
(is (== (set:difference #{1 2} #{3 4}) #{1 2}))
(is (== (set:difference #{1 2} #{1}) #{2}))
(is (== (set:difference #{1 2} #{2}) #{1}))
(is (== (set:difference #{1 2 4} #{2 3 4 5}) #{1}))
(is (== (set:difference #{1 2} #{2 3} #{5 2}) #{1}))
(is (== (set:difference #{1 2 3} #{1 3 4} #{1 3}) #{2}))
(is (== (set:difference #{1 2 3} #{3 4 5} #{8 2 3}) #{1})))
(test select-test
(is (== (set:select #'int? #{}) #{}))
(is (== (set:select #'int? #{1 2}) #{1 2}))
(is (== (set:select #'int? #{1 2 :a :b :c}) #{1 2}))
(is (== (set:select #'int? #{:a :b :c}) #{})))
(def compositions #{{:name "Canon in D" :composer "J. S. Bach"}
{:name "Jesu, joy of man's desiring" :composer "J. S. Bach"}
{:name "Jerusalem" :composer "Giuseppe Verdi"}
{:name "Requiem in D minor" :composer "W. A. Mozart"}})
(test project-test
(is (== (set:project compositions [:name]) #{{:name "Canon in D"}
{:name "Jesu, joy of man's desiring"}
{:name "Jerusalem"}
{:name "Requiem in D minor"}}))
(is (== (set:project compositions [:composer]) #{{:composer "W. A. Mozart"}
{:composer "Giuseppe Verdi"}
{:composer "J. S. Bach"}}))
(is (== (set:project compositions [:year]) #{{}}))
(is (== (set:project #{{}} [:name]) #{{}})))
(test rename-test
(is (== (set:rename compositions {:name :title}) #{{:title "Canon in D" :composer "J. S. Bach"}
{:title "Jesu, joy of man's desiring" :composer "J. S. Bach"}
{:title "Jerusalem" :composer "Giuseppe Verdi"}
{:title "Requiem in D minor" :composer "W. A. Mozart"}}))
(is (== (set:rename compositions {:year :decade}) #{{:composer "J. S. Bach" :name "Jesu, joy of man's desiring"}
{:composer "J. S. Bach" :name "Canon in D"}
{:composer "W. A. Mozart" :name "Requiem in D minor"}
{:composer "Giuseppe Verdi" :name "Jerusalem"}}))
(is (== (set:rename #{{}} {:year :decade}) #{{}})))
(test rename-keys-test
(is (== (set:rename-keys {:a "one" :b "two"} {:a :z}) {:z "one" :b "two"}))
(is (== (set:rename-keys {:a "one" :b "two"} {:a :z :c :y}) {:z "one" :b "two"}))
(is (== (set:rename-keys {:a "one" :b "two" :c "three"} {:a :b :b :a}) {:a "two" :b "one" :c "three"})))
(test index-test
(is (== (set:index #{{:c 2} {:b 1} {:a 1 :b 2}} [:b]) {{:b 2} #{{:a 1 :b 2}}, {:b 1} #{{:b 1}} {} #{{:c 2}}})))
(test join-test
(is (== (set:join compositions compositions) compositions))
(is (== (set:join compositions #{{:name "Canon in D" :genre "Classical"}})
#{{:name "Canon in D" :composer "J. S. Bach" :genre "Classical"}})))
(test map-invert-test
(is (== (set:map-invert {:a "one" :b "two"}) {"one" :a "two" :b})))
(test subset?-test
(is (set:subset? #{} #{}))
(is (set:subset? #{} #{1}))
(is (set:subset? #{1} #{1}))
(is (set:subset? #{1 2} #{1 2}))
(is (set:subset? #{1 2} #{1 2 42}))
(is (set:subset? #{'false} #{'false}))
(is (set:subset? #{nil} #{nil}))
(is (set:subset? #{nil} #{nil 'false}))
(is (set:subset? #{1 2 nil} #{1 2 nil 4}))
(is (not (set:subset? #{1} #{})))
(is (not (set:subset? #{2} #{1})))
(is (not (set:subset? #{1 3} #{1})))
(is (not (set:subset? #{nil} #{'false})))
(is (not (set:subset? #{'false} #{nil})))
(is (not (set:subset? #{'false nil} #{nil})))
(is (not (set:subset? #{1 2 nil} #{1 2}))))
(test superset?-test
(is (set:superset? #{} #{}))
(is (set:superset? #{1} #{}))
(is (set:superset? #{1} #{1}))
(is (set:superset? #{1 2} #{1 2}))
(is (set:superset? #{1 2 42} #{1 2}))
(is (set:superset? #{'false} #{'false}))
(is (set:superset? #{nil} #{nil}))
(is (set:superset? #{'false nil} #{'false}))
(is (set:superset? #{1 2 4 nil 'false} #{1 2 nil}))
(is (not (set:superset? #{} #{1})))
(is (not (set:superset? #{2} #{1})))
(is (not (set:superset? #{1} #{1 3})))
(is (not (set:superset? #{nil} #{'false})))
(is (not (set:superset? #{'false} #{nil})))
(is (not (set:superset? #{nil} #{'false nil})))
(is (not (set:superset? #{nil 2 3} #{'false nil 2 3}))))
;; (5am:run! :set-tests)
| 7,780 | Common Lisp | .lisp | 168 | 39.089286 | 114 | 0.446069 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | c4ce3cc9e7e5eb2ce15393e6c2360807efe8797f679e582ce5f57b7538b81283 | 22,599 | [
-1
] |
22,600 | hash-map.lisp | persidastricl_persidastricl/test/hash-map.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/hash-map.lisp
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :hash-map-tests
:description "testing hash map operations"
:in master-suite)
(in-suite :hash-map-tests)
(named-readtables:in-readtable persidastricl:syntax)
(test simple-persistent-hash-map-creation-test
(let ((m {:k1 :v1 :k2 :v2 :k3 :v3 :k4 :v4}))
(is (typep m 'persistent-hash-map))
(is (= 4 (count m)))
(is (== :v1 (lookup m :k1)))
(is (== :v2 (lookup m :k2)))
(is (== :v3 (lookup m :k3)))
(is (== :v4 (lookup m :k4)))))
(test simple-transient-hash-map-creation-test
(let ((m @{:k1 :v1 :k2 :v2 :k3 :v3 :k4 :v4}))
(is (typep m 'transient-hash-map))
(is (= 4 (count m)))
(is (== :v1 (lookup m :k1)))
(is (== :v2 (lookup m :k2)))
(is (== :v3 (lookup m :k3)))
(is (== :v4 (lookup m :k4)))))
(test hash-map-assoc-test
(let ((m1 {})
(m2 @{}))
(is (== {:a 1 :b 2} (assoc m1 :a 1 :b 2)))
(is (== @{:a 1 :b 2} (assoc m2 :a 1 :b 2)))))
(test hash-map-dissoc-test
(let ((m1 {:a 1 :b 2})
(m2 @{:a 1 :b 2}))
(is (== {:b 2} (dissoc m1 :a)))
(is (== @{:b 2} (dissoc m2 :a)))))
(test hash-map-as-plist
(is (== '(:a 1 :b 2) (into '() (->plist {:a 1 :b 2})))))
(test hash-map-as-alist
(let ((a-list (->alist {:a 1 :b 2})))
(is (every? #'consp a-list))
(is (== (set '((:a . 1) (:b . 2))) (set a-list)))))
(test hash-map-as-list
(is (== (list (map-entry :a 1) (map-entry :b 2))
(->list {:a 1 :b 2}))))
(test using-into-with-hash-maps-and-tables
(is (true?
(reduce
(fn (m1 m2)
(when (== m1 m2) m1))
[(into %{} '((:a . 1) (:b . 2) (:c . 3)))
(into %{} '((:a 1) (:b 2) (:c 3)))
(into %{} {:a 1 :b 2 :c 3})
(into %{} @{:a 1 :b 2 :c 3})
(into %{} %{:a 1 :b 2 :c 3})
(into %{} [[:a 1] [:b 2] [:c 3]])
(into %{} [(p::map-entry :a 1) (p::map-entry :b 2) (p::map-entry :c 3)])
(into %{} #{'(:a 1) '(:b 2) '(:c 3)})
(into %{} #{'(:a . 1) '(:b . 2) '(:c . 3)})])))
(is (true?
(reduce
(fn (m1 m2)
(when (== m1 m2) m1))
[(into @{} '((:a . 1) (:b . 2) (:c . 3)))
(into @{} '((:a 1) (:b 2) (:c 3)))
(into @{} {:a 1 :b 2 :c 3})
(into @{} @{:a 1 :b 2 :c 3})
(into @{} %{:a 1 :b 2 :c 3})
(into @{} [[:a 1] [:b 2] [:c 3]])
(into @{} [(p::map-entry :a 1) (p::map-entry :b 2) (p::map-entry :c 3)])
(into @{} #{'(:a 1) '(:b 2) '(:c 3)})
(into @{} #{'(:a . 1) '(:b . 2) '(:c . 3)})])))
(is (true?
(reduce
(fn (m1 m2)
(when (== m1 m2) m1))
[(into {} '((:a . 1) (:b . 2) (:c . 3)))
(into {} '((:a 1) (:b 2) (:c 3)))
(into {} {:a 1 :b 2 :c 3})
(into {} @{:a 1 :b 2 :c 3})
(into {} %{:a 1 :b 2 :c 3})
(into {} [[:a 1] [:b 2] [:c 3]])
(into {} [(p::map-entry :a 1) (p::map-entry :b 2) (p::map-entry :c 3)])
(into {} #{'(:a 1) '(:b 2) '(:c 3)})
(into {} #{'(:a . 1) '(:b . 2) '(:c . 3)})]))))
;;(5am:run! :hash-map-tests)
| 3,520 | Common Lisp | .lisp | 99 | 29.616162 | 82 | 0.424082 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 7da05e916bed44bdd6dbdef8c976d85d3ad281a7cd394844d61bc0f833512e83 | 22,600 | [
-1
] |
22,601 | string.lisp | persidastricl_persidastricl/test/string.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/string.lisp
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :string-tests
:description "testing string package operations"
:in master-suite)
(in-suite :string-tests)
(test split-test
:description "test splitting strings"
(is (== '("a" "b") (s:split "a-b" "-")))
(is (== '("a" "b-c") (s:split "a-b-c" "-" 2)))
(is (== '("abc") (s:split "abc" "-"))))
(test reverse-test
:description "test reversing a string"
(is (== "stressed" (s:reverse "desserts"))))
(test replace-test
:description "test string replacement"
(is (== "faabar" (s:replace "foobar" #\o #\a)))
(is (== "foobar" (s:replace "foobar" #\z #\a)))
(is (== "barbarbar" (s:replace "foobarfoo" "foo" "bar")))
(is (== "foobarfoo" (s:replace "foobarfoo" "baz" "bar")))
(is (== "f$$d" (s:replace "food" "o" "$")))
(is (== "f\\\\d" (s:replace "food" "o" "\\")))
(is (== "f\\$\\$d" (s:replace "food" "o" (s:re-quote-replacement "$"))))
(is (== "f\\\\d" (s:replace "food" "o" (s:re-quote-replacement "\\"))))
(is (== "FOObarFOO" (s:replace "foobarfoo" "foo" #'s:upper-case)))
(is (== "foobarfoo" (s:replace "foobarfoo" "baz" #'s:upper-case)))
(is (== "OObarOO" (s:replace "foobarfoo" "f(o+)" (lambda (mv) (s:upper-case (second mv))))))
(is (== "baz\\bang\\" (s:replace "bazslashbangslash" "slash" (constantly "\\")))))
(test replace-first-test
:description "test string replacement (only first match)"
(is (== "faobar" (s:replace-first "foobar" #\o #\a)))
(is (== "foobar" (s:replace-first "foobar" #\z #\a)))
(is (== "z.ology" (s:replace-first "zoology" #\o #\.)))
(is (== "barbarfoo" (s:replace-first "foobarfoo" "foo" "bar")))
(is (== "foobarfoo" (s:replace-first "foobarfoo" "baz" "bar")))
(is (== "f$od" (s:replace-first "food" "o" "$")))
(is (== "f\\od" (s:replace-first "food" "o" "\\")))
(is (== "f\\$od" (s:replace-first "food" "o" (s:re-quote-replacement "$"))))
(is (== "f\\od" (s:replace-first "food" "o" (s:re-quote-replacement "\\"))))
(is (== "FOObarfoo" (s:replace-first "foobarfoo" "foo" #'s:upper-case)))
(is (== "foobarfoo" (s:replace-first "foobarfoo" "baz" #'s:upper-case)))
(is (== "OObarfoo" (s:replace-first "foobarfoo" "f(o+)" (lambda (mv) (s:upper-case (second mv))))))
(is (== "baz\\bangslash" (s:replace-first "bazslashbangslash" "slash" (constantly "\\")))))
(test join-test-with-no-separator
:description "testing string joins with sequences of things"
(is (== "" (s:join nil)))
(is (== "" (s:join [])))
(is (== "1" (s:join [1])))
(is (== "12" (s:join [1 2]))))
(test join-test-with-separator
(is (== "1,2,3" (s:join #\, [1 2 3])))
(is (== "" (s:join #\, [])))
(is (== "1" (s:join #\, [1])))
(is (== "" (s:join #\, nil)))
(is (== "1 and-a 2 and-a 3" (s:join " and-a " [1 2 3]))))
(test trim-newline-test
:description "testing trim-newline"
(is (== "foo" (s:trim-newline (format nil "foo~c" #\newline))))
(is (== "foo" (s:trim-newline (format nil "foo~c~c" #\return #\newline))))
(is (== "foo" (s:trim-newline "foo")))
(is (== "" (s:trim-newline ""))))
(test capitalize-test
(is (== "Foobar" (s:capitalize "foobar")))
(is (== "Foobar" (s:capitalize "FOOBAR"))))
(test triml-test
(is (== "foo " (s:triml " foo ")))
(is (== "" (s:triml " ")))
#+sbcl
(is (== "bar" (s:triml (format nil "~c ~cbar" #\U+2002 #\tab)))))
(test trimr-test
(is (== " foo" (s:trimr " foo ")))
(is (== "" (s:trimr " ")))
#+sbcl
(is (== "bar" (s:trimr (format nil "bar~c ~c" #\tab #\U+2002)))))
(test trim-test
(is (== "foo" (s:trim (format nil " foo ~c~c" #\return #\newline))))
(is (== "" (s:trim " ")))
#+sbcl
(is (== "bar" (s:trim (format nil "~cbar~c ~c" #\U+2000 #\tab #\U+2002)))))
(test upper-case-test
(is (== "FOOBAR" (s:upper-case "Foobar"))))
(test lower-case-test
(is (== "foobar" (s:lower-case "FooBar"))))
(test nil-handling-test
:description "test how functions handle nil"
(signals simple-error (s:condense nil))
(signals simple-error (s:ends-with? nil "foo"))
(signals simple-error (s:includes? nil "foo"))
(signals simple-error (s:index-of nil "foo"))
(signals simple-error (s:last-index-of nil "foo"))
(signals simple-error (s:reverse nil))
(signals simple-error (s:replace nil "foo" "bar"))
(signals simple-error (s:replace-first nil "foo" "bar"))
(signals simple-error (s:re-quote-replacement nil))
(signals simple-error (s:capitalize nil))
(signals simple-error (s:upper-case nil))
(signals simple-error (s:lower-case nil))
(signals simple-error (s:split nil "-"))
(signals simple-error (s:split nil "-" 1))
(signals simple-error (s:starts-with? nil "foo"))
(signals simple-error (s:trim nil))
(signals simple-error (s:triml nil))
(signals simple-error (s:trimr nil))
(signals simple-error (s:trim-newline nil)))
(test escape-test
(is (== "<foo&bar>"
(s:escape "<foo&bar>" {#\& "&" #\< "<" #\> ">"})))
(is (== " \\\"foo\\\" "
(s:escape " \"foo\" " {#\" "\\\""})))
(is (== "faabor"
(s:escape "foobar" {#\a #\o, #\o #\a}))))
(test blank-test
(is (s:blank? nil))
(is (s:blank? ""))
(is (s:blank? " "))
(is (s:blank? (format nil " ~c ~c ~c " #\NEWLINE #\TAB #\RETURN)))
(is (not (s:blank? " foo "))))
(test split-lines-test
(let ((result (s:split-lines (format nil "one~%two~c~cthree" #\return #\newline))))
(is (== '("one" "two" "three") result)))
(is (== '("foo") (s:split-lines "foo"))))
(test index-of-test
(let ((s "tacos"))
(is (== 2 (s:index-of s "c")))
(is (== 2 (s:index-of s #\c)))
(is (== 1 (s:index-of s "ac")))
(is (== 3 (s:index-of s "o" 2)))
(is (== 3 (s:index-of s #\o 2)))
(is (== 3 (s:index-of s "o" -100)))
(is (== nil (s:index-of s "z")))
(is (== nil (s:index-of s #\z)))
(is (== nil (s:index-of s "z" 2)))
(is (== nil (s:index-of s #\z 2)))
(is (== nil (s:index-of s "z" 100)))
(is (== nil (s:index-of s "z" -10)))))
(test last-index-of-test
(let ((s "banana"))
(is (== 4 (s:last-index-of s "n")))
(is (== 4 (s:last-index-of s #\n)))
(is (== 3 (s:last-index-of s "an")))
(is (== 4 (s:last-index-of s "n" )))
(is (== 4 (s:last-index-of s "n" 5)))
(is (== 4 (s:last-index-of s #\n 5)))
(is (== 4 (s:last-index-of s "n" 500)))
(is (== nil (s:last-index-of s "z")))
(is (== nil (s:last-index-of s "z" 1)))
(is (== nil (s:last-index-of s #\z 1)))
(is (== nil (s:last-index-of s "z" 100)))
(is (== nil (s:last-index-of s "z" -10)))))
(test starts-with?-test
(is (s:starts-with? "common lisp rocks" "common"))
(is (not (s:starts-with? "persidastricl" "common"))))
(test ends-with?-test
(is (s:ends-with? "Common Lisp" "Lisp"))
(is (not (s:ends-with? "persidastricl" "stric"))))
(test includes?-test
(let ((s "Practical Common Lisp book is practical"))
(is (s:includes? s "on Lisp"))
(is (not (s:includes? s "perfection")))))
(test empty-collections
(is (== "" (str '())))
(is (== "{}" (str {})))
(is (== "[]" (str []))))
;;(5am:run! :string-tests)
| 7,485 | Common Lisp | .lisp | 181 | 38.254144 | 101 | 0.55719 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 9f1a5ab1a84714aa8878e2890e7e7c09997721f88364a896338f5d1e53c67c22 | 22,601 | [
-1
] |
22,602 | hash-set.lisp | persidastricl_persidastricl/test/hash-set.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/transient-hash-set.lisp
;;;
;;; -----
(in-package #:persidastricl)
(def-suite :hash-set-tests
:description "testing hash set operations"
:in master-suite)
(in-suite :hash-set-tests)
(named-readtables:in-readtable persidastricl:syntax)
(test transient-hash-set-test
(let ((s @#{:k1 :v1 :k2 :v2 :k3 :v3 :k4 :v4}))
(is (typep s 'transient-hash-set))
(is (= 8 (count s)))
(is (contains? s :k1))))
(test persistent-hash-set-test
(let ((s #{:k1 :v1 :k2 :v2 :k3 :v3 :k4 :v4}))
(is (typep s 'persistent-hash-set))
(is (= 8 (count s)))
(is (contains? s :k1))))
;;(5am:run! :hash-set-tests)
| 996 | Common Lisp | .lisp | 34 | 27.117647 | 65 | 0.626834 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f4663a36e5e71c943ff3bf975daba66198cf53089167c3e25057efa4b9c6795b | 22,602 | [
-1
] |
22,603 | thunk.lisp | persidastricl_persidastricl/test/thunk.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; test/thunk.lisp
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(def-suite :thunk-tests
:description "testing thunks"
:in master-suite)
(in-suite :thunk-tests)
(test force-delay-test
:description "test making a thunk via the delay macro"
(let* ((m {:a 1})
(th (delay (update m :a #'inc))))
(is (= 1 (get m :a)))
(is (functionp (slot-value th 'fn)))
(is (nil? (slot-value th 'r)))
(let ((m (force th)))
(is (= 2 (get m :a))))
(is (nil? (slot-value th 'fn)))
(is (== (slot-value th 'r) {:a 2}))))
;; (5am:run! :thunk-tests)
| 994 | Common Lisp | .lisp | 35 | 25.8 | 65 | 0.605263 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 6f7dbba57b4798ae2c295733c9bbca85d2e4c1fa18bb6d31d417ace75963e1fb | 22,603 | [
-1
] |
22,604 | package.lisp | persidastricl_persidastricl/src/package.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
(defpackage #:bits
(:nicknames #:bit #:b)
(:use #:cl)
(:shadow #:cl #:set)
(:export #:set?
#:clear
#:set
#:bits
#:below
#:index))
(defpackage #:hash
(:nicknames #:h)
(:use #:cl #:cl-murmurhash)
(:export #:hash
#:size))
(defpackage #:vector
(:nicknames #:v)
(:use #:cl)
(:shadow #:cl #:append #:delete)
(:export #:copy
#:append
#:insert
#:update
#:delete
#:modify))
(defpackage #:persidastricl
(:nicknames :pds :p)
(:use #:cl #:arrow-macros)
(:shadow #:cl
#:some
#:atom
#:keyword
#:cons
#:first
#:second
#:third
#:rest
#:nth
#:nth-value
#:last
#:butlast
#:assoc
#:dissoc
#:get
#:delete
#:remove
#:length
#:count
#:set
#:vector
#:merge
#:pop
#:reduce
#:replace
#:map
#:while
)
(:export
#:-<>
#:-<>>
#:->
#:->>
#:->alist
#:->array
#:->list
#:->plist
#:->vector
#:-vec
#:<!>
#:<>
#:==
#:as->
#:assoc
#:assoc-in
#:atom
#:bounded-count
#:butlast
#:collection?
#:comment
#:comp
#:compare
#:concat
#:cond->
#:cond->>
#:conj
#:cons
#:contains?
#:count
#:cycle
#:dec
#:dedup
#:def
#:defmemoized
#:delay
#:deref
#:destructure
#:disj
#:dissoc
#:distinct
#:distinct?
#:dlet
#:do-n
#:doall
#:dorun
#:dorun-n
#:dotted-pair?
#:drop
#:drop-last
#:drop-while
#:empty
#:empty?
#:even?
#:every-pred
#:every?
#:fact
#:false?
#:fdef
#:filter
#:filterv
#:first
#:flatten
#:fn
#:fnil
#:force
#:frequencies
#:get
#:get-in
#:group-by
#:identical?
#:if-let
#:if-not
#:inc
#:instance?
#:int?
#:integers
#:interleave
#:interpose
#:into
#:iterate
#:juxt
#:keep
#:keep-indexed
#:key
#:keys
#:keyword
#:last
#:lazy-cat
#:lazy-seq
#:length
#:line-seq
#:lookup
#:lseq
#:map
#:map-indexed
#:map?
#:mapcat
#:mapv
#:max-key
#:memoize
#:merge
#:merge-with
#:meta
#:metadata
#:min-key
#:n-choose-k
#:name
#:nat-int?
#:neg-int?
#:neg?
#:next
#:next-int
#:nil?
#:not-any?
#:not-every?
#:nth
#:odd?
#:only-valid-values
#:partial
#:partition
#:partition-all
#:partition-by
#:peek
#:persistent-hash-map
#:persistent-hash-set
#:persistent-vector
#:pop
#:pos-int?
#:pos?
#:put
#:quot
#:rand-nth
#:rand-seq
#:random-generator
#:range
#:re-seq
#:reduce
#:reduce-kv
#:reductions
#:repeat
#:repeatedly
#:replace
#:reset!
#:rest
#:rseq
#:run!
#:second
#:select-keys
#:seq
#:sequential?
#:set
#:set?
#:shuffle
#:slurp
#:some
#:some-<>
#:some-<>>
#:some->
#:some->>
#:some-fn
#:some?
#:spit
#:split-at
#:split-with
#:str
#:string?
#:subs
#:subseq
#:subvec
#:swap!
#:syntax
#:t-set
#:t-vec
#:take
#:take-last
#:take-nth
#:take-while
#:third
#:trampoline
#:transient!
#:transient-hash-map
#:transient-hash-set
#:transient-vector
#:tree-seq
#:true?
#:update
#:update-in
#:val
#:vals
#:value
#:vary-meta
#:vec
#:vector?
#:when-first
#:when-let
#:when-not
#:while
#:with-meta
#:zero?
#:zipmap))
(defpackage #:string
(:nicknames #:s #:str)
(:use #:cl #:persidastricl)
(:shadow #:cl #:replace #:reverse)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:keyword
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:second
#:third
#:nth
#:get
#:last
#:length
#:map
#:merge
#:pop
#:reduce
#:remove
#:rest
#:set
#:some
#:vector)
(:export #:blank?
#:capitalize
#:condense
#:ends-with?
#:escape
#:includes?
#:index-of
#:join
#:last-index-of
#:lower-case
#:re-quote-replacement
#:replace
#:replace-first
#:reverse
#:split
#:split-lines
#:starts-with?
#:trim
#:trim-newline
#:triml
#:trimr
#:upper-case))
(defpackage #:set
(:use #:cl #:persidastricl)
(:shadow #:cl #:union #:intersection)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:keyword
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:second
#:third
#:nth
#:get
#:last
#:length
#:map
#:merge
#:pop
#:reduce
#:remove
#:replace
#:rest
#:set
#:some
#:vector)
(:export #:difference
#:index
#:intersection
#:join
#:map-invert
#:project
#:rename
#:rename-keys
#:select
#:subset?
#:superset?
#:union))
(defpackage #:walk
(:use #:cl #:persidastricl)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:keyword
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:second
#:third
#:nth
#:get
#:last
#:length
#:map
#:merge
#:pop
#:reduce
#:remove
#:replace
#:rest
#:set
#:some
#:vector)
(:export
#:keywordize-keys
#:macroexpand-all
#:postwalk
#:postwalk-demo
#:postwalk-replace
#:prewalk
#:prewalk-demo
#:prewalk-replace
#:stringify-keys
#:walk))
(defpackage #:data
(:use #:cl #:persidastricl)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:keyword
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:second
#:third
#:nth
#:get
#:last
#:length
#:map
#:merge
#:pop
#:reduce
#:remove
#:replace
#:rest
#:set
#:some
#:vector)
(:export #:diff))
(defpackage #:combinatorics
(:nicknames #:c)
(:use #:cl #:persidastricl)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:keyword
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:second
#:third
#:nth
#:get
#:last
#:length
#:map
#:merge
#:pop
#:reduce
#:remove
#:replace
#:rest
#:set
#:some
#:vector)
(:export #:combinations
#:subsets
#:cartesian-product
#:selections
#:permutations
#:permuted-combinations
#:count-permutations
#:nth-permutation
#:drop-permutations
#:count-combinations
#:count-subsets
#:nth-combination
#:nth-subset
#:permutation-index))
(defpackage #:json
(:use #:cl #:persidastricl #:json-streams)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:keyword
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:second
#:third
#:nth
#:get
#:last
#:length
#:map
#:merge
#:pop
#:reduce
#:remove
#:replace
#:rest
#:set
#:some
#:vector)
(:export #:decode-file #:decode-string #:encode))
(defpackage #:user
(:use #:cl #:persidastricl #:arrow-macros)
(:shadowing-import-from #:persidastricl
#:assoc
#:atom
#:keyword
#:butlast
#:cons
#:count
#:delete
#:filter
#:first
#:second
#:third
#:nth
#:get
#:last
#:length
#:map
#:merge
#:pop
#:reduce
#:remove
#:replace
#:rest
#:set
#:some
#:vector))
| 12,173 | Common Lisp | .lisp | 530 | 10.326415 | 65 | 0.333649 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 2eb4374d3214c90e2457305a5dba0734981bf99275df5ef79b82a54e29f56d61 | 22,604 | [
-1
] |
22,605 | node-iterator.lisp | persidastricl_persidastricl/src/iterator/node-iterator.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; node-iterator.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defclass node-iterator (iterator)
((node :initarg :node :accessor :node)
(index :initarg :index :accessor :index)))
(defmethod iterator ((target node))
(make-instance 'node-iterator :node target :index 0))
(defmethod iterator ((target overflow-node))
(make-instance 'node-iterator :node target :index 0))
(defmethod has-next? ((iterator node-iterator))
(with-slots (index node) iterator
(when (and index node)
(< index (count node)))))
(defmethod current ((iterator node-iterator))
(with-slots (node index) iterator
(nth-value node index)))
(defmethod next ((iterator node-iterator))
(with-slots (node index) iterator
(when (< index (count node))
(let ((item (nth-value node index)))
(incf index)
item))))
| 1,202 | Common Lisp | .lisp | 38 | 28.973684 | 65 | 0.66609 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f4168a066657dbdb88b2507db2eac07d7f4e960b9f90d3c34ef5b42b6258bc3c | 22,605 | [
-1
] |
22,606 | hamt-iterator.lisp | persidastricl_persidastricl/src/iterator/hamt-iterator.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hamt-iterator.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defclass hamt-iterator (iterator)
((stack :initarg :stack)
(current :initarg :current)))
(defmethod iterator ((target hamt))
(let ((start (iterator (root target)))
(stack (coerce (sub-nodes (root target)) 'list)))
(multiple-value-bind (current stack) (if (has-next? start)
(values start stack)
(next-iterator stack))
(make-instance 'hamt-iterator :stack stack :current current))))
(defmethod has-next? ((iterator hamt-iterator))
(when-let ((current (slot-value iterator 'current)))
(has-next? (slot-value iterator 'current))))
(defun next-iterator (stack)
(if (empty? stack)
(values nil nil)
(let ((node (first stack)))
(if (> (count node) 0)
(values (iterator node) (concatenate 'list (sub-nodes node) (rest stack)))
(next-iterator (concatenate 'list (sub-nodes node) (rest stack)))))))
(defmethod current ((iterator hamt-iterator))
(current (slot-value iterator 'current)))
(defmethod next ((iterator hamt-iterator))
(with-slots (current stack) iterator
(let ((entry (next current)))
(unless (has-next? current)
(multiple-value-bind (next-current new-stack) (next-iterator stack)
(when next-current
(setf current next-current)
(setf stack new-stack))))
entry)))
| 1,834 | Common Lisp | .lisp | 49 | 31.591837 | 86 | 0.61677 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | e05fdf2664d33d0b376ddadd89923b5c1099b3d8d85376d164a4d6b107233a5a | 22,606 | [
-1
] |
22,607 | methods.lisp | persidastricl_persidastricl/src/iterator/methods.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; seqable.lisp
;;;
;;; CLOS marker class for collections that are capable of becoming sequences of items
;;;
;;; -----
(in-package #:persidastricl)
(defmethod seq ((it iterator))
(labels ((seq* (it)
(when (has-next? it)
(lseq (next it) (seq* it)))))
(seq* it)))
(defmethod seq ((object seqable))
(seq (iterator object)))
| 729 | Common Lisp | .lisp | 27 | 24.518519 | 85 | 0.616046 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 74b58b9be2012fb5e372e6eb76a611ca64bb16b354d3c615f973b67455ae5c78 | 22,607 | [
-1
] |
22,608 | iterator.lisp | persidastricl_persidastricl/src/iterator/iterator.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; iterator.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defclass iterator () ())
(defmethod iterator (target))
(defgeneric current (object))
(defgeneric has-next? (object))
| 549 | Common Lisp | .lisp | 22 | 23.772727 | 65 | 0.648184 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 3f2e7e5443b955a53dd1d34db741b1e17490a5e717640b501ab0b1cec679ab61 | 22,608 | [
-1
] |
22,609 | lazy-sequence.lisp | persidastricl_persidastricl/src/lazy/lazy-sequence.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; lazy-sequence.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; lazy-sequence
;;
;; -----
(defclass lazy-sequence ()
((head :initarg :head :reader :head)
(tail :initarg :tail :reader :tail)))
(defmacro lseq (head tail)
`(make-instance 'lazy-sequence :head ,head :tail (delay ,tail)))
(defmethod first ((seq lazy-sequence))
(slot-value seq 'head))
(defmethod rest ((seq lazy-sequence))
(when-let ((tail (slot-value seq 'tail))) (force tail)))
(defmethod nth ((seq lazy-sequence) n &optional (default nil))
(or (first (drop n seq)) default))
(defmethod next ((seq lazy-sequence))
(when-let ((tail (slot-value seq 'tail))) (force tail)))
(defmethod head ((seq lazy-sequence))
(slot-value seq 'head))
(defmethod tail ((seq lazy-sequence))
(when-let ((tail (slot-value seq 'tail))) (force tail)))
(defmethod ->list ((obj lazy-sequence))
(let ((lst))
(do* ((s obj (tail s))
(x (head s) (head s)))
((empty? s) lst)
(setf lst (append lst (list x))))))
(defmethod cl-murmurhash:murmurhash ((object lazy-sequence) &key (seed cl-murmurhash:*default-seed*) mix-only)
(cl-murmurhash:murmurhash (->list object) :seed seed :mix-only mix-only))
(defmethod ->array ((seq lazy-sequence))
(when seq
(let ((lst (->list seq)))
(make-array (cl:length lst) :initial-contents lst))))
(defgeneric lazy-seq (obj)
(:method (obj) (lazy-seq (list obj)))
(:method ((s sequence)) (lazy-seq (coerce s 'list)))
(:method ((obj function)) (lazy-seq (funcall obj)))
(:method ((obj lazy-sequence)) obj))
(defmethod lazy-seq ((obj list))
(unless (empty? obj)
(lseq (head obj) (lazy-seq (tail obj)))))
(defgeneric seq (object)
(:method ((object list)) (lazy-seq object))
(:method ((object sequence)) (seq (coerce object 'list)))
(:method ((object lazy-sequence)) object)
(:method ((object hash-table)) (seq (->list object))))
(defun take (n coll)
(labels ((take* (n s)
(when (seq s)
(cond
((= n 1) (list (head s)))
((pos? n) (lseq (head s) (take* (1- n) (tail s))))))))
(take* n (seq coll))))
(defun drop (n seq)
(labels ((drop* (n s)
(if (and (seq s) (pos? n))
(drop* (1- n) (tail s))
s)))
(drop* n (seq seq))))
(defvar *print-lazy-items* 10)
(defun pprint-lazy-sequence (stream ls &rest other-args)
(declare (ignore other-args))
(let ((*print-length* (min *print-lazy-items* (or *print-lines* *print-lazy-items*))))
(pprint-logical-block (stream (->list (take (inc *print-length*) ls)) :prefix "(" :suffix ")")
(pprint-exit-if-list-exhausted)
(loop
(write (pprint-pop) :stream stream)
(pprint-exit-if-list-exhausted)
(write-char #\space stream)
(pprint-newline :fill stream)))))
(defmethod print-object ((object lazy-sequence) stream)
(format stream "~/persidastricl::pprint-lazy-sequence/" object))
(set-pprint-dispatch 'lazy-sequence 'pprint-lazy-sequence)
(defmethod count ((object lazy-sequence))
"Danger! Endless loop on infinite lazy sequences! Use bounded-count for those"
(labels ((count* (seq n)
(if (empty? seq)
n
(count* (tail seq) (inc n)))))
(count* object 0)))
(defmethod bounded-count (n thing)
(labels ((bounded-count* (s i)
(if (and s (< i n))
(bounded-count* (tail s) (inc i))
i)))
(bounded-count* (seq thing) 0)))
(defmethod empty? ((seq lazy-sequence))
(= (bounded-count 1 seq) 0))
(defmethod compare ((s1 lazy-sequence) (s2 lazy-sequence))
(cond ((and (nil? s1) (nil? s2)) 0)
((nil? s1) -1)
((nil? s2) 1)
(t (let ((cf (compare (first s1) (first s2))))
(if (= 0 cf) (compare (rest s1) (rest s2)) cf)))))
| 4,206 | Common Lisp | .lisp | 112 | 32.651786 | 110 | 0.601918 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | fa06a7cbedb6919a265df57af5a68cc26ef13b16db83eade050fe902508f00c4 | 22,609 | [
-1
] |
22,610 | demo.lisp | persidastricl_persidastricl/src/lazy/demo.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; lazy-seq/examples.lisp
;;;
;;; -----
;;; just for fun :-)
(in-package #:persidastricl)
(time
(into [] (take 100 fib)))
(time
(into [] (take 50 trib)))
(time
(first (take 1 (drop 200 trib))))
(time
(into [] (take 30 (squares))))
(time
(into [] (take 30 (triangulars))))
(time
(into [] (take 30 (hexagonals))))
(time
(into [] (take 30 (catalan-seq))))
(time
(into [] (take 30 (catalan-seq 10))))
(time
(into [] (take 30 (primes-seq))))
(time
(into [] (take 30 (drop 5000 (primes-seq)))))
| 879 | Common Lisp | .lisp | 39 | 20.948718 | 65 | 0.61185 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 6598f19dd911434d32bee3c79eaceb037c5e13d239d9c18d1e275170f74d4e83 | 22,610 | [
-1
] |
22,611 | sequences.lisp | persidastricl_persidastricl/src/lazy/sequences.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; lazy-seq/sequences.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defun fact (i)
(cond
((= i 0) 1)
((= i 1) 1)
((< i 0) (- (fact (- i))))
(:otherwise (reduce #'* (nrange i :start i :step -1)))))
(defvar fib
(lseq 0 (lseq 1 (map #'+ fib (tail fib)))))
(defvar trib
(lseq 0 (lseq 1 (lseq 1 (lseq 2
(map #'+
(drop 1 trib)
(drop 2 trib)
(drop 3 trib)))))))
(defun squares ()
(map (lambda (i) (* i i)) (drop 1 (integers))))
(defun n-choose-k (n k)
(if (> k n)
1
(/ (fact n) (fact (- n k)) (fact k))))
(defun triangulars ()
(map (lambda (n) (n-choose-k (1+ n) 2)) (drop 1 (integers))))
(defun binomial-coefficients (&optional (n 0))
(lseq (mapv
(lambda (k)
(n-choose-k n k))
(nrange (inc n)))
(binomial-coefficients (inc n))))
(defun hexagonals ()
(map
(lambda (n)
(- (* 2 (* n n)) n))
(drop 1 (integers))))
(defun catalan (n)
(/ (fact (* 2 n)) (* (fact (1+ n)) (fact n))))
(defun catalan-seq (&optional (n 0))
(map #'catalan (drop n (integers))))
;; -----
;; primes' sieve of erasthenos (sp) with persistent hash map
;;
;; -----
(defun find-next-empty-multiple (factor multiple sieve)
(let ((target (* multiple factor)))
(if (and
(oddp target)
(not (get sieve target)))
multiple
(find-next-empty-multiple factor (+ multiple 2) sieve))))
(defun is-prime-p (n sieve)
(if-let ((value (get (deref sieve) n)))
(let ((factor (first value))
(multiple (second value)))
(let ((next (find-next-empty-multiple factor multiple (deref sieve))))
(swap! sieve (lambda (sieve)
(-> sieve
(assoc (* factor next) (list factor (+ next 2)))
(dissoc n))))
nil))
(let ((next (find-next-empty-multiple n 3 (deref sieve))))
(swap! sieve #'assoc (* n next ) (list n (+ next 2)))
t)))
(defun next-prime (p sieve)
(if (is-prime-p p sieve)
p
(next-prime (+ p 2) sieve)))
(defun lazy-primes (p sieve)
(let ((next (next-prime p sieve)))
(lseq next (lazy-primes (+ next 2) sieve))))
(defun primes-seq ()
(lseq 2 (lazy-primes 3 (atom (persistent-hash-map)))))
;; -----
;; primes' sieve of erasthenos (sp) with transient hash map
;;
;; -----
;; (defun find-next-empty-multiple (factor multiple sieve)
;; (let ((target (* multiple factor)))
;; (if (and
;; (oddp target)
;; (not (get sieve target)))
;; multiple
;; (find-next-empty-multiple factor (+ multiple 2) sieve))))
;; (defun is-prime-p (n sieve)
;; (if-let ((value (get sieve n)))
;; (let ((factor (first value))
;; (multiple (second value)))
;; (let ((next (find-next-empty-multiple factor multiple sieve)))
;; (-> sieve
;; (assoc (* factor next) (list factor (+ next 2)))
;; (dissoc n))
;; nil))
;; (let ((next (find-next-empty-multiple n 3 sieve)))
;; (assoc sieve (* n next ) (list n (+ next 2)))
;; t)))
;; (defun next-prime (p sieve)
;; (if (is-prime-p p sieve)
;; p
;; (next-prime (+ p 2) sieve)))
;; (defun lazy-primes (p sieve)
;; (let ((next (next-prime p sieve)))
;; (lseq next (lazy-primes (+ next 2) sieve))))
;; (defun primes-seq ()
;; (lseq 2 (lazy-primes 3 (transient-hash-map))))
| 3,877 | Common Lisp | .lisp | 120 | 27.533333 | 76 | 0.531083 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 55925c05afc2d68588805a5c4ea062d619fb982983e4bb799054ce8f9c8291b8 | 22,611 | [
-1
] |
22,612 | thunk.lisp | persidastricl_persidastricl/src/lazy/thunk.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; thunk.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; thunk
;;
;; -----
(defclass thunk ()
((fn :initarg :fn)
(r :initarg :r))
(:default-initargs :r nil))
(defmacro delay (&rest body)
`(make-instance 'thunk :fn (lambda () ,@body)))
(defgeneric force (obj)
(:method (obj) obj))
(defmethod force ((thunk thunk))
(when (slot-value thunk 'fn)
(setf (slot-value thunk 'r) (funcall (slot-value thunk 'fn)))
(setf (slot-value thunk 'fn) nil))
(slot-value thunk 'r))
| 872 | Common Lisp | .lisp | 35 | 23.057143 | 65 | 0.616867 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 43f6ae4e9813c32a49b946ca7aa30f0d724c32af99463c7e30c2f604a4fc18b4 | 22,612 | [
-1
] |
22,613 | counted.lisp | persidastricl_persidastricl/src/mixins/counted.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; counted.lisp
;;;
;;; CLOS class for tracking a count of items
;;;
;;; -----
(in-package #:persidastricl)
(defclass counted ()
((count :type integer :initarg :count))
(:default-initargs :count 0))
(defmethod count ((thing counted))
(slot-value thing 'count))
(defmethod length ((thing counted))
(count thing))
(defmethod bounded-count (n (thing counted))
(:method (n (thing counted)) (count thing)))
(defmethod empty? ((thing counted))
(zerop (count thing)))
| 847 | Common Lisp | .lisp | 31 | 25.709677 | 65 | 0.662546 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | ef78b153b5372489c49fc2d1cf5c4c6b472b6af0d67c3518757f168321f6a31d | 22,613 | [
-1
] |
22,614 | collection.lisp | persidastricl_persidastricl/src/mixins/collection.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; collection.lisp
;;;
;;; marker class for a collection of things
;;;
;;; -----
(in-package #:persidastricl)
(defclass collection () ())
(defgeneric contains? (collection item))
(defgeneric conj (collection &rest items))
(defgeneric disj (collection &rest items))
(defun collection? (x)
(or (typep x 'collection)
(typep x 'sequence)))
| 718 | Common Lisp | .lisp | 27 | 25.037037 | 65 | 0.662281 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 37aea8e4f608887a5d80f7411a6496500fe3806f1ae52ecade6c5a46eb1b24c2 | 22,614 | [
-1
] |
22,615 | seqable.lisp | persidastricl_persidastricl/src/mixins/seqable.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; seqable.lisp
;;;
;;; CLOS marker class for collections that are capable of becoming sequences of items
;;;
;;; -----
(in-package #:persidastricl)
(defclass seqable () ())
(defun sequential? (x)
(or (typep x 'sequence)
(typep x 'seqable)))
| 621 | Common Lisp | .lisp | 24 | 24.375 | 85 | 0.644182 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | a1feaeb58d8dab53794772536b94b2ea3e3343c3f45c08f7b26d6d1a3a454a1f | 22,615 | [
-1
] |
22,616 | meta.lisp | persidastricl_persidastricl/src/mixins/meta.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; meta.lisp
;;;
;;; CLOS class for metadata
;;;
;;; -----
(in-package #:persidastricl)
(defclass metadata ()
((meta :initarg :meta :reader :meta :documentation "map of metadata"))
(:default-initargs :meta nil))
(defgeneric with-meta (object meta))
(defgeneric meta (object)
(:method ((object metadata)) (with-slots (meta) object meta)))
(defun vary-meta (obj f &rest args)
(with-meta obj (apply f (meta obj) args)))
| 798 | Common Lisp | .lisp | 28 | 27 | 72 | 0.658377 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 30bd778a01b43663b188a1ef2a9677d0c71e80d89378786af14ad6b2c0a3ca3b | 22,616 | [
-1
] |
22,617 | associable.lisp | persidastricl_persidastricl/src/mixins/associable.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; associable.lisp
;;;
;;; marker class for an associable data structure
;;;
;;; -----
(in-package #:persidastricl)
(defclass associable () ())
(defgeneric keys (obj)
(:method ((obj (eql nil))) nil))
(defgeneric vals (obj)
(:method ((obj (eql nil))) nil))
(defgeneric assoc (associable k v &rest kv-pairs))
(defgeneric dissoc (associable &rest keys))
(defgeneric lookup (associable k &optional default))
(defgeneric get (associable k &optional default))
(defmethod assoc ((lst list) k1 v1 &rest kv-pairs)
(labels ((assoc* (l k v)
(check-type k integer)
(let ((start (->list (take k l))))
(concatenate 'list start (list* v (->list (drop (1+ k) l)))))))
(reduce
(lambda (l kv-pair)
(apply #'assoc* l kv-pair))
(->list (partition-all (list* k1 v1 kv-pairs) 2))
:initial-value lst)))
(defmethod dissoc ((lst list) &rest keys)
(labels ((dissoc* (l k)
(check-type k integer)
(let ((start (->list (take k l))))
(concatenate 'list start (->list (drop (1+ k) l))))))
(reduce
(lambda (l k)
(dissoc* l k))
keys
:initial-value lst)))
(defmethod lookup ((lst list) position &optional default)
(or (first (drop position lst)) default))
(defmethod get ((lst list) position &optional default)
(lookup lst position default))
(defmethod empty ((ht hash-table))
(make-hash-table :test #'equalp))
(defmethod assoc ((ht hash-table) k1 v1 &rest kv-pairs)
(labels ((assoc* (m k v)
(setf (gethash k m) v)
m))
(reduce-kv
#'assoc*
(->list (partition-all (list* k1 v1 kv-pairs) 2))
:initial-value ht)))
(defmethod dissoc ((ht hash-table) &rest keys)
(labels ((dissoc* (m k)
(remhash k m)
m))
(cl:reduce
#'dissoc*
keys
:initial-value ht)))
(defmethod lookup ((ht hash-table) k &optional default)
(gethash k ht default))
(defmethod get ((ht hash-table) k &optional default)
(gethash k ht default))
(defmethod keys ((ht hash-table))
(loop for key being the hash-keys of ht collect key))
(defmethod vals ((ht hash-table))
(loop for v being the hash-values of ht collect v))
(defmethod assoc ((vec array) index value &rest iv-pairs)
(labels ((assoc* (v i val)
(check-type i integer)
(if (= i (length v))
(v:append v val)
(v:update v i val))))
(reduce
(lambda (v iv-pair)
(apply #'assoc* v iv-pair))
(->list (partition-all (list* index value iv-pairs) 2))
:initial-value vec)))
(defmethod dissoc ((vec array) &rest indexes)
(labels ((dissoc* (v i)
(check-type i integer)
(v:delete v i)))
(reduce
(lambda (v i)
(apply #'dissoc* v i))
indexes
:initial-value vec)))
(defmethod lookup ((vec array) k &optional default)
(or (elt vec k) default))
(defmethod get ((vec array) k &optional default)
(or (elt vec k) default))
(defun funcallable-keyword? (k)
(handler-case
(symbol-function k)
(undefined-function ()
nil)))
(defun make-funcallable-keyword (k)
(assert (keywordp k))
(unless (funcallable-keyword? k)
(eval `(defun ,k (hm &optional (default nil)) (lookup hm ,k default)))))
(defun make-funcallable-keywords (&rest kws)
(dolist (k kws) (make-funcallable-keyword k)))
(defun pprint-hash-table (stream ht &rest other-args)
(declare (ignore other-args))
(pprint-logical-block (stream (->list ht) :prefix "%{" :suffix "}")
(pprint-exit-if-list-exhausted)
(loop
(pprint-logical-block (stream (pprint-pop))
(write (pprint-pop) :stream stream)
(write-char #\space stream)
(write (pprint-pop) :stream stream))
(pprint-exit-if-list-exhausted)
(write-char #\space stream)
(pprint-newline :fill stream))))
(defmethod print-object ((ht hash-table) stream)
(format stream "~/persidastricl::pprint-hash-table/" ht))
(set-pprint-dispatch 'hash-table 'pprint-hash-table)
(defmethod == ((ht1 hash-table) (ht2 hash-table))
(or (eq ht1 ht2)
(let ((ks1 (set (keys ht1))))
(and
(== ks1 (set (keys ht2)))
(every
(lambda (k)
(== (get ht1 k) (get ht2 k)))
(->list ks1))))))
| 4,665 | Common Lisp | .lisp | 138 | 28.601449 | 78 | 0.611914 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 393aeef33c2314076a86f72d4d50222a2b4500ea2050afeebbe2fcb06d7fb4a3 | 22,617 | [
-1
] |
22,618 | syntax.lisp | persidastricl_persidastricl/src/impl/syntax.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; syntax.lisp
;;;
;;; generic functions
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; reader macros for persistent-hash-map
;;
;; -----
(defconstant +hash+ #\#)
(defconstant +at+ #\@)
(defconstant +percent+ #\%)
(defconstant +left-brace+ #\{)
(defconstant +right-brace+ #\})
(defconstant +left-bracket+ #\[)
(defconstant +right-bracket+ #\])
(defconstant +comma+ #\,)
(defconstant +space+ #\ )
(defconstant +double-quote+ #\")
(defun read-separator (stream char)
(declare (ignore stream))
(error "Separator ~S shouldn't be read alone" char))
(defun read-delimiter (stream char)
(declare (ignore stream))
(error "Delimiter ~S shouldn't be read alone" char))
(def end-of-syntax-objects (gensym "EOSYNTAX_"))
(defun read-next-object (separators delimiter
&optional (input-stream *standard-input*))
(flet ((peek-next-char () (peek-char t input-stream t nil t))
(discard-next-char () (read-char input-stream t nil t)))
(if (and delimiter (char= (peek-next-char) delimiter))
(progn
(discard-next-char)
end-of-syntax-objects)
(let ((next-char (peek-next-char)))
(cond
((and delimiter (char= next-char delimiter)) end-of-syntax-objects)
((member next-char separators)
(discard-next-char)
(read-next-object separators delimiter input-stream))
(t
(read input-stream t nil t)))))))
(defun read-regex-literal* (stream)
(let (chars)
(do ((curr (read-char stream) (read-char stream)))
((char= curr #\"))
(push curr chars))
(coerce (nreverse chars) 'string)))
(defun read-regex-literal (stream char n-arg)
(declare (ignore char n-arg))
(let ((re-s (read-regex-literal* stream)))
(str:replace re-s "\\" "\\\\")))
(defun read-hash-table-literal (stream char n-arg)
(declare (ignore char n-arg))
(loop
for object = (read-next-object (list +space+ +comma+) +right-brace+ stream)
while (not (eql object end-of-syntax-objects))
collect object into objects
finally (return (if (not (empty? objects))
`(assoc (make-hash-table :test #'equalp) ,@objects)
`(make-hash-table :test #'equalp)))))
(defun read-persistent-map-literal (stream char)
(declare (ignore char))
(loop
for object = (read-next-object (list +space+ +comma+) +right-brace+ stream)
while (not (eql object end-of-syntax-objects))
collect object into objects
finally (return `(persidastricl::persistent-hash-map ,@objects))))
(defun read-transient-map-literal (stream char n-arg)
(declare (ignore char n-arg))
(loop
for object = (read-next-object (list +space+ +comma+) +right-brace+ stream)
while (not (eql object end-of-syntax-objects))
collect object into objects
finally (return `(persidastricl::transient-hash-map ,@objects))))
(defun read-persistent-set-literal (stream char n-arg)
(declare (ignore char n-arg))
(loop
for object = (read-next-object (list +space+ +comma+) +right-brace+ stream)
while (not (eql object end-of-syntax-objects))
collect object into objects
finally (return `(persidastricl::persistent-hash-set ,@objects))))
(defun expect (c stream)
(let ((input-char (read-char stream)))
(if-not (char= input-char c)
(error (format nil "Error: unexpected char: '~a' expected, but read '~c' instead~%" c input-char))
input-char)))
(defun read-transient-set-literal (stream char n-arg)
(declare (ignore char n-arg))
(expect +left-brace+ stream)
(loop
for object = (read-next-object (list +space+ +comma+) +right-brace+ stream)
while (not (eql object end-of-syntax-objects))
collect object into objects
finally (return `(persidastricl::transient-hash-set ,@objects))))
(defun read-persistent-vector-literal (stream char)
(declare (ignore char))
(loop
for object = (read-next-object (list +space+ +comma+) +right-bracket+ stream)
while (not (eql object end-of-syntax-objects))
collect object into objects
finally (return `(persidastricl::persistent-vector ,@objects))))
(defun read-transient-vector-literal (stream char n-arg)
(declare (ignore char n-arg))
(loop
for object = (read-next-object (list +space+ +comma+) +right-bracket+ stream)
while (not (eql object end-of-syntax-objects))
collect object into objects
finally (return `(persidastricl::transient-vector ,@objects))))
(named-readtables:defreadtable syntax
(:merge :standard)
(:macro-char +at+ :dispatch)
(:macro-char +percent+ :dispatch)
(:dispatch-macro-char +percent+ +left-brace+ #'read-hash-table-literal)
(:macro-char +right-brace+ #'read-delimiter nil)
(:macro-char +left-brace+ #'read-persistent-map-literal nil)
(:dispatch-macro-char +at+ +left-brace+ #'read-transient-map-literal)
(:dispatch-macro-char +hash+ +double-quote+ #'read-regex-literal)
(:dispatch-macro-char +hash+ +left-brace+ #'read-persistent-set-literal)
(:dispatch-macro-char +at+ +hash+ #'read-transient-set-literal)
(:macro-char +right-bracket+ #'read-delimiter nil)
(:macro-char +left-bracket+ #'read-persistent-vector-literal nil)
(:dispatch-macro-char +at+ +left-bracket+ #'read-transient-vector-literal)
(:case :invert))
| 5,665 | Common Lisp | .lisp | 139 | 36.366906 | 110 | 0.667878 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f7e53076f35c067a315d0540ecd9ae1bbeffad065a6dc25f0b046dfcb4205557 | 22,618 | [
-1
] |
22,619 | bpvt.lisp | persidastricl_persidastricl/src/impl/bpvt.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; bpvt.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defvar *print-bpvt-items* 100)
(defclass bpvt (metadata counted collection seqable)
((root :initarg :root :reader root)
(tail-end :initarg :tail-end :reader tail-end)
(tail-offset :initarg :tail-offset :reader tail-offset)))
(defmethod cl-murmurhash:murmurhash ((object bpvt) &key (seed cl-murmurhash:*default-seed*) mix-only)
(cl-murmurhash:murmurhash (->list object) :seed seed :mix-only mix-only))
(defgeneric rseq (obj)
(:method ((vector bpvt)) (let ((count (count vector)))
(when (pos? count)
(let ((index (dec count)))
(labels ((next* (i)
(when (>= i 0)
(let ((value (get vector i)))
(lseq value (next* (1- i)))))))
(lseq (get vector index) (next* (1- index)))))))))
| 1,381 | Common Lisp | .lisp | 34 | 31.264706 | 101 | 0.52871 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 940a8cc89ffafe311e5de7aa9f93d73339041fa4d2da923b63aba4de39a1a0db | 22,619 | [
-1
] |
22,620 | functions.lisp | persidastricl_persidastricl/src/impl/functions.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; impl/functions.lisp
;;;
;;; -----
(in-package #:persidastricl)
(labels ((replace* (s pattern replacement)
(cl-ppcre:regex-replace pattern s replacement :preserve-case t :simple-calls t))
(includes*? (s subs-or-regex)
(cl-ppcre:scan-to-strings subs-or-regex s)))
(defun persistent->transient-name (persistent-object)
(let ((object-name (str (type-of persistent-object))))
(unless (includes*? object-name "(?i)persistent")
(error "object ~a is not a persistent object!" object-name))
(-> object-name
(replace* "(?i)persistent" "transient")
read-from-string)))
(defun transient->persistent-name (transient-object)
(let ((object-name (str (type-of transient-object))))
(unless (includes*? object-name "(?i)transient")
(error "object ~a is not a transient object!" object-name))
(-> object-name
(replace* "(?i)transient" "persistent")
read-from-string))))
(defun transient! (obj)
"create a new transient object copy of the type of persistent object given without modifying the persistent object"
(let ((lst (->list obj)))
(-> (persistent->transient-name obj)
(apply lst))))
| 1,574 | Common Lisp | .lisp | 41 | 34.097561 | 117 | 0.645711 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 567b4482946cef0b13036abdfa06f98e7fea940dbecf4ca85e9c10ee7f2181fb | 22,620 | [
-1
] |
22,621 | hamt.lisp | persidastricl_persidastricl/src/impl/hamt.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hamt.lisp
;;;
;;; base class for persistent/transient hashed array mapped trie classes (sets, maps, etc)
;;;
;;; -----
(in-package #:persidastricl)
(defvar *print-hamt-items* 100)
(defclass hamt (metadata seqable) ())
(defmethod cl-murmurhash:murmurhash ((object hamt) &key (seed cl-murmurhash:*default-seed*) mix-only)
(cl-murmurhash:murmurhash (->list object) :seed seed :mix-only mix-only))
(defmethod count ((object hamt))
(count (seq object)))
(defmethod first ((object hamt))
(first (seq object)))
(defmethod rest ((object hamt))
(rest (seq object)))
(defmethod next ((object hamt))
(next (seq object)))
(defmethod head ((object hamt))
(head (seq object)))
(defmethod tail ((object hamt))
(tail (seq object)))
| 1,111 | Common Lisp | .lisp | 36 | 29.166667 | 101 | 0.678571 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f0b076bf309d34de690200e0605c8560bf0f99003c6d5a4158f8167089678c75 | 22,621 | [
-1
] |
22,622 | methods.lisp | persidastricl_persidastricl/src/impl/methods.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; methods.lisp
;;;
;;; generic functions
;;;
;;; -----
(in-package #:persidastricl)
(defgeneric persistent! (obj)
(:method (obj) (let ((new-object-type (transient->persistent-name obj)))
(change-class obj new-object-type))))
(defmethod empty? ((obj hamt))
(empty? (root obj)))
(defmethod empty? ((obj bpvt))
(zerop (count obj)))
| 729 | Common Lisp | .lisp | 27 | 24.851852 | 75 | 0.626973 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 89bd8ff26348badd8365eac73dfb65479b50dca7390e09ed85cbd0ce1d6af9c6 | 22,622 | [
-1
] |
22,623 | hash-map.lisp | persidastricl_persidastricl/src/impl/map/hash-map.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hash-map.lisp
;;;
;;; mixin class for persistent/transient -hash-map classes
;;;
;;; -----
(in-package #:persidastricl)
(defun ->entries (sequence)
(let ((sequence (->list sequence)))
(typecase (first sequence)
(entry sequence)
(cl:cons (cl:map 'list (lambda (c) (apply #'map-entry c)) sequence))
(t (cl:map 'list (lambda (kv) (apply #'map-entry kv)) (->list (partition-all sequence 2)))))))
(defclass hash-map (hamt associable)
((root :initarg :root :reader root)))
(defun map? (x)
(typep x 'hash-map))
(defmethod lookup ((hm hash-map) key &optional (default nil))
(with-slots (root) hm
(let ((hash (h:hash key)))
(loc root key :hash hash :depth 0 :default default))))
(defmethod get ((hm hash-map) key &optional (default nil))
(lookup hm key default))
(defmethod ->vector ((hm hash-map))
(cl:map 'cl:vector #'->vector (->list hm)))
(defmethod ->vec ((hm hash-map))
(into (persistent-vector) (map #'->vec (->list hm))))
(defmethod ->array ((hm hash-map))
(->vector hm))
(defmethod ->list ((hm hash-map))
(into '() (seq hm)))
(defmethod keys ((hm hash-map))
(map #'key hm))
(defmethod vals ((hm hash-map))
(map #'value hm))
(defmethod ->plist ((ht hash-table))
(apply #'concatenate 'list
(loop for v being each hash-values of ht using (hash-key k)
collect (list k (if (or (map? v) (typep v 'hash-table)) (->plist v) v)))))
(defmethod ->alist ((ht hash-table))
(->list
(map
(lambda (e)
(let ((k (first e))
(v (second e)))
(cond
((or (map? v) (typep v 'hash-table)) (cons k (->alist v)))
(:otherwise (cons k v)))))
ht)))
(defmethod ->plist ((hm hash-map))
(->list
(mapcat
(lambda (e)
(let ((k (key e))
(v (value e)))
(list k (if (or (map? v) (typep v 'hash-table)) (->plist v) v))))
hm)))
(defmethod ->alist ((hm hash-map))
(->list
(map
(lambda (e)
(let ((k (key e))
(v (value e)))
(cond
((or (map? v) (typep v 'hash-table)) (cons k (->alist v)))
(:otherwise (cons k v)))))
hm)))
(defmethod with-meta ((object hamt) (meta (eql nil))) object)
(defun select-keys (map keyseq)
(labels ((select-keys* (m keys)
(if keys
(let ((k (head keys)))
(select-keys*
(if-let ((v (get map k)))
(assoc m k v)
m)
(tail keys)))
m)))
(with-meta (select-keys* (empty map) (seq keyseq)) (meta map))))
(defmacro with-funcallable-map ((symbol definition) &body body)
`(let ((,symbol ,definition))
(labels ((,symbol (k &optional (default nil))
(lookup ,symbol k default)))
,@body)))
(defmethod == ((ht1 hash-map) ht2)
(when (or (instance? 'hash-table ht2) (instance? 'hash-map ht2))
(or (eq ht1 ht2)
(let ((ks1 (set (keys ht1))))
(and
(== ks1 (set (keys ht2)))
(every
(lambda (k)
(== (get ht1 k) (get ht2 k)))
(->list ks1)))))))
(defmethod == (ht1 (ht2 hash-map))
(== ht2 ht1))
(defmethod compare ((hm1 hash-map) (hm2 hash-map))
(compare (seq hm1) (seq hm2)))
| 3,637 | Common Lisp | .lisp | 111 | 26.954955 | 100 | 0.550385 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 069a8f38433287e1aff21e23932aa0f79c653c6db7c8fafa2d19eca09dc98b2f | 22,623 | [
-1
] |
22,624 | vector.lisp | persidastricl_persidastricl/src/impl/vector/vector.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; vector.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defclass vector (bpvt) ())
(defun vector? (x)
(typep x 'vector))
(defmethod get ((vector vector) index &optional (default nil))
(if (< index (count vector))
(if (>= index (tail-offset vector))
(loc (tail-end vector) index :default default)
(loc (root vector) index :default default))
default))
(defmethod first ((vector vector))
(get vector 0))
(defmethod peek ((vector vector))
(get vector (1- (count vector))))
(defmethod seq ((vector vector))
(when (pos? (count vector))
(labels ((next* (i)
(when (< i (count vector))
(let ((value (get vector i)))
(lseq value (next* (1+ i)))))))
(lseq (first vector) (next* 1)))))
(defmethod rest ((vector vector))
(drop 1 (seq vector)))
(defmethod nth ((vector vector) n &optional (default nil))
(nth (seq vector) n default))
(defmethod next ((vector vector))
(next (seq vector)))
(defmethod head ((vector vector))
(head (seq vector)))
(defmethod tail ((vector vector))
(tail (seq vector)))
(defmethod ->list ((v vector))
(cl:map 'list (lambda (i) (get v i)) (loop for i from 0 below (count v) collect i)))
(defmethod conj ((vector vector) &rest values)
(cl:reduce
#'(lambda (v value)
(cons value v))
values
:initial-value vector))
(defmethod compare ((v1 vector) (v2 vector))
(compare (seq v1) (seq v2)))
| 1,821 | Common Lisp | .lisp | 58 | 27.793103 | 86 | 0.62221 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 90b16188441d22a77de082bff6499557724491a53bd9216e8ddc1c1655de1747 | 22,624 | [
-1
] |
22,625 | hash-set.lisp | persidastricl_persidastricl/src/impl/set/hash-set.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hash-set.lisp
;;;
;;; mixin class for persistent/transient -hash-set classes
;;;
;;; -----
(in-package #:persidastricl)
(defclass hash-set (hamt collection)
((root :initarg :root :reader root)))
(defun set? (x)
(typep x 'hash-set))
(defmethod contains? ((hs hash-set) item)
(with-slots (root) hs
(let ((r (loc root item :hash (h:hash item) :depth 0 :default :not-found)))
(not (== r :not-found)))))
(defmethod ->vector ((hs hash-set))
(coerce (seq hs) 'cl:vector))
(defmethod ->array ((hs hash-set))
(->vector hs))
(defmethod ->vec ((hs hash-set))
(->vector hs))
(defmethod ->list ((hs hash-set))
(into '() (seq hs)))
(defmacro with-funcallable-set ((symbol definition) &body body)
`(let ((,symbol ,definition))
(labels ((,symbol (k)
(contains? ,symbol k)))
,@body)))
(defmethod compare ((s1 hash-set) (s2 hash-set))
(compare (seq s1) (seq s2)))
| 1,283 | Common Lisp | .lisp | 43 | 27.27907 | 79 | 0.624085 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | d47b9e27a013598bd77fed8d888c525cc490ec0ea3afc4532a3c1b461aae0af7 | 22,625 | [
-1
] |
22,626 | immutable-class.lisp | persidastricl_persidastricl/src/metaclass/immutable-class.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; immutable-class.lisp
;;;
;;; metaobject class to enforce immutable CLOS classes
;;;
;;; -----
(in-package #:persidastricl)
(defclass immutable-class (standard-class) ()
(:documentation "the class of classes that may not be modified after initialization"))
(defmethod c2mop:validate-superclass ((class immutable-class) (super standard-class)) t)
(define-condition invalid-access-to-immutable-object (error)
((slot-name :initarg :slot-name :reader slot-name)
(instance :initarg :instance :reader instance))
(:report (lambda (condition stream)
(format
stream
"attempt to modify slot with name `~A`~%in instance ~S~%an object of type `~S`~%which is a class defined with the metaclass `~S`~%and cannot be changed once bound!"
(slot-name condition)
(instance condition)
(type-of (instance condition))
(class-name (find-class 'immutable-class))))))
(defmethod (setf c2mop:slot-value-using-class) :before (value (class immutable-class) instance slot-definition)
(let ((slot-name (c2mop:slot-definition-name slot-definition)))
(when (slot-boundp instance slot-name)
(error (make-condition 'invalid-access-to-immutable-object :slot-name slot-name :instance instance) ))))
(defmacro define-immutable-class (class supers slots &rest options)
(when (cl:assoc ':metaclass options)
(error "Defining an immutable class with a metaclass?"))
`(defclass ,class ,supers ,slots
,@options
(:metaclass immutable-class)))
| 1,912 | Common Lisp | .lisp | 44 | 39.204545 | 178 | 0.684578 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 2506bf61d0ed6bf4f81f015193d549401ccf9e9b4aaae67c72ecf5c831caf47e | 22,626 | [
-1
] |
22,627 | hash-map-node.lisp | persidastricl_persidastricl/src/node/hash-map-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hash-map-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; hash-map-node
;;
;; mixin class for both persistent/transient -hash-map-nodes
(defclass hash-map-node (hamt-node) ())
(defmethod nth-value ((node hash-map-node) index)
(with-slots (dvec) node
(let ((idx (* 2 index)))
(map-entry (elt dvec idx) (elt dvec (1+ idx))))))
(defmethod value-at ((node hash-map-node) position)
(with-slots (dmap) node
(when (b:set? position dmap)
(nth-value node (b:index position dmap)))))
(defmethod add ((node hash-map-node) entry &key hash depth)
(with-slots (dmap nmap) node
(let ((key (key entry))
(value (value entry))
(position (b:bits hash depth)))
(cond
;; do we have a node for this hash slice at this depth
((b:set? position nmap)
(let* ((sub-node (subnode-at node position))
(new-node (add sub-node entry :hash hash :depth (1+ depth))))
(if (eq new-node sub-node)
node
(upd node position new-node))))
;; do we have data for this hash at this depth
((b:set? position dmap)
(let* ((current (value-at node position))
(current-key (key current))
(current-value (value current)))
;; do we have the same key?
(if (== key current-key)
;; do we have the same value
(if (== value current-value)
node
(upd node position entry))
;; different key with same hash at this depth
(let ((new-node (-> (empty-node node :hash hash :depth depth)
(add current :hash (h:hash current-key) :depth (1+ depth))
(add entry :hash hash :depth (1+ depth)))))
(-> node
(del position)
(ins position new-node))))))
;; otherwise no node, no data, so just add the entry to this node
(t (ins node position entry))))))
(defmethod loc ((node hash-map-node) key &key hash depth (default nil))
(with-slots (dmap nmap) node
(let ((position (b:bits hash depth)))
(cond
;; do we have a node for this hash at this depth
((b:set? position nmap)
(loc (subnode-at node position) key :hash hash :depth (1+ depth) :default default))
;; do we have data for this hash at this depth
((b:set? position dmap)
(let ((target (value-at node position)))
(if (== key (key target))
(value target)
default)))
;; it is not here at all so return default
(t default)))))
(defmethod remove ((node hash-map-node) key &key hash depth)
(with-slots (dmap nmap) node
(let ((position (b:bits hash depth)))
(cond
;; do we have a node for this hash at this depth
((b:set? position nmap)
(let* ((sub-node (subnode-at node position))
(new-node (remove sub-node key :hash hash :depth (1+ depth))))
(if (single-value-node? new-node)
(let ((keep (single-remaining-data new-node)))
(-> node
(del position)
(ins position keep)))
(upd node position new-node))))
;; do we have data for this hash at this level
((b:set? position dmap)
(let* ((current (value-at node position))
(current-key (key current)))
(if (== key current-key)
(del node position)
node)))
;; we have nothing so return original node
(t node)))))
| 4,075 | Common Lisp | .lisp | 102 | 30.696078 | 94 | 0.546673 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | b088d3be36f855fa24fba1a1588e49b8d4e32438464760fa8bfd25412bdfa535 | 22,627 | [
-1
] |
22,628 | transient-vector-leaf-node.lisp | persidastricl_persidastricl/src/node/transient-vector-leaf-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; transient-vector-leaf-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defclass transient-vector-leaf-node (vector-leaf-node) ()
(:default-initargs :data (make-array 32 :adjustable t :fill-pointer 0 :initial-element nil)))
(defmethod cons (item (node transient-vector-leaf-node))
(with-slots (data) node
(vector-push item data))
node)
(defmethod add ((node transient-vector-leaf-node) item &key index)
(with-slots (data) node
(let ((i (b:bits index 0)))
(setf (elt data i) item)))
node)
(defmethod pop ((node transient-vector-leaf-node))
(with-slots (data) node
(vector-pop data))
node)
| 1,000 | Common Lisp | .lisp | 33 | 28.151515 | 95 | 0.669095 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 8ee49f760bf26b61c7c7c5e571c44d6ea6910f633686d75d01070d459f6b7cb3 | 22,628 | [
-1
] |
22,629 | vector-leaf-node.lisp | persidastricl_persidastricl/src/node/vector-leaf-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; vector-leaf-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defparameter *items-per-node* 32)
(defclass vector-leaf-node (vector-node) ()
(:default-initargs :level 0))
(defmethod cons :before (item (node vector-leaf-node))
;; cannot add more items than we have bits in the hash
(assert (< (length (data node)) *items-per-node*)))
;; locate value at level 0 index
(defmethod loc ((node vector-leaf-node) index &key (default nil))
(let* ((i (b:bits index 0))
(v (elt (data node) i)))
(or v default)))
| 903 | Common Lisp | .lisp | 29 | 29.172414 | 65 | 0.649366 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f2b5a42c848a68707d17e098f9b93895ad8fe089da98ea654a2e5fcbdde2ac3d | 22,629 | [
-1
] |
22,630 | hash-set-overflow-node.lisp | persidastricl_persidastricl/src/node/hash-set-overflow-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hash-set-overflow-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; hash-set-overflow-node
;;
;; -----
(defclass hash-set-overflow-node (overflow-node) ())
(defmethod single-remaining-data ((node hash-set-overflow-node))
(first (data node)))
(defmethod loc ((node hash-set-overflow-node) item &key hash (default nil) &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(if-let ((target (member item data :test #'==)))
(first target)
default))
| 866 | Common Lisp | .lisp | 30 | 27.2 | 93 | 0.645783 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | d1796b1d583741dd905fc17c1bca80d486ff7120a8f0f909c792b7bc59a369a7 | 22,630 | [
-1
] |
22,631 | transient-hash-set-overflow-node.lisp | persidastricl_persidastricl/src/node/transient-hash-set-overflow-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; transient-hash-set-overflow-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; transient-hash-set-overflow-node
;;
;; -----
(defclass transient-hash-set-overflow-node (hash-set-overflow-node) ())
(defmethod add ((node transient-hash-set-overflow-node) item &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(unless (hash node) (setf (hash node) hash))
(setf (data node) (adjoin item (data node) :test #'==))
node)
(defmethod remove ((node transient-hash-set-overflow-node) item &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(unless (hash node) (setf (hash node) hash))
(setf (data node) (remove-if (lambda (e) (== item e)) (data node)))
node)
| 1,112 | Common Lisp | .lisp | 33 | 32.030303 | 92 | 0.656104 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 2846106c8828238b9b5eca336805858f0a03148ae2e753a105a36aa0d81c25f5 | 22,631 | [
-1
] |
22,632 | persistent-hash-map-node.lisp | persidastricl_persidastricl/src/node/persistent-hash-map-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; persistent-hash-map-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; persistent-hash-map-node
;;
;; -----
(define-immutable-class persistent-hash-map-node (hash-map-node) ())
(defmethod ins ((node persistent-hash-map-node) position (new-node persistent-hash-map-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap (b:set position nmap)
:nvec (v:insert nvec (b:index position nmap) new-node))))
(defmethod ins ((node persistent-hash-map-node) position (new-node persistent-hash-map-overflow-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap (b:set position nmap)
:nvec (v:insert nvec (b:index position nmap) new-node))))
(defmethod ins ((node persistent-hash-map-node) position (entry entry))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap (b:set position dmap)
:dvec (v:insert dvec (* (b:index position dmap) 2) (key entry) (value entry))
:nmap nmap
:nvec nvec)))
(defmethod upd ((node persistent-hash-map-node) position (new-node persistent-hash-map-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap nmap
:nvec (v:update nvec (b:index position nmap) new-node))))
(defmethod upd ((node persistent-hash-map-node) position (new-node persistent-hash-map-overflow-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap nmap
:nvec (v:update nvec (b:index position nmap) new-node))))
(defmethod upd ((node persistent-hash-map-node) position (entry entry))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec (v:update dvec (1+ (* (b:index position dmap) 2)) (value entry))
:nmap nmap
:nvec nvec)))
(defmethod del ((node persistent-hash-map-node) position)
(with-slots (dmap dvec nmap nvec) node
(cond
((b:set? position dmap)
(make-instance (type-of node) :dmap (b:clear position dmap)
:dvec (v:delete dvec (* (b:index position dmap) 2) 2)
:nmap nmap
:nvec nvec))
((b:set? position nmap)
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap (b:clear position nmap)
:nvec (v:delete nvec (b:index position nmap))))
(t (error "critical error: attempt to del position in persisetnt-hash-map-node that is not set for either data or subnode!")))))
| 3,619 | Common Lisp | .lisp | 73 | 35.945205 | 134 | 0.536523 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 6877e82f8e72550649cde9086cb1ed43f96f2127d050f56803d3ff5b3ba87f29 | 22,632 | [
-1
] |
22,633 | persistent-vector-node.lisp | persidastricl_persidastricl/src/node/persistent-vector-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; persistent-vector-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
(define-immutable-class persistent-vector-node (vector-node) ())
(defmethod add-leaf-node ((node persistent-vector-node) leaf first-index-of-values)
(with-slots (level data) node
(let ((i (b:bits first-index-of-values level))
(items-in-data (length data)))
(labels ((sub-node (idx)
(when (< idx items-in-data)
(elt data idx))))
(if (> level 1)
;; node of sub-nodes
(let ((sub-node (sub-node i)))
(if sub-node
;; have subnode for this level
(make-instance (type-of node) :level level :data (v:update data i (add-leaf-node sub-node leaf first-index-of-values)))
;; no sub-node for this level (need to add one)
(let ((new-sub-node (make-instance (type-of node) :level (1- level))))
(assert (= i items-in-data))
(make-instance (type-of node) :level level :data (v:append data (add-leaf-node new-sub-node leaf first-index-of-values))))))
;; level 1 node
(progn
(assert (= i items-in-data))
(make-instance (type-of node) :level level :data (v:append data leaf))))))))
(defmethod get-leaf-node ((node persistent-vector-node) first-index-of-values)
(with-slots (level data) node
(let ((i (b:bits first-index-of-values level))
(items-in-data (length data)))
(labels ((sub-node (idx)
(when (< idx items-in-data)
(elt data idx))))
(if (> level 1)
;; node of sub-nodes
(let ((sub-node (sub-node i)))
(if sub-node
;; have subnode for this level
(get-leaf-node sub-node first-index-of-values)
;; no sub-node for this level (should have one!)
(error "no subnode found when getting previous leaf node")))
;; level 1 node
(progn
(assert (= i (1- items-in-data)))
(elt data i)))))))
(defmethod remove-leaf-node ((node persistent-vector-node) first-index-of-values)
(with-slots (level data) node
(let ((i (b:bits first-index-of-values level))
(items-in-data (length data)))
(labels ((sub-node (idx)
(when (< idx items-in-data)
(elt data idx))))
(if (> level 1)
;; node of sub-nodes
(let ((sub-node (sub-node i)))
(if sub-node
;; have subnode for this level
(let ((new-node (remove-leaf-node sub-node first-index-of-values)))
(make-instance (type-of node)
:level level
:data (if (empty? (data new-node))
(v:delete data i)
(v:update data i))))
;; no sub-node for this level (should have one!)
(error "no subnode found when getting previous leaf node")))
;; level 1 node
(progn
(assert (= i (1- items-in-data)))
(make-instance (type-of node) :level level :data (v:delete data i))))))))
(defmethod add ((node persistent-vector-node) item &key index)
(with-slots (level data) node
(let ((i (b:bits index level)))
(make-instance (type-of node) :level level :data (add (elt data i) item :index index)))))
(defmethod update-instance-for-different-class :before ((old transient-vector-node)
(new persistent-vector-node)
&key)
(slot-makunbound new 'data)
(slot-makunbound new 'level)
(with-slots (data level) old
(setf (slot-value new 'data) (cl:map
'vector
(lambda (node)
(change-class node (transient->persistent-name node)))
(slot-value old 'data)))
(setf (slot-value new 'level) level)))
| 4,594 | Common Lisp | .lisp | 99 | 33.383838 | 144 | 0.517503 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 7c060edcc0eaeb7077c1910b6a2b0fe151283f8d64f3d1e1d11a97cf3085d128 | 22,633 | [
-1
] |
22,634 | persistent-hash-map-overflow-node.lisp | persidastricl_persidastricl/src/node/persistent-hash-map-overflow-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; persistent-hash-map-overflow-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; persistent-hash-map-overflow-node
;;
;; -----
(define-immutable-class persistent-hash-map-overflow-node (hash-map-overflow-node) ())
(defmethod add ((node persistent-hash-map-overflow-node) entry &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(let ((key (key entry))
(value (value entry)))
(make-instance (type-of node) :hash (or (hash node) hash) :data (->> (data node)
(remove-if (lambda (e) (== (car e) key)))
(acons key value)))))
(defmethod remove ((node persistent-hash-map-overflow-node) key &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(make-instance (type-of node) :hash (or (hash node) hash) :data (remove-if (lambda (e) (== (car e) key)) (data node))))
| 1,361 | Common Lisp | .lisp | 33 | 35.212121 | 121 | 0.581694 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 1a5d9fa67a9bda63ccc2203df8ca9c69a46e98e76cacef1005a706ed064ba342 | 22,634 | [
-1
] |
22,635 | overflow-node.lisp | persidastricl_persidastricl/src/node/overflow-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; overflow-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; overflow-node
;;
;; base class for overflow nodes
;; -----
(defclass overflow-node (node)
((hash :reader hash :initarg :hash)
(data :reader data :initarg :data))
(:default-initargs :hash nil :data '()))
(defmethod sub-nodes ((node overflow-node))
(declare (ignore node))
'())
(defmethod single-value-node? ((node overflow-node))
(= (length (data node)) 1))
(defmethod nth-value ((node overflow-node) index)
(elt (data node) index))
(defmethod count ((node overflow-node))
(length (data node)))
| 965 | Common Lisp | .lisp | 36 | 25.111111 | 65 | 0.649294 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 61a1f90906df4ad04dd7e1a873677b1827069efdebb23af77e7a312f733ac213 | 22,635 | [
-1
] |
22,636 | bpvt-node.lisp | persidastricl_persidastricl/src/node/bpvt-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; bpvt-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defgeneric add-leaf-node (node leaf first-index-of-values))
(defgeneric get-leaf-node (node first-index-of-values))
(defgeneric remove-leaf-node (node first-index-of-values))
;; -----
;; bpvt-node
;;
;; base class for transient/persistent dynamic vector nodes
(defclass bpvt-node (node) ())
| 727 | Common Lisp | .lisp | 26 | 26.769231 | 65 | 0.670977 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 191040c14c2186d7dc0e0aaef391a8ba4e005af2e74f8895f4de217560df0afb | 22,636 | [
-1
] |
22,637 | persistent-vector-leaf-node.lisp | persidastricl_persidastricl/src/node/persistent-vector-leaf-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; persistent-vector-leaf-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
(define-immutable-class persistent-vector-leaf-node (vector-leaf-node) ()
(:default-initargs :level 0))
(defmethod cons (item (node persistent-vector-leaf-node))
(make-instance (type-of node) :level 0 :data (v:append (data node) item)))
(defmethod add ((node persistent-vector-leaf-node) item &key index)
(with-slots (data) node
(let ((i (b:bits index 0)))
(make-instance (type-of node) :level 0 :data (v:update (data node) i item)))))
(defmethod pop ((node persistent-vector-leaf-node))
(with-slots (data) node
(make-instance (type-of node) :level 0 :data (v:delete data (1- (length data))))))
(defmethod update-instance-for-different-class :before ((old transient-vector-leaf-node)
(new persistent-vector-leaf-node)
&key)
(slot-makunbound new 'data)
(slot-makunbound new 'level)
(with-slots (data level) old
(let ((size (length data)))
(setf (slot-value new 'data) (make-array size :initial-contents data))
(setf (slot-value new 'level) level))))
| 1,559 | Common Lisp | .lisp | 38 | 35.710526 | 89 | 0.629874 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 761d145b3e0ec283b3b4a8b010d81b11c9948f6add3d2fbfa489e1f200ec588f | 22,637 | [
-1
] |
22,638 | vector-node.lisp | persidastricl_persidastricl/src/node/vector-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; vector-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; vector-node
;;
;; base class for transient/persistent dynamic vector nodes
(defclass vector-node (bpvt-node)
((level :initarg :level :reader level)
(data :initarg :data :reader data))
(:default-initargs :data (make-array 0) :level 1))
(defmethod add ((node vector-node) item &key index)
(let ((i (b:bits index (level node))))
(add (elt (data node) i) item :index index)))
;; locate walks nodes based on level
;; recursive to level of leaf-node node (which then returns value)
(defmethod loc ((node vector-node) index &key default)
(let ((i (b:bits index (level node))))
(loc (elt (data node) i) index :default default)))
(defmethod count ((node vector-node))
(cl:length (data node)))
| 1,157 | Common Lisp | .lisp | 36 | 30.333333 | 66 | 0.66487 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f594da4c3a9bfb2b6834e58d9bfe8d76875ab00d1bb07d033b7b31d45624c8ee | 22,638 | [
-1
] |
22,639 | node.lisp | persidastricl_persidastricl/src/node/node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; base class for all node objects
;;
;; -----
(defgeneric ins (node position item))
(defgeneric upd (node position item))
(defgeneric del (node position))
(defgeneric nth-value (node index))
(defgeneric value-at (node position))
(defgeneric add (node item &rest args))
(defgeneric loc (node item &rest args))
(defgeneric remove (node item &rest args))
(defclass node () ())
(defun empty-overflow-node (node)
"create an overflow node for the type of node we are currently using xxxx-node --> xxx-overflow-node"
(labels ((replace* (s pattern replacement)
(cl-ppcre:regex-replace pattern s replacement :preserve-case t :simple-calls t)))
(-> (type-of node)
str
(replace* "(?i)node$" "overflow-node")
read-from-string
make-instance)))
(defun empty-node (node &key hash depth)
"given the current node and the context of the caller, determine if we
need a new node or a new overflow node (ie. the max depth has been
reached) "
(declare (ignore hash))
(let ((max-depth (floor (/ (h:size) b::*default-hash-slice-bit-size*))))
(if (< depth max-depth)
(empty node)
(empty-overflow-node node))))
| 1,609 | Common Lisp | .lisp | 49 | 30 | 103 | 0.663443 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 880cb3d3777ed067582af63803cb1f8008b63caddce24b27156fbba9b5c7d8ef | 22,639 | [
-1
] |
22,640 | hamt-node.lisp | persidastricl_persidastricl/src/node/hamt-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hamt-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; base class for all hamt node objects
;;
;; HAMT node that contains:
;;
;; a bitmap/data vector for data items (dmap/dvec)
;; a bitmap/data vector for subnodes (nmap/nvec)
;;
;; in the paper below explaining optimized HAMT structures, the vector
;; storing the data and the subnodes is a single vector and indexed
;; from both ends using two separate bitmaps. Alternatively, the
;; nodes here in this implementation uses two distinct vectors (one
;; for each bitmap and indexed normally from the left) elliminating
;; the need to do any special vector offset arithmetic to store the
;; subnode data from the opposite end of the single vector. No
;; evidence of improved or even equal efficiency is offered. It only
;; seemed to make sense and made things a bit easier (no pun
;; intended). Alternative implementations and benchmarking are
;; warranted.
;;
;; (see 'https://michael.steindorfer.name/publications/oopsla15.pdf')
;; -----
(defclass hamt-node (node)
((dmap :initarg :dmap :reader dmap)
(dvec :initarg :dvec :reader dvec)
(nmap :initarg :nmap :reader nmap)
(nvec :initarg :nvec :reader nvec))
(:default-initargs :dmap 0 :dvec (make-array 0) :nmap 0 :nvec (make-array 0)))
(defgeneric sub-nodes (node)
(:method ((node hamt-node)) (slot-value node 'nvec)))
(defgeneric single-value-node? (node)
(:method ((node hamt-node)) (and (= (logcount (slot-value node 'dmap)) 1)
(= (logcount (slot-value node 'nmap)) 0))))
(defmethod nth-value ((node hamt-node) index)
(elt (slot-value node 'dvec) index))
(defun nth-subnode (node index)
(elt (slot-value node 'nvec) index))
(defmethod value-at ((node hamt-node) position)
(with-slots (dmap) node
(when (b:set? position dmap)
(nth-value node (b:index position dmap)))))
(defun subnode-at (node position)
(with-slots (nmap) node
(when (b:set? position nmap)
(nth-subnode node (b:index position nmap)))))
(defgeneric single-remaining-data (node)
(:method ((node hamt-node)) (nth-value node 0)))
(defmethod count ((node hamt-node))
(logcount (slot-value node 'dmap)))
(defmethod empty? ((node hamt-node))
(and (zerop (logcount (slot-value node 'dmap)))
(zerop (logcount (slot-value node 'nmap)))))
| 2,696 | Common Lisp | .lisp | 70 | 35.985714 | 80 | 0.689629 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 22ebe6f0d4059560baa72ce39aeab8713c44b49753f9d31a7e1a2aed6fb03cb8 | 22,640 | [
-1
] |
22,641 | transient-hash-map-node.lisp | persidastricl_persidastricl/src/node/transient-hash-map-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; transient-hash-map.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; transient-hash-map-node
;;
;; -----
(defclass transient-hash-map-node (hash-map-node) ())
(defmethod ins ((node transient-hash-map-node) position (new-node transient-hash-map-node))
(with-slots (nmap nvec) node
(setf nmap (b:set position nmap))
(setf nvec (v:insert nvec (b:index position nmap) new-node)))
node)
(defmethod ins ((node transient-hash-map-node) position (new-node transient-hash-map-overflow-node))
(with-slots (nmap nvec) node
(setf nmap (b:set position nmap))
(setf nvec (v:insert nvec (b:index position nmap) new-node)))
node)
(defmethod ins ((node transient-hash-map-node) position (entry entry))
(with-slots (dmap dvec) node
(setf dmap (b:set position dmap))
(setf dvec (v:insert dvec (* (b:index position dmap) 2) (key entry) (value entry))))
node)
(defmethod upd ((node transient-hash-map-node) position (new-node transient-hash-map-node))
(with-slots (nmap nvec) node
(setf nvec (v:modify nvec (b:index position nmap) new-node)))
node)
(defmethod upd ((node transient-hash-map-node) position (new-node transient-hash-map-overflow-node))
(with-slots (nmap nvec) node
(setf nvec (v:modify nvec (b:index position nmap) new-node)))
node)
(defmethod upd ((node transient-hash-map-node) position (entry entry))
(with-slots (dmap dvec) node
(v:modify dvec (1+ (* (b:index position dmap) 2)) (value entry)))
node)
(defmethod del ((node transient-hash-map-node) position)
(with-slots (dmap dvec nmap nvec) node
(cond
((b:set? position dmap)
(setf dmap (b:clear position dmap))
(setf dvec (v:delete dvec (* (b:index position dmap) 2) 2)))
((b:set? position nmap)
(setf nmap (b:clear position nmap))
(setf nvec (v:delete nvec (b:index position nmap))))
(t (error "critical error: attempt to del position in transient-hash-map-node that is not set for either data or subnode!"))))
node)
| 2,374 | Common Lisp | .lisp | 61 | 35.836066 | 132 | 0.678261 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 62d61207d8ac665b61981fc362d963cdba5546cd5fe4f2011e81ec8fdda995ee | 22,641 | [
-1
] |
22,642 | hash-map-overflow-node.lisp | persidastricl_persidastricl/src/node/hash-map-overflow-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hash-map-overflow-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; hash-map-overflow-node
;;
;; -----
(defclass hash-map-overflow-node (overflow-node) ())
(defmethod nth-value ((node hash-map-overflow-node) index)
(let ((e (elt (data node) index)))
(map-entry (first e) (rest e))))
(defmethod single-remaining-data ((node hash-map-overflow-node))
(let ((target (first (data node))))
(map-entry (first target) (rest target))))
(defmethod loc ((node hash-map-overflow-node) key &key hash (default nil) &allow-other-keys)
(when (hash node) (assert (= (hash node) hash)))
(if-let ((target (cl:assoc key (data node) :test #'==)))
(rest target)
default))
| 1,067 | Common Lisp | .lisp | 34 | 29.470588 | 92 | 0.641326 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | d1621dd1a3a68386153f3ff674403f964d1dd661ca159b7806fae49c9c552407 | 22,642 | [
-1
] |
22,643 | transient-hash-set-node.lisp | persidastricl_persidastricl/src/node/transient-hash-set-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; transient-hash-set-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; transient-hash-set-node
;;
;; -----
(defclass transient-hash-set-node (hash-set-node) ())
(defmethod ins ((node transient-hash-set-node) position (new-node transient-hash-set-node))
(with-slots (nmap nvec) node
(setf nmap (b:set position nmap))
(setf nvec (v:insert nvec (b:index position nmap) new-node)))
node)
(defmethod ins ((node transient-hash-set-node) position (new-node transient-hash-set-overflow-node))
(with-slots (nmap nvec) node
(setf nmap (b:set position nmap))
(setf nvec (v:insert nvec (b:index position nmap) new-node)))
node)
(defmethod ins ((node transient-hash-set-node) position item)
(with-slots (dmap dvec) node
(setf dmap (b:set position dmap))
(setf dvec (v:insert dvec (b:index position dmap) item)))
node)
(defmethod upd ((node transient-hash-set-node) position (new-node transient-hash-set-node))
(with-slots (nmap nvec) node
(setf nvec (v:modify nvec (b:index position nmap) new-node)))
node)
(defmethod upd ((node transient-hash-set-node) position (new-node transient-hash-set-overflow-node))
(with-slots (nmap nvec) node
(setf nvec (v:modify nvec (b:index position nmap) new-node)))
node)
(defmethod upd ((node transient-hash-set-node) position item)
(with-slots (dmap dvec) node
(setf dvec (v:modify dvec (b:index position dmap) item)))
node)
(defmethod del ((node transient-hash-set-node) position)
(with-slots (dmap dvec nmap nvec) node
(cond
((b:set? position dmap)
(setf dmap (b:clear position dmap))
(setf dvec (v:delete dvec (b:index position dmap))))
((b:set? position nmap)
(setf nmap (b:clear position nmap))
(setf nvec (v:delete nvec (b:index position nmap))))
(t (error "critical error: attempt to del position in transient-hash-set-node that is not set for either data or subnode!"))))
node)
| 2,318 | Common Lisp | .lisp | 61 | 34.918033 | 132 | 0.684046 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 3adff3d00a76326ea54a3736e9c59fb556d253ca71397eb846bb3d95431e8ab9 | 22,643 | [
-1
] |
22,644 | hash-set-node.lisp | persidastricl_persidastricl/src/node/hash-set-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hash-set-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; hash-set-node
;;
;; mixin class for both persistent/transient *-hash-set-nodes
(defclass hash-set-node (hamt-node) ())
(defmethod add ((node hash-set-node) item &key hash depth)
(with-slots (dmap nmap) node
(let ((position (b:bits hash depth)))
(cond
;; do we have a node for this hash at this depth
((b:set? position nmap)
(let* ((sub-node (subnode-at node position))
(new-node (add sub-node item :hash hash :depth (1+ depth))))
(if (eq new-node sub-node)
node
(upd node position new-node))))
;; do we have data for this hash at this depth
((b:set? position dmap)
(let* ((current (value-at node position)))
;; do we have the same item?
(if (== item current)
node
(let ((new-node (-> (empty-node node :hash hash :depth depth)
(add current :hash (h:hash current) :depth (1+ depth))
(add item :hash hash :depth (1+ depth)))))
(-> node
(del position)
(ins position new-node))))))
;; no data, no node, so just add the item to this node
(t (ins node position item))))))
(defmethod loc ((node hash-set-node) item &key hash depth (default nil))
(with-slots (dmap nmap) node
(let ((position (b:bits hash depth)))
(cond
;; do we have a node for this hash at this depth
((b:set? position nmap)
(loc (subnode-at node position) item :hash hash :depth (1+ depth) :default default))
;; do we have data for this hash at this depth
((b:set? position dmap)
(let ((target (value-at node position)))
(if (== item target)
target
default)))
;; we got nothing
(t default)))))
(defmethod remove ((node hash-set-node) item &key hash depth)
(with-slots (dmap nmap) node
(let ((position (b:bits hash depth)))
(cond
;; do we have a node for this hash at this depth
((b:set? position nmap)
(let* ((sub-node (subnode-at node position))
(new-node (remove sub-node item :hash hash :depth (1+ depth))))
(if (single-value-node? new-node)
(let ((keep (single-remaining-data new-node)))
(-> node
(del position)
(ins position keep)))
(upd node position new-node))))
;; do we have data for this hash at this depth
((b:set? position dmap)
(let* ((current (value-at node position)))
(if (== item current)
(del node position)
node)))
;; we have nothing so return original node
(t node)))))
| 3,288 | Common Lisp | .lisp | 85 | 29.717647 | 93 | 0.542346 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 914f3628ccc710af756ed03f283aed2a7c4e8513543c47b6a3afc4b39525e2ee | 22,644 | [
-1
] |
22,645 | persistent-hash-set-node.lisp | persidastricl_persidastricl/src/node/persistent-hash-set-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; persistent-hash-set-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; persistent-hash-set-node
;;
;; -----
(define-immutable-class persistent-hash-set-node (hash-set-node) ())
(defmethod ins ((node persistent-hash-set-node) position (new-node persistent-hash-set-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap (b:set position nmap)
:nvec (v:insert nvec (b:index position nmap) new-node))))
(defmethod ins ((node persistent-hash-set-node) position (new-node persistent-hash-set-overflow-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap (b:set position nmap)
:nvec (v:insert nvec (b:index position nmap) new-node))))
(defmethod ins ((node persistent-hash-set-node) position value)
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap (b:set position dmap)
:dvec (v:insert dvec (b:index position dmap) value)
:nmap nmap
:nvec nvec)))
(defmethod upd ((node persistent-hash-set-node) position (new-node persistent-hash-set-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap nmap
:nvec (v:update nvec (b:index position nmap) new-node))))
(defmethod upd ((node persistent-hash-set-node) position (new-node persistent-hash-set-overflow-node))
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap nmap
:nvec (v:update nvec (b:index position nmap) new-node))))
(defmethod upd ((node persistent-hash-set-node) position value)
(with-slots (dmap dvec nmap nvec) node
(make-instance (type-of node) :dmap dmap
:dvec (v:update dvec (b:index position dmap) value)
:nmap nmap
:nvec nvec)))
(defmethod del ((node persistent-hash-set-node) position)
(with-slots (dmap dvec nmap nvec) node
(cond
((b:set? position dmap)
(make-instance (type-of node) :dmap (b:clear position dmap)
:dvec (v:delete dvec (b:index position dmap))
:nmap nmap
:nvec nvec))
((b:set? position nmap)
(make-instance (type-of node) :dmap dmap
:dvec dvec
:nmap (b:clear position nmap)
:nvec (v:delete nvec (b:index position nmap))))
(t (error "critical error: attempt to del position in persisetnt-hash-set-node that is not set for either data or subnode!")))))
| 3,551 | Common Lisp | .lisp | 73 | 35 | 134 | 0.537684 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 644e116b3ce53a7805b67a69683ec3820f54ba852edb1b80c7d0daa55bdd6878 | 22,645 | [
-1
] |
22,646 | transient-vector-node.lisp | persidastricl_persidastricl/src/node/transient-vector-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; transient-vector-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defclass transient-vector-node (vector-node) ()
(:default-initargs :data (make-array 32 :adjustable t :fill-pointer 0 :initial-element nil)))
(defmethod add-leaf-node ((node transient-vector-node) leaf first-index-of-values)
(with-slots (level data) node
(let ((i (b:bits first-index-of-values level))
(items-in-data (length data)))
(labels ((sub-node (idx)
(when (< idx items-in-data)
(elt data idx))))
(if (> level 1)
;; node of sub-nodes
(let ((sub-node (sub-node i)))
(if sub-node
;; have subnode for this level
(add-leaf-node sub-node leaf first-index-of-values)
;; no sub-node for this level (need to add one)
(let ((new-sub-node (make-instance (type-of node) :level (1- level))))
(assert (= i items-in-data))
(vector-push (add-leaf-node new-sub-node leaf first-index-of-values) data))))
;; level 1 node
(progn
(assert (= i items-in-data))
(vector-push leaf data))))))
node)
(defmethod get-leaf-node ((node transient-vector-node) first-index-of-values)
(with-slots (level data) node
(let ((i (b:bits first-index-of-values level))
(items-in-data (length data)))
(labels ((sub-node (idx)
(when (< idx items-in-data)
(elt data idx))))
(if (> level 1)
;; node of sub-nodes
(let ((sub-node (sub-node i)))
(if sub-node
;; have subnode for this level
(get-leaf-node sub-node first-index-of-values)
;; no sub-node for this level (should have one!)
(error "no subnode found when getting previous leaf node")))
;; level 1 node
(progn
(assert (= i (1- items-in-data)))
(elt data i)))))))
(defmethod remove-leaf-node ((node transient-vector-node) first-index-of-values)
(with-slots (level data) node
(let ((i (b:bits first-index-of-values level))
(items-in-data (length data)))
(labels ((sub-node (idx)
(when (< idx items-in-data)
(elt data idx))))
(if (> level 1)
;; node of sub-nodes
(let ((sub-node (sub-node i)))
(if sub-node
;; have subnode for this level
(let ((new-node (remove-leaf-node sub-node first-index-of-values)))
(when (empty? (data new-node))
(vector-pop data)))
;; no sub-node for this level (should have one!)
(error "no subnode found when removing previous leaf node")))
;; level 1 node
(progn
(assert (= i (1- items-in-data)))
(vector-pop data))))))
node)
| 3,391 | Common Lisp | .lisp | 83 | 30.481928 | 97 | 0.531799 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | b23afe09b2059439048b637abca668d68c4f46e07386dfc63ce2febf462f2d98 | 22,646 | [
-1
] |
22,647 | transient-hash-map-overflow-node.lisp | persidastricl_persidastricl/src/node/transient-hash-map-overflow-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; transient-hash-map-overflow-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; transient-hash-map-overflow-node
;;
;; -----
(defclass transient-hash-map-overflow-node (hash-map-overflow-node) ())
(defmethod add ((node transient-hash-map-overflow-node) entry &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(let ((key (key entry))
(value (value entry)))
(unless hash (setf (hash node) hash))
(setf (data node) (->> (data node)
(remove-if (lambda (e) (== (car e) key)))
(acons key value))))
node)
(defmethod remove ((node transient-hash-map-overflow-node) key &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(unless (hash node) (setf (hash node) hash))
(setf (data node) (remove-if (lambda (e) (== (car e) key)) (data data)))
node)
| 1,261 | Common Lisp | .lisp | 37 | 30.810811 | 91 | 0.617406 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 356841e59da1da161a7b46623fb06877dcba0acc2491e02a7bc5a65e8a4bf30e | 22,647 | [
-1
] |
22,648 | persistent-hash-set-overflow-node.lisp | persidastricl_persidastricl/src/node/persistent-hash-set-overflow-node.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; persistent-hash-set-overflow-node.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; persistent-hash-set-overflow-node
;;
;; -----
(define-immutable-class persistent-hash-set-overflow-node (hash-set-overflow-node) ())
(defmethod add ((node persistent-hash-set-overflow-node) item &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(make-instance (type-of node) :hash (or (hash node) hash) :data (adjoin item (data node) :test #'==)))
(defmethod remove ((node persistent-hash-set-overflow-node) item &key hash &allow-other-keys)
(when (hash node) (assert (eq (hash node) hash)))
(make-instance (type-of node) (or (hash node) hash) :data (remove-if (lambda (e) (== item e)) (data node))))
| 1,109 | Common Lisp | .lisp | 29 | 36.758621 | 110 | 0.663873 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | a3f0878bd95b421985ddb0034bb5b54577eee1419fc95c79db4424f143a0b218 | 22,648 | [
-1
] |
22,649 | bits.lisp | persidastricl_persidastricl/src/init/bits.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; bits.lisp
;;;
;;; bit operations needed for hamt/bpvt classes
;;;
;;; -----
(in-package #:bits)
(proclaim '(inline set? set clear bits below index))
(defun set? (bit-position bitmap)
"Is the `bit-position` bit on?"
(> (logand (ash 1 bit-position) bitmap) 0))
(defun set (bit-position bitmap)
"Set the `bit-position` bit `on`"
(logior (ash 1 bit-position) bitmap))
(defun clear (bit-position bitmap)
"Set the `bit-position` bit off"
(if (set? bit-position bitmap)
(logxor (ash 1 bit-position) bitmap)
bitmap))
(defparameter *default-hash-slice-bit-size* 5)
(defun bits (hash depth &optional (size *default-hash-slice-bit-size*))
"Given a `hash`, break the `hash` into `size` bit slices and return
the `size` bits at the `depth` slice"
(ldb (byte size (* size depth)) hash))
(defun below (bit-position bitmap)
"Return bitmap of all bits below `bit-position` (exclusive)"
(ldb (byte bit-position 0) bitmap))
(defun index (bit-position bitmap)
"Determine the number of `1` or `on` bits below
bit-position (exclusive) (which will be the index into the data array
of a bitmap-indexed-vector (biv) used in HAMT)"
(logcount (below bit-position bitmap)))
| 1,563 | Common Lisp | .lisp | 45 | 32.711111 | 71 | 0.687003 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | b6c57b72f56b7b465b3824b2504538b901181eda51a1702cb5b2b13482a566d9 | 22,649 | [
-1
] |
22,650 | hash.lisp | persidastricl_persidastricl/src/init/hash.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; hash.lisp
;;;
;;; -----
(in-package #:hash)
(defclass hasher ()
((size :initarg :size)
(fn :initarg :fn)))
(defgeneric do-hash (fn object &rest args)
(:method (fn (object t) &rest args) (apply fn object args)))
(defvar murmur32 (make-instance 'hasher
:size 32
:fn (lambda (obj &rest args)
(let ((cl-murmurhash:*hash-size* 32))
(apply #'do-hash #'cl-murmurhash:murmurhash obj args)))))
(defvar murmur128 (make-instance 'hasher
:size 128
:fn (lambda (obj &rest args)
(let ((cl-murmurhash:*hash-size* 128))
(apply #'do-hash #'cl-murmurhash:murmurhash obj args)))))
(defvar sip-hash64 (make-instance 'hasher
:size 64
:fn (lambda (obj &rest args)
(apply #'do-hash #'sip-hash:hash-64-4-8 (babel:string-to-octets (str obj)) 0 0 args))))
(defvar sip-hash128 (make-instance 'hasher
:size 128
:fn (lambda (obj &rest args)
(multiple-value-bind (lo hi) (apply
#'do-hash
#'sip-hash:hash-128-4-8
(babel:string-to-octets (str obj)) 0 0 args)
(+ (ash hi 64) lo)))))
(defparameter *default-hasher* murmur32)
(defun size ()
(slot-value *default-hasher* 'size))
(defgeneric hash (obj &optional hasher &rest args)
(:method ((obj t) &optional (hasher *default-hasher*) &rest args) (apply (slot-value hasher 'fn) obj args)))
;;
;; for testing overflow nodes
;;
(defvar constant5bit (make-instance 'hasher
:size 5
:fn (lambda (obj &rest args)
#b00001)))
| 2,601 | Common Lisp | .lisp | 57 | 28.842105 | 127 | 0.447472 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | bc045360917b15aabe5a0aff2a17743f1b778cbbd59c95413dd90e700964b892 | 22,650 | [
-1
] |
22,651 | vector.lisp | persidastricl_persidastricl/src/init/vector.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; vector.lisp
;;;
;;; vector operations for data vectors in the hamt bitmap-data classes
;;;
;;; -----
(in-package #:vector)
(defun append (v &rest items)
"non-destructively append `items` onto the end of vector `v`"
(let* ((n (length items))
(len (length v))
(new (make-array (+ len n))))
(loop for i from 0 below len
do
(setf (elt new i) (elt v i)))
(loop for i from len below (+ len n)
do
(setf (elt new i) (elt items (- i len))))
new))
(defun insert (v index &rest items)
"non-destructively insert `items` into a vector `v` at the given
`index`; elements after the inserted `items` at `index` are now shifted
by (length items)"
(let* ((n (length items))
(len (length v))
(new (make-array (+ len n))))
(loop for i from 0 below index
do
(setf (elt new i) (elt v i)))
(loop for i from index below (+ index n)
do
(setf (elt new i) (elt items (- i index))))
(loop for i from index below len
do
(setf (elt new (+ n i)) (elt v i)))
new))
(defun update (v index &rest items)
"non-destructively update a vector `v` at `index` with the new `items`"
(let ((len (length v)))
(assert (<= index (1- len)))
(let* ((n (length items))
(len (max len (+ index n)))
(new (make-array len)))
(loop for i from 0 below index
do
(setf (elt new i) (elt v i)))
(loop for i from index below (+ index n)
do
(setf (elt new i) (elt items (- i index))))
(loop for i from (+ index n) below len
do
(setf (elt new i) (elt v i)))
new)))
(defun delete (v index &optional (n 1))
"non-destructively delete from vector `v` at `index`, shifting all
elements after `index` by -1"
(let ((len (length v)))
(assert (<= index (1- len)))
(let* ((n (min n (- len index)))
(new (make-array (- len n))))
(loop for i from 0 below index
do
(setf (elt new i) (elt v i)))
(loop for i from (+ index n) below len
do
(setf (elt new (- i n)) (elt v i)))
new)))
;;
;; destructive update
;;
(defun modify (v index &rest items)
"destructively update a vector `v` at `index` with the new `items`"
(let ((n-items (length items)))
(assert (<= index (- (length v) n-items)))
(loop for i from 0 below n-items
do
(setf (elt v (+ index i)) (elt items i)))
v))
| 2,932 | Common Lisp | .lisp | 91 | 26.076923 | 73 | 0.548535 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 933549bf130a7922e230caaaa904af1132c8e0ff0246cb01e9112e5709dc3960 | 22,651 | [
-1
] |
22,652 | entry.lisp | persidastricl_persidastricl/src/init/entry.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; entry.lisp
;;;
;;; -----
(in-package #:persidastricl)
(proclaim '(inline map-entry key value ->vec ->list ->cons))
(defclass entry (collection)
((key :initarg :key :reader key)
(value :initarg :value :reader value :reader val)))
(defun map-entry (k v)
(make-instance 'entry :key k :value v))
(defmethod ->vec ((entry entry))
(persistent-vector (key entry) (value entry)))
(defmethod ->array ((entry entry))
(cl:vector (key entry) (value entry)))
(defmethod ->vector ((entry entry))
(->array entry))
(defmethod ->list ((entry entry))
(list (key entry) (value entry)))
(defmethod count ((entry entry))
(length (->list entry)))
(defmethod length ((entry entry))
(length (->list entry)))
(defmethod first ((entry entry))
(key entry))
(defmethod rest ((entry entry))
(list (value entry)))
(defmethod head ((entry entry))
(key entry))
(defmethod tail ((entry entry))
(list (value entry)))
(defmethod next ((entry entry))
(list (value entry)))
(defmethod seq ((entry entry))
(->list entry))
(defmethod ->cons ((entry entry))
(cons (key entry) (value entry)))
(defun pprint-map-entry (stream entry &rest other-args)
(declare (ignore other-args))
(pprint-logical-block (stream (->list entry) :prefix "[" :suffix "]")
(write (pprint-pop) :stream stream)
(write-char #\space stream)
(write (pprint-pop) :stream stream)))
(defmethod print-object ((obj entry) stream)
(if (eq 'persidastricl:syntax (named-readtables:readtable-name *readtable*))
(format stream "~/persidastricl::pprint-map-entry/" obj)
(format stream "(persidastricl::map-entry ~s ~s)" (key obj) (value obj))))
(set-pprint-dispatch 'entry 'pprint-map-entry)
(defmethod make-load-form ((obj entry) &optional env)
(declare (ignore env))
`(persidastricl::map-entry ,(key obj) ,(value obj)))
(defmethod cl-murmurhash:murmurhash ((object entry) &key (seed cl-murmurhash:*default-seed*) mix-only)
(cl-murmurhash:murmurhash (->list object) :seed seed :mix-only mix-only))
(defmethod compare ((e1 entry) (e2 entry))
(compare (->list e1) (->list e2)))
| 2,461 | Common Lisp | .lisp | 68 | 33.794118 | 102 | 0.678345 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | f53eaf01d2b9f83af71336f543ce624393e4153b67fc78e38fa6c209cbdaca16 | 22,652 | [
-1
] |
22,653 | equality.lisp | persidastricl_persidastricl/src/init/equality.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; equality.lisp
;;;
;;; -----
(in-package #:persidastricl)
;; -----
;; there is no defined notion of equality for CLOS objects in LISP
;; so here, we define what we think we need ourselves (subject to change, of course :-))
;;
(defun slot-values (obj)
(let ((_class (class-of obj)))
(cl:map
'list
(lambda (slot-def)
(c2mop:slot-value-using-class _class obj slot-def))
(c2mop:class-slots _class))))
(defgeneric == (obj1 obj2)
(:method ((obj1 (eql nil)) obj2) (eql obj2 nil))
(:method (obj1 (obj2 (eql nil))) (eql obj1 nil))
(:method (obj1 obj2) (equalp obj1 obj2)))
;; -----
;; equality of CLOS objects is defined here as:
;;
;; objects are 'equal'
;; IF
;; they are the same type of object
;; AND
;; they are EITHER
;; indeed the same object (at the same address)
;; OR
;; every slot defined for this class has `==` values
;;
(defmethod == ((obj1 standard-object) (obj2 standard-object))
(and (equalp (class-of obj1) (class-of obj2))
(or (eq obj1 obj2)
(every
(lambda (v1 v2)
(== v1 v2))
(slot-values obj1)
(slot-values obj2)))))
(defmethod == ((s1 string) (s2 string))
(string= s1 s2))
(defmethod == ((s1 character) (s2 character))
(char= s1 s2))
(defmethod == ((v1 sequence) (v2 sequence))
(cond
((and (dotted-pair? v1)
(dotted-pair? v2)) (and (== (car v1) (car v2))
(== (cdr v1) (cdr v2))))
((dotted-pair? v2) nil)
((dotted-pair? v1) nil)
((and (nil? v1) (nil? v2)) t)
((or (nil? v1) (nil? v2)) nil)
(t (or (eq v1 v2)
(and (== (cl:length v1) (cl:length v2))
(every
(lambda (e1 e2)
(== e1 e2))
v1
v2))))))
| 2,190 | Common Lisp | .lisp | 73 | 25.068493 | 89 | 0.554394 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | ac74fc272f045fc349edfb37995611ba7cd3881895f776bfe114cb6c99bdb0ad | 22,653 | [
-1
] |
22,654 | functions.lisp | persidastricl_persidastricl/src/init/functions.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; functions.lisp
;;;
;;; -----
(in-package #:persidastricl)
(proclaim '(inline nil? pos? neg? zero? even? odd? int? pos-int? neg-int? nat-int? inc dec fnil))
(defun nil? (x)
(null x))
(defun false? (x)
(null x))
(defun true? (x)
(not (false? x)))
(defun pos? (n)
(> n 0))
(defun neg? (n)
(< n 0))
(defun zero? (n)
(zerop n))
(defun even? (n)
(evenp n))
(defun odd? (n)
(oddp n))
(defun int? (n)
(integerp n))
(defun pos-int? (n)
(and (int? n)
(pos? n)))
(defun neg-int? (n)
(and (int? n)
(neg? n)))
(defun nat-int? (n)
(and (int? n)
(not (neg? n))))
(defun string? (s)
(stringp s))
(defun identical? (x y)
(eq x y))
(defun dotted-pair? (x)
(and (consp x)
(not (listp (cdr x)))))
(defun inc (n)
(1+ n))
(defun dec (n)
(1- n))
(defun quot (x y)
(truncate x y))
(defun fnil (f default)
(lambda (x &rest args)
(apply f (or x default) args)))
(defun ->fillable (array)
"non-destructively retuan a copy of a non-fillable array as a fillable array "
(let ((n (cl:length array)))
(make-array n :fill-pointer n :initial-contents array)))
(defun flatten (x)
"return list of all leaf nodes in x"
(labels ((flatten* (x acc)
(cond ((null x) acc)
((cl:atom x) (cons x acc))
(t (flatten* (first x) (flatten* (rest x) acc))))))
(flatten* x nil)))
(defun instance? (type object)
(typep object type))
(defun some? (x)
(not (nil? x)))
(defmacro alias (name fn)
`(setf (fdefinition ',name) #',fn))
(defgeneric to-string (obj)
(:method (obj) (format nil "~s" (or obj "")))
(:method ((obj (eql nil))) "")
(:method ((obj character)) (format nil "~a" (or obj "")))
(:method ((s string)) s))
(defun str (&rest things)
"take a list and concatenate the elements into a string"
(cl:reduce
#'(lambda (r &optional s)
(concatenate 'string r (to-string s)))
things
:initial-value ""))
(defun subs (s start &optional (end (cl:length s)))
(subseq s start end))
(defun comp (&rest functions)
(let ((fns (reverse functions)))
(lambda (&rest args)
(reduce
(lambda (current f)
(funcall f current))
(rest fns)
:initial-value (apply (first fns) args)))))
(defun partial (f &rest initial-args)
(lambda (&rest more-args)
(apply f (append initial-args more-args))))
(defun keyword (s)
(if (keywordp s) s
(let* ((s (str s))
(s (cond
((every (complement #'upper-case-p) s) (string-upcase s))
((every (complement #'lower-case-p) s) (string-downcase s))
(t s))))
(intern s "KEYWORD"))))
(defun name (sym)
(let ((s (symbol-name sym)))
(cond ((every (complement #'upper-case-p) s) (string-upcase s))
((every (complement #'lower-case-p) s) (string-downcase s))
(t s))))
(defun println (&rest args)
(format *standard-output* "~a~%" (apply #'str args)))
(defun newline ()
(format *standard-output* "~%"))
(defun println-str (&rest args)
(with-output-to-string (s)
(format s "~a" (apply #'str args))))
| 3,494 | Common Lisp | .lisp | 124 | 24.137097 | 97 | 0.584458 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 59a1179f8e75e1eeb5e1c55e03bffd4516485b85e20b213c1b2985438b891e52 | 22,654 | [
-1
] |
22,655 | methods.lisp | persidastricl_persidastricl/src/init/methods.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; methods.lisp
;;;
;;; generic functions
;;;
;;; -----
(in-package #:persidastricl)
(defgeneric empty (object)
(:documentation "return an empty data-object of the same type as the original object argument")
(:method ((lst list)) '())
(:method ((object t)) (make-instance (type-of object))))
(defgeneric empty? (thing)
(:method ((thing (eql nil))) t)
(:method ((a array)) (zerop (length a)))
(:method ((l list)) (zerop (length l))))
(labels
((count* (thing &optional (n 0))
(cond
((null thing) n)
((dotted-pair? thing) (+ n 2))
((null (seq thing)) n)
(:otherwise (count* (rest thing) (1+ n))))))
(defgeneric count (thing)
(:method (thing) (count* thing))
(:method ((ht hash-table)) (hash-table-count ht))))
(defgeneric length (thing)
(:method (thing) (cl:length thing))
(:method ((ht hash-table)) (hash-table-count ht)))
(defgeneric bounded-count (n thing))
(defgeneric cons (se1 se2)
(:method (se1 se2) (cl:cons se1 se2)))
(defgeneric first (thing)
(:method (thing) (cl:first thing))
(:method ((lst list)) (cl:first lst))
(:method ((seq sequence)) (first (coerce seq 'list))))
(defgeneric rest (thing)
(:method (thing) (cl:rest thing))
(:method ((lst list)) (cl:rest lst))
(:method ((seq sequence)) (rest (coerce seq 'list))))
(defgeneric second (thing)
(:method (thing) (first (rest thing))))
(defgeneric third (thing)
(:method (thing) (first (rest (rest thing)))))
(defgeneric nth (thing n &optional default)
(:method (thing n &optional (default nil)) (or (cl:nth n thing) default))
(:method ((l list) n &optional (default nil)) (or (cl:nth n l) default))
(:method ((s sequence) n &optional (default nil)) (nth (coerce s 'list) n default)))
(defgeneric next (thing)
(:method (thing) (cl:rest thing))
(:method ((lst list)) (cl:rest lst))
(:method ((seq sequence)) (rest (coerce seq 'list))))
(defgeneric last (thing)
(:method (thing) (cl:last thing))
(:method ((lst list)) (cl:last lst))
(:method ((seq sequence)) (cl:last (coerce seq 'list))))
(defgeneric butlast (thing &optional n)
(:method (thing &optional (n 1)) (cl:butlast thing n))
(:method ((lst list) &optional (n 1)) (cl:butlast lst n))
(:method ((seq sequence) &optional (n 1)) (cl:butlast (coerce seq 'list) n)))
(defgeneric head (obj)
(:method (obj) (first obj))
(:method ((seq sequence)) (first (coerce seq 'list))))
(defgeneric tail (obj)
(:method (obj) (rest obj))
(:method ((seq sequence)) (rest (coerce seq 'list))))
(defgeneric ->list (object)
(:method ((lst list)) lst)
(:method ((seq sequence)) (coerce seq 'list)))
(defmethod ->list ((ht hash-table))
(loop for v being each hash-values of ht using (hash-key k)
collect (list k (if (typep v 'hash-table) (->list v) v))))
(defgeneric ->array (object)
(:method (object) (make-array (length object) :initial-contents object))
(:method ((ht hash-table)) (make-array (length ht) :initial-contents (cl:map 'list #'cl:vector (->list ht)))))
(defgeneric ->vector (object)
(:method (object) (->array object)))
(defgeneric ->plist (object))
(defgeneric ->alist (object))
(defgeneric pop (target)
(:method ((lst list)) (cl:pop lst) lst)
(:method ((v array)) (if (array-has-fill-pointer-p v)
(progn (vector-pop v) v)
(pop (->fillable v)))))
(defgeneric peek (coll)
(:method ((lst list)) (first lst))
(:method ((v array)) (elt v (1- (length v)))))
| 3,859 | Common Lisp | .lisp | 99 | 35.626263 | 112 | 0.631297 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | efb6c9aee2a7d20d2c7066d3253deb2820c62cdb065c8f6976774402b5da13af | 22,655 | [
-1
] |
22,656 | compare.lisp | persidastricl_persidastricl/src/init/compare.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; compare.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defgeneric compare (item1 item2))
(defmethod compare ((n1 number) (n2 number))
(cond ((< n1 n2) -1)
((> n1 n2) 1)
(t 0)))
(defmethod compare ((c1 character) (c2 character))
(cond ((char< c1 c2) -1)
((char> c1 c2) 1)
(t 0)))
(defmethod compare ((s1 string) (s2 string))
(cond ((string< s1 s2) -1)
((string> s1 s2) 1)
(t 0)))
(defmethod compare ((l1 list) (l2 list))
(cond ((and (nil? l1) (nil? l2)) 0)
((nil? l1) -1)
((nil? l2) 1)
(t (let ((cf (compare (first l1) (first l2))))
(if (= 0 cf) (compare (rest l1) (rest l2)) cf)))))
(defmethod compare ((s1 sequence) (s2 sequence))
(compare (coerce s1 'list) (coerce s2 'list)))
(defmethod compare ((sym1 symbol) (sym2 symbol))
(compare (name sym1) (name sym2)))
| 1,245 | Common Lisp | .lisp | 41 | 26.780488 | 65 | 0.574895 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 08fdaf5e3edd13738a71e48a69914f398d32ed55a862a8d906b1ca947d86e87b | 22,656 | [
-1
] |
22,657 | macros.lisp | persidastricl_persidastricl/src/init/macros.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; macros.lisp
;;;
;;; -----
(in-package #:persidastricl)
(defmacro while (condition &rest body)
`(loop while ,condition
do (progn ,@body)))
(defmacro if-not (pred truthy &optional falsey)
`(if (not ,pred) ,truthy ,falsey ))
(defmacro when-not (pred &body body)
`(when (not ,pred)
,@body))
(defmacro if-let (bindings then &optional else)
(let ((binding (first bindings)))
(assert (= (length binding) 2))
(let ((var (elt binding 0))
(form (elt binding 1))
(temp (gensym)))
`(let ((,temp ,form))
(if ,temp
(let ((,var ,temp))
,then)
,else)))))
(defmacro when-let (bindings &body body)
(let ((binding (first bindings)))
(assert (= (length binding) 2))
(let ((var (elt binding 0))
(form (elt binding 1))
(temp (gensym)))
`(let ((,temp ,form))
(when ,temp
(let ((,var ,temp))
,@body))))))
(defmacro fn (name-or-args &rest args-and-or-body)
(if (not (listp name-or-args))
`(labels ((,name-or-args ,(first args-and-or-body) ,@(rest args-and-or-body)))
#',name-or-args)
`(lambda ,name-or-args
,@args-and-or-body)))
(defmacro comment (&body body)
(declare (ignore body)))
(defmacro def (name value &optional doc-string)
`(defparameter ,name ,value ,doc-string))
| 1,741 | Common Lisp | .lisp | 57 | 25.666667 | 84 | 0.580048 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 244a4c1d4651453503f7ec229539013342408033f9b902035b286b25ad62c761 | 22,657 | [
-1
] |
22,658 | atom.lisp | persidastricl_persidastricl/src/stm/atom.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -----
;;; -*- mode: Lisp; -*-
;;;
;;; atom.lisp
;;;
;;; -----
(in-package #:persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
;; -----
;; atom
;;
;; -----
(defclass atom (metadata)
((value :initarg :value :reader :value)
(watches :initarg :watches :reader :watches))
(:default-initargs :value nil :watches {}))
(defun atom (&optional value)
(make-instance 'atom :value value))
(defmethod cl-murmurhash:murmurhash ((object atom) &key (seed cl-murmurhash:*default-seed*) mix-only)
(cl-murmurhash:murmurhash (list "atom" (slot-value object 'value)) :seed seed :mix-only mix-only))
(defgeneric deref (thing)
(:method ((atom atom)) (slot-value atom 'value)))
(defun add-watch (atom k f)
(with-slots (watches) atom
(setf watches (assoc watches k f)))
atom)
(defun remove-watch (atom k)
(with-slots (watches) atom
(setf watches (dissoc watches k)))
atom)
(defun notify-watches (atom old-val new-val)
(with-slots (watches) atom
(let ((ks (->list (keys watches))))
(loop for k in ks
do (let ((f (get watches k)))
(when f (funcall f k atom old-val new-val)))))))
#+atomics-cas-slot-value
(defun reset! (atom new-value)
(let ((v (deref atom)))
(atomics:atomic-update
(slot-value atom 'value)
(lambda (v)
(declare (ignore v))
new-value))
(notify-watches atom v new-value))
new-value)
#+atomics-cas-slot-value
(defun swap! (atom fn &rest args)
(loop do (let* ((v (deref atom))
(nv (apply fn v args)))
(when (atomics:cas (slot-value atom 'value) v nv)
(notify-watches atom v nv)
(return nv)))))
;; -----
;; when `atomics:cas` not supported default to `setf` for now :-(
;; (not ideal ... we can do better; maybe our own CLOS style locks as in Keene eventually??))
;; -----
#-atomics-cas-slot-value
(defun reset! (atom new-value)
(let ((v (deref atom)))
(setf
(slot-value atom 'value)
new-value)
(notify-watches atom v new-value))
new-value)
#-atomics-cas-slot-value
(defun swap! (atom fn &rest args)
(let* ((v (deref atom))
(nv (apply fn v args)))
(setf (slot-value atom 'value) nv)
(notify-watches atom v nv)
nv))
(defmethod with-meta ((a atom) (meta hash-map))
(setf (slot-value a 'meta) meta)
a)
| 2,670 | Common Lisp | .lisp | 86 | 27.325581 | 101 | 0.632009 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | c076e01274887aa29e3ec6be6e598dc00c313ef5aaf4211916ca74eb7ba6c4f5 | 22,658 | [
-1
] |
22,659 | combinatorics.lisp | persidastricl_persidastricl/src/core/combinatorics.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; combinatorics.lisp
;;;
;;; -----
(in-package :combinatorics)
(named-readtables:in-readtable persidastricl:syntax)
(defun all-different? (items)
(apply #'distinct? (->list items)))
(defun less-than (a b)
(when (= -1 (compare a b)) t))
(defun index-combinations (n cnt)
(labels ((iter-comb (c j)
(labels ((iter* (c* j*)
(if (= j* 1)
[c* j*]
(iter* (assoc c* (dec j*) (dec (get c* j*))) (dec j*)))))
(if (> j n) nil
(let ((c (assoc c j (dec (get c j)))))
(if (< (get c j) j)
[c (inc j)]
(iter* c j))))))
(step* (c j)
(lseq (rseq (subvec c 1 (inc n)))
(let ((next-step (iter-comb c j)))
(when next-step (step* (get next-step 0) (get next-step 1)))))))
(let ((c (vec (cons nil (loop for j from 1 upto n collect (+ j cnt (- (inc n))))))))
(step* c 1))))
(defun distribute (m index total distribution already-distributed)
(labels ((distribute* (distribution index already-distributed)
(if (>= index (count m)) nil
(let* ((quantity-to-distribute (- total already-distributed))
(mi (get m index)))
(if (<= quantity-to-distribute mi)
(conj distribution [index quantity-to-distribute total])
(distribute* (conj distribution [index mi (+ already-distributed mi)])
(inc index)
(+ already-distributed mi)))))))
(distribute* distribution index already-distributed)))
(defun next-distribution (m total distribution)
(labels ((f (distribution)
(dlet (([index this-bucket this-and-to-the-left] (peek distribution))
(distribution (if (= this-bucket 1)
(pop distribution)
(conj (pop distribution)
[index (dec this-bucket) (dec this-and-to-the-left)]))))
(cond
((<= (- total (dec this-and-to-the-left)) (apply #'+ (->list (subvec m (inc index)))))
(distribute m (inc index) total distribution (dec this-and-to-the-left)))
((seq distribution) (f distribution))))))
(dlet (([index this-bucket this-and-to-the-left] (peek distribution)))
(cond
((< index (dec (count m)))
(if (= this-bucket 1)
(conj (pop distribution) [(inc index) 1 this-and-to-the-left])
(conj (pop distribution)
[index (dec this-bucket) (dec this-and-to-the-left)]
[(inc index) 1 this-and-to-the-left])))
((= this-bucket total) nil)
(t (f (pop distribution)))))))
(defun bounded-distributions (m n)
(labels ((step* (distribution)
(lseq distribution
(let ((next-step (next-distribution m n distribution)))
(when next-step
(step* next-step))))))
(step* (distribute m 0 n [] 0))))
(defun multi-comb (lst n)
(let* ((f (frequencies lst))
(v (vec (distinct lst)))
(m (mapv (lambda (i) (get f (get v i))) (range (count v))))
(qs (bounded-distributions m n)))
(map
(lambda (q)
(mapcat
(lambda (d)
(let ((index (get d 0))
(this-bucket (get d 1)))
(take this-bucket (repeat (get v index)))))
q))
qs)))
(defun combinations (items n)
(let ((v-items (vec (reverse (->list items)))))
(if (zero? n) (list ())
(let ((cnt (count items)))
(cond ((> n cnt) nil)
((= n 1) (map (lambda (item) (list item)) (distinct items)) )
((all-different? items) (if (= n cnt)
(list (->list items))
(map (lambda (c) (map (lambda (d) (get v-items d)) c)) (index-combinations n cnt))))
(t (multi-comb items n)))))))
(defun subsets (items)
(mapcat
(lambda (n)
(combinations items n))
(range (inc (count items)))))
(defun cartesian-product (&rest seqs)
(let ((v-original-seqs (vec seqs)))
(labels ((step* (v-seqs)
(labels ((increment (v-seqs)
(labels ((p (i vs)
(if (= i -1) nil
(let ((rst (next (get vs i))))
(if rst
(assoc vs i rst)
(p (dec i) (assoc vs i (get v-original-seqs i))))))))
(p (dec (count v-seqs)) v-seqs))))
(when v-seqs
(lseq (map #'first v-seqs) (step* (increment v-seqs)))))))
(when (every? #'seq seqs)
(step* v-original-seqs)))))
(defun selections (items n)
(apply #'cartesian-product (->list (take n (repeat items)))))
(defun iter-perm (v)
(let* ((len (count v))
(j (labels ((jl (i)
(cond
((= i -1) nil)
((< (get v i) (get v (inc i))) i)
(t (jl (dec i))))))
(jl (- len 2)))))
(when j
(let* ((vj (get v j))
(l (labels ((ll (i)
(if (< vj (get v i)) i (ll (dec i)))))
(ll (dec len)))))
(labels ((vl (v k l)
(if (< k l)
(vl (assoc v k (get v l) l (get v k)) (inc k) (dec l))
v)))
(vl (assoc v j (get v l) l vj) (inc j) (dec len)))))))
(defun vec-lex-permutations (v)
(when v (lseq v (vec-lex-permutations (iter-perm v)))))
(defun lex-permutations (c)
(let ((vec-sorted (vec (sort (->list c) #'less-than))))
(if (zero? (count vec-sorted))
(list [])
(vec-lex-permutations vec-sorted))))
(defun sorted-numbers? (s)
(and (every? #'numberp s)
(or (empty? s) (apply #'<= (->list s)))))
(defun multi-perm (l)
(let* ((f (frequencies l))
(v (vec (distinct l)))
(indices (mapcat
(lambda (i)
(take (get f (get v i)) (repeat i)))
(range (count v)))))
(map
(lambda (idxs)
(map
(lambda (idx)
(get v idx))
idxs))
(lex-permutations indices))))
(defun permutations (items)
(cond
((sorted-numbers? items) (lex-permutations items))
((all-different? items)
(let ((v (vec items)))
(map
(lambda (idxs)
(map
(lambda (idx)
(get v idx))
idxs))
(lex-permutations (range (count v))))))
(t (multi-perm items))))
(defun permuted-combinations (items n)
(->> (combinations items n)
(mapcat #'permutations)
concat))
(defun factorial (n)
(assert (and (integerp n) (not (neg? n))))
(labels ((fact* (n acc) (if (<= n 1) acc (fact* (dec n) (* acc n)))))
(fact* n 1)))
;;
;; see http://en.wikipedia.org/wiki/Factorial_number_system)
;;
(defun factorial-numbers (n)
(assert (and (integerp n) (not (neg? n))))
(labels ((digits (n d divisor)
(if (zero? n) d
(let ((q (quot n divisor))
(r (rem n divisor)))
(digits q (cons r d) (inc divisor))))))
(digits n '() 1)))
(defun remove-nth (l n)
(labels ((ll (l n acc)
(if (zero? n) (into acc (rest l))
(ll (rest l) (dec n) (conj acc (first l))))))
(ll l n [])))
(defun nth-permutation-distinct (l n)
(when (>= n (factorial (count l)))
(error "~a is too large. Input has only ~a permutations." n (factorial (count l))))
(let ((length (count l))
(fact-nums (factorial-numbers n)))
(labels ((perm* (indices l perm)
(if (empty? indices) perm
(let* ((i (first indices))
(item (nth l i)))
(perm* (rest indices) (remove-nth l i) (conj perm item))))))
(perm* (concat (take (- length (count fact-nums)) (repeat 0)) fact-nums) l []))))
(defun count-permutations-from-frequencies (freqs)
(let ((counts (vals freqs)))
(reduce
#'/
(map #'factorial counts)
:initial-value (factorial (apply #'+ (->list counts))))))
(defun count-permutations (l)
(if (all-different? l)
(factorial (count l))
(count-permutations-from-frequencies (frequencies l))))
(defun initial-perm-numbers (freqs)
(reductions
#'+
(map
(lambda (e)
(let ((k (key e))
(v (val e)))
(count-permutations-from-frequencies (assoc freqs k (dec v)))))
freqs)
:initial-value 0))
(defun index-remainder (perm-numbers n)
(labels ((ir* (pn index)
(if (and (<= (first pn) n)
(< n (second pn)))
[index (- n (first pn))]
(ir* (rest pn) (inc index)))))
(ir* perm-numbers 0)))
(defun dec-key (m k)
(if (= 1 (get m k))
(dissoc m k)
(update m k #'dec)))
(defun factorial-numbers-with-duplicates (n fr)
(labels ((digits* (n digits freqs)
(let ((skeys (sort (->list (keys freqs)) #'less-than)))
(if (zero? n) (into digits (take (apply #'+ (->list (vals freqs))) (repeat 0)))
(let* ((ir (index-remainder (initial-perm-numbers freqs) n))
(index (get ir 0))
(remainder (get ir 1)))
(digits* remainder
(conj digits index)
(let ((nth-key (nth skeys index))) (dec-key freqs nth-key))))))))
(digits* n [] fr)))
(defun nth-permutation-duplicates (l n)
(when (>= n (count-permutations l))
(error "~a is too large. Input has only ~a permutations." n (count-permutations l)))
(let ((f (frequencies l)))
(labels ((perm* (freqs indices perm)
(let ((skeys (sort (->list (keys freqs)) #'less-than)))
(if (empty? indices) perm
(let* ((i (first indices))
(item (nth skeys i)))
(perm* (dec-key freqs item)
(rest indices)
(conj perm item)))))))
(perm* f (factorial-numbers-with-duplicates n f) []))))
(defun nth-permutation (items n)
(if (sorted-numbers? items)
(if (all-different? items)
(nth-permutation-distinct items n)
(nth-permutation-duplicates items n))
(if (all-different? items)
(let ((v (vec items))
(perm-indices (nth-permutation-distinct (range (count items)) n)))
(vec (map (lambda (idx) (get v idx)) perm-indices)))
(let* ((v (vec (distinct items)))
(f (frequencies items))
(indices (mapcat (lambda (i) (take (get f (get v i)) (repeat i))) (range (count v)))))
(vec (map (lambda (idx) (get v idx)) (nth-permutation-duplicates indices n)))))))
(defun drop-permutations (items n)
(cond
((zero? n) (permutations items))
((= n (count-permutations items)) ())
(t (if (sorted-numbers? items)
(if (all-different? items)
(vec-lex-permutations (nth-permutation-distinct items n))
(vec-lex-permutations (nth-permutation-duplicates items n)))
(if (all-different? items)
(let ((v (vec items))
(perm-indices (nth-permutation-distinct (range (count items)) n)))
(map
(lambda (idxs)
(map
(lambda (idx)
(get v idx))
idxs))
(vec-lex-permutations perm-indices)))
(let* ((v (vec (distinct items)))
(f (frequencies items))
(indices (mapcat (lambda (i) (take (get f (get v i)) (repeat i))) (range (count v)))))
(map
(lambda (idxs)
(map
(lambda (idx)
(get v idx))
idxs))
(vec-lex-permutations (nth-permutation-duplicates indices n)))))))))
(defun n-take-k (n k)
(cond
((< k 0) 0)
((> k n) 0)
((zero? k) 1)
((= k 1) n)
((> k (quot n 2)) (n-take-k n (- n k)))
(t (/ (apply #'* (->list (range (inc (- n k)) (inc n))))
(apply #'* (->list (range 1 (inc k))))))))
(defun count-combinations-from-frequencies (freqs n)
(let* ((counts (vals freqs))
(sum (apply #'+ (->list counts))))
(cond
((zero? n) 1)
((= n 1) (count freqs))
((every? (lambda (i) (= i 1)) counts) (n-take-k (count freqs) n))
((> n sum) 0)
((= n sum) 1)
((= (count freqs) 1) 1)
(t (let ((new-freqs (dec-key freqs (first (keys freqs)))))
(+ (count-combinations-from-frequencies new-freqs (dec n))
(count-combinations-from-frequencies (dissoc freqs (first (keys freqs))) n)))))))
;;
;; TODO: figure out how to do the correct memoization (or the same effect) as in the original code
;;
(defun count-combinations (items n)
(if (all-different? items)
(n-take-k (count items) n)
(count-combinations-from-frequencies (frequencies items) n)))
(defun count-subsets (items)
(cond
((empty? items) 1)
((all-different? items) (expt 2 (count items)))
(t (apply #'+ (map (lambda (i) (count-combinations items i)) (range 0 (inc (count items))))))))
(defun nth-combination-distinct (items tt n)
(labels ((comb* (comb items tt n)
(if (or (zero? n) (empty? items)) (into comb (take tt items))
(let ((dc-dt (n-take-k (dec (count items)) (dec tt))))
(if (< n dc-dt)
(comb* (conj comb (first items)) (rest items) (dec tt) n)
(comb* comb (rest items) tt (- n dc-dt)))))))
(comb* [] items tt n)))
(defun nth-combination-freqs (freqs tt n)
(labels ((comb* (comb freqs tt n)
(let ((skeys (sort (->list (keys freqs)) #'less-than)))
(if (or (zero? n) (empty? freqs))
(into comb (take tt (mapcat
(lambda (freq)
(take (get freq 1) (repeat (get freq 0))))
(map (lambda (k) [k (get freqs k)]) skeys))))
(let* ((first-key (first skeys))
(remove-one-key (dec-key freqs first-key))
(dc-dt (count-combinations-from-frequencies remove-one-key (dec tt))))
(if (< n dc-dt)
(comb* (conj comb first-key) remove-one-key (dec tt) n)
(comb* comb (dissoc freqs first-key) tt (- n dc-dt))))))))
(comb* [] freqs tt n)))
(defun nth-combination (items tt n)
(when (>= n (count-combinations items tt))
(error "~a is too large. Input has only ~a permutations." n (count-combinations items tt)))
(if (all-different? items)
(nth-combination-distinct items tt n)
(let* ((v (vec (distinct items)))
(f (frequencies items))
(indices (mapcat (lambda (i) (take (get f (get v i)) (repeat i))) (range (count v)))))
(vec (map (lambda (idx) (get v idx)) (nth-combination-freqs (frequencies indices) tt n))))))
(defun nth-subset (items n)
(when (>= n (count-subsets items))
(error "~a is too large. Input has only ~a subsets." n (count-subsets items)))
(labels ((subset* (size n)
(let ((num-combinations (count-combinations items size)))
(if (< n num-combinations)
(nth-combination items size n)
(subset* (inc size) (- n num-combinations))))))
(subset* 0 n)))
(defun list-index (l item)
"The opposite of nth, i.e., from an item in a list, find the n"
(labels ((n* (ll n)
(assert (seq ll))
(if (== item (first ll)) n
(n* (rest ll) (inc n)))))
(n* l 0)))
(defun permutation-index-distinct (l)
(labels ((index* (ll index n)
(if (empty? ll) index
(index* (rest ll)
(+ index (* (factorial n) (list-index (sort (->list ll) #'less-than) (first ll))))
(dec n)))))
(index* l 0 (dec (count l)))))
(defun permutation-index-duplicates (l)
(labels ((index* (ll index freqs)
(let ((skeys (sort (->list (keys freqs)) #'less-than)))
(if (empty? ll) index
(index* (rest ll)
(reduce
#'+
(map
(lambda (k)
(count-permutations-from-frequencies (dec-key freqs k)))
(take-while (lambda (k) (neg? (compare k (first ll)))) skeys))
:initial-value index)
(dec-key freqs (first ll)))))))
(index* l 0 (frequencies l))))
(defun permutation-index (items)
"Input must be a sortable collection of items. Returns the n such that
(nth-permutation (sort items) n) is items."
(if (all-different? items)
(permutation-index-distinct items)
(permutation-index-duplicates items)))
| 18,046 | Common Lisp | .lisp | 420 | 31.009524 | 128 | 0.487569 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | a03081a179ee20b44f639e9ef899fb1d3ec3c561e4fe05e358e38e20ec9c6426 | 22,659 | [
-1
] |
22,660 | when-first.lisp | persidastricl_persidastricl/src/core/when-first.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; when-first.lisp
;;;
;;; -----
(in-package :persidastricl)
(named-readtables:in-readtable persidastricl:syntax)
(defmacro when-first (bindings &rest body)
(assert (and (= 1 (count bindings))
(= 2 (count (first bindings)))))
(dlet (([x xs] (first bindings)))
(let ((ss (gensym)))
`(let ((,ss (seq ,xs)))
(when ,ss
(let ((,x (first ,ss)))
,@body))))))
| 786 | Common Lisp | .lisp | 28 | 24.714286 | 65 | 0.579576 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 0d4c15f2d249a35d28f44c4e03af06c6d880c19ae9efdfd35f4184127a5dcc00 | 22,660 | [
-1
] |
22,661 | json.lisp | persidastricl_persidastricl/src/core/json.lisp | ;;; -----
;;;
;;; Copyright (c) 2019-2023 Michael D Pendergrass, pupcus.org
;;;
;;; This program and the accompanying materials are made
;;; available under the terms of the Eclipse Public License 2.0
;;; which is available at https://www.eclipse.org/legal/epl-2.0/
;;;
;;; SPDX-License-Identifier: EPL-2.0
;;;
;;; -----
;;; -------
;;; -*- mode: Lisp; -*-
;;;
;;; json.lisp --- still a [wip]
;;;
;;; -----
(in-package #:json)
(named-readtables:in-readtable persidastricl:syntax)
(labels ((dispatch (stream token)
(cond
((eq token :eof) nil)
((eq token :begin-object) (input-object stream))
((eq token :begin-array) (input-array stream))
(t token)))
(input-object (stream &optional (object {}))
(let ((k (json-streams:json-read stream)))
(cond
((eq k :end-object) object)
((string? k) (input-object stream (assoc object k (dispatch stream (json-streams:json-read stream)))))
(:otherwise (error "unexpected token when expected key for object")))))
(input-array (stream &optional (object []))
(let ((v (json-streams:json-read stream)))
(cond
((eq v :end-array) object)
(:otherwise (input-array stream (conj object (dispatch stream v))))))))
(defun json-stream (json &key close)
(json-streams:make-json-input-stream json :multiple t :close-stream close))
(defun json-seq (json)
(let* ((json (str:trim json))
(json (if (char= #\[ (first json)) (subseq (str:trim json) 1 (str:last-index-of json "]")) json)))
(labels ((json-seq* (js)
(let ((v (dispatch js (json-streams:json-read js))))
(when v (lseq v (json-seq* js))))))
(json-seq* (json-stream json)))))
(defun decode-string (json)
(let ((js (json-stream json)))
(dispatch js (json-streams:json-read js))))
(defun decode-file (filename)
(let ((js (json-stream (slurp filename) :close t)))
(dispatch js (json-streams:json-read js)))))
(defgeneric encode* (obj))
(defmethod encode* ((v t)) (json-streams:json-output-value v))
(defmethod encode* ((k symbol)) (json-streams:json-output-value (name k)))
(defmethod encode* ((s string)) (json-streams:json-output-value s))
(defmethod encode* ((ls p::lazy-sequence))
(encode* (->list ls)))
(defmethod encode* ((s sequence)) (json-streams:with-json-array (mapv #'encode* s)))
(defmethod encode* ((hm p::hash-map))
(json-streams:with-json-object
(reduce-kv
(lambda (_ k v)
(declare (ignore _))
(encode* k)
(encode* v))
hm
:initial-value nil)))
(defmethod encode* ((hs p::hash-set))
(json-streams:with-json-array (mapv #'encode* hs)))
(defmethod encode* ((v p::bpvt))
(json-streams:with-json-array (mapv #'encode* v)))
(defun encode (obj)
(json-streams:with-json-output (nil :key-encoder #'string-downcase)
(encode* obj)))
;;(encode {:a 1 :b 2})
;;(encode {:a 1 :b {:c #{1 2 3}}})
;;(encode (map (fn (k v) [k v]) (range 100) (range 100 200 1)))
;; (json-seq "{\"a\" : 1} \"test\" 1 2 3 {\"b\" : 5} ")
;; (encode (json-seq "[ {\"a\" : 1 } {\"b\" : 2 } \"test\" 1 2 3 {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } ]"))
;; (map #'walk:keywordize-keys (json-seq "[ {\"a\" : 1 } {\"b\" : 2 } \"test\" 1 2 3 {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } ]"))
;; {:b 1}
;; (json-seq "[ {\"a\" : 1 } {\"b\" : 2 } \"test\" 1 2 3 {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } ]")
;; (let* ((json "[ {\"a\" : 1 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } {\"b\" : 2 } ]")
;; (js (subseq json (inc (str:index-of json "\\\[")) (str:last-index-of json "]")))
;; )
;; js)
;; (walk:keywordize-keys (decode-file "scratch/colors.json"))
| 4,352 | Common Lisp | .lisp | 87 | 44.586207 | 310 | 0.500945 | persidastricl/persidastricl | 2 | 0 | 2 | EPL-2.0 | 9/19/2024, 11:28:00 AM (Europe/Amsterdam) | 2b5dd5a73565591ab449e6c680456684deebe900c5fae8828f002afed178156e | 22,661 | [
-1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.