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
sequencelengths
1
47
40,917
region.lisp
foggynight_gravedigger/src/region.lisp
(in-package #:gravedigger) (defstruct region "Region structure representing a region of a dungeon, used to divide a dungeon into regions and sub-regions. Top-left and bottom-right refer to the corresponding corner tiles of the region, and are represented by a cons containing a y-x pair of coordinates." (top-left '(0 . 0) :type cons) (bottom-right '(0 . 0) :type cons)) (defun region-top-left-y (region) "Get the y coordinate of the top-left corner tile of a region." (car (region-top-left region))) (defun region-top-left-x (region) "Get the x coordinate of the top-left corner tile of a region." (cdr (region-top-left region))) (defun region-bottom-right-y (region) "Get the y coordinate of the bottom-right corner tile of a region." (car (region-bottom-right region))) (defun region-bottom-right-x (region) "Get the x coordinate of the bottom-right corner tile of a region." (cdr (region-bottom-right region))) (defun region-height (region) "Get the height of a region." (1+ (- (region-bottom-right-y region) (region-top-left-y region)))) (defun region-width (region) "Get the width of a region." (1+ (- (region-bottom-right-x region) (region-top-left-x region)))) (defun region-squareness (region) "Get the squareness of a region, where squareness refers to how similar the height and width of a region are and is represented by a number: - = 0: height = width - < 0: height < width - > 0: height > width" (flet ((mean (a b) (/ (+ a b) 2))) (let ((h (region-height region)) (w (region-width region))) (/ (- h w) (mean h w))))) (defun verify-region (region) "Verify that a region is valid, i.e. are the coordinates of the top-left corner tile less-than or equal-to the coordinates of the bottom-right corner tile. Returns nil if the region is invalid, otherwise returns the region." (if (or (null region) (> (region-top-left-y region) (region-bottom-right-y region)) (> (region-top-left-x region) (region-bottom-right-x region))) nil region)) (defun verify-sub-region (region sub-region) "Verify that a sub-region is a valid sub-region of another region, i.e. does the sub-region lie completely within the other region. This function expects that the other region has already been verified to be a valid region. Returns nil if the sub-region is invalid, otherwise returns the sub-region." (if (or (null sub-region) (< (region-top-left-y sub-region) (region-top-left-y region)) (< (region-top-left-x sub-region) (region-top-left-x region)) (> (region-bottom-right-y sub-region) (region-bottom-right-y region)) (> (region-bottom-right-x sub-region) (region-bottom-right-x region)) (> (region-top-left-y sub-region) (region-bottom-right-y region)) (> (region-top-left-x sub-region) (region-bottom-right-x region)) (< (region-bottom-right-y sub-region) (region-top-left-y region)) (< (region-bottom-right-x sub-region) (region-top-left-x region))) nil sub-region)) (defun split-region (region direction position) "Split a region into two sub-regions and return them as a cons pair. DIRECTION determines the direction along which to split the region: - 0 (horizontal): Split the region into top and bottom sub-regions - 1 (vertical): Split the region into left and right sub-regions POSITION refers to the position on which to split the region, x position for vertical, y position for horizontal, and is represented by a decimal number between 0 and 1, corresponding to the relative position within the region. Should the split result in one of the sub-regions being invalid, nil will be returned for that sub-region. This may cause the cons pair returned from this function to appear to be a list if it is the second sub-region which is invalid. e.g. (split-region (make-region :top-left '(0 . 0) :bottom-right '(3 . 3)) 0 0.25) => (#S(REGION :TOP-LEFT (0 . 0) :BOTTOM-RIGHT (0 . 3)) . #S(REGION :TOP-LEFT (1 . 0) :BOTTOM-RIGHT (3 . 3))) (split-region (make-region :top-left '(0 . 0) :bottom-right '(4 . 4)) 1 0.5) => (#S(REGION :TOP-LEFT (0 . 0) :BOTTOM-RIGHT (4 . 1)) . #S(REGION :TOP-LEFT (0 . 2) :BOTTOM-RIGHT (4 . 4))) (split-region (make-region :top-left '(0 . 0) :bottom-right '(3 . 3)) 0 0.0) => (NIL . #S(REGION :TOP-LEFT (0 . 0) :BOTTOM-RIGHT (3 . 3))) (split-region (make-region :top-left '(0 . 0) :bottom-right '(3 . 3)) 0 1.0) => (#S(REGION :TOP-LEFT (0 . 0) :BOTTOM-RIGHT (3 . 3)))" (unless (verify-region region) (error (format nil "Error: Invalid region: ~A" region))) (when (or (not (integerp direction)) (< direction 0) (> direction 1)) (error (format nil "Error: Invalid direction: ~A" direction))) (when (or (< position 0) (> position 1)) (error (format nil "Error: Invalid position: ~A" position))) (let ((first-bottom-right nil) (second-top-left nil)) (if (zerop direction) ;; Split horizontally (let ((height (1+ (- (region-bottom-right-y region) (region-top-left-y region))))) (setq first-bottom-right (cons (1- (+ (region-top-left-y region) (floor (* height position)))) (region-bottom-right-x region))) (setq second-top-left (cons (+ (region-top-left-y region) (floor (* height position))) (region-top-left-x region)))) ;; Split vertically (let ((width (1+ (- (region-bottom-right-x region) (region-top-left-x region))))) (setq first-bottom-right (cons (region-bottom-right-y region) (1- (+ (region-top-left-x region) (floor (* width position)))))) (setq second-top-left (cons (region-top-left-y region) (+ (region-top-left-x region) (floor (* width position))))))) (cons (verify-sub-region region (make-region :top-left (region-top-left region) :bottom-right first-bottom-right)) (verify-sub-region region (make-region :top-left second-top-left :bottom-right (region-bottom-right region))))))
6,478
Common Lisp
.lisp
123
44.691057
80
0.630606
foggynight/gravedigger
0
0
0
GPL-2.0
9/19/2024, 11:48:48 AM (Europe/Amsterdam)
8299470b5d9f904ceda53b8d74a8f8c5e5a2bc1407d94cd3e841be819f707b18
40,917
[ -1 ]
40,918
dungeon.lisp
foggynight_gravedigger/src/dungeon.lisp
(in-package #:gravedigger) (defparameter *default-dungeon-height* 22 "Default height of a dungeon in number of tiles.") (defparameter *default-dungeon-width* 80 "Default width of a dungeon in number of tiles.") (defstruct dungeon "Dungeon structure representing a dungeon in the world." (tiles #2A() :type simple-array)) (defmethod generate-dungeon ((type (eql :default)) &key (height *default-dungeon-height*) (width *default-dungeon-width*) (symbol *default-tile-symbol*)) "Generate a default dungeon." (make-dungeon :tiles (make-tile-array2 height width symbol))) (defun dungeon-height (dungeon) "Get the height of DUNGEON in number of tiles." (array-dimension (dungeon-tiles dungeon) 0)) (defun dungeon-width (dungeon) "Get the width of DUNGEON in number of tiles." (array-dimension (dungeon-tiles dungeon) 1)) (defun dungeon-region (dungeon) "Get the region covering DUNGEON." (make-region :top-left (cons 0 0) :bottom-right (cons (1- (dungeon-height dungeon)) (1- (dungeon-width dungeon))))) (defun print-dungeon (dungeon &optional (stream *standard-output*)) "Print the text representation of DUNGEON to STREAM." (let ((tiles (dungeon-tiles dungeon))) (fresh-line stream) (dotimes (y (array-dimension tiles 0)) (dotimes (x (array-dimension tiles 1)) (princ (tile-symbol (aref tiles y x)) stream)) (terpri stream)))) (flet ((fresh-char-set () (loop for i from 0 to 25 collect (code-char (+ i (char-code #\a)))))) (let ((char-set (fresh-char-set))) (defun set-dungeon-region-tile-symbol (dungeon region &optional symbol) "Set the tile symbol of the tiles within the given region of a dungeon. Should SYMBOL be omitted, a lowercase letter will be used instead. This letter is selected from the front of a set that initially contains the lowercase alphabet, the letters are removed upon selection, and the set is refilled when there are no remaining letters." (when (null symbol) (when (endp char-set) (setq char-set (fresh-char-set))) (setq symbol (car char-set)) (setq char-set (cdr char-set))) (loop for y from (region-top-left-y region) to (region-bottom-right-y region) do (loop for x from (region-top-left-x region) to (region-bottom-right-x region) do (setf (tile-symbol (aref (dungeon-tiles dungeon) y x)) symbol))))))
2,557
Common Lisp
.lisp
56
38.821429
78
0.663323
foggynight/gravedigger
0
0
0
GPL-2.0
9/19/2024, 11:48:48 AM (Europe/Amsterdam)
c46aa1e0bbb4495324b1950c1aef536339fb2cf4ecafa7e423f6a4a2d82ec745
40,918
[ -1 ]
40,919
main.lisp
foggynight_gravedigger/src/main.lisp
(in-package #:gravedigger) (setq *random-state* (make-random-state t)) (defun main () (print-dungeon (generate-dungeon :bsp-rooms)))
137
Common Lisp
.lisp
4
32.25
48
0.725191
foggynight/gravedigger
0
0
0
GPL-2.0
9/19/2024, 11:48:48 AM (Europe/Amsterdam)
7df7603eae92e8582f645b04abe6e1fd699622db08bbd51eef922e2e0696e80b
40,919
[ -1 ]
40,920
tile.lisp
foggynight_gravedigger/src/tile.lisp
(in-package #:gravedigger) (defparameter *default-tile-symbol* #\space) (defparameter *tile-type-symbol-alist* '((floor . #\.) (cwall . #\+) (hwall . #\-) (vwall . #\|) (stairs . #\%) (void . #\space)) "Alist of tile symbol and type pairs.") (defstruct tile "Tile structure representing a tile in a dungeon." (symbol *default-tile-symbol* :type standard-char)) (defun make-tile-list2 (height width &optional (symbol *default-tile-symbol*)) "Make a new list2 of tiles." (loop for y from 0 below height collect (loop for x from 0 below width collect (make-tile :symbol symbol)))) (defun make-tile-array2 (height width &optional (symbol *default-tile-symbol*)) "Make a new array2 of tiles." (make-array (list height width) :initial-contents (make-tile-list2 height width symbol))) (defun tile_type->symbol (type) "Get the symbol associated with a tile type." (cdr (assoc type *tile-type-symbol-alist*)))
997
Common Lisp
.lisp
25
35.28
79
0.664596
foggynight/gravedigger
0
0
0
GPL-2.0
9/19/2024, 11:48:48 AM (Europe/Amsterdam)
d9bfb217ce8785949673cb1c5fe0f98715047bb83d026ca555fcb9d8fc50e679
40,920
[ -1 ]
40,921
bsp-rooms.lisp
foggynight_gravedigger/src/bsp-rooms.lisp
;;;; Dungeon Generation using BSP Rooms ;; ;; Functions used to generate dungeons containing rooms connected by corridors ;; using the BSP (Binary Space Partitioning) Rooms algorithm. ;; ;; Reference: http://www.roguebasin.com/index.php?title=Basic_BSP_Dungeon_generation (in-package #:gravedigger) (defparameter *default-min-room-length* 5 "Default minimum height and width of a room. Three is the minimum sensible value as rooms must contain at least one walkable tile, and the walkable tiles must be surrounded by wall and door tiles.") (defparameter *default-max-room-length* 25 "Default maximum height and width of a room.") (defparameter *default-center-deviation* 0.25 "Default center deviation used to decide what position on which to split a region in GENERATE-BSP-ROOMS.") (defparameter *default-recursion-depth* 4 "Default recursion depth of GENERATE-BSP-ROOMS, determines how many levels of sub-regions to split the region covering a dungeon into.") (defparameter *default-squareness-threshold* 0.25 "Default squareness threshold used to decide what direction to split a region in GET-SPLIT-DIRECTION and GENERATE-BSP-ROOMS.") (defun get-random-room-dimensions (region &key (min-room-length *default-min-room-length*) (max-room-length *default-max-room-length*)) "Get the dimensions of a random room whose size is determined by the dimensions of REGION and the room length parameters. If no room can fit within REGION, this function returns NIL, otherwise, it returns a cons pair containing the height and width of a random room. For a room to fit within REGION, there must be a position within REGION where the room can be placed such that it lies completely within REGION, with a one-tile gap between the walls of the room and the edges of REGION." (let ((region-height (region-height region)) (region-width (region-width region))) (if (or (< (- region-height 2) min-room-length) (< (- region-width 2) min-room-length)) nil (cons (min (+ min-room-length (random (1+ (- (- region-height 2) min-room-length)))) max-room-length) (min (+ min-room-length (random (1+ (- (- region-width 2) min-room-length)))) max-room-length))))) (defun get-room-region (region room-dimensions &optional (random-placement nil)) "Get the region representing a room of size ROOM-DIMENSIONS placed in the center of REGION, this function assumes there is a valid position for the room to be placed within REGION. Should RANDOM-PLACEMENT be non-nil, the room region is randomly placed within REGION such that there is a one-tile gap between the walls of the room and the edges of REGION, instead of at REGION's center." (let ((offset-y nil) (offset-x nil)) (if random-placement (setq offset-y (1+ (random (1+ (- (- (region-height region) 2) (car room-dimensions))))) offset-x (1+ (random (1+ (- (- (region-width region) 2) (cdr room-dimensions)))))) (setq offset-y (floor (- (region-height region) (car room-dimensions)) 2) offset-x (floor (- (region-width region) (cdr room-dimensions)) 2))) (make-region :top-left (cons (+ (region-top-left-y region) offset-y) (+ (region-top-left-x region) offset-x)) :bottom-right (cons (+ (region-top-left-y region) offset-y (1- (car room-dimensions))) (+ (region-top-left-x region) offset-x (1- (cdr room-dimensions))))))) (defun add-room-tiles (dungeon room) "Add the floor and wall tiles of ROOM to DUNGEON." (let ((tly (region-top-left-y room)) (tlx (region-top-left-x room)) (bry (region-bottom-right-y room)) (brx (region-bottom-right-x room))) ;; Add corner tiles (setf (tile-symbol (aref (dungeon-tiles dungeon) tly tlx)) (tile_type->symbol 'cwall) (tile-symbol (aref (dungeon-tiles dungeon) tly brx)) (tile_type->symbol 'cwall) (tile-symbol (aref (dungeon-tiles dungeon) bry tlx)) (tile_type->symbol 'cwall) (tile-symbol (aref (dungeon-tiles dungeon) bry brx)) (tile_type->symbol 'cwall)) ;; Add left and right wall tiles (loop for y from (1+ tly) to (1- bry) do (setf (tile-symbol (aref (dungeon-tiles dungeon) y tlx)) (tile_type->symbol 'vwall) (tile-symbol (aref (dungeon-tiles dungeon) y brx)) (tile_type->symbol 'vwall))) ;; Add top and bottom wall tiles (loop for x from (1+ tlx) to (1- brx) do (setf (tile-symbol (aref (dungeon-tiles dungeon) tly x)) (tile_type->symbol 'hwall) (tile-symbol (aref (dungeon-tiles dungeon) bry x)) (tile_type->symbol 'hwall))) ;; Add floor tiles (loop for y from (1+ tly) to (1- bry) do (loop for x from (1+ tlx) to (1- brx) do (setf (tile-symbol (aref (dungeon-tiles dungeon) y x)) (tile_type->symbol 'floor)))))) (defun add-random-room (dungeon region &optional (random-placement nil)) "Add a random room to REGION. The room is of random size and is placed in the center of the region unless RANDOM-PLACEMENT is non-nil, in which case the room is placed at a random position within the region. This function must be called only once on a given region, as it does not check for other rooms, only for the boundaries of the region. If no room can fit within REGION, this function does nothing." (let ((room-dimensions (get-random-room-dimensions region))) (unless (null room-dimensions) (add-room-tiles dungeon (get-room-region region room-dimensions random-placement))))) (defun get-random-deviation (deviation) "Get a random value within the range: +/- DEVATION" (float (* deviation (/ (- (random 201) 100) 100)))) (defun get-random-center-deviation (deviation) "Get a random value within the range: 0.5 +/- DEVIATION" (+ 0.5 (get-random-deviation deviation))) (defun get-split-direction (region &optional (squareness-threshold *default-squareness-threshold*)) "Get a direction along which to split REGION based on its squareness. If the squareness of REGION is below SQUARENESS-THRESHOLD, the direction is chosen randomly, otherwise the chosen direction is that which splits the larger dimension of REGION. The direction is represented by a number: - 0 (horizontal): Split REGION into top and bottom sub-regions - 1 (vertical): Split REGION into left and right sub-regions" (let ((squareness (region-squareness region))) (if (< (abs squareness) squareness-threshold) (random 2) (if (> squareness 0) 0 1)))) ;; TODO Implement this (defun connect-region-pair (region-pair)) (defun generate-bsp-rooms (dungeon region recursion-depth center-deviation squareness-threshold) "Auxiliary function to GENERATE-BSP-ROOMS, should not be called on its own!" ;; Must check if the region is null and do nothing if so, as region splitting ;; in recursively higher level calls to GENERATE-BSP-ROOMS-AUX may result in ;; invalid regions should CENTER-DEVIATION be great enough. (unless (null region) (if (zerop recursion-depth) (add-random-room dungeon region) (let* ((position (get-random-center-deviation center-deviation)) (direction (get-split-direction region squareness-threshold)) (region-pair (split-region region direction position))) (generate-bsp-rooms dungeon (car region-pair) (1- recursion-depth) center-deviation squareness-threshold) (generate-bsp-rooms dungeon (cdr region-pair) (1- recursion-depth) center-deviation squareness-threshold) (connect-region-pair region-pair))))) (defmethod generate-dungeon ((type (eql :bsp-rooms)) &key (dungeon (generate-dungeon :default :symbol #\space)) (region (dungeon-region dungeon)) (recursion-depth *default-recursion-depth*) (center-deviation *default-center-deviation*) (squareness-threshold *default-squareness-threshold*)) "Generate a dungeon containing rooms connected by corridors using the BSP Rooms algorithm. Should a dungeon be passed to the DUNGEON key parameter, that dungeon will be modified instead of generating a new one. Should a region be passed to the REGION key parameter, only that region of the dungeon will be modified." (generate-bsp-rooms dungeon region recursion-depth center-deviation squareness-threshold) dungeon)
9,520
Common Lisp
.lisp
185
40.92973
84
0.62747
foggynight/gravedigger
0
0
0
GPL-2.0
9/19/2024, 11:48:48 AM (Europe/Amsterdam)
5639f5fbbaa96a4a45a33529b8b54079f57e2bf4f189c24117819756101bdc66
40,921
[ -1 ]
40,922
gravedigger.asd
foggynight_gravedigger/gravedigger.asd
(asdf:defsystem #:gravedigger :description "Procedural dungeon generator for rogue-likes and other tile-based games." :author "Robert Coffey" :license "GPLv2" :version "0.1.0" :pathname "src/" :serial t :components ((:file "package") (:file "tile") (:file "region") (:file "dungeon") (:file "bsp-rooms") (:file "main")))
415
Common Lisp
.asd
14
21.928571
70
0.565657
foggynight/gravedigger
0
0
0
GPL-2.0
9/19/2024, 11:48:48 AM (Europe/Amsterdam)
08d98d4d36767a24dbba973f4aa64a2b054ca06444964360f9f32661e2fdd522
40,922
[ -1 ]
40,943
binary-tree.lisp
foggynight_sylva/src/binary-tree.lisp
(in-package #:sylva) (defstruct (binary-tree (:include general-tree)) "BINARY-TREE struct representing a binary tree. That is, a tree with no constraints on the order of its nodes, but where each of its nodes have at most two children.") (defmethod %sexp->tree (sexp (tree-type (eql :binary-tree))) (%%sexp->tree sexp #'make-binary-tree)) (defun left (binary-tree) "Get the left sub-tree of BINARY-TREE." (first (binary-tree-children binary-tree))) (defun right (binary-tree) "Get the right sub-tree of BINARY-TREE." (second (binary-tree-children binary-tree))) (defmethod insert ((data binary-tree) (tree binary-tree)) "Insert DATA into TREE by performing a breadth-first search on TREE and adding DATA to the list of children of the first node encountered which has less than two children." (do ((queue (list tree) (reduce #'append (remove-if #'null (mapcar #'binary-tree-children queue)))) (found nil (dolist (node queue) (when (< (child-count node) 2) (add-child data node) (return t))))) (found))) (defmethod insert (data (tree binary-tree)) "Create a new BINARY-TREE with DATA as the value of its DATA slot, and insert it into TREE using the INSERT method." (insert (make-binary-tree :data data) tree)) (defun sorted? (binary-tree &key (test #'<=)) "Is BINARY-TREE sorted? BINARY-TREE is deemed to be sorted if any of the following conditions are met: - BINARY-TREE is not a struct of type BINARY-TREE - BINARY-TREE is a leaf node, that is, it has no children - The list resulting from an inorder traversal of BINARY-TREE is sorted The test used to determine if the list resulting from an inorder traversal of BINARY-TREE is sorted may be specified using the TEST key parameter." (flet ((sorted-list? (list) (every test list (rest list)))) (or (not (binary-tree-p binary-tree)) (leaf? binary-tree) (sorted-list? (traverse binary-tree :order :inorder)))))
2,114
Common Lisp
.lisp
45
40.355556
80
0.667476
foggynight/sylva
0
0
0
GPL-2.0
9/19/2024, 11:48:56 AM (Europe/Amsterdam)
a157dd8e047eee360a69de5547fbb99360599d59760b1168d605a4a11de5aef1
40,943
[ -1 ]
40,944
package.lisp
foggynight_sylva/src/package.lisp
(defpackage #:sylva (:documentation "Library for various types of trees with a unified interface in Common Lisp.") (:use #:cl) (:nicknames #:syl) (:export ;; general-tree.lisp #:sexp->tree #:tree->sexp #:equal? #:leaf? #:size #:empty? #:depth #:height #:traverse ;; binary-tree.lisp #:left #:right #:sorted? ))
367
Common Lisp
.lisp
21
13.809524
78
0.612245
foggynight/sylva
0
0
0
GPL-2.0
9/19/2024, 11:48:56 AM (Europe/Amsterdam)
62d8221f938e50c01548cb92df627fe66772d246ca46ae22bf2ee21c7225b2cd
40,944
[ -1 ]
40,945
general-tree.lisp
foggynight_sylva/src/general-tree.lisp
(in-package #:sylva) (defstruct general-tree "GENERAL-TREE struct representing a tree with no constraints on the order of its nodes, nor the number of children its nodes have." data (children nil :type list)) (defun %%sexp->tree (sexp constructor) (if (atom sexp) sexp (funcall constructor :data (first sexp) :children (mapcar (lambda (e) (%%sexp->tree e constructor)) (rest sexp))))) (defgeneric %sexp->tree (sexp tree-type)) (defmethod %sexp->tree (sexp (tree-type (eql :general-tree))) (%%sexp->tree sexp #'make-general-tree)) (defun sexp->tree (sexp &optional (tree-type :general-tree)) "Convert SEXP into a tree. The type of tree to convert SEXP into may be specified by passing a symbol naming the tree type to the TREE-TYPE parameter." (%sexp->tree sexp tree-type)) (defun tree->sexp (tree) "Convert TREE into a sexp." (if (general-tree-p tree) (cons (general-tree-data tree) (mapcar #'tree->sexp (general-tree-children tree))) tree)) (defun equal? (tree-0 tree-1 &key test) "Are two trees equal? The test function may be specified by passing a function to the TEST key parameter, the default test is the default test of TREE-EQUAL, which is EQL." (tree-equal (tree->sexp tree-0) (tree->sexp tree-1) :test test)) (defun size (tree) "Get the number of nodes in TREE." (if (general-tree-p tree) (1+ (reduce #'+ (mapcar #'size (general-tree-children tree)))) (if (null tree) 0 1))) (defun empty? (tree) "Is TREE empty?" (zerop (size tree))) (defun leaf? (tree) "Is TREE a leaf node?" (endp (general-tree-children tree))) (defun child-count (tree) "Get the number of children of TREE." (length (general-tree-children tree))) (defun add-child (child tree) "Add CHILD to the list of children of TREE, after converting it into the type of TREE." (setf (general-tree-children tree) (append (general-tree-children tree) (list child)))) (defun depth (tree root &optional (start 0)) "Get the depth of TREE relative to ROOT, where depth is defined as the number of branches between a node and the root of its containing tree." (if (eql tree root) start (if (and (general-tree-p root) (not (leaf? root))) (apply #'max (mapcar (lambda (e) (depth tree e (1+ start))) (general-tree-children root))) -1))) (defun height (tree &optional (start 0)) "Get the height of TREE, where height is defined as the depth of the deepest node in a tree." (if (and (general-tree-p tree) (not (leaf? tree))) (apply #'max (mapcar (lambda (e) (height e (1+ start))) (general-tree-children tree))) start)) (defgeneric insert (data tree) (:documentation "Insert DATA into TREE. If the type of DATA is not GENERAL-TREE or one of it's subtypes, DATA is converted into a GENERAL-TREE before inserting it.")) (defmethod insert ((data general-tree) (tree null)) "Return DATA." data) (defmethod insert (data (tree null)) "Return a new GENERAL-TREE with DATA as the value of its DATA slot." (make-general-tree :data data)) (defmethod insert ((data general-tree) (tree general-tree)) "Add DATA to the list of children of TREE." (add-child data tree)) (defmethod insert (data (tree general-tree)) "Create a new GENERAL-TREE with DATA as the value of its DATA slot, and insert it into TREE using the INSERT method." (insert (make-general-tree :data data) tree)) (defgeneric %traverse (tree order function)) (defmethod %traverse (tree (order (eql :preorder)) function) (if (general-tree-p tree) (cons (if function (funcall function (general-tree-data tree)) (general-tree-data tree)) (reduce #'append (mapcar (lambda (e) (%traverse e :preorder function)) (general-tree-children tree)))) (list (if function (funcall function tree) tree)))) (defmethod %traverse (tree (order (eql :postorder)) function) (if (general-tree-p tree) (append (reduce #'append (mapcar (lambda (e) (%traverse e :postorder function)) (general-tree-children tree))) (list (if function (funcall function (general-tree-data tree)) (general-tree-data tree)))) (list (if function (funcall function tree) tree)))) (defmethod %traverse (tree (order (eql :inorder)) function) (if (general-tree-p tree) (let* ((children (general-tree-children tree)) (center-index (ceiling (length children) 2))) (append (reduce #'append (mapcar (lambda (e) (%traverse e :inorder function)) (subseq children 0 center-index))) (list (if function (funcall function (general-tree-data tree)) (general-tree-data tree))) (reduce #'append (mapcar (lambda (e) (%traverse e :inorder function)) (subseq children center-index))))) (list (if function (funcall function tree) tree)))) (defun traverse (tree &key (order :preorder) function) "Traverse a tree and collect the data at each visited node in a list. The order of the traversal may be specified by passing a symbol naming the traversal order to the ORDER key parameter. A function may be passed to the FUNCTION key parameter, it will be called on each of the nodes in the tree by passing the data point of the node as the only argument to FUNCTION, its result taking the place of the node's data point in the list returned from this function." (%traverse tree order function))
6,017
Common Lisp
.lisp
138
35.449275
80
0.627585
foggynight/sylva
0
0
0
GPL-2.0
9/19/2024, 11:48:56 AM (Europe/Amsterdam)
8494895e2d01aa6990cf0e77e7418cf02a4f8554bdb4ac87e307d2d2eab55130
40,945
[ -1 ]
40,946
sylva.asd
foggynight_sylva/sylva.asd
(asdf:defsystem #:sylva :description "Library for various types of trees with a unified interface in Common Lisp." :author "Robert Coffey" :license "GPLv2" :version "0.1.0" :serial t :pathname "src/" :components ((:file "package") (:file "general-tree") (:file "binary-tree")))
325
Common Lisp
.asd
11
24.272727
78
0.639871
foggynight/sylva
0
0
0
GPL-2.0
9/19/2024, 11:48:56 AM (Europe/Amsterdam)
09ac9a062544a22966132f85a584042cb6d373b6ee519f88416927d91b722d89
40,946
[ -1 ]
40,966
polynomials.asd
Wafelack_polynomials/polynomials.asd
(defsystem "polynomials" :description "Common Lisp library to resolve quadratic polynomials." :version "0.1.0" :author "Wafelack <[email protected]>" :licence "LGPL-3.0-or-later" :components ((:file "polynomials")))
228
Common Lisp
.asd
6
35.333333
70
0.734234
Wafelack/polynomials
0
0
0
GPL-3.0
9/19/2024, 11:49:04 AM (Europe/Amsterdam)
f71208ad0f1bf695abc8ee6714e7ce8fad70c3a57c33830612887240f5512c24
40,966
[ -1 ]
40,983
murakami-nasako.lisp
goose121_murakami-nasako/murakami-nasako.lisp
(in-package #:murakami-nasako) (defvar *random*) (defmacro with-secure-random ((&optional (path #P"/dev/urandom")) &body body) (with-gensyms (random) `(let* ((,random (open ,path :element-type '(unsigned-byte 8) :if-does-not-exist :error)) (*random* ,random)) (unwind-protect (progn ,@body) (close ,random))))) (defun secure-random (limit) (multiple-value-bind (n-bytes n-top-bits) (ceiling (integer-length (- limit 1)) 8) (let ((bytes (make-array n-bytes :element-type '(unsigned-byte 8))) (rand-num 0)) (loop :do (assert (= (read-sequence bytes *random*) (length bytes))) (setf (aref bytes (- (length bytes) 1)) (ldb (byte (+ n-top-bits 8) 0) (aref bytes (- (length bytes) 1))) rand-num (reduce (lambda (b n) (+ (* 256 n) b)) bytes :from-end t :initial-value 0)) :when (< rand-num limit) :return rand-num)))) (defun test-random (limit n) (with-secure-random () (let ((arr (make-array limit :initial-element 0))) (loop :repeat n :do (incf (aref arr (secure-random limit)))) arr))) (defun binary-search (value array &optional (start 0) (end (length array))) (let ((low start) (high (1- end))) (do () ((< high low) (values low nil)) (let ((middle (floor (+ low high) 2))) (cond ((> (aref array middle) value) (setf high (1- middle))) ((< (aref array middle) value) (setf low (1+ middle))) (t (return (values middle t)))))))) ;; ;; Calculates the GCD of a and b based on the Extended Euclidean Algorithm. The function also returns ;; the Bézout coefficients s and t, such that gcd(a, b) = as + bt. ;; ;; The algorithm is described on page http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Iterative_method_2 ;; (defun egcd (a b) (do ((r (cons b a) (cons (- (cdr r) (* (car r) q)) (car r))) ; (r+1 r) i.e. the latest is first. (s (cons 0 1) (cons (- (cdr s) (* (car s) q)) (car s))) ; (s+1 s) (u (cons 1 0) (cons (- (cdr u) (* (car u) q)) (car u))) ; (t+1 t) (q nil)) ((zerop (car r)) (values (cdr r) (cdr s) (cdr u))) ; exit when r+1 = 0 and return r s t (setq q (floor (/ (cdr r) (car r)))))) ; inside loop; calculate the q ;; ;; Calculates the inverse module for a = 1 (mod m). ;; ;; Note: The inverse is only defined when a and m are coprimes, i.e. gcd(a, m) = 1.” ;; (defun invmod (a m) (multiple-value-bind (r s k) (egcd a m) (unless (= 1 r) (error "invmod: Values ~a and ~a are not coprimes." a m)) s)) (defun chinese-remainder (am) "Calculates the Chinese Remainder for the given set of integer modulo pairs. Note: All the ni and the N must be coprimes." (loop :for (a . m) :in am :with mtot = (reduce #'* (mapcar #'(lambda(X) (cdr X)) am)) :with sum = 0 :finally (return (mod sum mtot)) :do (incf sum (* a (invmod (/ mtot m) m) (/ mtot m))))) (defmacro auntil (condition &body body) `(do ((it (progn ,@body) (progn ,@body))) (,condition it))) (defun nshuffle (vec) (loop :for i :from (length vec) :downto 2 do (rotatef (aref vec (secure-random i)) (aref vec (1- i)))) vec) (defvar *s-p-q-random-amount* (expt 2 8) "The limit for the random numbers generated for s^(P) and s^(Q) in MAKE-KEY") (defclass key () (((key-length :initarg :key-length :accessor key-length) (sp :initarg :sp :accessor sp) (sq :initarg :sq :accessor sq) (h :initarg :h :accessor h) (l :initarg :l :accessor l) (p :initarg :p :accessor p) (q :initarg :q :accessor q) (permutation :initarg :permutation :accessor permutation) (public-key :initarg :public-key :accessor public-key)))) (defun make-key (n) (let ((u (floor n 2)) (s (make-array n)) (sp (make-array n)) (sq (make-array n)) (h (make-array n)) (l (make-array n)) (h-len 0) (l-len 0)) (loop :for i :from 0 :below n :do (cond ((= (secure-random 2) 0) (setf (aref h h-len) i) (incf h-len)) (t (setf (aref l l-len) i) (incf l-len)))) (let ((alpha-u+1 (binary-search (+ u 1) l 0 l-len)) (h-ind (- h-len 1)) (l-ind (- l-len 1)) (p 0) (q 0) (sp-sum 0) (sq-sum 0)) (loop :for i :from (- n 1) :downto u :for i-in-h-p := (cond ((= (aref h h-ind) i) ;; Avoid setting h-ind below 0 (setf h-ind (max 0 (- h-ind 1))) t) ((= (aref l l-ind) i) ;; Avoid setting l-ind below 0 (setf l-ind (max 0 (- l-ind 1))) nil) (t (error (format nil "Index ~A not in h or l" i)))) :for f-val := (- (binary-search i l 0 l-len) alpha-u+1) :do (setf (aref sp i) (ash (logior 1 (secure-random *s-p-q-random-amount*)) alpha-u+1) (aref sq i) (if i-in-h-p (+ (ash (+ 1 (secure-random *s-p-q-random-amount*)) f-val) ;; Must be greater than the sum of all sq so far (logand sq-sum (lognot (- (ash 1 f-val) 1)))) (ash (logior 1 (secure-random *s-p-q-random-amount*)) f-val))) (incf sp-sum (aref sp i)) (incf sq-sum (aref sq i))) (loop :for i :from (- u 1) :downto 0 :for i-in-h-p := (cond ((= (aref h h-ind) i) ;; Avoid setting h-ind below 0 (setf h-ind (max 0 (- h-ind 1))) t) ((= (aref l l-ind) i) ;; Avoid setting l-ind below 0 (setf l-ind (max 0 (- l-ind 1))) nil) (t (error (format nil "Index ~A not in h or l" i)))) :for f-val := (binary-search i l 0 l-len) :do (setf (aref sp i) (if i-in-h-p ;; Must also be greater than the sum of all sp so far (+ (ash (+ 1 (secure-random *s-p-q-random-amount*)) f-val) (logand sp-sum (lognot (- (ash 1 f-val) 1)))) (ash (logior 1 (secure-random *s-p-q-random-amount*)) f-val)) (aref sq i) (secure-random *s-p-q-random-amount*)) (incf sp-sum (aref sp i)) (incf sq-sum (aref sq i))) (setf (values p q) (loop :for p := (+ sp-sum (secure-random (ash 1 (+ (integer-length n) 50))) (ash 1 (+ (integer-length n) 20))) :for q := (+ sq-sum (secure-random (ash 1 (+ (integer-length n) 50))) (ash 1 (+ (integer-length n) 20))) :when (= (gcd p q) 1) :return (values p q))) (loop :for i :from 0 :below n :do (setf (aref s i) (chinese-remainder `((,(aref sp i) . ,p) (,(aref sq i) . ,q))))) (let ((perm (make-array n)) (public-key (make-array n))) (loop :for i :below n :do (setf (aref perm i) i)) (nshuffle perm) (loop :for i :below (length perm) :do (setf (aref public-key (aref perm i)) (aref s i))) (make-instance 'key :key-length n :sp sp :sq sq :h (subseq h 0 h-len) :l (subseq l 0 l-len) :p p :q q :permutation perm :public-key public-key))))) (defun encrypt (bits key) (assert (<= (length bits) (length key))) (loop :for bit :across bits :for elem :across key :summing (* bit elem))) (defun trailing-zeroes (n) (if (= n 0) 0 (loop :for i :upfrom 0 :when (logbitp i n) :return i))) (defun decrypt (c key) (with-slots (h l sp sq p q permutation key-length) key (let ((u (floor key-length 2)) (cp (mod c p)) (cq (mod c q)) (msg-hat (make-array key-length :element-type 'bit)) (msg (make-array key-length :element-type 'bit)) (h-ind 0) (l-ind 0)) (loop :for i :from 0 :below u :for i-in-h-p := (cond ((= (aref h h-ind) i) ;; Avoid setting h-ind outside h (setf h-ind (min (- (length h) 1) (+ h-ind 1))) t) ((= (aref l l-ind) i) ;; Avoid setting l-ind outside l (setf l-ind (min (- (length l) 1) (+ l-ind 1))) nil) (t (error (format nil "Index ~A not in h or l" i)))) :do (setf (sbit msg-hat i) (if i-in-h-p (if (>= cp (aref sp i)) 1 0) (if (= (trailing-zeroes cp) (trailing-zeroes (aref sp i))) 1 0)) cp (- cp (* (sbit msg-hat i) (aref sp i))) cq (- cq (* (sbit msg-hat i) (aref sq i))))) (loop :for i :from u :below key-length :for i-in-h-p := (cond ((= (aref h h-ind) i) ;; Avoid setting h-ind outside h (setf h-ind (min (- (length h) 1) (+ h-ind 1))) t) ((= (aref l l-ind) i) ;; Avoid setting l-ind outside l (setf l-ind (min (- (length l) 1) (+ l-ind 1))) nil) (t (error (format nil "Index ~A not in h or l" i)))) :do (setf (sbit msg-hat i) (if i-in-h-p (if (>= cq (aref sq i)) 1 0) (if (= (trailing-zeroes cq) (trailing-zeroes (aref sq i))) 1 0)) cp (- cp (* (sbit msg-hat i) (aref sp i))) cq (- cq (* (sbit msg-hat i) (aref sq i))))) (assert (= (mod cp p) (mod cq q) 0) () "Invalid ciphertext") (loop :for i :below (length permutation) :do (setf (sbit msg (aref permutation i)) (sbit msg-hat i))) msg)))
10,700
Common Lisp
.lisp
269
27.903346
114
0.45907
goose121/murakami-nasako
0
0
0
AGPL-3.0
9/19/2024, 11:49:04 AM (Europe/Amsterdam)
d87b8f4bd1ae60b7b95c0c2508a490b4347d8473c160779cbbbd5d8d6dcf4df0
40,983
[ -1 ]
40,984
murakami-nasako.asd
goose121_murakami-nasako/murakami-nasako.asd
;;;; murakami-nasako.asd (asdf:defsystem #:murakami-nasako :description "Implementation of Murakami and Nasako's knapsack cryptosystem" :author "goose121 <goose121@[email protected]>" :license "AGPLv3" :version "0.0.1" :serial t :depends-on ("alexandria") :components ((:file "package") (:file "murakami-nasako")))
360
Common Lisp
.asd
10
32
78
0.704871
goose121/murakami-nasako
0
0
0
AGPL-3.0
9/19/2024, 11:49:04 AM (Europe/Amsterdam)
be14e167fb512ad08b7be22f3532e2736c181a458f5cfa9bf1d6455d5cc65d3e
40,984
[ -1 ]
41,016
caraOuCoroa.lisp
teixeirazeus_Jogos-em-Lisp/caraOuCoroa.lisp
; Thiago S. Teixeira <[email protected]> (defun printNreturn (value) (format t value) value) (defun get-number () (let ((number (random 2 (make-random-state t)))) (if (= number 0) (printNreturn "Cara!") (printNreturn "Coroa!")))) (defun prompt () (format t "Digite cara ou coroa: ") (defvar chute (string-downcase (read))) (if (equal chute "cara") "Cara!" (if (equal chute "coroa") "Coroa!"))) (defun game () (if (string= (prompt) (get-number)) (format t "Você ganhou!") (format t "Você perdeu!"))) (game)
606
Common Lisp
.lisp
21
23.380952
52
0.583765
teixeirazeus/Jogos-em-Lisp
0
0
0
GPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
0b445586e3780f808ad4a24195a93255f50d6f6289a36b73bec07c9cbf1a49cf
41,016
[ -1 ]
41,017
pedraPapel.lisp
teixeirazeus_Jogos-em-Lisp/pedraPapel.lisp
; Thiago S. Teixeira <[email protected]> ; rock, paper and scissors (defun gen_choice () (let ((number (random 3 (make-random-state t)))) (cond ((= number 0) "pedra") ((= number 1) "papel") ((= number 2) "tesoura")))) (defun input(string) (format t string) (string-downcase (read))) (defun get_user_choice () (let ((choice (input "Escolha pedra, papel ou tesoura: "))) (cond ((string= choice "pedra") "pedra") ((string= choice "papel") "papel") ((string= choice "tesoura") "tesoura") (t (get_user_choice))))) (defun game() (defvar user_choice (get_user_choice)) (defvar robot_choice (gen_choice)) (format t "Usuario: ~A~%" user_choice) (format t "Robo: ~A~%" robot_choice) (format t "~A~%" (cond ((string= user_choice robot_choice) "Empate") ((or (and (string= user_choice "papel") (string= robot_choice "pedra")) (and (string= user_choice "pedra") (string= robot_choice "tesoura")) (and (string= user_choice "tesoura") (string= robot_choice "papel"))) "Você ganhou!") (t "Você perdeu!")))) (game)
1,144
Common Lisp
.lisp
27
36.185185
95
0.59586
teixeirazeus/Jogos-em-Lisp
0
0
0
GPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
f3171cf9035d66d19b7d8973aa500250b313d09515a73c5a6d0c2d8c98b53853
41,017
[ -1 ]
41,035
cliki-convert.lisp
ashok-khanna_cliki/cliki-convert/cliki-convert.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. ;;; WARNING! ;;; use "convmv -f latin1 -t utf8 --nosmart --replace --notest *" ;;; for prepare old cliki pages (in-package #:cliki2.converter) (defun convert-content (content) (flet ((fixup-tag (regex str fixup) (ppcre:regex-replace-all regex str (lambda (match register) (declare (ignore match)) (funcall fixup register)) :simple-calls t)) (fmt-category (category) (format nil "/(~A)" category)) (fmt-package (url) (format nil "_P(~A)" url)) (fmt-hyperspec (symbol) (format nil "_H(~A)" symbol))) (loop for regex in '(":\\(CLHS \"(.*?)\"\\)" ":\\(package \"(.*?)\"\\)" "/\\(\"(.*?)\".*?\\)") for action in (list #'fmt-hyperspec #'fmt-package #'fmt-category) do (setf content (fixup-tag regex content action))) (remove #\Return content))) (defstruct (edit (:type list)) date article-name author summary) (defun load-edits (old-article-dir) (with-open-file (s (merge-pathnames "admin/recent-changes.dat" old-article-dir) :external-format :latin1) (loop for x = (read s nil) while x collect x))) (defun edits-for-article (article-name edits) (remove-if (lambda (edit) (not (equal article-name (edit-article-name edit)))) edits)) (defun unknown-edit (date article-name) (list date article-name "no edit summary available" "import from CLiki")) (defun match-edits-to-files (article-name edits files) (let ((num-edits (length edits)) (num-files (length files)) (edits (let ((timestamp-skew 0)) (mapcar (lambda (edit) (cons (+ (edit-date edit) (incf timestamp-skew)) (cdr edit) )) edits)))) (cond ((> num-edits num-files) (subseq edits (- num-edits num-files))) ((= num-edits 0) (let ((timestamp-skew 0)) (loop for file in files collecting (unknown-edit (+ (incf timestamp-skew 60) (file-write-date file)) article-name)))) (t (let ((edit-date (edit-date (car edits)))) (append (reverse (loop repeat (- num-files num-edits) do (decf edit-date 60) collect (unknown-edit edit-date article-name))) edits)))))) (defun copy-revision-content (revision old-file) (let ((new-file (ensure-directories-exist (cliki2::revision-path revision)))) (alexandria:write-string-into-file (convert-content (alexandria:read-file-into-string old-file :external-format :latin1)) new-file :external-format :utf-8) (let ((unix-date (local-time:timestamp-to-unix (local-time:universal-to-timestamp (cliki2::revision-date revision))))) (sb-posix:utimes new-file unix-date unix-date))) revision) (defun import-revisions (article-title edits old-files) (loop for old-file in old-files for edit in edits collect (copy-revision-content (cliki2::make-revision :parent-title article-title :revision-date (edit-date edit) :summary (format nil "~@[~A ~]~@[(~A)~]" (hunchentoot:escape-for-html (edit-summary edit)) (edit-author edit)) :author-name "cliki-import" :author-ip "0.0.0.0") old-file))) (defun write-article (name revisions) (cliki2::write-to-file (cliki2::file-path 'cliki2::article name) (list name (reverse revisions)))) (defun decode-article-name (file-name) (cliki2::cut-whitespace (hunchentoot:url-decode (substitute #\% #\= file-name) hunchentoot::+latin-1+))) (defun load-old-articles (wiki-home old-article-dir) (let ((cliki2::*wiki* (cliki2::make-wiki-struct :home-directory wiki-home)) (old-articles (make-hash-table :test 'equalp)) ;; case insensitive (all-edits (load-edits old-article-dir))) (dolist (file (remove-if #'cl-fad:directory-pathname-p (cl-fad:list-directory old-article-dir))) (let ((article-name (decode-article-name (pathname-name file)))) (setf (gethash article-name old-articles) (merge 'list (gethash article-name old-articles) (list file) #'< :key (lambda (x) (parse-integer (or (pathname-type x) "0") :junk-allowed t)))))) (loop for article-title being the hash-key of old-articles for revision-paths being the hash-value of old-articles do (write-article article-title (import-revisions article-title (match-edits-to-files article-title (edits-for-article article-title all-edits) revision-paths) revision-paths))))) ;; (cliki2.converter::load-old-articles "/home/viper/tmp/cliki-converted/" "/home/viper/tmp/cliki-august/")
6,343
Common Lisp
.lisp
126
37.785714
107
0.566312
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
48c7234cf2a0294ded671865be8411b3c4b2441465b6f7a42f6dd8cc6d967004
41,035
[ -1 ]
41,036
markup.lisp
ashok-khanna_cliki/src/markup.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; Copyright 2012 Goheeca ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (sanitize:define-sanitize-mode +links-only+ :elements ("a") :attributes (("a" . ("href" "class"))) :protocols (("a" . (("href" . (:ftp :http :https :mailto :relative)))))) (sanitize:define-sanitize-mode +cliki-tags+ :elements ("a" "blockquote" "q" "dd" "dl" "dt" "h1" "h2" "h3" "h4" "h5" "h6" "hgroup" "pre" "code" "kbd" "samp" "cite" "var" "time" "figure" "figcaption" "img" "table" "caption" "tbody" "td" "tfoot" "th" "thead" "tr" "col" "colgroup" "ul" "ol" "li" "b" "em" "i" "small" "big" "tt" "strike" "strong" "dfn" "s" "sub" "sup" "u" "abbr" "ruby" "rp" "rt" "bdo" "mark" "br" "hr") :attributes ((:all . ("dir" "lang" "title" "class")) ("a" . ("href")) ("abbr" . ("title")) ("bdo" . ("dir")) ("blockquote" . ("cite")) ("col" . ("span" "width" "align" "valign")) ("colgroup" . ("span" "width" "align" "valign")) ("img" . ("align" "alt" "height" "src" "width")) ("ol" . ("start" "reversed" "type")) ("ul" . ("type")) ("code" . ("lang")) ("q" . ("cite")) ("table" . ("summary" "width")) ("td" . ("abbr" "axis" "colspan" "rowspan" "width")) ("th" . ("abbr" "axis" "colspan" "rowspan" "scope" "width"))) :protocols (("a" . (("href" . (:ftp :http :https :mailto :relative)))) ("blockquote" . (("cite" . (:http :https :relative)))) ("img" . (("src" . (:http :https :relative)))) ("q" . (("cite" . (:http :https :relative)))))) (defun generate-html-from-markup (markup) #H[<div id="article">] (let ((start 0) tag-start close-tag) (labels ((find-tag (tag start) (search tag markup :start2 start :test #'string-equal)) (find-next-tag (start) (let ((next-pre (find-tag "<pre>" start)) (next-code (find-tag "<code" start)) min) (when next-pre (setf close-tag "</pre>" min next-pre)) (when next-code (unless (and next-pre (< next-pre next-code)) (setf close-tag "</code>" min next-code))) min))) (loop while (setf tag-start (find-next-tag start)) do (write-string (parse-markup-fragment markup start tag-start) *html-stream*) (setf start (+ (length close-tag) (or (find-tag close-tag tag-start) (return)))) (write-string (funcall (if (equal close-tag "</pre>") #'escape-pre-block #'markup-code) markup tag-start start) *html-stream*))) (write-string (parse-markup-fragment markup start (length markup)) *html-stream*)) #H[</div>]) (defun parse-markup-fragment (markup start end) (ppcre:regex-replace-all "\\n\\n" (sanitize:clean (ppcre:regex-replace-all "< " (parse-cliki-markup (escape-parens-in-href-links markup start end)) "&lt; ") +cliki-tags+) "<p>")) (defun escape-pre-block (markup start end) (ppcre:regex-replace "<(?:PRE|pre)>((?:.|\\n)*?)</(?:PRE|pre)>" markup (lambda (match preformatted) (declare (ignore match)) #?[<pre>${(escape-for-html preformatted)}</pre>]) :simple-calls t :start start :end end)) (defun escape-parens-in-href-links (markup start end) (ppcre:regex-replace-all "(?:href|HREF)=\"[^\"]*\"" markup (lambda (match) (with-output-to-string (s) (loop for c across match do (princ (case c (#\( "%28") (#\) "%29") (t c)) s)))) :simple-calls t :start start :end end)) (defun parse-cliki-markup (markup) (ppcre:regex-replace-all "(_|\\*|/|_H|_P)\\(((?:\\\\\\)|[^\\)])*)\\)" markup (lambda (match prefix title) (declare (ignore match)) (with-output-to-string (*html-stream*) (funcall (cdr (assoc prefix '(("_" . pprint-article-underscore-link) ("*" . pprint-topic-link) ("/" . format-topic-list) ("_H" . format-hyperspec-link) ("_P" . format-package-link)) :test #'string=)) (ppcre:regex-replace-all "\\\\\\)" title ")")))) :simple-calls t)) (defun pprint-article-underscore-link (title) (destructuring-bind (&optional (real-title "") link-title) (ppcre:split "\\|" title) (%print-article-link real-title "internal" (or link-title real-title)))) (defun article-description (article-title) (let ((c (cached-content article-title))) (subseq c 0 (ppcre:scan "\\.(?:\\s|$)|\\n|$" c)))) (defun pprint-article-summary-li (article-title separator) #H[<li>] (pprint-article-link article-title) #H[ ${separator} ${(sanitize:clean (with-output-to-string (*html-stream*) (generate-html-from-markup (article-description article-title))) +links-only+)} </li>]) (defun format-topic-list (topic) ;; /( #H[<ul>] (dolist (article (articles-by-topic topic)) (pprint-article-summary-li article "-")) #H[</ul>]) (defun format-hyperspec-link (symbol) ;; _H( #H[<a href="${(clhs-lookup:spec-lookup symbol)}" class="hyperspec">${symbol}</a>]) (defun format-package-link (link) ;; _P( #H[<a href="${link}">ASDF-install package (obsolete) ${link}</a>]) (let ((supported-langs (sort (mapcar (lambda (x) (symbol-name (car x))) colorize::*coloring-types*) #'> :key #'length))) (defun markup-code (markup start end) (ppcre:regex-replace "<(?:CODE|code)(.*?)?>((?:.|\\n)*?)</(?:CODE|code)>" markup (lambda (match maybe-lang code) (declare (ignore match)) (let ((lang (loop for lang in supported-langs when (search lang maybe-lang :test #'char-equal) return (find-symbol lang :keyword)))) (if lang (let ((colorize::*css-background-class* "nonparen")) #?[<div class="code">${(colorize::html-colorization lang code)}</div>]) #?[<code>${(escape-for-html code)}</code>]))) :simple-calls t :start start :end end)))
7,925
Common Lisp
.lisp
168
35.642857
86
0.503942
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
e3c2c143b396bef7818365ba16895fb95361a8c1533a74f626c94758a107bee1
41,036
[ -1 ]
41,037
package.lisp
ashok-khanna_cliki/src/package.lisp
(in-package #:cl) (defpackage #:cliki2 (:use #:cl #:named-readtables #:anaphora #:uri-template #:hunchentoot #:bordeaux-threads) (:shadow #:session) (:export #:start-cliki-server))
196
Common Lisp
.lisp
6
29.166667
71
0.671958
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
40b0836a3e28ecc4e9197f8883e58e96f03caf90cf0f713284fa535751ed8300
41,037
[ -1 ]
41,038
html-rendering.lisp
ashok-khanna_cliki/src/html-rendering.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012, 2019 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defvar *title* "") (defvar *footer* "") (defvar *header* "") (defun render-header () #H[<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>${(format nil "~A~@[: ~A~]" (wiki-name *wiki*) *title*)}</title> ${*header*} <link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/colorize.css"> </head> <body> <span class="hidden">${ (wiki-name *wiki*) } - ${*title*}</span> <div id="content"><div id="content-area">]) (defun render-footer () #H[</div> <div id="footer" class="buttonbar"><ul>${*footer*}</ul></div> </div> <div id="header-buttons" class="buttonbar"> <ul> <li><a href="/">Home</a></li> <li><a href="$(#/site/recent-changes)">Recent Changes</a></li> <li><a href="/${(wiki-name *wiki*)}">About</a></li> <li><a href="/Text%20Formatting">Text Formatting</a></li> <li><a href="$(#/site/tools)">Tools</a></li> </ul> <div id="search"> <form action="$(#/site/search)"> <label for="search_query" class="hidden">Search ${(wiki-name *wiki*)}</label> <input type="text" name="query" id="search_query" value="${(escape-for-html (or (get-parameter "query") ""))}" /> <input type="submit" value="search" /> </form> </div> </div> <div id="pageheader"> <div id="header"> <span id="logo">${(wiki-name *wiki*)}</span> <span id="slogan">${(description *wiki*)}</span> <div id="login">] (if *account* #H[<div id="logout"> <span>${(account-link (account-name *account*))}</span> <div id="logout_button"><a href="$(#/site/logout)">Log out</a></div> </div>] #H[<form method="post" action="$(#/site/login)"> <label for="login_name" class="hidden">Account name</label> <input type="text" name="name" id="login_name" class="login_input" /> <label for= "login_password" class="hidden">Password</label> <input type="password" name="password" id="login_password" class="login_input" /> <input type="submit" name="login" value="login" id="login_submit" /><br /> <div id="register"><a href="$(#/site/register)">register</a></div> <input type="submit" name="reset-pw" value="reset password" id="reset_pw" /> </form>]) #H[ </div> </div> </div> </body></html>]) (defmacro render-page (title &body body) `(let* ((*header* *header*) (*footer* *footer*) (*title* *title*) ;; in case ,title does setf (*title* ,title) (body (with-output-to-string (*html-stream*) ,@body))) (with-output-to-string (*html-stream*) (render-header) (princ body *html-stream*) (render-footer))))
3,819
Common Lisp
.lisp
87
37.321839
121
0.594304
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
9e9d9c9f8930d049ccabf83b60233c4db242db9ede472e413a7a5fd78d0ee8f5
41,038
[ -1 ]
41,039
acceptor.lisp
ashok-khanna_cliki/src/acceptor.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2012, 2019 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (defvar *wiki*) (defvar *account* nil) (defclass cliki2-acceptor (easy-acceptor) ((dispatch-table :reader dispatch-table :initarg :dispatch-table) (wikis :reader wikis :initarg :wikis))) (defmethod acceptor-dispatch-request ((acceptor cliki2-acceptor) request) (let* ((host (subseq (host) 0 (or (position #\: (host)) (length (host))))) (*wiki* (cadr (assoc host (wikis acceptor) :test #'string=)))) (setf (header-out "Content-Security-Policy") "default-src 'none'; style-src 'self' 'unsafe-inline'; img-src *; form-action 'self';") (if *wiki* (let ((*account* (account-auth))) (loop for dispatcher in (dispatch-table acceptor) for action = (funcall dispatcher request) when action return (funcall action) finally (call-next-method))) (call-next-method))))
1,758
Common Lisp
.lisp
32
50.3125
97
0.69092
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
b0e82ff1293810f9911408b340d9bf5ce026a47d472952a2006f3f6d068fe7ec
41,039
[ -1 ]
41,040
article.lisp
ashok-khanna_cliki/src/article.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defun cut-whitespace (str) (string-trim #(#\Space #\Tab #\Newline #\Return) (ppcre:regex-replace-all "\\s+" str " "))) ;;; article (defstruct (article (:type list) (:conc-name nil)) article-title revisions) (defun deleted? (article) (equal "" (cached-content (article-title article)))) (defun article-link (x) (format nil "/~A" (uri-encode (cut-whitespace x)))) (defun latest-revision (article) (car (revisions article))) (defun %print-article-link (title class &optional (display-title title)) (let* ((article (find-article title)) (class (if (and article (not (deleted? article))) class "new"))) #H[<a href="${ (article-link title) }" class="${ class }">${ (escape-for-html display-title) }</a>])) (defun pprint-article-link (title) (%print-article-link title "internal")) (defun pprint-topic-link (title) (%print-article-link title "category")) ;;; revisions (defstruct (revision (:type list) (:conc-name nil)) parent-title revision-date summary UNUSED-revision-delete ;; here only to work w/old data format author-name author-ip) (defun add-revision (article content summary) (record-revision (make-revision :parent-title (article-title article) :revision-date (get-universal-time) :summary summary :author-name (if *account* (account-name *account*) (real-remote-addr)) :author-ip (real-remote-addr)) (string-trim #(#\Space #\Newline #\Tab) (remove #\Return content)))) (defun edit-link (revision text) #?[<a href="$(#/site/edit-article?title={ (parent-title revision) }&amp;from-revision={ (revision-date revision) })">${ text }</a>]) (defun article-footer (revision) (with-output-to-string (*html-stream*) (let ((title (parent-title revision))) #H[<li><a href="${ (article-link title) }">Current version</a></li> <li><a href="$(#/site/history?article={ title })">History</a></li> <li><a href="$(#/site/backlinks?article={ title })">Backlinks</a></li>] (unless (youre-banned?) #H[<li>${ (edit-link revision "Edit") }</li>] #H[<li><a href="$(#/site/edit-article?create=t)">Create</a></li>])))) (defun render-revision (revision &optional (content (revision-content revision))) (generate-html-from-markup content) (setf *footer* (article-footer revision))) (defun find-revision (article-title date-string) (find (parse-integer date-string) (revisions (find-article article-title :error t)) :key #'revision-date)) (defpage /site/view-revision () (article date) (let* ((revision (find-revision article date)) (revision-name #?"Revision ${ (rfc-1123-date (revision-date revision)) }")) (setf *title* #?"${ (escape-for-html article) } ${ revision-name }") #H[<div class="centered">${ revision-name }</div>] (render-revision revision))) (defun revision-link (revision) #/site/view-revision?article={ (parent-title revision) }&date={ (revision-date revision) }) (defun pprint-revision-link (revision) #H[<a class="internal" href="${ (revision-link revision) }">${ (rfc-1123-date (revision-date revision)) }</a>]) ;;; edit article (defun render-edit-article-common (title content summary &key edit-title error) (if edit-title #H[<span>Title: </span> <input type="text" name="title" size="50" value="${title}"/>] (progn (setf *title* #?"Editing ${title}") #H[<h1>Editing '${title}'</h1>] #H[<input type="hidden" name="title" value="${title}" />])) #H[<textarea rows="18" cols="80" name="content">${(escape-for-html content)}</textarea> <dl class="prefs"> <dt><label for="summary">Edit summary:</label></dt> <dd><input type="text" name="summary" size="50" value="${summary}" /></dd>] (unless *account* (maybe-show-form-error error t "Wrong captcha answer") (let ((captcha (make-captcha))) #H[<dt><label for="captcha">${captcha} is:</label></dt><dd>] (emit-captcha-inputs captcha "" 50) #H[</dd>])) #H[</dl> <input type="submit" value="Save" name="save" /> <input type="submit" value="Preview" name="preview" />] (when content #H[<h1>Article preview:</h1>] (generate-html-from-markup (remove #\Return content)))) (defpage /site/edit-article () (title content summary from-revision save create) (let ((maybe-article (find-article title))) #H[<form method="post" action="$(#/site/edit-article)">] (cond ((youre-banned?) (redirect #/)) (save (if (and (or *account* (check-captcha)) (< 0 (length (cut-whitespace title)))) (progn (add-revision (or maybe-article (wiki-new 'article (make-article :article-title (cut-whitespace title)))) content summary) (redirect (article-link title))) (render-edit-article-common title content summary :edit-title (not maybe-article) :error t))) (create (setf *title* "Create new article") (render-edit-article-common "" "" "created page" :edit-title t)) (t (render-edit-article-common title (cond (content content) (from-revision (revision-content (find-revision title from-revision))) (maybe-article (cached-content title)) (t "")) (if (and (not maybe-article) (not summary)) "created page" (or summary "")) :edit-title (not maybe-article)))) #H[</form>]))
6,873
Common Lisp
.lisp
146
38.910959
134
0.602271
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
1a13256d3d207474e7a9d9645ccd70bb9aed7a8bdfe951a4d643f24b9fdc07bb
41,040
[ -1 ]
41,041
tools.lisp
ashok-khanna_cliki/src/tools.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defpage /site/tools "Tools" () #H[<h2>Tools</h2> <ul> <li><a href="$(#/site/all-articles)">All articles</a></li> <li><a href="$(#/site/all-topics)">All topics</a></li> <li><a href="$(#/site/uncategorized)">Uncategorized articles</a></li> <li><a href="$(#/site/deleted-articles)">Deleted articles</a></li> <li><a href="$(#/site/blacklist)">Blacklist of users/IPs</a></li> </ul>]) (defpage /site/blacklist "Blacklist" () #H[<h3>Banned accounts/IPs</h3> <ul>] (dolist (banned (get-blacklist)) #H[<li>${ (account-link banned) }</li>]) #H[</ul>]) (defpage /site/all-articles "All articles" (start) (paginate-article-summaries start (get-all-articles (complement #'deleted?)))) (defpage /site/deleted-articles "Deleted articles" (start) (paginate-article-summaries start (get-all-articles #'deleted?))) (defpage /site/uncategorized "Uncategorized articles" (start) (paginate-article-summaries start (get-all-articles (lambda (article) (not (or (deleted? article) (topics (cached-content (article-title article))))))))) (defpage /site/all-topics "All topic markers" () #H[<ul>] (dolist (topic (sort (all-topics) #'string-lessp)) #H[<li>] (pprint-topic-link topic) #H[</li>]) #H[</ul>])
2,237
Common Lisp
.lisp
51
39.54902
72
0.672644
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
31d759f381a00238b118c10e0901ec07e287f34fc4f0eae2e392f56217e2cccf
41,041
[ -1 ]
41,042
authentication.lisp
ashok-khanna_cliki/src/authentication.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defstruct session account expires-at password-digest) (defun logout () (with-lock-held ((session-lock *wiki*)) (remhash (cookie-in "cliki2auth") (sessions *wiki*))) (set-cookie "cliki2auth" :value "" :path "/") nil) (defun expire-old-sessions (wiki) (with-lock-held ((session-lock wiki)) (loop for x being the hash-key of (sessions wiki) using (hash-value session) do (when (< (session-expires-at session) (get-universal-time)) (remhash x (sessions wiki)))))) (defun next-expiry-time () (+ (get-universal-time) (* 60 60 24 180))) (defun login (account) (let (secret) (with-lock-held ((session-lock *wiki*)) (loop while (gethash (setf secret (make-random-string 60)) (sessions *wiki*))) (setf (gethash secret (sessions *wiki*)) (make-session :account account :expires-at (next-expiry-time) :password-digest (account-password-digest account)))) (set-cookie "cliki2auth" :value secret :path "/" :expires (next-expiry-time)))) (defun account-auth () (let* ((secret (cookie-in "cliki2auth"))) (awhen (with-lock-held ((session-lock *wiki*)) (gethash secret (sessions *wiki*))) (if (and (< (get-universal-time) (session-expires-at it)) (string= (account-password-digest (session-account it)) (session-password-digest it))) (progn (setf (session-expires-at it) (next-expiry-time)) (session-account it)) (logout))))) ;;; captcha (defvar captcha-ops '(floor ceiling truncate round)) (defun make-captcha () (list (elt captcha-ops (random (length captcha-ops))) (- (random 40) 20) (1+ (random 10)))) (defun emit-captcha-inputs (captcha class size) #H[<input class="${class}" name="captcha-answer" size="${size}" /> <input type="hidden" name="captcha-op" value="${(elt captcha 0)}" /> <input type="hidden" name="captcha-x" value="${(elt captcha 1)}" /> <input type="hidden" name="captcha-y" value="${(elt captcha 2)}" />]) (defun check-captcha () (let ((x (parse-integer (parameter "captcha-x") :junk-allowed t)) (y (parse-integer (parameter "captcha-y") :junk-allowed t)) (answer (parse-integer (parameter "captcha-answer") :junk-allowed t)) (op (find (parameter "captcha-op") captcha-ops :key #'symbol-name :test #'string-equal))) (when (and op x y answer) (= (funcall op x y) answer))))
3,484
Common Lisp
.lisp
72
42.125
83
0.639282
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
3615ce47f2784fa929d72e8d1082d4a833888b37686e5b8f7e08a88c7d1ca89b
41,042
[ -1 ]
41,043
accounts.lisp
ashok-khanna_cliki/src/accounts.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; Copyright 2015 Goheeca ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defstruct (account (:type list)) name email password-salt password-digest (admin nil :type (member nil :administrator :moderator))) (defun account-link (account-name) #?[<a class="internal" href="${ #/site/account?name={account-name} }">${ account-name }</a>]) ;;; passwords (let ((kdf (ironclad:make-kdf 'ironclad:pbkdf2 :digest 'ironclad:sha256))) (defun password-digest (password salt) (ironclad:byte-array-to-hex-string (ironclad:derive-key kdf (flexi-streams:string-to-octets password :external-format :utf-8) (flexi-streams:string-to-octets salt :external-format :utf-8) 1000 128) :element-type 'character))) (let ((AN "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) (defun make-random-string (length) (map-into (make-string length) (lambda () (aref AN (random 62)))))) ;;; registration (defun maybe-show-form-error (error expected-error message) (when (equal error expected-error) #H[<div class="error-info">${ message }</div>])) (defpage /site/register "Register" (name email error) (if (or *account* (youre-banned?)) (redirect #/) (progn #H[ <div> <h3>Create account</h3> <form id="registration" class="prefs" method="post" action="$(#/site/do-register)"> <dl>] (maybe-show-form-error error "name" "Name required") (maybe-show-form-error error "nametaken" "An account with this name already exists") #H[<dt><label for="name">Name:</label></dt> <dd><input class="regin" name="name" size="30" value="${(if name name "")}" /></dd>] (maybe-show-form-error error "email" "Invalid email address") #H[<dt><label for="email">Email:</label></dt> <dd><input class="regin" name="email" size="30" value="${(if email email "")}" /></dd>] (maybe-show-form-error error "password" "Password too short") #H[<dt><label for="password">Password:</label></dt> <dd><input class="regin" name="password" type="password" size="30" /></dd>] (maybe-show-form-error error "captcha" "Wrong captcha answer") (let ((captcha (make-captcha))) #H[<dt><label for="captcha">${captcha} is:</label></dt><dd>] (emit-captcha-inputs captcha "regin" 30) #H[</dd>]) #H[<dt /><dd><input type="submit" value="Create account" /></dd> </dl> </form> </div>]))) (defun password? (pw) (and pw (not (< (length pw) 8)))) (defun email-address? (str) (and str (not (string= str "")))) (defun new-account (name email password) (let* ((salt (make-random-string 50)) (account (make-account :name name :email email :password-salt salt :password-digest (password-digest password salt)))) (wiki-new 'account account))) (defhandler /site/do-register (name email password) (let ((name (if name (escape-for-html name) ""))) (acond ((youre-banned?) #/) ((cond ((or (not name) (string= name "")) "name") ((find-account name) "nametaken") ((not (email-address? email)) "email") ((not (password? password)) "password") ((not (check-captcha)) "captcha")) #/site/register?name={name}&email={email}&error={it}) (t (login (new-account (cut-whitespace name) email password)) #/)))) ;;; password recovery (defun reset-password (account) (let ((salt (make-random-string 50)) (password (make-random-string 14))) (update-account account account-password-digest (password-digest password salt) account-password-salt salt) (cl-smtp:send-email "localhost" (password-reminder-email-address *wiki*) (account-email account) #?"Your new ${ (wiki-name *wiki*) } wiki password" #?"Someone (hopefully you) requested a password reset for a lost password on the ${ (wiki-name *wiki*) } wiki. Your new password is: ${ password }"))) (defpage /site/reset-ok "Password reset successfully" () #H[Password reset successfully. Check your inbox.]) ;;; login (defun check-password (password account) (and password (not (equal "" password)) (equal (account-password-digest account) (password-digest password (account-password-salt account))))) (defhandler /site/login (name password reset-pw) (let ((account (find-account name))) (cond (*account* (referer)) ((not account) #/site/cantfind?name={name}) (reset-pw (reset-password account) #/site/reset-ok) ((check-password password account) (login account) (referer)) (t #/site/invalid-login)))) (defpage /site/invalid-login "Invalid Login" () #H[Account name and/or password is incorrect]) (defpage /site/cantfind "Account does not exist" (name) #H[Account with name '${name}' doesn't exist]) (defpage /site/logout () () (logout) (redirect #/)) ;;; user page (defun youre-banned? () (or (and *account* (banned? (account-name *account*))) (banned? (real-remote-addr)))) (defpage /site/account #?"Account: ${name}" (name) (let ((account (find-account name)) (edits (edits-by-author name))) (if (or account edits) (progn #H[<h1>${name} account info page</h1>] (when *account* (flet ((ban (&key (un "")) (when (and (not (youre-banned?)) (account-admin *account*)) #H[<form method="post" action="$(#/site/{un}ban?name={name})"> <input type="submit" value="${un}ban" /> </form>]))) (cond ((equal name (account-name *account*)) #H[<a href="$(#/site/preferences)">Edit preferences</a>]) ((banned? name) #H[<em>banned user</em>] (ban :un "un")) (account (case (account-admin account) (:administrator #H[<em>Administrator</em>]) (:moderator #H[<em>Moderator</em>] (ban)) (t (ban) (when (account-admin *account*) #H[<br /> <form method="post" action="$(#/site/make-moderator?name={name})"> <input type="submit" value="Make moderator" /> </form>])))) (t (ban))))) #H[<br />User page: ] (pprint-article-link name) #H[<br />Edits by ${name}: <ul>] (map nil #'render-revision-summary (edits-by-author name)) #H[</ul>]) (redirect #/site/cantfind?name={name})))) ;;; user preferences (defpage /site/preferences-ok "Preferences updated" (what) #H[${what} updated successfully]) (defhandler /site/change-email (email password) (flet ((err (e) #/site/preferences?email={email}&error={e})) (cond ((not *account*) #/) ((not (email-address? email)) (err "email")) ((check-password password *account*) (update-account *account* account-email email) #/site/preferences-ok?what=Email) (t (err "pw"))))) (defhandler /site/change-password (new-password confirm-password password) (flet ((err (e) #/site/preferences?error={e})) (cond ((not *account*) #/) ((not (password? new-password)) (err "npw")) ((not (string= new-password confirm-password)) (err "cpw")) ((check-password password *account*) (let ((salt (make-random-string 50))) (update-account *account* account-password-digest (password-digest new-password salt) account-password-salt salt)) #/site/preferences-ok?what=Password) (t (err "opw"))))) (defpage /site/preferences "Account preferences" (email error) (if *account* (progn #H[<h3>Change account preferences</h3> <form id="changepassword" class="prefs" method="post" action="$(#/site/change-password)"> <fieldset class="prefs"> <legend>Password</legend> <dl>] (maybe-show-form-error error "npw" "Bad password") #H[<dt><label for="new-password">New password:</label></dt> <dd><input class="regin" type="password" name="new-password" title="new password" /></dd>] (maybe-show-form-error error "cpw" "Different passwords") #H[<dt><label for="confirm-password">Confirm password:</label></dt> <dd><input class="regin" type="password" name="confirm-password" title="confirm password" /></dd>] (maybe-show-form-error error "opw" "Wrong password") #H[<dt><label for="password">Old password:</label></dt> <dd><input class="regin" type="password" name="password" /></dd> <dt /><dd><input type="submit" value="change password" /></dd> </dl> </fieldset> </form>] #H[<form id="changemail" class="prefs" method="post" action="$(#/site/change-email)"> <fieldset class="prefs"> <legend>Email</legend> <dl>] (maybe-show-form-error error "email" "Bad email address") #H[<dt><label for="email">New email:</label></dt> <dd><input class="regin" type="text" name="email" title="new email" value="${(if email email "")}" /></dd>] (maybe-show-form-error error "pw" "Wrong password") #H[<dt><label for="password">Enter password:</label></dt> <dd><input class="regin" type="password" name="password" /></dd> <dt /><dd><input type="submit" value="change email" /></dd> </dl> </fieldset> </form>]) (redirect #/))) ;;; moderation (defmacro moderator-handler (uri &body actions) `(defhandler ,uri () (let ((name (cut-whitespace (get-parameter "name")))) (cond ((youre-banned?) #/) ((not (account-admin *account*)) (referer)) (t ,@actions))))) (moderator-handler /site/make-moderator (aif (find-account name) (progn (update-account it account-admin :moderator) (referer)) #/site/cantfind?name={name})) (moderator-handler /site/ban (unless (aand (find-account name) (eq (account-admin it) :administrator)) (update-blacklist name t)) (referer)) (moderator-handler /site/unban (update-blacklist name nil) (referer))
11,563
Common Lisp
.lisp
249
38.819277
110
0.589514
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
86c64944e77b2c8c85202778caf13581c961fa9fcf74309e9c54838d28c3d991
41,043
[ -1 ]
41,044
http-resource.lisp
ashok-khanna_cliki/src/http-resource.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (defmacro %defpage (page method parameters &body body) (let ((page-uri (symbol-name (if (listp page) (car page) page)))) `(progn (pushnew (list ,page-uri) %defined-uris :test #'equal) (define-easy-handler (,(if (listp page) (cadr page) page) :uri ,(string-downcase page-uri) :default-request-type ,method) ,parameters ,@body)))) (defmacro defpage (page title parameters &body body) `(%defpage ,page :both ,parameters (render-page ,title ,@body))) (defmacro defhandler (page parameters &body body) `(%defpage ,page :post ,(mapcar (lambda (p) (list p :request-type :both)) parameters) (redirect (or (progn ,@body) "/") :code 303)))
1,617
Common Lisp
.lisp
29
50.586207
140
0.688608
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
50ea1a1935d6640ce1ad6fbb1bac19b9d1cb5e861c994d3d34a2e352f8b21431
41,044
[ -1 ]
41,045
history.lisp
ashok-khanna_cliki/src/history.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defun output-undo-button (revision) (unless (youre-banned?) #H[<input type="hidden" name="undo-revision" value="${ (revision-date revision) }" /> (<input type="submit" name="undo" value="undo" class="undo" />)])) (defun output-compare-link (old new text) #H[(<a class="internal" href="$(#/site/compare-revisions?article={ (parent-title new) }&old={ (revision-date old) }&diff={ (revision-date new) })">${text}</a>)]) (defpage /site/history () (article) (let ((article-obj (find-article article :error t))) (setf *title* #?'History of article: "${ (article-title article-obj) }"' *header* #?[<link rel="alternate" type="application/atom+xml" title="article changes" href="$(#/site/feed/article.atom?title={ (article-title article-obj) })">] *footer* (article-footer (latest-revision article-obj))) #H[<h1>History of article ] (pprint-article-link article) #H[</h1> <a class="internal" href="$(#/site/feed/article.atom?title={ (article-title article-obj) })">ATOM feed</a> <form method="post" action="$(#/site/history-with-undo)"> <input type="hidden" name="article" value="${ article }" /> <input type="submit" value="Compare selected versions" /> <table id="pagehistory">] (loop for rhead on (revisions article-obj) for revision = (car rhead) for author = (author-name revision) for first = t then nil do (flet ((radio (x) #H[<td><input type="radio" name="${x}" value="${ (revision-date revision) }" /></td>])) #H[<tr><td>] (awhen (cadr rhead) (output-compare-link it revision "prev")) #H[</td>] (radio "old") (radio "diff") #H[<td>] (pprint-revision-link revision) #H[ ${ (account-link author) } (<em>${ (escape-for-html (summary revision)) }</em>) ] (when first (output-undo-button revision)) #H[</td></tr>])) #H[</table> <input type="submit" value="Compare selected versions" /> </form>])) ;;; undo (defpage /site/not-latest "Revision not the latest" (article) #H[Can't undo this revision because it is not the latest. <a href="$(#/site/history?article={article})">Go back to history page</a>.]) (defun undo-latest-revision (article) (let ((revision (first (revisions article))) (restored-revision (second (revisions article)))) (when restored-revision (add-revision article (revision-content restored-revision) #?"undid last revision by ${ (author-name revision) }")))) (defun undo-revision (article-title revision-date) (let ((revision (find-revision article-title revision-date)) (article-object (find-article article-title))) (if (eq revision (latest-revision article-object)) (progn (unless (youre-banned?) (undo-latest-revision article-object)) (article-link article-title)) #/site/not-latest?article={article-title}))) (defhandler /site/history-with-undo (article old diff undo undo-revision) (if undo (undo-revision article undo-revision) #/site/compare-revisions?article={article}&old={old}&diff={diff})) (defhandler /site/undo (article undo-revision) (undo-revision article undo-revision))
4,197
Common Lisp
.lisp
77
48.545455
170
0.656836
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
cc65778c2edd80892e30fe2351a458d0019b4f1b62b0dcf2835f424640f6e67e
41,045
[ -1 ]
41,046
recent-changes.lisp
ashok-khanna_cliki/src/recent-changes.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defun find-previous-revision (revision) (cadr (member revision (revisions (find-article (parent-title revision) :error t))))) (defun %render-revision-summary (revision) (pprint-revision-link revision) #H[ <a class="internal" href="${ (article-link (parent-title revision)) }">${ (escape-for-html (parent-title revision)) }</a> - ${ (escape-for-html (summary revision)) } ${ (account-link (author-name revision)) } ] (awhen (find-previous-revision revision) (output-compare-link it revision "diff"))) (defun render-revision-summary (revision) #H[<li>] (%render-revision-summary revision) #H[</li>]) (defpage /site/recent-changes "Recent Changes" () (setf *header* #?[<link rel="alternate" type="application/atom+xml" title="recent changes" href="$(#/site/feed/recent-changes.atom)">]) #H[<h1>Recent Changes</h1> <a class="internal" href="$(#/site/feed/recent-changes.atom)">ATOM feed</a> <ul>] (map nil #'render-revision-summary (get-recent-changes)) #H[</ul>]) ;;; feed (defun iso8601-time (time) (multiple-value-bind (second minute hour date month year) (decode-universal-time time 0) (format nil "~4,'0d-~2,'0d-~2,'0dT~2,'0d:~2,'0d:~2,'0dZ" year month date hour minute second))) (defun feed-doc (title link updated entries-body) (setf (content-type*) "application/atom+xml") (with-output-to-string (*html-stream*) #H[<?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>${title}</title> <link href="${ (escape-for-html link) }" /> <updated>${ (iso8601-time updated) }</updated>] (funcall entries-body) #H[</feed>])) (defun feed-format-content (revision) (escape-for-html (with-output-to-string (*html-stream*) (%render-revision-summary revision) (render-diff-table (find-previous-revision revision) revision nil)))) (defun feed-present-revision (revision) #H[<entry> <title>${ (parent-title revision) } - ${ (escape-for-html (summary revision)) } ${ (author-name revision) }</title> <link href="${ (escape-for-html (revision-link revision)) }" type="text/html" /> <updated>${ (iso8601-time (revision-date revision)) }</updated> <content type="html">${ (feed-format-content revision) }</content> </entry>]) (%defpage /site/feed/recent-changes.atom :get () (feed-doc #?"${(wiki-name *wiki*)} Recent Changes" #/site/feed/recent-changes.atom (revision-date (car (get-recent-changes))) (lambda () (map nil #'feed-present-revision (get-recent-changes))))) (%defpage /site/feed/article.atom :get (title) (let ((article (find-article title :error t))) (feed-doc #?"${(wiki-name *wiki*)} Article ${ (escape-for-html title) } Edits" #/site/feed/article.atom?title={title} (revision-date (latest-revision article)) (lambda () (loop repeat 20 for revision in (revisions article) do (feed-present-revision revision))))))
3,852
Common Lisp
.lisp
75
47.466667
137
0.687051
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
f12dc9b7aaad9b7d56e927a1eb160ed83d85afcf82bd55fceeec55db9b8f1008
41,046
[ -1 ]
41,047
readtable.lisp
ashok-khanna_cliki/src/readtable.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (defparameter %defined-uris '(("/"))) (defparameter %referenced-uris ()) (defvar *html-stream* *standard-output*) (defreadtable cliki2 (:merge :standard uri-template:uri-template) (:case :invert) (:dispatch-macro-char #\# #\? #'cl-interpol::interpol-reader) (:dispatch-macro-char #\# #\H (lambda (&rest args) `(princ ,(apply #'cl-interpol::interpol-reader args) *html-stream*))) (:dispatch-macro-char #\# #\/ (lambda (stream subchar arg) (declare (ignore subchar arg)) (let ((uri-path (with-output-to-string (x) (princ #\/ x) (loop until (member (peek-char nil stream nil #\Space t) '(#\Space #\Newline #\Tab #\? #\) #\{)) do (princ (read-char stream) x))))) (pushnew (cons uri-path (or *compile-file-pathname* *load-pathname*)) %referenced-uris :key #'car :test #'equal) `(concatenate 'string ,uri-path ,@(uri-template:read-uri-template stream))))))
1,907
Common Lisp
.lisp
42
39.738095
76
0.655897
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
767f000b3815d1b6b9958a5c8a55235582b3026c94cca75330e4a2e1edea9a96
41,047
[ -1 ]
41,048
backlinks.lisp
ashok-khanna_cliki/src/backlinks.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defun print-link-list (links printer) #H[<ul>] (dolist (link links) #H[<li>] (funcall printer link)) #H[</ul>]) (defpage /site/backlinks () (article) (let* ((article-obj (find-article article :error t)) (content (cached-content article))) (setf *title* #?'Link information for "${ (article-title article-obj) }"' *footer* (article-footer (latest-revision article-obj))) #H[<h1>Link information for ] (pprint-article-link article) #H[</h1> Topics:] (print-link-list (topics content) #'pprint-topic-link) #H[Links to other articles:] (print-link-list (page-links content) #'pprint-article-link) #H[Links from other articles:] (print-link-list (article-backlinks article) #'pprint-article-link) #H[Articles in '${ article }' topic:] (print-link-list (articles-by-topic article) #'pprint-article-link)))
1,763
Common Lisp
.lisp
34
48.647059
78
0.71412
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
105bca469835186221b9abbccd081bba78391b240645b78aecfa680a43a11e2e
41,048
[ -1 ]
41,049
dispatcher.lisp
ashok-khanna_cliki/src/dispatcher.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defun guess-article-name () (subseq (url-decode (script-name*)) 1)) (defun show-deleted-article-page (article) (setf (return-code*) 404 *footer* (with-output-to-string (*html-stream*) #H[<li><a href="$(#/site/history?article={ (article-title article) })">History</a></li>])) #H[Article was deleted]) (defun render-article (article &optional (page-title (article-title article))) (let ((*header* #?[<link rel="alternate" type="application/atom+xml" title="ATOM feed of edits to current article" href="$(#/site/feed/article.atom?title={ (article-title article) })">])) (render-page page-title (if (deleted? article) (show-deleted-article-page article) (progn #H[<div id="article-title">${ (article-title article) }</div>] (render-revision (latest-revision article) (cached-content (article-title article)))))))) (defun article-dispatcher (request) (lambda () (let ((article (find-article (guess-article-name)))) (cond ((not article) (setf (return-code*) 404) (render-page "Article not found" #H[<h1>Article not found</h1> <a href="$(#/site/edit-article?title={(guess-article-name)})">Create</a>])) ((get-parameter "download" request) (redirect (elt (nth-value 1 (ppcre:scan-to-strings #?/_P\((.*?)\)/ (cached-content (article-title article)))) 0))) (t (render-article article)))))) (defmethod acceptor-status-message :around ((acceptor cliki2-acceptor) status-code &key &allow-other-keys) (unless (and (equal status-code 404) (not (boundp '*wiki*))) (call-next-method))) (define-easy-handler (root :uri "/") () (render-article (find-article "index") (description *wiki*))) (%defpage /robots.txt :both () "User-agent: * Disallow: /site/") (defun wiki-static-dispatcher () (create-prefix-dispatcher "/static/" (lambda () (let ((request-path (request-pathname *request* "/static/"))) (setf (header-out :cache-control) "max-age=31536000") (handle-static-file (merge-pathnames request-path (wiki-path "static/")))))))
3,257
Common Lisp
.lisp
70
39
116
0.628859
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
30663eabb8d2214f7c9070f6c2a652fa0353689fa948a635fc42ae99d412770c
41,049
[ -1 ]
41,050
wiki.lisp
ashok-khanna_cliki/src/wiki.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2012 Vladimir Sedach <[email protected]> ;;; Copyright 2012 Jianshi Huang <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) (defstruct (wiki (:conc-name nil) (:constructor make-wiki-struct)) ;; config home-directory wiki-name description password-reminder-email-address ;; locks (update-lock (make-lock "update lock")) (data-lock (make-lock "data lock")) (index-lock (make-lock "index lock")) (session-lock (make-lock "session lock")) ;; data (accounts (make-hash-table :test 'equal)) (articles (make-hash-table :test 'equal)) (blacklist (make-hash-table :test 'equal)) ;; cache (article-cache (make-hash-table :test 'equal)) (last-timestamp 0) ;; indexes (topic-index (make-hash-table :test 'equal)) ;; article name (backlink-index (make-hash-table :test 'equal)) ;; article name (search-index (make-hash-table :test 'equal)) ;; article name (author-index (make-hash-table :test 'equal)) ;; revision obj (recent-changes ()) ;; revision obj ;; sessions (sessions (make-hash-table :test 'equal))) ;;; access (defun find-account (name) (with-lock-held ((data-lock *wiki*)) (gethash (cut-whitespace name) (accounts *wiki*)))) (defun banned? (account-name) (with-lock-held ((data-lock *wiki*)) (gethash account-name (blacklist *wiki*)))) (defun get-blacklist () (with-lock-held ((data-lock *wiki*)) (alexandria:hash-table-keys (blacklist *wiki*)))) (define-condition cannot-find-article-error (error) ((title :initarg :title) (link :initarg :link) (referer :initarg :referer)) (:report (lambda (e stream) (format stream "Cannot find article entitled '~A' (link ~A refered by ~A)" (slot-value e 'title) (slot-value e 'link) (slot-value e 'referer))))) (defun find-article (title &key error) (let ((article (with-lock-held ((data-lock *wiki*)) (gethash (canonicalize title) (articles *wiki*))))) (if (and error (not article)) (error 'cannot-find-article-error :title title :link (request-uri*) :referer (referer)) article))) (defun get-all-articles (filter) (sort (mapcar #'article-title (remove-if-not filter (with-lock-held ((data-lock *wiki*)) (alexandria:hash-table-values (articles *wiki*))))) #'string-lessp)) (defun edits-by-author (name) (with-lock-held ((index-lock *wiki*)) (gethash name (author-index *wiki*)))) (defun cached-content (title) (with-lock-held ((data-lock *wiki*)) (gethash (canonicalize title) (article-cache *wiki*)))) (defun get-recent-changes () (with-lock-held ((index-lock *wiki*)) (recent-changes *wiki*))) ;;; paths (defun wiki-path (path) (merge-pathnames path (home-directory *wiki*))) (defun file-path (type id) (let ((id (uri-encode (if (eq type 'article) (canonicalize id) id)))) (wiki-path (ecase type (account #?"accounts/${ id }") (article #?"articles/${ id }/article"))))) ;;; storage (defun write-to-file (to-file obj &optional (tmpdir (wiki-path "tmp/"))) (let* ((content (if (stringp obj) obj (with-standard-io-syntax (let ((*readtable* (named-readtables:find-readtable :common-lisp))) (prin1-to-string obj))))) (buffer (flexi-streams:string-to-octets content :external-format :utf-8)) tmp-file) (loop while (probe-file (setf tmp-file (ensure-directories-exist (merge-pathnames (format nil "~A.~A" (file-namestring to-file) (random 10000)) tmpdir))))) (with-open-file (out tmp-file :direction :output :if-exists :error :if-does-not-exist :create :element-type '(unsigned-byte 8)) (write-sequence buffer out) (finish-output out)) (unless (= (length buffer) (with-open-file (x tmp-file :element-type '(unsigned-byte 8)) (file-length x))) (error "Length mismatch in temporary file, aborting write")) ;; CL rename-file doesn't specify what to do if file exists (osicat-posix:rename (namestring tmp-file) (namestring (ensure-directories-exist to-file))))) ;;; create (defun wiki-new (what obj) (with-lock-held ((update-lock *wiki*)) ;; protocol: car is id (write-to-file (file-path what (car obj)) obj) (with-lock-held ((data-lock *wiki*)) (ecase what (article (setf (gethash (canonicalize (article-title obj)) (articles *wiki*)) obj)) (account (setf (gethash (account-name obj) (accounts *wiki*)) obj))))) obj) ;;; update (defmacro update-account (account &rest updates) (let ((copy (gensym)) (name (gensym))) `(with-lock-held ((update-lock *wiki*)) (let* ((,name (account-name ,account)) (,copy (copy-account (find-account ,name)))) (setf ,@(loop for (accessor newval) on updates by #'cddr collect `(,accessor ,copy) collect newval)) (write-to-file (file-path 'account ,name) ,copy) (with-lock-held ((data-lock *wiki*)) (setf (gethash ,name (accounts *wiki*)) ,copy)))))) (defun update-blacklist (account-name banned?) (with-lock-held ((update-lock *wiki*)) (with-lock-held ((data-lock *wiki*)) (if banned? (setf (gethash account-name (blacklist *wiki*)) t) (remhash account-name (blacklist *wiki*)))) (write-to-file (wiki-path "blacklist") (get-blacklist)))) ;;; revisions (defun record-revision (revision content) (let ((title (canonicalize (parent-title revision)))) (with-lock-held ((update-lock *wiki*)) (when (<= (revision-date revision) (last-timestamp *wiki*)) (warn "Clock seems to be running backwards") (setf (revision-date revision) (1+ (last-timestamp *wiki*)))) (save-revision-content revision content) (setf (last-timestamp *wiki*) (revision-date revision)) (let ((article (copy-article (find-article title))) old-content) (push revision (revisions article)) (write-to-file (file-path 'article title) article) (with-lock-held ((data-lock *wiki*)) (setf old-content (gethash title (article-cache *wiki*) "") (gethash title (articles *wiki*)) article (gethash title (article-cache *wiki*)) content)) (with-lock-held ((index-lock *wiki*)) (push revision (gethash (author-name revision) (author-index *wiki*))) (let ((recent-changes (cons revision (recent-changes *wiki*)))) (setf (recent-changes *wiki*) (subseq recent-changes 0 (min 100 (length recent-changes)))))) (reindex-article (article-title article) content old-content)))) revision) (defun revision-path (revision) (wiki-path #?"articles/${ (uri-encode (canonicalize (parent-title revision))) }/revisions/${ (revision-date revision) }")) (defun revision-content (revision) (let ((revision-path (revision-path revision))) (if (probe-file revision-path) (alexandria:read-file-into-string revision-path :external-format :utf-8) (error "Cannot find revision content file of revision dated ~A of article ~A (path ~A)" (revision-date revision) (parent-title revision) revision-path)))) (defun save-revision-content (revision content) ;; not locked (let ((path (revision-path revision))) (if (probe-file path) (error "Revision dated ~A of article ~A already exists, aborting write" (revision-date revision) (parent-title revision)) (write-to-file path content)))) ;;; indexing (defun articles-by-search-word (word) (with-lock-held ((index-lock *wiki*)) (gethash word (search-index *wiki*)))) (defun articles-by-topic (topic) (with-lock-held ((index-lock *wiki*)) (gethash (canonicalize topic) (topic-index *wiki*)))) (defun article-backlinks (article-title) (with-lock-held ((index-lock *wiki*)) (gethash (canonicalize article-title) (backlink-index *wiki*)))) (defun all-topics () (with-lock-held ((index-lock *wiki*)) (loop for topic being the hash-key of (topic-index *wiki*) using (hash-value articles) if articles collect topic else do (remhash topic (topic-index *wiki*))))) (defun reindex-article (title new-content old-content) (let ((title-words (words title))) (flet ((reindex (index extract-function) (let ((old (funcall extract-function old-content)) (new (funcall extract-function new-content))) (with-lock-held ((index-lock *wiki*)) (dolist (x (set-difference old new :test #'string=)) (setf (gethash x index) (remove title (gethash x index) :test #'string=))) (dolist (x (set-difference new old :test #'string=)) (setf (gethash x index) (merge 'list (list title) (gethash x index) #'string-lessp)))))) (words-for-search (content) (awhen (words content) (union title-words it :test #'string=)))) (reindex (topic-index *wiki*) #'topics) (reindex (backlink-index *wiki*) #'page-links) (reindex (search-index *wiki*) #'words-for-search)))) (defun init-recent-changes () (let ((recent-changes (reduce (lambda (&optional r1s r2s) (let ((merged (merge 'list (copy-list r1s) (copy-list r2s) #'> :key #'revision-date))) (subseq merged 0 (min 100 (length merged))))) (with-lock-held ((data-lock *wiki*)) (alexandria:hash-table-values (articles *wiki*))) :key #'revisions))) (with-lock-held ((index-lock *wiki*)) (setf (recent-changes *wiki*) recent-changes)))) ;;; lock file (defun get-directory-lock (dir) (let ((pulse 1) (lockfile (merge-pathnames "lock" dir)) nonce) (flet ((take-lock () (bt:make-thread (lambda () (loop (let ((nonce1 (when (probe-file lockfile) (read-file lockfile)))) (if (and nonce (not (equal nonce nonce1))) ;; someone else is writing to lock file ;;(osicat-posix:exit 1) (error "Nonces not equal ~A ~A" nonce nonce1) (with-open-file (out lockfile :direction :output :if-exists :supersede) (prin1 (setf nonce (random most-positive-fixnum)) out)))) (sleep (+ pulse (random 1.0)))))))) (if (probe-file lockfile) (let ((nonce (read-file lockfile))) (sleep (+ (* pulse 2) (random 3.0))) (if (equal nonce (read-file lockfile)) (take-lock) (error "Lock file for ~A held by someone else, quitting" dir))) (take-lock))))) ;;; load (defun read-file (file &optional (empty-file-value nil empty-file-value-p)) (with-open-file (in file :direction :input :if-does-not-exist :error :external-format :utf-8) (with-standard-io-syntax (let ((*read-eval* nil) (*readtable* (named-readtables:find-readtable :common-lisp))) (read in (not empty-file-value-p) empty-file-value))))) (defun load-wiki-article (path) (let* ((article (read-file (merge-pathnames "article" path))) (title (canonicalize (article-title article))) (rev (car (revisions article))) (content (revision-content rev))) (setf (gethash title (articles *wiki*)) article (gethash title (article-cache *wiki*)) content (last-timestamp *wiki*) (max (last-timestamp *wiki*) (revision-date rev))) (dolist (r (revisions article)) (push r (gethash (author-name r) (author-index *wiki*)))) (reindex-article (article-title article) content ""))) (defun load-wiki (*wiki*) (get-directory-lock (home-directory *wiki*)) ;; set up empty file for diff (open (wiki-path "empty_file") :direction :probe :if-does-not-exist :create) ;; set up empty file for blacklist (open (wiki-path "blacklist") :direction :probe :if-does-not-exist :create) (map nil #'load-wiki-article (cl-fad:list-directory (wiki-path "articles/"))) (loop for author being the hash-key of (author-index *wiki*) using (hash-value author-revisions) do (setf (gethash author (author-index *wiki*)) (sort author-revisions #'> :key #'revision-date))) (dolist (afile (cl-fad:list-directory (wiki-path "accounts/"))) (let ((account (read-file afile))) (setf (gethash (account-name account) (accounts *wiki*)) account))) (dolist (banned (read-file (wiki-path "blacklist") nil)) (setf (gethash banned (blacklist *wiki*)) t)) (init-recent-changes)) ;;; start (defun make-wiki (name description homedir email) (let ((wiki (make-wiki-struct :home-directory homedir :wiki-name name :description description :password-reminder-email-address email))) (load-wiki wiki) wiki))
15,065
Common Lisp
.lisp
324
36.762346
124
0.580944
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
80535afc4f40be78601963511e45bdb2cad1b305d4aa9e32d33dc3bc56f1522f
41,050
[ -1 ]
41,051
indexes.lisp
ashok-khanna_cliki/src/indexes.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2012 Vladimir Sedach <[email protected]> ;;; Copyright 2012 Jianshi Huang <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) (in-readtable cliki2) ;;; topics and backlinks (defun canonicalize (title) (string-downcase (cut-whitespace title))) (defun collect-links (link-type content) (let (names) (ppcre:do-register-groups (name) (#?/${link-type}\(([^\)]*)\)/ content) (pushnew (canonicalize name) names :test #'string=)) names)) (defun topics (content) (collect-links "\\*" content)) (defun page-links (content) (collect-links "\\_" content)) ;;; full-text search (defparameter *common-words* '("" "a" "also" "an" "and" "are" "as" "at" "be" "but" "by" "can" "for" "from" "has" "have" "here" "i" "if" "in" "is" "it" "not" "of" "on" "or" "s" "see" "so" "that" "the" "there" "this" "to" "us" "which" "with" "you")) (defun words (content) (let (words) (dolist (word (ppcre:split "<.*?>|_|\\s|[^\\w]" (string-downcase content))) (unless (member word *common-words* :test #'string=) (pushnew (stem:stem word) words :test #'string=))) words)) (defun search-articles (phrase) (let ((words (words phrase))) (when words (sort (copy-list (reduce (lambda (&optional a b) (intersection a b :test #'string=)) (mapcar #'articles-by-search-word words))) #'< :key (lambda (title) (let ((title (canonicalize title))) (loop for word in words for weight from 0 by 100 thereis (awhen (search word title) (+ (* it 100) weight (length title))) finally (return most-positive-fixnum)))))))) (defun paginate-article-summaries (start articles &optional (next-page-uri "?")) (let ((page-size 10) (start (or (parse-integer (or start "0") :junk-allowed t) 0))) (flet ((page-uri (page# label) #H[<span><a href="${next-page-uri}&start=${(* page# page-size)}">${label}</a></span>])) #H[<ol start="${(1+ start)}">] (loop for i from start below (min (+ start page-size) (length articles)) do (pprint-article-summary-li (elt articles i) "<br />")) #H[</ol> <div id="paginator"> <span>Result page:</span>] (unless (= 0 start) (page-uri (ceiling (- start page-size) page-size) "&lt;")) (dotimes (page# (ceiling (length articles) page-size)) (if (= start (* page# page-size)) #H[<span>${(1+ page#)}</span>] (page-uri page# (1+ page#)))) (unless (>= (+ start page-size) (length articles)) (page-uri (ceiling (+ start page-size) page-size) "&gt;")) #H[</div>]))) (defpage /site/search "Search results" (query start) #H[<h1>Search results</h1>] (aif (search-articles query) (paginate-article-summaries start it #U?query={query}) #H[No results found]))
3,801
Common Lisp
.lisp
78
41.358974
100
0.601187
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
9290b98938cf1ff07c5b74d230aa2a712d5da085a4dde9aa823789fc0399bc58
41,051
[ -1 ]
41,052
start.lisp
ashok-khanna_cliki/src/start.lisp
;;; Copyright 2011 Andrey Moskvitin <[email protected]> ;;; Copyright 2011, 2012 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2) ;;; unreferenced uri checking (dolist (unreferenced-uri (set-difference %referenced-uris %defined-uris :key #'car :test #'string-equal)) (warn "Reference warning: referencing unknown URI resource ~a in file ~a" (car unreferenced-uri) (cdr unreferenced-uri))) (defvar *cliki-server* nil) (defun start-cliki-server (port homedir wikis) (if *cliki-server* (progn (warn "CLiki server already running") *cliki-server*) (progn ;; SBCL, CCL and possibly others always start w/same pseudo-random seed (setf *random-state* (make-random-state t)) ;; set up HyperSpec paths (setf clhs-lookup::*hyperspec-pathname* (merge-pathnames "HyperSpec/" homedir) clhs-lookup::*hyperspec-map-file* (merge-pathnames "HyperSpec/Data/Symbol-Table.text" homedir) clhs-lookup::*hyperspec-root* "/site/HyperSpec/") (bt:make-thread (lambda () (loop (map nil (lambda (x) (expire-old-sessions (cadr x))) wikis) (sleep (* 60 60 24))))) (let ((error-log (merge-pathnames "error-log" homedir)) (access-log (merge-pathnames "access-log" homedir))) (open error-log :direction :probe :if-does-not-exist :create) (open access-log :direction :probe :if-does-not-exist :create) (let ((acceptor (make-instance 'cliki2-acceptor :port port :access-log-destination access-log :message-log-destination error-log :wikis wikis :dispatch-table (list (wiki-static-dispatcher) (create-folder-dispatcher-and-handler "/site/HyperSpec/" (merge-pathnames #p"HyperSpec/" homedir)) (create-static-file-dispatcher-and-handler "/site/error-log" error-log "text/plain") 'dispatch-easy-handlers 'article-dispatcher)))) (start acceptor) (setf *cliki-server* acceptor))))))
3,148
Common Lisp
.lisp
62
39.677419
80
0.601951
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
80d964b1be04ebf5bf315107affd83f55546748f9215b1364ef6b99b6be6377b
41,052
[ -1 ]
41,053
tests.lisp
ashok-khanna_cliki/tests/tests.lisp
;;; Copyright 2019 Vladimir Sedach <[email protected]> ;;; SPDX-License-Identifier: AGPL-3.0-or-later ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU Affero 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 ;;; Affero General Public License for more details. ;;; You should have received a copy of the GNU Affero General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. (in-package #:cliki2.tests) (def-suite cliki2-tests) (defvar *test-wiki* (cliki2::make-wiki "test" "" (ensure-directories-exist #P"/tmp/cliki2test/") "")) (defun run-tests () (let ((cliki2::*wiki* *test-wiki*)) (run! 'cliki2-tests))) (defmacro mtest (name expected markup) `(test ,name (is (string= ,expected (cliki2::parse-cliki-markup ,markup))))) (in-suite cliki2-tests) (mtest parse-internal-link1 "<a href=\"/Foo%20bar\" class=\"new\">Foo bar</a>" "_(Foo bar)") (mtest parse-internal-link2 "<a href=\"/Something%20else\" class=\"new\">Shortname</a>" "_(Something else|Shortname)") (mtest parse-internal-link3 "<a href=\"/Foo%20bar\" class=\"new\">Foo bar</a>)))" "_(Foo bar))))") (mtest parse-empty-internal-link "<a href=\"/\" class=\"new\"></a>" "_()") (mtest parse-empty-internal-link1 "<a href=\"/\" class=\"new\"></a>" "_(|)") (mtest parse-empty-internal-link2 "<a href=\"/\" class=\"new\">x</a>" "_(|x)") (mtest parse-hyperspec-link "<a href=\"NIL\" class=\"hyperspec\">setf</a>" "_H(setf)") (mtest parse-topic-link "<a href=\"/fruit\" class=\"new\">fruit</a>" "*(fruit)") (mtest parse-topic-list "<ul></ul>" "/(list of lists)") (mtest parse-empty-topic-list "<ul></ul>" "/()") (mtest bunch-of-links "<a href=\"/foo\" class=\"new\">foo</a> something <a href=\"/bar\" class=\"new\">bar</a> <a href='http://common-lisp.net'>somewhere</a> <ul></ul>" "_(foo) something *(bar) <a href='http://common-lisp.net'>somewhere</a> /(baz)") (test escape-parens-in-href-links (is (string= "*(baz) <a href=\"foo %28bar%29\">foo (bar)</a> _(not bar)" (cliki2::escape-parens-in-href-links "*(baz) <a href=\"foo (bar)\">foo (bar)</a> _(not bar)" 0 51)))) (mtest parse-article-link-with-escaped-parentheses "<a href=\"/Foo%20%28bar%29\" class=\"new\">Foo (bar)</a>" "_(Foo (bar\\))") (mtest parse-article-link-with-escaped-parentheses1 "<a href=\"/Foo%20%28bar%29%20baz\" class=\"new\">Foo (bar) baz</a>" "_(Foo (bar\\) baz)") (mtest parse-article-link-with-escaped-parentheses2 "<a href=\"/Foo%20%28bar%29\" class=\"new\">Foo (bar)</a>)" "_(Foo (bar\\)))") (mtest parse-empty-article "" "") (mtest parse-short-article "a" "a") (mtest parse-short-article1 "ab" "ab") (mtest parse-short-article2 "abc" "abc") (mtest parse-short-article3 "(" "(") (mtest parse-short-article4 "_(" "_(") (mtest parse-short-article5 ")" ")") (mtest parse-short-article6 "()" "()") (mtest parse-some-article "something <a href=\"/Foo%20bar\" class=\"new\">Foo bar</a> baz" "something _(Foo bar) baz") (mtest parse-some-article1 "(abc <a href=\"/Foo%20bar\" class=\"new\">Foo bar</a> xyz)" "(abc _(Foo bar) xyz)") (mtest parse-some-article2 "abc <a href=\"/Foo%20bar\" class=\"new\">Foo bar</a> (xyz" "abc _(Foo bar) (xyz")
3,671
Common Lisp
.lisp
109
30.87156
137
0.644539
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
427164961a3a4315672ff3f5dfd38f81b4a8b023aca5a05ffa0d3bcab35d8bd9
41,053
[ -1 ]
41,054
cliki2.tests.asd
ashok-khanna_cliki/cliki2.tests.asd
;;; -*- lisp -*- (defsystem :cliki2.tests :license "AGPL-3.0-or-later" :description "Test for CLiki2" :components ((:module :tests :serial t :components ((:file "package") (:file "tests")))) :depends-on (:cliki2 :fiveam))
316
Common Lisp
.asd
9
23.666667
55
0.480392
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
75cf37c398feb5cccbd5e8dc2f06f765c40b92e5c0238cb7b8ce7732db32ad91
41,054
[ -1 ]
41,055
cliki2.asd
ashok-khanna_cliki/cliki2.asd
(asdf:defsystem :cliki2 :description "The Common Lisp wiki" :author "Andrey Moskvitin <[email protected]>, Vladimir Sedach <[email protected]>" :maintainer "Vladimir Sedach <[email protected]>" :license "AGPL-3.0-or-later" :version "2.0" :depends-on (#:alexandria #:hunchentoot #:bordeaux-threads #:ironclad #:colorize #:sanitize #:diff #:cl-interpol #:uri-template #:flexi-streams #:cl-ppcre #:cl-smtp #:cl-fad #:anaphora #:stem #:osicat ;; used for rename ) :components ((:module "src" :serial t :components ((:file "package") (:file "readtable") (:file "acceptor") (:file "http-resource") (:file "html-rendering") (:file "wiki") (:file "authentication") (:file "accounts") (:file "article") (:file "markup") (:file "diff") (:file "indexes") (:file "recent-changes") (:file "history") (:file "backlinks") (:file "tools") (:file "dispatcher") (:file "start")))))
1,390
Common Lisp
.asd
45
18.488889
92
0.447584
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
0f958f78815826c49009c751ffe1ded191cc46f5f472eedd3da86c712ddf966f
41,055
[ -1 ]
41,056
cliki-convert.asd
ashok-khanna_cliki/cliki-convert.asd
(asdf:defsystem :cliki-convert :components ((:module "cliki-convert" :components ((:file "package") (:file "cliki-convert" :depends-on ("package"))))) :depends-on (#:cliki2 #:iterate #:cl-fad #:external-program #:local-time))
269
Common Lisp
.asd
6
36.666667
76
0.596958
ashok-khanna/cliki
0
0
0
AGPL-3.0
9/19/2024, 11:49:12 AM (Europe/Amsterdam)
5012afcd4ea6a5b2a85e9e9c74ea369b9ce5084eb679fa021de9155ff80b81f1
41,056
[ -1 ]
41,095
package.lisp
Izaakwltn_simple-blog/package.lisp
;;;;package.lisp (defpackage #:simple-blog (:documentation "A simple blog template for lisp") (:use #:cl #:spinneret #:hunchentoot))
139
Common Lisp
.lisp
4
32.25
52
0.708955
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
be56d06440695570d78c763355bf5adf0d3c436601dabd23de6c3f758490ee88
41,095
[ -1 ]
41,096
blog-page-template.lisp
Izaakwltn_simple-blog/blog-page-template.lisp
;;;;blog-page.lisp (in-package :simple-blog) (defmacro with-blog-page ((&key title) &body body) `(spinneret::with-html-string (:doctype) (:html (:head (:meta :charset "utf-8") (:meta :name "viewport" :content "width=device-width, initial-scale=1") (:link :rel "stylesheet" :href "https://cdn.simplecss.org/simple.min.css") (:title ,title)) (:header (:nav (:a :href "blog.html" "Blog"))) (:body ,@body))))
479
Common Lisp
.lisp
16
24.3125
72
0.596452
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
1af5a2e9efba0389ce98643cac0bd5db3528a1543d868f12e6d895aa8fad2419
41,096
[ -1 ]
41,097
site-builder.lisp
Izaakwltn_simple-blog/site-builder.lisp
;;;;site-builder.lisp (in-package :simple-blog) (defvar *blog-server* (make-instance 'hunchentoot:easy-acceptor :port 4242 :document-root #p"/simple-blog/www/")) ;;;http://127.0.0.1:4242/blog.html
206
Common Lisp
.lisp
5
38.4
74
0.726804
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
9fb12616879155b472865183c096ae0d559b2b766f6ad5c617f1c854bc7ae5e0
41,097
[ -1 ]
41,098
blog-entry.lisp
Izaakwltn_simple-blog/blog-entry.lisp
;;;;blog-entry.lisp (in-package :simple-blog) ;;;blog-entry class (defparameter *blog-list* nil) (defclass blog-entry () ((title :initarg :title :accessor title) (url-extension :initarg :url-ext :accessor url-ext) (description :initarg :description :accessor description) (article :initarg :article :accessor article))) (defmethod print-object ((obj blog-entry) stream) (print-unreadable-object (obj stream :type t) (with-accessors ((title title) (description description) (article article)) obj (format stream "Title:~a~%~%Description:~a~%~%Article:~%~A~%" title description article)))) (defun post-blog-entry (title-string url-extension description-string article-function) "Performs two functions: pushes the blog entry's information to *blog-list* for use on the main page, and pushes the page to the *dispatch-table*." (progn (push (make-instance 'blog-entry :title title-string :url-ext url-extension :description description-string :article article-function) ;use (blog1) or something similar *blog-list*) (push (hunchentoot::create-prefix-dispatcher url-extension article-function) hunchentoot:*dispatch-table*)))
1,279
Common Lisp
.lisp
31
35.709677
103
0.694489
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
1a9be1755f962abc56496c2e828e51cd023bf7229c4d8b0cf01d0b310da29bab
41,098
[ -1 ]
41,099
blog-post2.lisp
Izaakwltn_simple-blog/www/blog-post2.lisp
;;;;blog-post1.lisp (in-package :simple-blog) (defun blog-post2 () (with-blog-page (:title "Sample blog #2") (:header (:h1 "Sample Blog # 2")) (:p "fringilla urna porttitor rhoncus dolor purus non enim praesent elementum facilisis leo vel fringilla est ullamcorper eget nulla facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus in ornare quam viverra orci sagittis eu volutpat odio facilisis mauris sit amet massa vitae tortor condimentum lacinia quis vel eros"))) (post-blog-entry "Sample Blog #2" "/blog-post2.html" "Read and learn!" #'blog-post2)
609
Common Lisp
.lisp
11
51.909091
357
0.751261
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
675e24be48753953eb0f7ad2504e6bdb35c5a4188c799353c697ffe0e5bc374c
41,099
[ -1 ]
41,100
blog-post3.lisp
Izaakwltn_simple-blog/www/blog-post3.lisp
;;;;blog-post3.lisp (in-package :simple-blog) (defun blog-post3 () (with-blog-page (:title "Sample blog #3") (:header (:h1 "Sample Blog # 3")) (:p "fringilla urna porttitor rhoncus dolor purus non enim praesent elementum facilisis leo vel fringilla est ullamcorper eget nulla facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus in ornare quam viverra orci sagittis eu volutpat odio facilisis mauris sit amet massa vitae tortor condimentum lacinia quis vel eros"))) (post-blog-entry "Sample Blog #3" "/blog-post3.html" "A real blog's blog." #'blog-post3)
613
Common Lisp
.lisp
11
52.272727
357
0.749583
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
82776d3e8662a814fdf7ac552ff3aa6f016bbf7c53be5979b9459ff32f46fe78
41,100
[ -1 ]
41,101
blog-home-page.lisp
Izaakwltn_simple-blog/www/blog-home-page.lisp
;;;;blog-home-page.lisp (in-package :simple-blog) (defun blog-home-page () (with-blog-page (:title "Blog") (:header (:h1 "Blog")) (:section (:ul (loop for b in *blog-list* do (:li (:a :href (url-ext b) (:button (format nil "~a" (title b)))) (:i (description b)))))))) (push (hunchentoot:create-prefix-dispatcher "/blog.html" #'blog-home-page) hunchentoot:*dispatch-table*)
416
Common Lisp
.lisp
12
30.083333
74
0.611529
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
bb78fa02ee7c0c2e49b9e54bdfaab6ba65bf97b0ea7749b2994a4aaccf5c6f61
41,101
[ -1 ]
41,102
admin.lisp
Izaakwltn_simple-blog/www/admin.lisp
;;;;admin.lisp (in-package :simple-blog) (defvar admin-username "aardvark") (defvar admin-password "123456789") (defvar session-code) ;;;;maybe (session) function that generates the section suffix ;;;;shit maybe this isn't necessary, instead just use the logout page to push a blank/logged out (defun admin-login () (with-blog-page (:title "Admin Log-in") (:header (:h1 "Admin Log-in")) (:section (:form :action "/admin-login" :id "admin-login" :method "get" (:p "Username: ") (:input :type "text" :id "username" :name "username" :form "admin-login") (:p "Password: ") (:input :type "password" :form "admin-login" :id "pass" :name "password" :minlength "8" :autocomplete "current-password" :required) (:input :type "submit" :value "Sign in" :class "button"))))) (push (hunchentoot:create-prefix-dispatcher "/admin.html" #'admin-login) hunchentoot:*dispatch-table*) ;;;;------------------------------------------------------------------------ ;;;;Make a handler for the username/password: ;;;;------------------------------------------------------------------------ (hunchentoot::define-easy-handler (admin-login :uri "/admin-login") (username password) (setf (hunchentoot:content-type*) "text/html") (setq session-code (jumble 10)) (if (and (equal (write-to-string username) (write-to-string admin-username)) (equal (write-to-string password) (write-to-string admin-password))) (progn (push (hunchentoot:create-prefix-dispatcher ;(concatenate 'string ; "/" ; session-code "/admin.html" #'admin-page) hunchentoot:*dispatch-table*) (spinneret::with-html-string (:doctype) (:html (:head (:meta :http-equiv "refresh" :content "0; url=http://127.0.0.1:4242/admin.html"))))) ;(concatenate 'string ; "0; url=http://127.0.0.1:4242/" ; session-code ; "admin-page.html")))))) (format nil "nope"))) ;(format nil "~a~a~a~a~a" username password (write-to-string password) (write-to-string admin-password); (equal (write-to-string password) (write-to-string admin-password)))) ; (if (equal (write-to-string password) (write-to-string admin-password)) ; (with-page (:title "You did it!") ; (:header ; (:h1 "You did it!"))) ; (with-page (:title "You fucked up") ; (:header ; (:h1 "You fucked up"))))) (defun log-out () ( (spinneret::with-html-string (:doctype) (:html (:head (progn (:meta :http-equiv "refresh" :content "0; url=http://127.0.0.1:4242/blog.html"))))) ;;;;------------------------------------------------------------------------ ;;;;The proper admin page: ;;;;------------------------------------------------------------------------ (defun admin-page () (with-blog-page (:title "Admin Access") (:header (:h1 "Admin Access")) (:section (:p "Hello there!") (:button :value "Log out" :onclick (progn ((push (hunchentoot:create-prefix-dispatcher "/admin.html" #'admin-login) hunchentoot:*dispatch-table*))))) (hunchentoot::define-easy-handler (log-out :uri "/log-out") () (setf (hunchentoot:content-type*) "text/html") (push (hunchentoot:create-prefix-dispatcher "/admin.html" #'admin-login) hunchentoot:*dispatch-table*) (spinneret::with-html-string (:doctype) (:html (:head (:meta :http-equiv "refresh" :content "0; url=http://127.0.0.1:4242/admin-page.html")))) (format nil "nope")) (push (hunchentoot:create-prefix-dispatcher "/admin-page.html" #'admin-page) hunchentoot:*dispatch-table*) (push (hunchentoot:create-prefix-dispatcher "/admin-page.html" #'admin-login) hunchentoot:*dispatch-table*) ;;;;security (passwords/usernames/encryption) (defun jumble (n) "Makes a number jumble of length n" (cond ((zerop n) nil) (t (concatenate 'string (write-to-string (random 10)) (jumble (- n 1))))))
4,009
Common Lisp
.lisp
103
34.349515
176
0.590687
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
029aba657ab7c735c61f70863fac8cdc095682ad5879c8ad42ae98159feee321
41,102
[ -1 ]
41,103
blog-post1.lisp
Izaakwltn_simple-blog/www/blog-post1.lisp
;;;;blog-post1.lisp (in-package :simple-blog) (defun blog-post1 () (with-blog-page (:title "Sample blog #1") (:header (:h1 "Sample Blog # 1")) (:p "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. In eu mi bibendum neque egestas congue quisque. Ipsum a arcu cursus vitae. Ut morbi tincidunt augue interdum velit euismod in. Scelerisque felis imperdiet proin fermentum leo vel orci porta non. Massa massa ultricies mi quis hendrerit dolor magna eget. Mi tempus imperdiet nulla malesuada pellentesque elit eget. Praesent elementum facilisis leo vel fringilla. Pellentesque nec nam aliquam sem et tortor consequat id porta. Sed velit dignissim sodales ut eu sem integer vitae. Purus gravida quis blandit turpis cursus in. Neque viverra justo nec ultrices dui sapien. Nunc vel risus commodo viverra maecenas accumsan lacus vel facilisis. Sit amet consectetur adipiscing elit pellentesque habitant morbi tristique senectus. Leo vel fringilla est ullamcorper eget nulla facilisi. Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi."))) (post-blog-entry "Sample Blog #1" "/blog-post1.html" "This is the description of a rather interesting article" #'blog-post1)
1,276
Common Lisp
.lisp
11
112.545455
984
0.790016
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
d74c4da26128e53ecc6883e4fa23eb34748bbed882640415547cc679a562008f
41,103
[ -1 ]
41,104
simple-blog.asd
Izaakwltn_simple-blog/simple-blog.asd
;;;;simple-blog.asd (asdf:defsystem #:simple-blog :version "0.0.1" :author "Izaak Walton <[email protected]>" :license "GNU General Purpose License" :description "A simple blog layout written in Lisp" :depends-on (#:hunchentoot #:spinneret) :serial t :components ((:file "package") (:file "site-builder") (:file "blog-page-template") (:file "blog-entry") (:module "www" :serial t :components ((:file "blog-home-page") (:file "blog-post1") (:file "blog-post2") (:file "blog-post3")))))
564
Common Lisp
.asd
18
26.166667
53
0.623853
Izaakwltn/simple-blog
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
3313359affb6657890688c0a96dd1881653a71cf924ac423c5db609470e35446
41,104
[ -1 ]
41,130
renoise.lisp
brandflake11_cl-renoise/renoise.lisp
;; Cl-renoise ;; Copyright (C) 2021 Brandon Hale ;; 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 <https://www.gnu.org/licenses/>. ;; You need to have CM-INCUDINE installed. Normal CM just won't do. ;; Incudine is used for realtime and osc (defpackage :renoise (:use :cl :cm) (:export :renoise)) (in-package :renoise) ;; Setup where you want to send osc messages to. Both address and port. (defparameter *address* "127.0.0.1") (defparameter *port* 3091) ;; Define *renoise-out* for sending OSC messages (defparameter *oscout* (incudine.osc:open :direction :output :host *address* :port *port*)) (cm::osc-open-default :host *address* :port *port* :direction :output) (defun renoise (message &optional arg arg2) (labels ((bool-to-num (val) (if (eql val t) 1 (if (or (eql val 0) (eql val 1)) val)))) (cond ((or (eql message 1) (eql message :start) (eql message :play)) (sprout (new cm::osc :time 0 :types "" :message "" :path "/renoise/transport/start"))) ((or (eql message 0) (eql message :stop)) (sprout (new cm::osc :time 0 :types "" :message "" :path "/renoise/transport/stop"))) ((or (eql message 2) (eql message :continue)) (sprout (new cm::osc :time 0 :types "" :message "" :path "/renoise/transport/continue"))) ((eql message :loop) (sprout (new cm::osc :time 0 :types "i" :message arg :path "/renoise/transport/loop/pattern"))) ((or (eql message 6) (eql message :panic)) (sprout (new cm::osc :time 0 :types "" :message "" :path "/renoise/transport/panic"))) ((or (eql message :schedule) (eql message :schedule-pattern)) (sprout (new cm::osc :time 0 :types "i" :message arg :path "/renoise/song/sequence/schedule_set"))) ((or (eql message :trigger) (eql message :trigger-pattern) (eql message :pattern)) (sprout (new cm::osc :time 0 :types "i" :message (+ 1 arg) :path "/renoise/song/sequence/trigger"))) ((eql message :bpm) (sprout (new cm::osc :time 0 :types "i" :message arg :path "/renoise/song/bpm"))) ((eql message :lpb) (sprout (new cm::osc :time 0 :types "i" :message arg :path "/renoise/song/lpb"))) ((or (eql message :octave) (eql message :oct)) (sprout (new cm::osc :time 0 :types "i" :message arg :path "/renoise/song/edit/octave"))) ((eql message :edit) (sprout (new cm::osc :time 0 :types "i" :message (bool-to-num arg) :path "/renoise/song/edit/mode"))) ((or (eql message :metro) (eql message :metronome)) (sprout (new cm::osc :time 0 :types "i" :message arg :path "/renoise/song/record/metronome"))) ((or (eql message :pre-metro) (eql message :metronome-precount) (eql message :precount-metronome) (eql message :metro-pre) (eql message :pre-metronome)) (sprout (new cm::osc :time 0 :types "i" :message arg :path "/renoise/song/record/metronome_precount"))) ((eql message :solo) (sprout (new cm::osc :time 0 :types "" :message "" ;; Use -1 as arg to solo currently selected track :path (concatenate 'string "/renoise/song/track/" (write-to-string arg) "/solo")))) ((eql message :mute) (sprout (new cm::osc :time 0 :types "" :message "" ;; Use -1 as arg to solo currently selected track :path (concatenate 'string "/renoise/song/track/" (write-to-string arg) "/mute")))) ((eql message :unmute) (sprout (new cm::osc :time 0 :types "" :message "" ;; Use -1 as arg to solo currently selected track :path (concatenate 'string "/renoise/song/track/" (write-to-string arg) "/unmute")))) ;; :bypass-effect and :enable-effect takes two arguments. First is track number and second is effect number. ((or (eql message :bypass-effect) (eql message :disable-effect)) (sprout (new cm::osc :time 0 :types "i" :message 1 ;; Use -1 as arg to solo currently selected track :path (concatenate 'string "/renoise/song/track/" (write-to-string arg) "/device/" (write-to-string (1+ arg2)) "/bypass")))) ((eql message :enable-effect) (sprout (new cm::osc :time 0 :types "i" :message 0 ;; Use -1 as arg to solo currently selected track :path (concatenate 'string "/renoise/song/track/" (write-to-string arg) "/device/" (write-to-string (1+ arg2)) "/bypass"))))))) ;; Some Examples Below: ;; Change octave of renoise ;; (renoise :oct 3) ;; ;; Change the transport's bpm ;; (renoise :bpm 123) ;; ;; Start/stop renoise's transport ;; (renoise :start) ;; (renoise :stop) ;; ;; You can even use a function to alter renoise's parameters ;; (renoise :bpm (random 150)) ;; ;; Turn off everything, hits renoise's panic button ;; (renoise :panic) ;; ;; Turn on pattern 1 ;; (renoise :trigger-pattern 1) ;; ;; Queue up pattern 1 as the next pattern to play after playing the current one ;; (renoise :schedule-pattern 9)
5,887
Common Lisp
.lisp
166
29.506024
111
0.615627
brandflake11/cl-renoise
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
61f0b96ad8097c9d64ff8294323e67652689b8aed6e269a0ab0e6da21f2f58eb
41,130
[ -1 ]
41,131
renoise.asd
brandflake11_cl-renoise/renoise.asd
(asdf:defsystem :renoise :description "Control renoise in Common Lisp with Open Sound Control." :version "1.0" :author "Brandon Hale <[email protected]>" :license "GNU General Public License v3" :depends-on ("cm-incudine" #:incudine #:cm) :components ((:file "renoise")))
310
Common Lisp
.asd
9
30.333333
72
0.697674
brandflake11/cl-renoise
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
0e60232eeb963b9c64ee314d7d264a7f18f085fbf17cbfb79c0bcf7674a2714a
41,131
[ -1 ]
41,148
startup-database.lisp
CCL-GR_grade-database/startup-database.lisp
(defun abspath (path-string &optional (dir-name (uiop:getcwd))) (uiop:unix-namestring (uiop:ensure-absolute-pathname (uiop:merge-pathnames* (uiop:parse-unix-namestring path-string)) dir-name))) (load (abspath "/home/carson/code/lisp/grade-database/string-libs.lisp")) (ql:quickload :cl-csv) (load (abspath "/home/carson/code/lisp/grade-database/command-line-tools.lisp")) (load (abspath "/home/carson/code/lisp/grade-database/csv-handling.lisp")) (load (abspath "/home/carson/code/lisp/grade-database/grade-database.lisp"))
555
Common Lisp
.lisp
12
42.666667
80
0.736162
CCL-GR/grade-database
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
fbf4764762f5b5cb94591fdbd00173c0f757368533ae4884b89596e38653419f
41,148
[ -1 ]
41,149
student-notes.lisp
CCL-GR_grade-database/student-notes.lisp
(defclass student-note () ((student-name :initarg :name :accessor name) (student-grade :initarg :grade :accessor cnum) (notes :initarg :notes :accessor notes)))
193
Common Lisp
.lisp
10
15.1
25
0.650273
CCL-GR/grade-database
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
078e637a5528490aa1e14468895d396f03fac27f6b7e00b50aa1e06327eb77f8
41,149
[ -1 ]
41,150
student.lisp
CCL-GR_grade-database/student.lisp
(defclass student () ((name :initarg :name :accessor name) (grade-level :initarg :grade-level :accessor grade-level) (score :initarg :score :accessor score) (grades :initarg :grades :accessor grades) (comments :initarg :comments :accessor comments))) (defvar *student-roster* (list 'a 'b 'c)) (defvar *staged-student* (make-instance 'student :name "" :grade-level 0 :score 0 :grades '(0 1 2 3 4) :comments '((0 1) (1 5) (2 5) (3 5) (4 4)))) (defmacro stage-student (name grade-level score grades comments) "mutates the staged student to have the attributes of a given student" `(progn (setf (name *staged-student*) ,name) (setf (grade-level *staged-student*) ,grade-level) (setf (score *staged-student*) ,score) (setf (grades *staged-student*) ,grades) (setf (comments *staged-student*) ,comments))) (defmacro dump-scores (student grade-set) `(format t "~a" (if (equalp ,grade-set 'grades) (grades ,student) (comments ,student)))) (defvar *staged-student-data* (list 'student "some-name" 7 100 '(5 5 5 5 5) '((0 5) (1 5) (2 5) (3 5) (4 5)))) (defvar *staged-student-data-set* (list *staged-student-data* *staged-student-data* *staged-student-data*)) ;currently fake data - check where it's used before shipping (defmacro instantiate-student (student-data) "takes a list of student data and creates a student object - list is to be SOP for creating/saving a student" `(let ((name (second ,student-data)) (grade-level (third ,student-data)) (score (fourth ,student-data)) (grades (fifth ,student-data)) (comments (sixth ,student-data))) (make-instance 'student :name name :grade-level grade-level :score score :grades grades :comments comments))) (defun load-student (student student-data) "Used to mapcar students into the roster" (setf student (instantiate-student student-data))) (defun load-student-roster () "takes in the data for the students and puts them in the roster" (setf *student-roster* (mapcar #'load-student *student-roster* *staged-student-data-set*))) (defmacro dump-student-data (student) "takes in a student object and converts it to a list" `(list 'student (name ,student) (grade-level ,student) (score ,student) (grades ,student) (comments ,student))) (defun alist->stu (db-student) "Takes a student alist from the *grade-db* and sets the variable *made-student* to them so that they can be manipulated as a student object" (setf *staged-student* (instantiate-student (list 'student (second db-student) (fourth db-student) (tenth db-student) (sixth db-student) (nth 11 db-student))))) (defun stu->alist (student) "updates comments and grades for given students" (progn (update (where :name (name student)) :comments (comments student)) (update (where :name (name student)) :grade (grades student)))) (defun add-student-comment (name comment &optional (student *staged-student*)) (progn (alist->stu (car (select (where :name name)))) (update (where :name name) :comments (cons comment (comments student))) (setf (comments student) (cons comment (comments student)))))
3,817
Common Lisp
.lisp
82
35.426829
168
0.583244
CCL-GR/grade-database
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
ea02c10a57aed56849b79798ae8390f7dc748cc78de0b7501b5048c7a0d40229
41,150
[ -1 ]
41,151
grade.lisp
CCL-GR_grade-database/grade.lisp
(defclass grade () ((score :initarg :score :accessor score) (max-score :initarg :max-score :accessor max-score) (assignment-name :initform :assignment-name :accessor assignment-name) (grade-category :initform nil :accessor grade-category))) (defmethod pass-p (grade &optional (percentage .7)) ;;percentage to tell if they pass (if (> (/ (score grade) (float (max-score grade))) percentage) t nil)) ; Concept scores are for concept quizzes which have a max score of 4 in first test and 5 in next test ; These are quizzes designed around mastery learning. *concept-names* are the titles of the topics in ; the quiz and each one is tested twice or more times for students to obtain full mastery of the material. ; At certain points throughout the year, the mastery topics are consolidated into a single grade, and the ; material starts over, at that point, *concept-names* will need to be rewritten or reentered. ; TODO: get *concept-names* to be read in from a file on load (defparameter *concept-names* (list "Graphing Proportional Relationships" "Constant of Proportionality" "Analyzing Proptional Relationship Graphs" "Constructing Relationship Graphs" "Straight Tax" "Simple Interest" "Added Costs" "Error Margins" "Sign Combination" "Integer Inverses" "Multiplication of Integers" "PEMDAS" "Multiple Representations of Rational Numbers" "Rational Operations" "Rational PEMDAS" "Simplification and Reduction" "Balancing Equations" "Adding Linear Equations" "Simplifying Rational Linear Equations")) (defvar *staged-concept* nil) (defvar *staged-grade* nil) (defclass concept () ((concept-name :initarg :concept-name :accessor name) (concept-number :initarg :concept-number :accessor cnum) (current-score :initarg :current-score :initform 0 :accessor current-score) (possible-score :initarg :possible-score :initform 4 :accessor possible-score))) (defmacro get-concept-name (cnum) `(nth ,cnum *concept-names*)) (defmethod (setf current-score) (new-score (obj concept)) "Ensures setting scores higher than current possible maximum scores doesn't happen" (if (> new-score (slot-value obj 'possible-score)) (progn (format t "Reverting to maximum ~a" (slot-value obj 'possible-score)) (setf (slot-value obj 'current-score) (slot-value obj 'possible-score))) (setf (slot-value obj 'current-score) new-score))) (defun generate-name (whose concept-number) "Creates a string representation of name and concept number to use for creating concept score names" (format nil "~a~a" whose concept-number)) ;(format t "~a~a" whose concept-number)) Use one of these for formating as text depending on future dev (defun create-concept (score-set &optional (possible-score 4)) "clobbers *staged-concept* and creates an object which obeys the grading rules of concept question quizzes" (progn (setq *staged-concept* (make-instance 'concept :concept-name (get-concept-name (car score-set)) :concept-number (car score-set) :possible-score possible-score)) (setf (current-score *staged-concept*) (second score-set)))) (defmacro concept->grade (concept) `(defvar *staged-grade* (make-instance 'grade :max-score 1 :score (/ (float (current-score ,concept)) (float (possible-score ,concept)))))) (defmethod concept-p (num concept) "returns if the numbered concept exists, returns t" (if (eq num (cnum concept)) t nil)) (defmethod exists-concept-p (num scores) "tells you if a cnum exists in a set of concepts" (loop for cnum in scores thereis (concept-p num cnum)))
3,930
Common Lisp
.lisp
76
44.315789
161
0.684279
CCL-GR/grade-database
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
9b484d365d38df197271c1538f31a27180c85defd10bd49ba3780ac18771eab4
41,151
[ -1 ]
41,152
gradebook.lisp
CCL-GR_grade-database/gradebook.lisp
(defclass gradebook () ((students :initarg :students :accessor students) (grade-level :initarg :grade-level :accessor grade-level))) (defvar *c1* (make-instance 'concept :concept-number 1 :concept-name "me1")) (defvar *c2* (make-instance 'concept :concept-number 2 :concept-name "me2")) (defvar *c3* (make-instance 'concept :concept-number 3 :concept-name "me3")) (defvar *c4* (make-instance 'concept :concept-number 4 :concept-name "me4")) (defvar *c5* (make-instance 'concept :concept-number 5 :concept-name "me5")) (defvar *c6* (make-instance 'concept :concept-number 6 :concept-name "me6")) (defvar *c7* (make-instance 'concept :concept-number 7 :concept-name "me7")) (defvar *a* (make-instance 'student :name "a" :grade-level 7 :score 1 :grades '(1 2 3 4 5) :concept-scores (list *c1* *c2* *c3* *c4*))) (defvar *b* (make-instance 'student :name "b" :grade-level 7 :score 2 :grades '(2 2 3 4 5) :concept-scores (list *c3* *c4* *c5* *c6*))) (defvar *c* (make-instance 'student :name "c" :grade-level 7 :score 3 :grades '(3 3 3 4 5) :concept-scores (list *c7* *c6* *c5* *c4*))) ; a test student's gradebook (defvar *gradebook* nil) (defvar *staged-gradebook-entry* (make-instance 'gradebook :students (list *a* *b* *c*) :grade-level 7)) (defmacro stage-gradebook-entry (student) "mutates the gradebook entry to be a specific student object representation" `(progn (setf (name *staged-gradebook-entry*) (name ,student)) (setf (set-of-grades *staged-gradebook-entry*) (cons (concept-quiz ,student) (grades ,student))) (setf (grade-level *staged-gradebook-entry*) (grade-level ,student)))) (defun concept-score-entered-p (num &optional (gradebook *staged-gradebook-entry*)) "returns t if all students in the gradebook have the concept-score listed, nil if one is missing it" (not (loop for stu in (students gradebook) thereis (not (exists-concept-p num (concept-scores stu))))))
2,026
Common Lisp
.lisp
31
59.580645
135
0.670523
CCL-GR/grade-database
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
5eea971b3ae26b7ea706a5f8adecd8e035847259a1af37dce18b2e734f72ff82
41,152
[ -1 ]
41,154
fall_2021.db
CCL-GR_grade-database/fall_2021.db
((:NAME "Tiffany" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "Zhao Zhiwei") (:NAME "Ham" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "Zhao Zihan") (:NAME "Emily" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "Zhao Lanxin") (:NAME "Kai" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "You Kai Cheng") (:NAME "Rachel" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "Liang Bingqi") (:NAME "Isaac" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "Yang Muen") (:NAME "Ivan" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "Zhang Yiwen") (:NAME "Peter" :CLASS 1 :SCORE 0 :GRADE 7 :ATTENDANCE (1 1) :PINYIN "Yiyi"))
658
Common Lisp
.l
1
656
657
0.656012
CCL-GR/grade-database
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
ca0ddd737dfb7f7561d15fa670ad9dfc7e7d0901dcdee5703b99711b4b6579e4
41,154
[ -1 ]
41,158
fall_2021.csv
CCL-GR_grade-database/fall_2021.csv
Name,Eng Name,2021-12-2,2021-6-2,2021-6-1,2021-5-27,2021-5-26,2021-5-25 7,Tiffany,1,1 7,Ham,1,1 7,Emily,1,1 7,Kai,1,1 7,Rachel,1,1 7,Isaac,1,1 7,Ivan,1,1 7,Peter,1,1
166
Common Lisp
.l
9
17.444444
71
0.719745
CCL-GR/grade-database
0
0
0
GPL-3.0
9/19/2024, 11:49:20 AM (Europe/Amsterdam)
83cfac9d5bbeba9829d924ce054a847c7719b74a0e481280a258d2fbf37ec7e4
41,158
[ -1 ]
41,175
package.lisp
goose121_cl-stat-benchmark/package.lisp
;; Copyright 2021 Morgan Hager ;; This file is part of cl-stat-benchmark. ;; cl-stat-benchmark is free software: you can redistribute it and/or modify ;; it under the terms of the GNU Affero General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; cl-stat-benchmark 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 Affero General Public License for more details. ;; You should have received a copy of the GNU Affero General Public License ;; along with cl-stat-benchmark. If not, see <https://www.gnu.org/licenses/>. (defpackage #:cl-stat-benchmark (:use #:cl))
804
Common Lisp
.lisp
14
55.857143
78
0.767857
goose121/cl-stat-benchmark
0
0
0
AGPL-3.0
9/19/2024, 11:49:28 AM (Europe/Amsterdam)
0c6fed171fd256f884e049aedb39de22095c2c280e4a8d5338d421368ab9c3ca
41,175
[ -1 ]
41,176
cl-stat-benchmark.asd
goose121_cl-stat-benchmark/cl-stat-benchmark.asd
;; Copyright 2021 Morgan Hager ;; This file is part of cl-stat-benchmark. ;; cl-stat-benchmark is free software: you can redistribute it and/or modify ;; it under the terms of the GNU Affero General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; cl-stat-benchmark 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 Affero General Public License for more details. ;; You should have received a copy of the GNU Affero General Public License ;; along with cl-stat-benchmark. If not, see <https://www.gnu.org/licenses/>. (asdf:defsystem #:cl-stat-benchmark :description "Benchmark functions and compare the results using statistical tests" :author "Morgan Hager <[email protected]>" :license "GNU Affero General Public License, version 3 or later" :version "0.0.1" :depends-on (#:dynamic-mixins #:cl-mathstats #:alexandria) :serial t :components ((:file "package") (:file "cl-stat-benchmark")))
1,206
Common Lisp
.asd
23
48.652174
84
0.735993
goose121/cl-stat-benchmark
0
0
0
AGPL-3.0
9/19/2024, 11:49:28 AM (Europe/Amsterdam)
6cc155db3d9a662bab7c2438c0100afa5589433014e4cfd4a09313984b528218
41,176
[ -1 ]
41,194
pathnames.lisp
Diemo-zz_PracticalCommonLisp/PortablePathNames/pathnames.lisp
(defun component-present-p (value) (and value (not (eql value :unspecific)))) (defun directory-pathname-p (p) (and (not (component-present-p (pathname-name p))) (not (component-present-p (pathname-type p))) p)) (defun pathname-as-directory (name) (let (( pathname (pathname name))) (when (wild-pathname-p pathname) (error "Can't reliably convert wildcard pathnames.")) (if (not (directory-pathname-p name)) (make-pathname :directory (append (or (pathname-directory pathname) (list :relative )) (list (file-namestring pathname))) :name nil :type nil :defaults pathname) pathname))) (defun directory-wildcard (dirname) (make-pathname :name :wild :type #-clisp :wild #+clisp nil :defaults (pathname-as-directory dirname))) #+clisp (defun clisp-subdirectories-wildcard (wildcard) (make-pathname :directory (append (pathname-directory wildcard) (list :wild)) :name nil :type nil :defaults wildcard)) #+clisp (defun pathname-as-file (name) (let ((pathname (pathname name))) (when (wild-pathname-p pathname) (error "Can't reliably convert wild pathnames")) (if (directory-pathname-p name) (let* ((directory (pathname-directory pathname)) (name-and-type (pathname (first (last directory))))) (make-pathname :directory (butlast directory) :name (pathname-name name-and-type) :type (pathname-type name-and-type) :defaults pathname)) pathname))) (defun list-directory (dirname) (when (wild-pathname-p dirname) (error "Can only list concrete directory pathnames.")) (let ((wildcard (directory-wildcard dirname))) #+ (or sbcl cmu lispworks) (directory wildcard) #+openmcl (directory wildcard :directories t) #+allegro (directory wildcard :directories-are-files nil) #+clisp (nconc (directory wildcard) (directory (clisp-subdirectories-wildcard wildcard))) #-(or sbcl cmu lispworks openmcl allegro clisp) (error "list-directory is not implemented for this implementation of lisp."))) (defun file-exists-p (pathname) #+(or sbcl lispworks openmcl) (probe-file pathname) #+(or allegro cmu) (or (probe-file (pathname-as-file pathname)) (probe-file pathname)) #+clisp (or (ignore-errors (probe-file (pathname-as-file pathname))) (ignore-errors (let ((directory-form (pathname-as-directory pathname))) (when ( ext:probe-directory directory-form) direcory-form)))) #- (or sbcl cmu lispworks openmcl allegro clisp) (error "file-exists-p not implemented for this implementation of lisp.")) (defun walk-directory (dirname fn &key directories (test (constantly t))) (labels ((walk (name) (cond ((directory-pathname-p name) (when (and directories (funcall test name)) (funcall fn name)) (dolist (x (list-directory- name)) (walk x))) ((funcall test name) (funcall fn name))))) (walk (pathname-as-directory dirname))))
3,162
Common Lisp
.lisp
86
30.290698
82
0.654664
Diemo-zz/PracticalCommonLisp
0
0
0
GPL-3.0
9/19/2024, 11:49:37 AM (Europe/Amsterdam)
789e46d8f4297f736555246e721205de7442ce9f1da665cb92c4534ab3ba5b1a
41,194
[ -1 ]
41,195
framework.lisp
Diemo-zz_PracticalCommonLisp/UnitTesting/framework.lisp
(defvar *testname* nil) (defun report-result (result form) (format t "~:[FAIL~;pass~] ~A ... ~a~%" result *testname* form) result) (defmacro check (&body forms) `(combine-results ,@(loop for f in forms collect `(report-result ,f ',f)))) (defmacro with-gensyms (syms &body body) `(let ,(loop for s in syms collect `(,s (gensym))) ,@body)) (defmacro combine-results (&body forms) (with-gensyms (result) `(let ((,result t)) ,@(loop for f in forms collect `(unless ,f (setf ,result nil))) ,result))) (defmacro deftest (name parameters &body body) `(defun ,name ,parameters (let ((*testname* (append *testname* (list ',name)))) ,@body))) (deftest test-+ () (check (= (+ 1 2) 3) (= (+ 1 2 3) 6) (= (+ -1 -3) -4 ))) (deftest test* () (check (= (* 1 1) 1) (= (* 4 5) 20))) (deftest run-all-tests () (combine-results (test-+) (test*)))
984
Common Lisp
.lisp
30
26.6
84
0.540741
Diemo-zz/PracticalCommonLisp
0
0
0
GPL-3.0
9/19/2024, 11:49:37 AM (Europe/Amsterdam)
029d0d6e94e66d95d9b2536b420ad9f82b849c6e59f907aa913e5135fc102c95
41,195
[ -1 ]
41,213
models.lisp
jmdaemon_treeleaves-lisp/src/models.lisp
(defpackage treeleaves.models (:use :cl) (:use :iter) (:documentation "Generate directory based file tags") (:import-from #:treeleaves.format #:fmt #:format-tags #:make-tag) (:export :connect :ensure-tables :write-to-db :find-doc :find-docs :initdb :querydb :document :*database-table-types* :add-to-db )) (in-package :treeleaves.models) (require "mito") (require "sxql") (require "str") (require "iterate") ;; Database Functions (defun connect (dbname) "Connect to the database" (mito:connect-toplevel :sqlite3 :database-name dbname)) (defun ensure-tables (tables) "Creates database tables if not already existing" (mapcar #'mito:ensure-table-exists tables)) (defun write-to-db (table tags filepath) "Create and write table entries to the database" (mito:create-dao table :tags tags :filepath filepath)) (defgeneric find-doc (table key-name key-value) (:documentation "Retrieves a document from the data base by one of the unique keys.")) (defmethod find-doc (table (key-name (eql :id)) (key-value integer)) (mito:find-dao table key-value)) (defmethod find-doc (table key-name key-value) (mito:select-dao table (sxql:where (:like :tags key-value)))) (defun find-docs (&key query (order :desc)) "Return a list of documents. If a query string is given, search on both the tags and the filepath fields. Usage: (find-docs :query \"Books\") " (mito:select-dao 'document (when (str:non-blank-string-p query) (sxql:where `(:and ,@(loop for word in (str:words query) :collect `(:or (:like :tags ,(str:concat "%" word "%")) (:like :filepath ,(str:concat "%" word "%"))))))) (sxql:order-by `(,order :created-at)))) (defun initdb (db tables) "Initializes the database and the database tables" (connect db) (ensure-tables tables)) (defun showdocs (docs) "Show all document filepaths found in docs" (iterate (for doc in docs) (print (slot-value doc 'filepath))) (format t "~%")) (defun query-db-all (tables query) "Queries the database across all tables and for all document fields" (defparameter docs nil) (iterate (for search-term in query) (iterate (for table in tables) (setq docs (find-docs table :query search-term)) (showdocs docs)))) (defun querydb (tables kword search-term) "Query the database and show matches Note that this function only queries for tag matches only " ;(defparameter docs nil) (iterate (for table in tables) (setq docs (find-doc table kword search-term)) (showdocs docs))) ; Define the document class ;(mito:deftable document () ;((tags :col-type (:varchar 4096)) ;(filepath :col-type (:varchar 4096)))) (defclass document () ((tags :col-type (:varchar 4096) :accessor tags) (filepath :col-type (:varchar 4096) :accessor filepath)) (:metaclass mito:dao-table-class)) ; Define the types of database tables available to be selected (defparameter *database-table-types* (make-hash-table :test #'equal)) ; Add the document class (setf (gethash "document" *database-table-types*) 'document) (defun add-to-db (db files) "Add new document entries to the database" (iter (for filepath in files) (if filepath (write-to-db db (format-tags (make-tag filepath)) (uiop:native-namestring filepath)))))
3,602
Common Lisp
.lisp
97
31.010309
99
0.65155
jmdaemon/treeleaves-lisp
0
0
0
AGPL-3.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
7b9d6491c590f9d224d6f76416c984e27b567104b919d96c71074ae974bc31ab
41,213
[ -1 ]
41,214
treeleaves.lisp
jmdaemon_treeleaves-lisp/src/treeleaves.lisp
(defpackage :treeleaves (:use :cl :treeleaves.models) (:documentation "Generate directory based file tags") (:import-from #:treeleaves.models #:connect #:ensure-tables #:write-to-db #:find-doc #:query #:document #:add-to-db) (:import-from #:treeleaves.format #:split-dir #:make-tag #:print-tags #:format-tags #:format-args #:fmt) (:import-from #:treeleaves.cli #:build-cli #:show-usage #:show-verbose #:parse-opts) (:export :main)) (in-package :treeleaves) (require "uiop") (require "unix-opts") ; TODO: ; Pruning: ; - Find dead filepaths and remove them from the database (reindex) ; Indexing ; - Find dead filepaths, remove them from the database, and add new files to the database ; - Add commands to ; - Reindex a file ; - Reindex a directory ; - Reindex all files in a database ; - Reindex missing files ; With support for ; - Automigration ; Automigration: ; - Find and compare similar file names, and automatically update filepath name (defun main () "Main application entry point" ; Define CLI & Parse Args (build-cli) (parse-opts (uiop:command-line-arguments)) ; Show debug info (if show-verbose (progn (if dir (format t "Using Directory: ~a~%" dir)) (if db (format t "Using Database: ~a~%" db)) (if pat (format t "With Globbing Pattern: ~a~%" pat)))) (opts:exit) ; Expands the directory path, and collects all the files (defparameter file-dir (concatenate 'string (uiop:native-namestring dir) pat)) (defparameter files (directory file-dir)) ; Connect and write to database (connect db) (ensure-tables (list 'document)) (add-to-db 'document files))
1,891
Common Lisp
.lisp
59
25.610169
89
0.617325
jmdaemon/treeleaves-lisp
0
0
0
AGPL-3.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
ca4df343026bbfc2b2cedef7948af42531bc6df6b16cae513e211d0f264f7337
41,214
[ -1 ]
41,215
main.lisp
jmdaemon_treeleaves-lisp/tests/main.lisp
(defpackage treeleaves/tests/main (:use :cl :treeleaves :fiveam) (:documentation "Unit tests for Treeleaves") (:import-from #:treeleaves.models #:*database-table-types* ) (:import-from #:treeleaves.format #:split-dir #:fmt #:format-tags #:format-args #:find-tables #:parse-search-args #:parse-database-args ) (:import-from #:treeleaves.cli) (:import-from #:treeleaves) ) (in-package :treeleaves/tests/main) ; Imports (require "treeleaves") (require "fiveam") ; Helper functions (defun list= (l1 l2 &key (test #'eql)) "Check if two lists are equal to each other " (loop for i in l1 for j in l2 always (funcall test i j))) (defun type-equal (t1 t2) "Check if two types are equal to each other" (and (subtypep t1 t2) (subtypep t2 t1))) ; Treeleaves Tests Suite (def-suite treeleaves :description "Main Treeleaves Test Suite") ; Treeleaves Models Suite (def-suite treeleaves.models :description "Treeleaves.Models Test Suite" :in treeleaves) (in-suite treeleaves.models) ; Test the database lookup (test test-database-table-types ; Index into the database table types (let ((result (gethash "document" *database-table-types*))) (is (not (null result)) "result should not be null") (is (type-equal 'document result) "*database-table-types* should contain the document class: ~a" result))) ; Treeleaves Format Suite (def-suite treeleaves.format :description "Treeleaves.Format Tests Suite" :in treeleaves) (in-suite treeleaves.format) ; split-dir (test test-split-dir (let ((result (split-dir "/home/user/"))) (is (equal (list "" "home" "user" "") result) "split-dir should split the directory into a list: ~a" result))) ; format-tags (test test-format-tags (let ((result (format-tags (list "Books" "Historical" "Fiction")))) (is (equal "Books Historical Fiction " result)) "format-tags should format tags into a string")) ; fmt (test test-fmt (let ((result (fmt "Hello"))) (is (equal "Hello" result)) "fmt should format text into a string")) ; format-tags (test test-format-args (let ((result (format-args (list "Books" "Historical" "Fiction")))) (is (equal "Books Historical Fiction" result)) "format-args should format arguments into a string")) ; find-tables (test test-find-tables-nil (let ((result (find-tables "document -f ./documents.sqlite -q :tags Books %"))) (is (equal nil result)) "find-tables should return nil when -t is not passed in: ~a" result)) (test test-find-tables-document (let ((result (find-tables "-t document -f ./documents.sqlite -q :tags Books %"))) (is (equal "document " result)) "find-tables should return the name of the database table: ~a" result)) (test test-find-tables-full (let ((result (find-tables "./bin/treeleaves -t document -f ./documents.sqlite -q \":tags\" \"Books\" %"))) (is (equal "document " result)) "find-tables should return the name of the database table: ~a" result)) ; parse-search-args (test test-parse-search-args-tags (let ((result (parse-search-args ":tags Books %"))) (is (equal (list ":tags" "Books %") result)) "parse-search-args should return the keyword and the search term from the arguments" )) (test test-parse-search-args-full (let ((result (parse-search-args "document -f ./documents.sqlite -qa :tags Books %"))) (is (equal (list ":tags" "Books %") result)) "parse-search-args should return the keyword and the search term from the arguments" )) ; parse-database-args (test test-parse-database-args (let ((result (parse-database-args "document -f ./documents.sqlite -qa :tags Books %"))) (is (equal "./documents.sqlite" result) "parse-database-args should return the file path of the database from the arguments"))) ; Treeleaves CLI Suite (def-suite treeleaves.cli :description "Treeleaves.CLI Test Suite" :in treeleaves) (in-suite treeleaves.format) ;(test test-this-should-fail ;(let ((result nil)) ;(is (equal t result)) ;"Manual test to ensure asdf is running the test suite")) ; Run test suite manually (run! 'treeleaves) ; treeleaves.model ; find-docs ;(defparameter db "documents.sqlite") ;(defparameter tables (list 'document)) ;(connect db) ;(ensure-tables tables) ;(find-docs :query "Books") ; query-db ; query-db-all
4,693
Common Lisp
.lisp
128
30.96875
107
0.650451
jmdaemon/treeleaves-lisp
0
0
0
AGPL-3.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
e4fbe02be5cdcae8fe1e54db5b990d0e3d977ac2c48a5d985597a7e97b8f9cc0
41,215
[ -1 ]
41,216
treeleaves.asd
jmdaemon_treeleaves-lisp/treeleaves.asd
(require "asdf") (asdf:defsystem "treeleaves" :version "0.3.1" :author "Joseph Diza <[email protected]>" :license "AGPLv3" :depends-on (:cl-utilities :cl-ppcre :unix-opts :uiop :sxql :mito :iterate :str :log4cl) :components ((asdf:module "src" :components ((:file "format") (:file "models") (:file "cli") (:file "treeleaves") ))) :description "Directory tag generator for files" :build-operation "program-op" ;; leave as is :build-pathname "bin/treeleaves" :entry-point "treeleaves:main" :in-order-to ((asdf:test-op (asdf:test-op "treeleaves/tests")))) (asdf:defsystem "treeleaves/tests" :author "Joseph Diza <[email protected]>" :license "AGPLv3" :depends-on (:treeleaves :fiveam) :components ((asdf:module "tests" :components ((:file "main")))) :description "Test system for treeleaves" :perform (asdf:test-op (op c) (symbol-call :fiveam :run! (find-symbol* "treeleaves" "treeleaves/tests"))))
1,146
Common Lisp
.asd
32
27.3125
108
0.581312
jmdaemon/treeleaves-lisp
0
0
0
AGPL-3.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
2fa97b56713ae6fbc7659ebe060d605dd3dcc7200b61d0592c721844d469d55b
41,216
[ -1 ]
41,219
Makefile
jmdaemon_treeleaves-lisp/Makefile
LISP ?= sbcl EXE = treeleaves QL = /usr/lib/quicklisp/setup.lisp BIN_PREFIX = bin BUILD_EXEC = $(BIN_PREFIX)/$(EXE) # Set install path ifeq ($(PREFIX),) PREFIX := /usr/local endif # Rules build: $(LISP) --load $(QL) \ --eval "(load \"$(EXE).asd\")" \ --eval "(ql:quickload :$(EXE))" \ --eval "(asdf:make :$(EXE))" \ --eval "(asdf:test-system :$(EXE))" \ --eval "(quit)" install: build $(BUILD_EXEC) install $(BUILD_EXEC) $(DESTDIR)$(PREFIX)/bin/$(EXE) uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/$(EXE)
522
Common Lisp
.l
21
22.809524
53
0.616935
jmdaemon/treeleaves-lisp
0
0
0
AGPL-3.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
d8fa1650e0802b469877a3b9aeddff4593e539c2f05875b0f32956026d0acd73
41,219
[ -1 ]
41,237
package.lisp
mrossini-ethz_lisp-struct/package.lisp
(defpackage :lisp-struct (:nicknames :struct) (:use :common-lisp :parseq) (:export pack unpack limit-error argument-error use-value clip-value wrap-value))
162
Common Lisp
.lisp
4
38
83
0.753165
mrossini-ethz/lisp-struct
0
0
0
GPL-2.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
7e48a88710cbc96ee25cdcc1c5091fc238ce39ece78a70d112a7fdc1d7eadd6d
41,237
[ -1 ]
41,238
lisp-struct.lisp
mrossini-ethz_lisp-struct/lisp-struct.lisp
;; lisp-struct ;; ---------------------------------------------------------------------------------------- ;; This code implements something similar to the 'struct' module from python. The 'struct' ;; module allows the user to extract integers (and other values) from an array of bytes. ;; For example, a long integer is encoded as four bytes in the array in either the little- ;; endian (least significant byte first) or big-endian (most significant byte first). The ;; integer can be either signed or unsigned. In python the bytearray could be stored in a ;; variable, e.g. 'data'. The function ;; ;; tuple_of_integers = struct.unpack("<LhbBH", data) ;; ;; will extract five integers from the data in the following order: an unsigned long integer ;; (L), a signed short integer (h), a signed charater (b), an unsigned character (B) and an ;; unsigned short integer. The first character in the string (<) means that all integers are ;; stored in little-endian byte order. The opposite would be (>), i.e. big endian. ;; ;; In lisp, we would like to do something similar. We would like to write the following: ;; ;; (setf list-of-integers (struct:unpack "<LhbBH" data)) ;; ;; However, we might want struct-unpack to be a macro such that the string "<LhbBH" will be ;; interpreted at compile time and the code will run faster. (in-package :lisp-struct) (define-condition limit-error (error) ()) ;; --- Helper functions/macros ----------------------------------------------------- (defmacro f-error (type (&rest initargs) control &rest args) "Like (error ...), but allows the condition type to be specified (which is required to inherit from simple-condition)." `(error ',type ,@initargs :format-control ,control :format-arguments (list ,@args))) ;; Helper macro: like (incf ...) but returning the old instead of the new value (defmacro post-incf (place &optional (delta 1)) (let ((var (gensym))) `(let ((,var ,place)) (incf ,place ,delta) ,var))) ;; Function that checks the ASCII value of characters (defun character-limit (char) (when (> (char-code char) 255) (error 'limit-error)) char) ;; Function that converts an unsigned integer uint into a signed integer by interpreting ;; the unsigned value as the two's complement of the signed value. (defun unsigned-to-signed (uint length) ;; Check integer size (let ((maxval (ash 1 (* 8 length)))) (if (< uint (ash maxval -1)) uint (- uint maxval)))) ;; Function that converts a signed integer sint into an unsigned integer by encoding the ;; signed value usig two's complement. (defun signed-to-unsigned (sint length) (if (minusp sint) (- (ash 1 (* 8 length)) (abs sint)) sint)) ;; Checks whether the given integer fits into the specified number of bytes. (defun integer-limit-unsigned (integer bytes) (let ((maxval (1- (ash 1 (* 8 bytes))))) (if (and (>= integer 0) (<= integer maxval)) integer (restart-case (error 'limit-error) (use-value (value) value) (clip-value () (if (minusp integer) 0 maxval)) (wrap-value () (mod integer (1+ maxval))))))) ;; Checks whether the given integer fits into the specified number of bytes when ;; using two's complement. (defun integer-limit-signed (integer bytes) (let ((maxval (ash 1 (1- (* 8 bytes))))) (if (and (>= integer (- maxval)) (< integer maxval)) integer (restart-case (error 'limit-error) (use-value (value) (signed-to-unsigned value bytes)) (clip-value () (if (minusp integer) (- maxval) (1- maxval))))))) ;; Produces code to unpack an unsigned integer of given length and byte order from an array of bytes at the given position. ;; This function will be used in a macro expansion. (defun unpack-unsigned (array pos length byte-order) `(+ ,@(loop for i below length for index = (* i 8) for shift = (case byte-order (:little-endian (+ pos i)) (:big-endian (- (+ pos length) i 1)) (t (error "Invalid byte order specified"))) collect `(ash (elt ,array ,shift) ,index)))) ;; Produces code to unpack a signed integer of given length and byte order from an array of bytes at the given position. ;; This function will be used in a macro expansion. (defun unpack-signed (array pos length byte-order) `(unsigned-to-signed ,(unpack-unsigned array pos length byte-order) ,length)) ;; Produces code to pack an unsigned integer of given length into an array of bytes in given byte order and at the given position. ;; This function will be used in a macro expansion. (defun pack-unsigned (pos length byte-order) (declare (ignore pos)) (let ((value (gensym))) (loop for i below length for index = (case byte-order (:little-endian (* i 8)) (:big-endian (* (- length i 1) 8)) (t (error "Invalid byte order specified"))) collect `(ldb (byte 8 ,index) ,value) into results finally (return `(,value (integer-limit-unsigned ,value ,length) ,results))))) ;; Produces code to pack a signed integer of given length into an array of bytes in given byte order and at the given position. ;; This function will be used in a macro expansion. (defun pack-signed (pos length byte-order) (declare (ignore pos)) (let ((value (gensym))) (loop for i below length for index = (case byte-order (:little-endian (* i 8)) (:big-endian (* (- length i 1) 8)) (t (error "Invalid byte order specified"))) collect `(ldb (byte 8 ,index) ,value) into results finally (return `(,value (signed-to-unsigned (integer-limit-signed ,value ,length) ,length) ,results))))) ;; --- Parseq rules ---------------------------------------------------------------- ;; Parseq rule for generating the code that processes the data for unpacking ;; Returns a list consisting of the number of bytes and a list of lisp expressions (defrule unpack-format (array-var) (and alignment (* (unpack-format-char array-var))) (:let (align :little-endian) (bytes 0)) (:lambda (a code) (declare (ignore a)) `(,bytes ,(apply #'concatenate 'list code)))) ;; Parseq rule for generating the code that processes the data for packing (defrule pack-format () (and alignment (* (pack-format-char))) (:let (align :little-endian) (bytes 0)) (:lambda (a code) (declare (ignore a)) `(,bytes ,(apply #'concatenate 'list code)))) ;; Parseq rule for processing the byte order in the format string (defrule alignment () (or #\< #\>) (:external align) (:lambda (x) (if (char= x #\<) (setf align :little-endian) (setf align :big-endian)) x)) ;; Parseq rule for numbers (used for character repetition) (defrule rep-number () (and (char "1-9") (* (char "0-9"))) (:string) (:function #'parse-integer)) ;; Parseq rule for character repetition (defaults to 1 repetition) (defrule reps () (? rep-number) (:lambda (&rest n) (if n (first n) 1))) ;; Parseq rule for unpacking the individual data type elements of the format string (defrule unpack-format-char (array-var) (or unpack-padding (unpack-char array-var) (unpack-string array-var) (unpack-bool array-var) (unpack-unsigned-char array-var) (unpack-signed-char array-var) (unpack-unsigned-short array-var) (unpack-signed-short array-var) (unpack-unsigned-long array-var) (unpack-signed-long array-var) (unpack-unsigned-long-long array-var) (unpack-signed-long-long array-var))) ;; Parseq rule for packing the individual data type elements of the format string (defrule pack-format-char () (or pack-padding pack-char pack-string pack-bool pack-unsigned-char pack-signed-char pack-unsigned-short pack-signed-short pack-unsigned-long pack-signed-long pack-unsigned-long-long pack-signed-long-long)) ;; Parseq rule for 'unpacking' padding bytes (defrule unpack-padding () (and reps "x") (:external bytes) (:lambda (n c) (declare (ignore c)) (incf bytes n) nil)) ;; Parseq rule for 'packing' padding bytes (defrule pack-padding () (and reps "x") (:external bytes) (:lambda (n c) (declare (ignore c)) (incf bytes n) (loop for i below n collect `(nil nil (0))))) ;; Parseq rule for unpacking characters (defrule unpack-char (array-var) (and reps "c") (:external bytes) (:lambda (n c) (declare (ignore c)) (loop for i below n collect `(code-char (elt ,array-var ,(post-incf bytes)))))) ;; Parseq rule for packing characters (defrule pack-char () (and reps "c") (:external bytes) (:lambda (n c) (declare (ignore c)) (incf bytes n) (loop for i below n for var = (gensym) collect `(,var (character-limit ,var) ((char-code ,var)))))) ;; Parseq rule for unpacking strings (defrule unpack-string (array-var) (and reps "s") (:external bytes) (:lambda (n c) (declare (ignore c)) `((concatenate 'string ,@(loop for i below n collect `(list (code-char (elt ,array-var ,(post-incf bytes))))))))) ;; Parseq rule for packing strings (defrule pack-string () (and reps "s") (:external bytes) (:lambda (n c) (declare (ignore c)) (incf bytes n) (let ((var (gensym))) `((,var (map 'string #'character-limit ,var) ,(loop for i below n collect `(char-code (elt ,var ,i)))))))) ;; Parseq rule for unpacking boolean values (defrule unpack-bool (array-var) (and reps "?") (:external bytes) (:lambda (n c) (declare (ignore c)) (loop for i below n collect `(not (zerop (elt ,array-var ,(post-incf bytes))))))) ;; Parseq rule for packing boolean values (defrule pack-bool () (and reps "?") (:external bytes) (:lambda (n c) (declare (ignore c)) (incf bytes n) (loop for i below n for var = (gensym) collect `(,var nil ((if ,var 1 0)))))) ;; Macro that helps defining unpack rules for the different integer types (defmacro define-integer-unpack-rule (character length signedness variable) `(defrule ,variable (array-var) (and reps ,character) (:external align bytes) (:lambda (n c) (declare (ignore c)) ,(case signedness (:unsigned `(loop for i below n collect (unpack-unsigned array-var (post-incf bytes ,length) ,length align))) (:signed `(loop for i below n collect (unpack-signed array-var (post-incf bytes ,length) ,length align))) (t (error "Invalid signedness specified!")))))) ;; Macro that helps defining pack rules for the different integer types (defmacro define-integer-pack-rule (character length signedness variable) `(defrule ,variable () (and reps ,character) (:external align bytes) (:lambda (n c) (declare (ignore c)) ,(case signedness (:unsigned `(loop for i below n collect (pack-unsigned (post-incf bytes ,length) ,length align))) (:signed `(loop for i below n collect (pack-signed (post-incf bytes ,length) ,length align))) (t (error "Invalid signedness specified!")))))) ;; Use the helper macro to define the integer type unpack rules (define-integer-unpack-rule #\Q 8 :unsigned unpack-unsigned-long-long) (define-integer-unpack-rule #\q 8 :signed unpack-signed-long-long) (define-integer-unpack-rule #\L 4 :unsigned unpack-unsigned-long) (define-integer-unpack-rule #\l 4 :signed unpack-signed-long) (define-integer-unpack-rule #\H 2 :unsigned unpack-unsigned-short) (define-integer-unpack-rule #\h 2 :signed unpack-signed-short) (define-integer-unpack-rule #\B 1 :unsigned unpack-unsigned-char) (define-integer-unpack-rule #\b 1 :signed unpack-signed-char) ;; Use the helper macro to define the integer type pack rules (define-integer-pack-rule #\Q 8 :unsigned pack-unsigned-long-long) (define-integer-pack-rule #\q 8 :signed pack-signed-long-long) (define-integer-pack-rule #\L 4 :unsigned pack-unsigned-long) (define-integer-pack-rule #\l 4 :signed pack-signed-long) (define-integer-pack-rule #\H 2 :unsigned pack-unsigned-short) (define-integer-pack-rule #\h 2 :signed pack-signed-short) (define-integer-pack-rule #\B 1 :unsigned pack-unsigned-char) (define-integer-pack-rule #\b 1 :signed pack-signed-char) ;; --- Main macro definitions ------------------------------------------------------ (define-condition argument-error (simple-condition) ()) ;; Define the unpack macro (defmacro unpack (format data) ;; Check the format string (unless (stringp format) (f-error argument-error () "The argument 'format' must be a literal string!")) ;; Evaluate the data once (let* ((array-var (gensym)) (result (parseq `(unpack-format ,array-var) format))) (unless result (f-error argument-error () "Invalid format string!")) (destructuring-bind (bytes code) result `(let ((,array-var ,data)) (unless (= (length ,array-var) ,bytes) (f-error argument-error () "Invalid number of bytes. Expected: ~a" ,bytes)) ;; Generate the code for unpacking using the parseq rule (list ,@code))))) ;; Define the pack macro (defmacro pack (format value-list) ;; Check the format string (unless (stringp format) (f-error argument-error () "The argument 'format' must be a literal string!")) (let ((values (gensym)) (result (parseq `pack-format format))) (unless result (f-error argument-error () "Invalid format string!")) (destructuring-bind (bytes code) result (let ((args (count-if-not #'null code :key #'first))) `(let ((,values ,value-list)) (when (/= (length ,values) ,args) (f-error argument-error () "Invalid number of values. Expected: ~a" ,args)) (destructuring-bind ,(remove nil (mapcar #'first code)) ,values ;; Convert values and check limits ,@(loop for c in code for a = (first c) for b = (second c) when (and a b) collect `(setf ,a ,b)) ;; Create the byte array (make-array ,bytes :element-type '(unsigned-byte 8) :initial-contents (list ,@(loop for c in code append (third c))))))))))
14,661
Common Lisp
.lisp
277
46.00722
150
0.635229
mrossini-ethz/lisp-struct
0
0
0
GPL-2.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
5971350d8ce29a262516a9e3d99cf3e526829bb1fd9247beb989711157d4dd6b
41,238
[ -1 ]
41,239
test.lisp
mrossini-ethz_lisp-struct/test/test.lisp
(in-package :lisp-struct/test) (defun array= (a b) (and (= (length a) (length b)) (every #'identity (map 'list #'= a b)))) (test character-tests (is (equal '(#\A) (lisp-struct:unpack ">c" #(65)))) (is (equal '(#\A) (lisp-struct:unpack "<c" #(65)))) (is (equal '(#\A #\B #\C) (lisp-struct:unpack ">ccc" #(65 66 67)))) (is (equal '(#\A #\B #\C) (lisp-struct:unpack "<ccc" #(65 66 67)))) (is (equal '(#\A #\B #\C) (lisp-struct:unpack ">3c" #(65 66 67)))) (is (equal '(#\A #\B #\C) (lisp-struct:unpack "<3c" #(65 66 67)))) (is (array= #(65) (lisp-struct:pack ">c" '(#\A)))) (is (array= #(65) (lisp-struct:pack "<c" '(#\A)))) (is (array= #(65 66 67) (lisp-struct:pack ">ccc" '(#\A #\B #\C)))) (is (array= #(65 66 67) (lisp-struct:pack "<ccc" '(#\A #\B #\C)))) (is (array= #(65 66 67) (lisp-struct:pack ">3c" '(#\A #\B #\C)))) (is (array= #(65 66 67) (lisp-struct:pack "<3c" '(#\A #\B #\C))))) (test (string-tests :depends-on character-tests) (is (equal '("A") (lisp-struct:unpack ">s" #(65)))) (is (equal '("A") (lisp-struct:unpack "<s" #(65)))) (is (equal '("ABC") (lisp-struct:unpack ">3s" #(65 66 67)))) (is (equal '("ABC") (lisp-struct:unpack "<3s" #(65 66 67)))) (is (equal '(#\x "ABC" #\y) (lisp-struct:unpack ">c3sc" #(120 65 66 67 121)))) (is (equal '(#\x "ABC" #\y) (lisp-struct:unpack "<c3sc" #(120 65 66 67 121)))) (is (array= #(65) (lisp-struct:pack ">s" '("A")))) (is (array= #(65) (lisp-struct:pack "<s" '("A")))) (is (array= #(65 66 67) (lisp-struct:pack ">3s" '("ABC")))) (is (array= #(65 66 67) (lisp-struct:pack "<3s" '("ABC")))) (is (array= #(120 65 66 67 121) (lisp-struct:pack ">c3sc" '(#\x "ABC" #\y)))) (is (array= #(120 65 66 67 121) (lisp-struct:pack "<c3sc" '(#\x "ABC" #\y))))) (test (padding-tests :depends-on character-tests) ;; Unpack (is (equal '() (lisp-struct:unpack ">x" #(65)))) (is (equal '() (lisp-struct:unpack "<x" #(65)))) (is (equal '() (lisp-struct:unpack ">xxx" #(65 66 67)))) (is (equal '() (lisp-struct:unpack "<xxx" #(65 66 67)))) (is (equal '() (lisp-struct:unpack ">3x" #(65 66 67)))) (is (equal '() (lisp-struct:unpack "<3x" #(65 66 67)))) (is (equal '(#\A #\B #\C) (lisp-struct:unpack ">xcxcxcx" #(119 65 120 66 121 67 122)))) (is (equal '(#\A #\B #\C) (lisp-struct:unpack "<xcxcxcx" #(119 65 120 66 121 67 122)))) ;; Pack (is (array= #(0) (lisp-struct:pack ">x" '()))) (is (array= #(0) (lisp-struct:pack "<x" '()))) (is (array= #(0 0 0) (lisp-struct:pack ">xxx" '()))) (is (array= #(0 0 0) (lisp-struct:pack "<xxx" '()))) (is (array= #(0 0 0) (lisp-struct:pack ">3x" '()))) (is (array= #(0 0 0) (lisp-struct:pack "<3x" '()))) (is (array= #(0 65 0 66 0 67 0) (lisp-struct:pack ">xcxcxcx" '(#\A #\B #\C)))) (is (array= #(0 65 0 66 0 67 0) (lisp-struct:pack "<xcxcxcx" '(#\A #\B #\C))))) (test (boolean-tests :depends-on character-tests) ;; Unpack (is (equal '(nil) (lisp-struct:unpack ">?" #(0)))) (is (equal '(nil) (lisp-struct:unpack "<?" #(0)))) (is (equal '(t) (lisp-struct:unpack ">?" #(1)))) (is (equal '(t) (lisp-struct:unpack ">?" #(2)))) (is (equal '(t) (lisp-struct:unpack ">?" #(255)))) (is (equal '(t) (lisp-struct:unpack "<?" #(1)))) (is (equal '(t) (lisp-struct:unpack "<?" #(2)))) (is (equal '(t) (lisp-struct:unpack "<?" #(255)))) (is (equal '(t nil t) (lisp-struct:unpack "<???" #(4 0 200)))) (is (equal '(t nil t) (lisp-struct:unpack ">???" #(4 0 200)))) (is (equal '(t nil t) (lisp-struct:unpack "<3?" #(4 0 200)))) (is (equal '(t nil t) (lisp-struct:unpack ">3?" #(4 0 200)))) ;; Pack (is (array= #(0) (lisp-struct:pack ">?" '(nil)))) (is (array= #(0) (lisp-struct:pack "<?" '(nil)))) (is (array= #(1) (lisp-struct:pack "<?" '(t)))) (is (array= #(1) (lisp-struct:pack ">?" '(t)))) (is (array= #(1 0 1) (lisp-struct:pack ">???" '(t nil t)))) (is (array= #(1 0 1) (lisp-struct:pack "<???" '(t nil t)))) (is (array= #(1 0 1) (lisp-struct:pack ">3?" '(t nil t)))) (is (array= #(1 0 1) (lisp-struct:pack "<3?" '(t nil t))))) (test conversion-tests ;; unsigned to signed, 8 bits (is (= 0 (lisp-struct::unsigned-to-signed 0 1))) (is (= 1 (lisp-struct::unsigned-to-signed 1 1))) (is (= 2 (lisp-struct::unsigned-to-signed 2 1))) (is (= 126 (lisp-struct::unsigned-to-signed 126 1))) (is (= 127 (lisp-struct::unsigned-to-signed 127 1))) (is (= -128 (lisp-struct::unsigned-to-signed 128 1))) (is (= -127 (lisp-struct::unsigned-to-signed 129 1))) (is (= -2 (lisp-struct::unsigned-to-signed 254 1))) (is (= -1 (lisp-struct::unsigned-to-signed 255 1))) ;; unsigned to signed, 32 bits (is (= 0 (lisp-struct::unsigned-to-signed 0 4))) (is (= 1 (lisp-struct::unsigned-to-signed 1 4))) (is (= 2 (lisp-struct::unsigned-to-signed 2 4))) (is (= 2147483646 (lisp-struct::unsigned-to-signed 2147483646 4))) (is (= 2147483647 (lisp-struct::unsigned-to-signed 2147483647 4))) (is (= -2147483648 (lisp-struct::unsigned-to-signed 2147483648 4))) (is (= -2147483647 (lisp-struct::unsigned-to-signed 2147483649 4))) (is (= -2 (lisp-struct::unsigned-to-signed 4294967294 4))) (is (= -1 (lisp-struct::unsigned-to-signed 4294967295 4))) ;; signed to unsigned, 8 bits (is (= 0 (lisp-struct::signed-to-unsigned 0 1))) (is (= 1 (lisp-struct::signed-to-unsigned 1 1))) (is (= 2 (lisp-struct::signed-to-unsigned 2 1))) (is (= 126 (lisp-struct::signed-to-unsigned 126 1))) (is (= 127 (lisp-struct::signed-to-unsigned 127 1))) (is (= 128 (lisp-struct::signed-to-unsigned -128 1))) (is (= 129 (lisp-struct::signed-to-unsigned -127 1))) (is (= 254 (lisp-struct::signed-to-unsigned -2 1))) (is (= 255 (lisp-struct::signed-to-unsigned -1 1))) ;; signed to unsigned, 32 bits (is (= 0 (lisp-struct::signed-to-unsigned 0 4))) (is (= 1 (lisp-struct::signed-to-unsigned 1 4))) (is (= 2 (lisp-struct::signed-to-unsigned 2 4))) (is (= 2147483646 (lisp-struct::signed-to-unsigned 2147483646 4))) (is (= 2147483647 (lisp-struct::signed-to-unsigned 2147483647 4))) (is (= 2147483648 (lisp-struct::signed-to-unsigned -2147483648 4))) (is (= 2147483649 (lisp-struct::signed-to-unsigned -2147483647 4))) (is (= 4294967294 (lisp-struct::signed-to-unsigned -2 4))) (is (= 4294967295 (lisp-struct::signed-to-unsigned -1 4)))) (test integer-limits ;; unsigned, 8 bits (signals limit-error (lisp-struct::integer-limit-unsigned 256 1)) (signals limit-error (lisp-struct::integer-limit-unsigned -1 1)) ;; unsigned, 16 bits (signals limit-error (lisp-struct::integer-limit-unsigned 65537 2)) (signals limit-error (lisp-struct::integer-limit-unsigned -1 2)) ;; unsigned, 32 bits (signals limit-error (lisp-struct::integer-limit-unsigned 4294967296 4)) (signals limit-error (lisp-struct::integer-limit-unsigned -1 4)) ;; signed, 8 bits (signals limit-error (lisp-struct::integer-limit-signed 128 1)) (signals limit-error (lisp-struct::integer-limit-signed -129 1)) ;; signed, 16 bits (signals limit-error (lisp-struct::integer-limit-signed 32768 2)) (signals limit-error (lisp-struct::integer-limit-signed -32769 2)) ;; signed, 32 bits (signals limit-error (lisp-struct::integer-limit-signed 2147483648 4)) (signals limit-error (lisp-struct::integer-limit-signed -2147483649 4)) ;; restarts (use value) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-unsigned -500 1)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-unsigned +500 1)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-unsigned -500000 2)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-unsigned +500000 2)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-unsigned -5000000000 4)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-unsigned +5000000000 4)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-signed -500 1)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-signed +500 1)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-signed -500000 2)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-signed +500000 2)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-signed -5000000000 4)))) (is (= 55 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'use-value 55)))) (lisp-struct::integer-limit-signed +5000000000 4)))) ;; restarts (clip value) (is (= 0 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-unsigned -500 1)))) (is (= 255 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-unsigned +500 1)))) (is (= 0 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-unsigned -500000 2)))) (is (= 65535 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-unsigned +500000 2)))) (is (= 0 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-unsigned -5000000000 4)))) (is (= 4294967295 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-unsigned +5000000000 4)))) (is (= -128 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-signed -500 1)))) (is (= +127 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-signed +500 1)))) (is (= -32768 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-signed -500000 2)))) (is (= +32767 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-signed +500000 2)))) (is (= -2147483648 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-signed -5000000000 4)))) (is (= +2147483647 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'clip-value)))) (lisp-struct::integer-limit-signed +5000000000 4)))) ;; restarts (wrap value) (is (= 255 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'wrap-value)))) (lisp-struct::integer-limit-unsigned -1 1)))) (is (= 0 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'wrap-value)))) (lisp-struct::integer-limit-unsigned 256 1)))) (is (= 65535 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'wrap-value)))) (lisp-struct::integer-limit-unsigned -1 2)))) (is (= 0 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'wrap-value)))) (lisp-struct::integer-limit-unsigned 65536 2)))) (is (= 4294967295 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'wrap-value)))) (lisp-struct::integer-limit-unsigned -1 4)))) (is (= 0 (handler-bind ((limit-error #'(lambda (c) (declare (ignore c)) (invoke-restart 'wrap-value)))) (lisp-struct::integer-limit-unsigned 4294967296 4))))) (test (integer-unpack-tests :depends-on conversion-tests) ;; 8 bits unsigned (is (equal '(0 1 2 254 255) (unpack ">BBBBB" #(0 1 2 254 255)))) (is (equal '(0 1 2 254 255) (unpack "<BBBBB" #(0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack ">hBBBBB" #(255 254 0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack "<hBBBBB" #(254 255 0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack ">lBBBBB" #(255 255 255 254 0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack "<lBBBBB" #(254 255 255 255 0 1 2 254 255)))) (is (equal '(0 1 2 254 255) (unpack ">B3BB" #(0 1 2 254 255)))) (is (equal '(0 1 2 254 255) (unpack "<B3BB" #(0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack ">hB3BB" #(255 254 0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack "<hB3BB" #(254 255 0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack ">lB3BB" #(255 255 255 254 0 1 2 254 255)))) (is (equal '(-2 0 1 2 254 255) (unpack "<lB3BB" #(254 255 255 255 0 1 2 254 255)))) ;; 8 bits signed (is (equal '(0 1 2 -2 -1) (unpack ">bbbbb" #(0 1 2 254 255)))) (is (equal '(0 1 2 -2 -1) (unpack "<bbbbb" #(0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack ">Hbbbbb" #(0 1 0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack "<Hbbbbb" #(1 0 0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack ">Lbbbbb" #(0 0 0 1 0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack "<Lbbbbb" #(1 0 0 0 0 1 2 254 255)))) (is (equal '(0 1 2 -2 -1) (unpack ">b3bb" #(0 1 2 254 255)))) (is (equal '(0 1 2 -2 -1) (unpack "<b3bb" #(0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack ">Hb3bb" #(0 1 0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack "<Hb3bb" #(1 0 0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack ">Lb3bb" #(0 0 0 1 0 1 2 254 255)))) (is (equal '(1 0 1 2 -2 -1) (unpack "<Lb3bb" #(1 0 0 0 0 1 2 254 255)))) ;; 16 bits unsigned (is (equal '(0 1 255 256 65535) (unpack ">HHHHH" #(0 0 0 1 0 255 1 0 255 255)))) (is (equal '(0 1 255 256 65535) (unpack "<HHHHH" #(0 0 1 0 255 0 0 1 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack ">bHHHHH" #(254 0 0 0 1 0 255 1 0 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack "<bHHHHH" #(254 0 0 1 0 255 0 0 1 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack ">lHHHHH" #(255 255 255 254 0 0 0 1 0 255 1 0 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack "<lHHHHH" #(254 255 255 255 0 0 1 0 255 0 0 1 255 255)))) (is (equal '(0 1 255 256 65535) (unpack ">H3HH" #(0 0 0 1 0 255 1 0 255 255)))) (is (equal '(0 1 255 256 65535) (unpack "<H3HH" #(0 0 1 0 255 0 0 1 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack ">bH3HH" #(254 0 0 0 1 0 255 1 0 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack "<bH3HH" #(254 0 0 1 0 255 0 0 1 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack ">lH3HH" #(255 255 255 254 0 0 0 1 0 255 1 0 255 255)))) (is (equal '(-2 0 1 255 256 65535) (unpack "<lH3HH" #(254 255 255 255 0 0 1 0 255 0 0 1 255 255)))) ;; 16 bits signed (is (equal '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack ">hhhhhhhhhhh" #(0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0)))) (is (equal '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack "<hhhhhhhhhhh" #(0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack ">Bhhhhhhhhhhh" #(1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack "<Bhhhhhhhhhhh" #(1 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack ">Lhhhhhhhhhhh" #(0 0 0 1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack "<Lhhhhhhhhhhh" #(1 0 0 0 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128)))) (is (equal '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack ">h9hh" #(0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0)))) (is (equal '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack "<h9hh" #(0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack ">Bh9hh" #(1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack "<Bh9hh" #(1 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack ">Lh9hh" #(0 0 0 1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0)))) (is (equal '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768) (unpack "<Lh9hh" #(1 0 0 0 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128)))) ;; 32 bits unsigned (is (equal '(0 1 255 256 4294967295) (unpack ">LLLLL" #(0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255)))) (is (equal '(0 1 255 256 4294967295) (unpack "<LLLLL" #(0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack ">bLLLLL" #(0 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack "<bLLLLL" #(0 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack ">hLLLLL" #(0 0 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack "<hLLLLL" #(0 0 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255)))) (is (equal '(0 1 255 256 4294967295) (unpack ">L3LL" #(0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255)))) (is (equal '(0 1 255 256 4294967295) (unpack "<L3LL" #(0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack ">bL3LL" #(0 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack "<bL3LL" #(0 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack ">hL3LL" #(0 0 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255)))) (is (equal '(0 0 1 255 256 4294967295) (unpack "<hL3LL" #(0 0 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255)))) ;; 32 bits signed (is (equal '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack ">lllllllllll" #(0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0)))) (is (equal '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack "<lllllllllll" #(0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack ">Blllllllllll" #(0 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack "<Blllllllllll" #(0 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack ">Hlllllllllll" #(0 0 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack "<Hlllllllllll" #(0 0 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128)))) (is (equal '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack ">l9ll" #(0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0)))) (is (equal '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack "<l9ll" #(0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack ">Bl9ll" #(0 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack "<Bl9ll" #(0 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack ">Hl9ll" #(0 0 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0)))) (is (equal '(0 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648) (unpack "<Hl9ll" #(0 0 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128)))) ;; mixed (is (equal '(-2 1 -2 1 -2 1) (unpack ">bHlBhL" #(254 0 1 255 255 255 254 1 255 254 0 0 0 1)))) (is (equal '(-2 1 -2 1 -2 1) (unpack "<bHlBhL" #(254 1 0 254 255 255 255 1 254 255 1 0 0 0)))) (is (equal '(-2 -2 1 1 -2 -2 1 1 -2 -2 1 1) (unpack ">2b2H2l2B2h2L" #(254 254 0 1 0 1 255 255 255 254 255 255 255 254 1 1 255 254 255 254 0 0 0 1 0 0 0 1)))) (is (equal '(-2 -2 1 1 -2 -2 1 1 -2 -2 1 1) (unpack "<2b2H2l2B2h2L" #(254 254 1 0 1 0 254 255 255 255 254 255 255 255 1 1 254 255 254 255 1 0 0 0 1 0 0 0))))) (test (integer-pack-tests :depends-on conversion-tests) ;; 8 bits unsigned (is (array= #(0 1 2 254 255) (pack ">BBBBB" '(0 1 2 254 255)))) (is (array= #(0 1 2 254 255) (pack "<BBBBB" '(0 1 2 254 255)))) (is (array= #(255 254 0 1 2 254 255) (pack ">hBBBBB" '(-2 0 1 2 254 255)))) (is (array= #(254 255 0 1 2 254 255) (pack "<hBBBBB" '(-2 0 1 2 254 255)))) (is (array= #(255 255 255 254 0 1 2 254 255) (pack ">lBBBBB" '(-2 0 1 2 254 255)))) (is (array= #(254 255 255 255 0 1 2 254 255) (pack "<lBBBBB" '(-2 0 1 2 254 255)))) (is (array= #(0 1 2 254 255) (pack ">B3BB" '(0 1 2 254 255)))) (is (array= #(0 1 2 254 255) (pack "<B3BB" '(0 1 2 254 255)))) (is (array= #(255 254 0 1 2 254 255) (pack ">hB3BB" '(-2 0 1 2 254 255)))) (is (array= #(254 255 0 1 2 254 255) (pack "<hB3BB" '(-2 0 1 2 254 255)))) (is (array= #(255 255 255 254 0 1 2 254 255) (pack ">lB3BB" '(-2 0 1 2 254 255)))) (is (array= #(254 255 255 255 0 1 2 254 255) (pack "<lB3BB" '(-2 0 1 2 254 255)))) ;; 8 bits signed (is (array= #(0 1 2 254 255) (pack ">bbbbb" '(0 1 2 -2 -1)))) (is (array= #(0 1 2 254 255) (pack "<bbbbb" '(0 1 2 -2 -1)))) (is (array= #(0 1 0 1 2 254 255) (pack ">Hbbbbb" '(1 0 1 2 -2 -1)))) (is (array= #(1 0 0 1 2 254 255) (pack "<Hbbbbb" '(1 0 1 2 -2 -1)))) (is (array= #(0 0 0 1 0 1 2 254 255) (pack ">Lbbbbb" '(1 0 1 2 -2 -1)))) (is (array= #(1 0 0 0 0 1 2 254 255) (pack "<Lbbbbb" '(1 0 1 2 -2 -1)))) (is (array= #(0 1 2 254 255) (pack ">b3bb" '(0 1 2 -2 -1)))) (is (array= #(0 1 2 254 255) (pack "<b3bb" '(0 1 2 -2 -1)))) (is (array= #(0 1 0 1 2 254 255) (pack ">Hb3bb" '(1 0 1 2 -2 -1)))) (is (array= #(1 0 0 1 2 254 255) (pack "<Hb3bb" '(1 0 1 2 -2 -1)))) (is (array= #(0 0 0 1 0 1 2 254 255) (pack ">Lb3bb" '(1 0 1 2 -2 -1)))) (is (array= #(1 0 0 0 0 1 2 254 255) (pack "<Lb3bb" '(1 0 1 2 -2 -1)))) ;; 16 bits unsigned (is (array= #(0 0 0 1 0 2 0 255 1 0 255 255) (pack ">HHHHHH" '(0 1 2 255 256 65535)))) (is (array= #(0 0 1 0 2 0 255 0 0 1 255 255) (pack "<HHHHHH" '(0 1 2 255 256 65535)))) (is (array= #(254 0 0 0 1 0 2 0 255 1 0 255 255) (pack ">bHHHHHH" '(-2 0 1 2 255 256 65535)))) (is (array= #(254 0 0 1 0 2 0 255 0 0 1 255 255) (pack "<bHHHHHH" '(-2 0 1 2 255 256 65535)))) (is (array= #(255 255 255 254 0 0 0 1 0 2 0 255 1 0 255 255) (pack ">lHHHHHH" '(-2 0 1 2 255 256 65535)))) (is (array= #(254 255 255 255 0 0 1 0 2 0 255 0 0 1 255 255) (pack "<lHHHHHH" '(-2 0 1 2 255 256 65535)))) (is (array= #(0 0 0 1 0 2 0 255 1 0 255 255) (pack ">H4HH" '(0 1 2 255 256 65535)))) (is (array= #(0 0 1 0 2 0 255 0 0 1 255 255) (pack "<H4HH" '(0 1 2 255 256 65535)))) (is (array= #(254 0 0 0 1 0 2 0 255 1 0 255 255) (pack ">bH4HH" '(-2 0 1 2 255 256 65535)))) (is (array= #(254 0 0 1 0 2 0 255 0 0 1 255 255) (pack "<bH4HH" '(-2 0 1 2 255 256 65535)))) (is (array= #(255 255 255 254 0 0 0 1 0 2 0 255 1 0 255 255) (pack ">lH4HH" '(-2 0 1 2 255 256 65535)))) (is (array= #(254 255 255 255 0 0 1 0 2 0 255 0 0 1 255 255) (pack "<lH4HH" '(-2 0 1 2 255 256 65535)))) ;; 16 bits signed (is (array= #(0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0) (pack ">hhhhhhhhhhh" '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128) (pack "<hhhhhhhhhhh" '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0) (pack ">Bhhhhhhhhhhh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(1 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128) (pack "<Bhhhhhhhhhhh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(0 0 0 1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0) (pack ">Lhhhhhhhhhhh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(1 0 0 0 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128) (pack "<Lhhhhhhhhhhh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0) (pack ">h9hh" '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128) (pack "<h9hh" '(0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0) (pack ">Bh9hh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(1 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128) (pack "<Bh9hh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(0 0 0 1 0 0 0 1 255 255 0 127 255 128 0 128 255 127 127 254 128 1 127 255 128 0) (pack ">Lh9hh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) (is (array= #(1 0 0 0 0 0 1 0 255 255 127 0 128 255 128 0 127 255 254 127 1 128 255 127 0 128) (pack "<Lh9hh" '(1 0 1 -1 127 -128 128 -129 32766 -32767 32767 -32768)))) ;; 32 bits unsigned (is (array= #(0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255) (pack ">LLLLL" '(0 1 255 256 4294967295)))) (is (array= #(0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255) (pack "<LLLLL" '(0 1 255 256 4294967295)))) (is (array= #(255 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255) (pack ">bLLLLL" '(-1 0 1 255 256 4294967295)))) (is (array= #(255 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255) (pack "<bLLLLL" '(-1 0 1 255 256 4294967295)))) (is (array= #(255 255 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255) (pack ">hLLLLL" '(-1 0 1 255 256 4294967295)))) (is (array= #(255 255 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255) (pack "<hLLLLL" '(-1 0 1 255 256 4294967295)))) (is (array= #(0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255) (pack ">L3LL" '(0 1 255 256 4294967295)))) (is (array= #(0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255) (pack "<L3LL" '(0 1 255 256 4294967295)))) (is (array= #(255 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255) (pack ">bL3LL" '(-1 0 1 255 256 4294967295)))) (is (array= #(255 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255) (pack "<bL3LL" '(-1 0 1 255 256 4294967295)))) (is (array= #(255 255 0 0 0 0 0 0 0 1 0 0 0 255 0 0 1 0 255 255 255 255) (pack ">hL3LL" '(-1 0 1 255 256 4294967295)))) (is (array= #(255 255 0 0 0 0 1 0 0 0 255 0 0 0 0 1 0 0 255 255 255 255) (pack "<hL3LL" '(-1 0 1 255 256 4294967295)))) ;; 32 bits signed (is (array= #(0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0) (pack ">lllllllllll" '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128) (pack "<lllllllllll" '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0) (pack ">Blllllllllll" '(255 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128) (pack "<Blllllllllll" '(255 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 255 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0) (pack ">Hlllllllllll" '(65535 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 255 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128) (pack "<Hlllllllllll" '(65535 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0) (pack ">l9ll" '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128) (pack "<l9ll" '(0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0) (pack ">Bl9ll" '(255 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128) (pack "<Bl9ll" '(255 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 255 0 0 0 0 0 0 0 1 255 255 255 255 0 0 0 127 255 255 255 128 0 0 0 128 255 255 255 127 127 255 255 254 128 0 0 1 127 255 255 255 128 0 0 0) (pack ">Hl9ll" '(65535 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) (is (array= #(255 255 0 0 0 0 1 0 0 0 255 255 255 255 127 0 0 0 128 255 255 255 128 0 0 0 127 255 255 255 254 255 255 127 1 0 0 128 255 255 255 127 0 0 0 128) (pack "<Hl9ll" '(65535 0 1 -1 127 -128 128 -129 2147483646 -2147483647 2147483647 -2147483648)))) ;; Mixed (is (array= #(254 0 1 255 255 255 254 1 255 254 0 0 0 1) (pack ">bHlBhL" '(-2 1 -2 1 -2 1)))) (is (array= #(254 1 0 254 255 255 255 1 254 255 1 0 0 0) (pack "<bHlBhL" '(-2 1 -2 1 -2 1)))) (is (array= #(254 254 0 1 0 1 255 255 255 254 255 255 255 254 1 1 255 254 255 254 0 0 0 1 0 0 0 1) (pack ">2b2H2l2B2h2L" '(-2 -2 1 1 -2 -2 1 1 -2 -2 1 1)))) (is (array= #(254 254 1 0 1 0 254 255 255 255 254 255 255 255 1 1 254 255 254 255 1 0 0 0 1 0 0 0) (pack "<2b2H2l2B2h2L" '(-2 -2 1 1 -2 -2 1 1 -2 -2 1 1))))) (test (usage-tests :depends-on (and character-tests integer-unpack-tests integer-pack-tests)) ;; Number of arguments (unpack) (finishes (unpack ">bHlBhL" #(0 0 0 0 0 0 0 0 0 0 0 0 0 0))) (signals argument-error (unpack ">bHlBhL" #(0 0 0 0 0 0 0 0 0 0 0 0 0))) (signals argument-error (unpack ">bHlBhL" #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))) (finishes (unpack ">B12H2L" #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))) (signals argument-error (unpack ">B12H2L" #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))) (signals argument-error (unpack ">B12H2L" #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))) ;; Number of arguments (pack) (finishes (pack ">bHlBhL" '(0 0 0 0 0 0))) (signals argument-error (pack ">bHlBhL" '(0 0 0 0 0))) (signals argument-error (pack ">bHlBhL" '(0 0 0 0 0 0 0))) (finishes (pack ">B12H2L" '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))) (signals argument-error (pack ">B12H2L" '(0 0 0 0 0 0 0 0 0 0 0 0 0 0))) (signals argument-error (pack ">B12H2L" '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))) ;; Format string (signals argument-error (eval '(unpack "" '()))) (signals argument-error (eval '(pack "" '()))) (signals argument-error (eval '(unpack "b" '(0)))) (signals argument-error (eval '(pack "b" '(0)))) (signals argument-error (eval '(unpack ">0b" '()))) (signals argument-error (eval '(pack ">0b" '()))) ;; Return type (is-true (typep (unpack ">bHlBhL" '(0 0 0 0 0 0 0 0 0 0 0 0 0 0)) 'list)) (is-true (typep (pack ">bHlBhL" '(0 0 0 0 0 0)) '(simple-array (unsigned-byte 8) (14))))) (defun lisp-struct-test () (run!))
36,423
Common Lisp
.lisp
383
87.558747
197
0.573427
mrossini-ethz/lisp-struct
0
0
0
GPL-2.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
06092cf62edbe1c144ac235b8fe9a69153469082b76e7760c117ec7da3083f87
41,239
[ -1 ]
41,240
lisp-struct.asd
mrossini-ethz_lisp-struct/lisp-struct.asd
(defsystem "lisp-struct" :description "A library for packing/unpacking structured data." :version "0.1.0" :author "Marco Rossini" :license "GPLv2" :depends-on (:parseq) :serial t :components ((:file "package") (:file "lisp-struct")) :in-order-to ((test-op (test-op :lisp-struct/test)))) (defsystem "lisp-struct/test" :description "Unit testing for lisp-struct." :author "Marco Rossini" :license "GPLv2" :depends-on (:lisp-struct :fiveam) :serial t :components ((:file "test/package") (:file "test/test"))) (defmethod perform ((operation test-op) (system (eql (find-system :lisp-struct/test)))) (funcall (intern "LISP-STRUCT-TEST" :lisp-struct/test)))
713
Common Lisp
.asd
20
31.55
87
0.672938
mrossini-ethz/lisp-struct
0
0
0
GPL-2.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
c1026c5755b9b2a73326a1211bae62ea4f3098c6b27977e69e8c78e3a4df8153
41,240
[ -1 ]
41,244
compile-test.sh
mrossini-ethz_lisp-struct/test/compile-test.sh
#!/bin/bash if [[ $# != 1 ]] then echo "Argument error!" echo "Usage: $0 <sbcl|cmucl|ecl|clisp|all>" exit 1 fi if [[ "$1" == "sbcl" ]] || ([[ "$1" == "all" ]] && which sbcl) then sbcl --noinform \ --disable-ldb \ --lose-on-corruption \ --end-runtime-options \ --no-sysinit \ --no-userinit \ --disable-debugger \ --eval '(require :asdf)' \ --eval '(asdf:load-system :lisp-struct :force t)' \ --quit \ --end-toplevel-options fi if [[ "$1" == "cmucl" ]] || ([[ "$1" == "all" ]] && which lisp) then lisp -batch \ -eval '(require :asdf)' \ -eval '(asdf:load-system :lisp-struct :force t)' \ -eval '(quit)' fi if [[ "$1" == "ecl" ]] || ([[ "$1" == "all" ]] && which ecl) then ecl -q \ -eval '(require :asdf)' \ -eval '(asdf:load-system :lisp-struct :force t)' \ -eval '(quit)' fi if [[ "$1" == "clisp" ]] || ([[ "$1" == "all" ]] && which clisp) then clisp -q \ -x '(require :asdf)' \ -x '(asdf:load-system :lisp-struct :force t)' fi
975
Common Lisp
.l
41
21.609756
64
0.547901
mrossini-ethz/lisp-struct
0
0
0
GPL-2.0
9/19/2024, 11:49:45 AM (Europe/Amsterdam)
d719875bd2def4bfa059b2c3c9d16078b890870269faf028b574d71d953e7015
41,244
[ -1 ]
41,275
gear.lisp
DrBluefall_lispdotink/src/gear.lisp
(defpackage :co.prismarine.splatdotink.gear (:nicknames :splatdotink.gear :sdi.gear) (:use :cl) (:export :gear-item :gear-kind)) (in-package :co.prismarine.splatdotink.gear) (deftype gear-kind () '(member :clothes :shoes :head)) (defclass gear-item () ((name :type string :initarg :name :initform (error "Must specify :name. STOP.")) (end-time :type integer :initarg :end-time :initform (error "Must specify :end-time. STOP.") :documentation "A unix timestamp for when this gear will no longer be available.") (kind :type gear-kind :initarg :kind :initform (error "Must specify :kind. STOP.") :documentation "The type of this gear. Can be one of :CLOTHES, :SHOES, or :HEAD.") (price :type (cons integer integer) :initarg :price :initform (error "Must specify :price. STOP.") :documentation "The prices of this gear in its original form and on the SplatNet 2 Shop respectively.") (ability :type (cons (cons integer string) (cons integer string)) :initarg :ability :initform (error "Must specify :ability. STOP.") :documentation "The abilities this gear comes with. The CAR is the original ability, and the CDR is the ability currently available on the SplatNet 2 Shop.") (rarity :type (integer 0 2) :initarg :rarity :initform (error "Must specify :rarity. STOP.") :documentation "The rarity of this gear. This coresponds to the number of slots this gear item comes with, minus one.") (id :type integer :initarg :id :initform (error "Must specify :id. STOP.") :documentation "The SplatNet 2 ID for this gear item.") (brand :type (cons integer string) :initarg :brand :initform (error "Must specify :brand. STOP.") :documentation "The brand for this gear item."))) (defun make-gear-item-from-hash (table) (let ((original-gear (gethash "original_gear" table)) (item (gethash "gear" table))) (make-instance 'gear-item :end-time (gethash "end_time" table) :kind (read-from-string (concatenate 'string ":" (gethash "kind" table))) :price (cons (gethash "price" table) (gethash "price" original-gear)) :ability (let ((ability (gethash "skill" table)) (original (gethash "skill" original-gear))) (cons (cons (parse-integer (gethash "id" original)) (gethash "name" original)) (cons (parse-integer (gethash "id" ability)) (gethash "name" ability)))) :name (gethash "name" item) :rarity (gethash "rarity" item) :id (parse-integer (gethash "id" item)) :brand (let ((brand (gethash "brand" item))) (cons (parse-integer (gethash "id" brand)) (gethash "name" brand))))))
2,931
Common Lisp
.lisp
63
37.968254
161
0.620942
DrBluefall/lispdotink
0
0
0
LGPL-3.0
9/19/2024, 11:49:53 AM (Europe/Amsterdam)
5fa4827e3ec034a5cdbda9d669bdd5ddfd9f024887bf301d1613a330b403266f
41,275
[ -1 ]
41,276
lib.lisp
DrBluefall_lispdotink/src/lib.lisp
(defpackage :co.prismarine.splatdotink (:nicknames :splatdotink :sdi) (:use :cl) (:local-nicknames (:jzon :com.inuoe.jzon)) (:export :pvp-schedules :salmon-schedule :merchandise)) (in-package :co.prismarine.splatdotink) (defun pvp-schedules () "Return a plist of sdi.rotation:rotation with the league, ranked, and Turf War map and mode rotations." (let* ((schedules (jzon:parse (drakma:http-request "http://splatoon2.ink/data/schedules.json"))) (turf (gethash "regular" schedules)) (ranked (gethash "gachi" schedules)) (league (gethash "league" schedules))) (loop for t1 across turf for t2 across ranked for t3 across league collect (sdi.rotation::make-rotation-from-hash t1) into turflist collect (sdi.rotation::make-rotation-from-hash t2) into rankedlist collect (sdi.rotation::make-rotation-from-hash t3) into leaguelist finally (return (list :turf turflist :ranked rankedlist :league leaguelist))))) (defun salmon-schedule () "Return a list of sdi.rotation:salmon-rotation." (let ((response (jzon:parse (drakma:http-request "http://splatoon2.ink/data/coop-schedules.json")))) (loop for schedule across (gethash "schedules" response) for detail-list = (coerce (gethash "details" response) 'list) then (cdr detail-list) for detail = (car detail-list) collect (sdi.rotation::make-salmon-rotation-from-hash (or detail schedule))))) (defun merchandise () "Return a list with the current gear available on the SplatNet 2 Shop." (let ((merch (gethash "merchandises" (jzon:parse (drakma:http-request "http://splatoon2.ink/data/merchandises.json"))))) (loop for gear across merch collect (sdi.gear::make-gear-item-from-hash gear))))
1,891
Common Lisp
.lisp
39
40.74359
105
0.667389
DrBluefall/lispdotink
0
0
0
LGPL-3.0
9/19/2024, 11:49:53 AM (Europe/Amsterdam)
89aceeb6439b59629b5e2cebbe87c6d3eee25df3cc95fb9518f7253efabec6c5
41,276
[ -1 ]
41,277
splatdotink.asd
DrBluefall_lispdotink/splatdotink.asd
(asdf:defsystem :splatdotink :name "splatdotink" :description "A Common Lisp library to simplify fetching data from splatoon2.ink." :version "0.0.0" :author "Alexander Bisono <[email protected]>" :licence "LGPL-3.0-or-later" :depends-on (:drakma :com.inuoe.jzon) :components ((:module "src" :serial t :components ((:file "gear") (:file "rotation") (:file "lib")))))
471
Common Lisp
.asd
12
29.583333
84
0.572985
DrBluefall/lispdotink
0
0
0
LGPL-3.0
9/19/2024, 11:49:53 AM (Europe/Amsterdam)
456316c26f0abfeb191593fe8f1a4918b603607e2293ec872123bc19d2035753
41,277
[ -1 ]
41,296
interactive_sum.lisp
dat-adi_the-lisperer/basics/interactive_sum.lisp
;;;; Interactive Summation ;;;; Copyright (C) 2022 G V Datta Adithya ;;;; 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 <https://www.gnu.org/licenses/>. (defun Addition() (princ "Enter the first number: ") (setq a (read)) (princ "Enter the second number: ") (setq b (read)) (setq sum (+ a b)) (princ "Summation => ") (write sum)) (Addition)
921
Common Lisp
.lisp
21
42.714286
75
0.729097
dat-adi/the-lisperer
0
0
0
GPL-3.0
9/19/2024, 11:49:53 AM (Europe/Amsterdam)
f4a96cf6df5cd0eced0e5028c81a1e02fa246791849978e3876c315ac732a3da
41,296
[ -1 ]
41,297
setq.lisp
dat-adi_the-lisperer/basics/setq.lisp
;;;; Setq functionality ;;;; Copyright (C) 2022 G V Datta Adithya ;;;; 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 <https://www.gnu.org/licenses/>. (setq x 10) (setq y 20.40) (setq ch nil) (setq n 242.33) (setq bg 11.0e+4) (setq comm 134/2) (print x) (print y) (print ch) (print n) (print bg) (print comm)
889
Common Lisp
.lisp
24
35.875
75
0.732869
dat-adi/the-lisperer
0
0
0
GPL-3.0
9/19/2024, 11:49:53 AM (Europe/Amsterdam)
1fdbe9bee6740ffe7540406e695e5900738326ae02e7c3d6470072cfcae10ab5
41,297
[ -1 ]
41,298
arithmetic.lisp
dat-adi_the-lisperer/basics/arithmetic.lisp
;;;; Simple arithmetic operations ;;;; Copyright (C) 2022 G V Datta Adithya ;;;; 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 <https://www.gnu.org/licenses/>. (princ "Quite something you've got there.") (let ((x 8) (y 4)) (terpri) (write x) (terpri) (write y) (terpri) (princ "Here's the sum of both the variables: ") (setq z (+ x y)) (write z) (terpri) (princ "Here's the difference of both the variables: ") (setq z (- x y)) (write z) (terpri) (princ "Here's the product of both the variables: ") (setq z (* x y)) (write z) (terpri) (princ "Here's the division result of both the variables: ") (setq z (/ x y)) (write z) )
1,254
Common Lisp
.lisp
36
32.416667
75
0.689712
dat-adi/the-lisperer
0
0
0
GPL-3.0
9/19/2024, 11:49:53 AM (Europe/Amsterdam)
18082a64a401b89ef2f1f477932a1081d296771689414720f227633229a053ef
41,298
[ -1 ]
41,317
factorial.lisp
texaco_Learning-Lisp/Exercices/Factorial/factorial.lisp
; function to get factorial number ; the number must be bigger than 0 or 0 (defun factorial (x) (if (= 0 x) 1 (* x (factorial (- x 1) ))) ) (format t "~d~%" (factorial 4)) (format t "~d~%" (factorial 5)) (format t "~d~%" (factorial 6)) (format t "~d~%" (factorial 7)) (format t "~d~%" (factorial 8)) (format t "~d~%" (factorial 9)) (format t "~d~%" (factorial 10))
376
Common Lisp
.lisp
12
29.416667
49
0.596685
texaco/Learning-Lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
6ee0276c266082edd01da986700ef5651aed2316cc8d7362ea6d99e9b64f593a
41,317
[ -1 ]
41,318
helloworld.lisp
texaco_Learning-Lisp/Exercices/HelloWorld/helloworld.lisp
; simple hello world in clisp (format t "Hello, World!")
58
Common Lisp
.lisp
2
27.5
29
0.727273
texaco/Learning-Lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
76fc4e76ac7c3cd70c8a03113e90dcf9f6671d78aa5fbb77aa8bbc826c7d254c
41,318
[ -1 ]
41,320
recommended-minimal-configuration.el
texaco_Learning-Lisp/Examples/recommended-minimal-configuration.el
;;; recommended-minimal-configuration.el --- Provides minimal recommended configuration ;; Homepage: https://github.com/89453728/Learning-Lisp.git ;; Version: 0 ;; Package-Requires: ((use-package "0.1")) ;;; Commentary: ;; This are recommended bare-minimal configuration. Keep in mind that ;; depends on `use-package' by jwiegley. More over on ;; https://github.com/jwiegley/use-package ;;; Code: (require 'use-package) ;; Relative line number. ;; Only enabled for programming major modes. (setq display-line-numbers-type 'relative) (add-hook 'prog-mode-hook 'display-line-numbers-mode) ;; Visual line mode shows a line wrapped if the line is longer than ;; window size. you will see a visual indication that the line has ;; been wrapped. (use-package simple :diminish visual-line-mode global-visual-line-mode :config (global-visual-line-mode 1)) ;; `show-paren-mode' hightlight the matching paren (show-paren-mode) ;; Change `yes or no' dialog to `y or n'. (defalias 'yes-or-no-p 'y-or-n-p) ;; Enables `which-key-mode' that helps you to know which key have you ;; available once you start a key chore. (use-package which-key :diminish :config (which-key-mode)) (provide 'recommended-minimal-configuration) ;;; recommended-minimal-configuration.el ends here
1,279
Common Lisp
.l
32
38.3125
87
0.760518
texaco/Learning-Lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
7711693eb464ee8232302e4e597c816e453444d7e26d4e1da939307d3324a627
41,320
[ -1 ]
41,337
11.lisp
fayelee0_practical-common-lisp/11.lisp
;;;; 11 collections (vector) (vector 1) (vector 1 2) (make-array 5 :initial-element nil) (defparameter *x* (make-array 5 :fill-pointer 0)) (vector-push 'a *x*) (vector-push 'b *x*) (vector-push 'c *x*) (vector-push 'd *x*) (vector-push 'e *x*) (vector-push 'f *x*) *x* (defparameter *y* (make-array 5 :fill-pointer 0 :adjustable t :element-type 'character)) ;; (vector-push-extend "你好" *y*) (vector-push #\a *y*) (vector-push #\a *y*) (vector-push #\a *y*) (vector-push #\a *y*) (vector-push #\a *y*) *y* (vector-push-extend #\b *y*) *y* (defparameter *z* (vector 1 2 3)) (length *z*) (elt *z* 0) ;; (elt *z* 3) (setf (elt *z* 2) 10) *z* ;;; vector (let ((x #(1 2 3 4))) (progn x ;; (vector-push 5 x) (aref x 3) (setf (aref x 3) 5) x)) (let ((x (make-array 5 :initial-element nil))) (progn x ;; (dotimes (i 6) ;; (vector-push-extend i x)) (dotimes (i 5) (setf (aref x i) i)) x)) (let ((x (make-array 5 :fill-pointer 0))) (progn x (dotimes (i 6) (vector-push i x) ;; (vector-push-extend i x) ) x)) (let ((x (make-array 5 :fill-pointer 0 :adjustable t))) (progn (format t "~d~%" (length x)) (dotimes (i 8) (vector-push i x)) (format t "~d~%" (length x)) (dotimes (i 8) (vector-push-extend i x)) (format t "~d~%" (length x)) (dotimes (i 10) (vector-pop x)) (format t "~d~%" (length x)))) (let ((x #(1 2 1 2 3 1 2 3 4)) (y '(1 2 1 2 3 1 2 3 4)) (z "foobarbaz")) (count 1 x) (remove 1 x) (remove 1 y) (remove #\a z) (substitute 10 1 x) (substitute 10 1 y) (find 1 x) (find 10 x) (position 1 x)) (let () (count "foo" #("foo" "bar" "baz") :test #'string=) (find 'c #((a 10) (b 20) (c 30) (d 40)) :key #'first)) (let ((x '(1 2 3 4 4 3 2 1 1 2 3 4 4 3 2 1))) (format t "~a~%" x) (sort x #'<) (format t "~a~%" x)) (fboundp 'merge) (let () (merge 'vector #(1 3 5) '(2 4 6) #'<) (merge 'list #(1 3 5) '(2 3 4) #'<)) (let* ((x "foobarbaz") (y (copy-seq x))) y (setf (subseq y 3 6) "xxx") (format t "~a ~a ~%" x y) (setf (subseq y 3 6) "abcd") (format t "~a ~a ~%" x y) (setf (subseq y 3 6) "xx") (format t "~a ~a ~%" x y)) (let ((x #(1 2 3 4 5))) (every #'evenp x) (some #'evenp x) (notany #'evenp x) (notevery #'evenp x)) (let ((x #(1 2 3 4)) (y #(5 4 3 2))) (every #'> x y) (some #'> x y) (notany #'> x y) (notevery #'> x y)) (map 'vector #'* #(1 2 3 4 5) #(10 9 8 7 6)) (let ((a '(1 2 3)) (b '(4 5 6)) (c '(5 6 7))) (map-into a #'+ a b c)) (reduce #'+ '(1 2 3 4 5 6 7 8 9 0)) (reduce #'max '(1 2 3 4 5 6 7 8 9 0)) (let ((h (make-hash-table))) (gethash 'foo h) (setf (gethash 'foo h) 'quux) (gethash 'foo h)) (defun show-value (key hash-table) (multiple-value-bind (value present) (gethash key hash-table) (if present (format nil "Value ~a actually present." value) (format nil "Value ~a because key not found." value)))) (let ((x (make-hash-table))) (show-value 'foo x) (setf (gethash 'foo x) 'bar) (show-value 'foo x) (setf (gethash 'bar x) 'bar) (setf (gethash 'baz x) 'baz) (maphash #'(lambda (k v) (format t "~a => ~a~%" k v)) x))
3,246
Common Lisp
.lisp
131
21.343511
88
0.536355
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
6439c7152f9fb9be5fc385e7e18b3719aa89faaf5d080a0966d5b03dce1119d3
41,337
[ -1 ]
41,338
08.lisp
fayelee0_practical-common-lisp/08.lisp
;;;; 08 Macros ;;; Macros are part of the language to allow you to create abstractions on top of the core language and ;;; standard library that move you closer toward being able to directly express the things you want to express. (defmacro $when (condition &rest body) `(if ,condition (progn ,@body))) (defun foo (x) ($when (> x 10) (print 'big))) (macroexpand-1 '($when (> x 10) (print 'big))) (foo 10) (foo 11) ;; do-primes (defun primep (number) ($when (> number 1) (loop for fac from 2 to (isqrt number) never (zerop (mod number fac))))) (primep 3) (primep 1125) (defun next-prime (number) (loop for n from number when (primep n) return n)) (next-prime 4) ;; (do-primes (p 0 19) ;; (format t "~d " p)) (do ((p (next-prime 0) (next-prime (1+ p)))) ((> p 19)) (format t "~d " p)) (defmacro do-primes (var-and-range &rest body) (let ((var (first var-and-range)) ; 可以使用 destructuring (start (second var-and-range)) (end (third var-and-range))) `(do ((,var (next-prime ,start) (next-prime (1+ ,var)))) ((> ,var ,end)) ,@body))) (defmacro do-primes ((var start end) &body body) `(do ((,var (next-prime ,start) (next-prime (1+ ,var)))) ((> ,var ,end)) ,@body)) (macroexpand-1 '(do-primes (p 0 19) (format t "~d " p))) (macroexpand-1 '(do-primes (p 0 (random 100)) (format t "~d " p))) ;; (defmacro do-primes ((var start end) &body body) ;; `(do ((ending-value ,end) ;; (,var (next-prime ,start) (next-prime (1+ ,var)))) ; 存在参数加载顺序的问题 ;; ((> ,var ending-value)) ;; ,@body)) ;; (defmacro do-primes ((var start end) &body body) ;; `(do ((,var (next-prime ,start) (next-prime (1+ ,var))) ;; (ending-value ,end)) ; 变量重名问题,shadow ;; ((> ,var ending-value)) ;; ,@body)) (macroexpand-1 '(do-primes (ending-value 0 10) (print ending-value))) (macroexpand-1 '(let ((ending-value 0)) (do-primes (p 0 10) (incf ending-value p)) ending-value)) (defmacro do-primes ((var start end) &body body) (let ((ending-value-name (gensym))) `(do ((,var (next-prime ,start) (next-prime (1+ ,var))) (,ending-value-name ,end)) ((> ,var ,ending-value-name)) ,@body))) ;; It's actually fairly simple if you follow these rules of thumb: ;; + Unless there's a particular reason to do otherwise, include any subforms in the expansion in positions that will be evaluated in the same order as the subforms appear in the macro call. ;; + Unless there's a particular reason to do otherwise, make sure subforms are evaluated only once by creating a variable in the expansion to hold the value of evaluating the argument form and then using that variable anywhere else the value is needed in the expansion. ;; + Use *GENSYM* at macro expansion time to create variable names used in the expansion. (defmacro do-primes ((var start end) &body body) (with-gensyms (ending-value-name) `(do ((,var (next-prime ,start) (next-prime (1+ ,var))) (,ending-value-name ,end)) ((> ,var ,ending-value-name)) ,@body))) (defmacro with-gensyms ((&rest names) &body body) `(let ,(loop for n in names collect `(,n (gensym))) ,@body))
3,274
Common Lisp
.lisp
77
38.402597
270
0.634849
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
a77ef708f8f2a2929d99f11daa0bc5ad6663faf1acb4ac881f6be6897794389f
41,338
[ -1 ]
41,339
06.lisp
fayelee0_practical-common-lisp/06.lisp
;;;; 06 variables ;;; CL supports two kinds of variables: ;;; 1. lexical ;;; 2. dynamic ;;; Each time a function is called, Lisp creates new *bindings* to hold the arguments passed by the function's caller. ;;; A binding is the runtime manifestation of a variable. (macroexpand-1 '(incf x)) (macroexpand-1 '(incf x 10)) (macroexpand-1 '(incf (aref *array* (random (length *array*))))) (defvar a 10) (defvar b 20) (shiftf a b 30) a b (rotatef a b) a b (setf a 10) (setf b 20) (let ((a 1) (b 2)) (+ a b)) (+ a b) ;;; The *scope* of function parameters and LET variables ;;; the area of the program where the variable name can be used to refer to the variable's binding ;;; is delimited by the form that introduces the variable ;;; ;;; This form ;;; the function or the LET ;;; is called the *binding form* (defun foooo (x) (format t "parameter: ~a~%" x) (let ((x 2)) (format t "outer let: ~a~%" x) (let ((x 3)) (format t "inner let: ~a~%" x)) (format t "outer let: ~a~%" x)) (format t "parameter: ~a~%" x)) (foooo 10) (macroexpand-1 '(dotimes (x 10) (format t "~d " x))) ;;; By default all binding forms in Common Lisp introduce *lexically scoped* variables. ;;; Laxically scoped variables can be referred to only by code that's textually within the binding form. (defparameter *fn* (let ((count 0)) #'(lambda () (setf count (1+ count))))) (funcall *fn*) (funcall *fn*) ;;; The key thing to understand about closures is that it's the binding, not the value of the variable, that's captured. ;;; Thus, a closure can not only access the value of the variables it closes over but can also assign new values that will persist between calls to the closure. (let ((count 0)) (list #'(lambda () (incf count)) #'(lambda () (decf count)) #'(lambda () count))) ;;; dynamic scop (defvar *x* 10) (defun foo () (format t "X: ~d~%" *x*)) (foo) (let ((*x* 20)) (foo)) (foo) (defun bar () (foo) (let ((*x* 20)) (foo)) (foo)) (bar) (defun foo () (format t "before assignment ~18tX: ~d~%" *x*) (setf *x* (+ 1 *x*)) (format t "after assignment ~18tX: ~d~%" *x*)) (foo) (bar) ;;; The name of every variable defined with *DEFVAR* and *DEFPARAMETER* is automatically declared globally special. (macroexpand-1 '(setf x 10)) ;; setf ;; ;; incf ;; decf ;; ;; random ;; ;; push ;; pop ;; ;; rotatef ;; shiftf
2,407
Common Lisp
.lisp
90
24.355556
160
0.65204
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
beaeb035ef3804b98598e2980d9868ff6c5f692d78393b05ae9ba353feaf2e46
41,339
[ -1 ]
41,340
02.lisp
fayelee0_practical-common-lisp/02.lisp
;;;; 02 Lather, Rinse, Repeat: A Tour of the REPL 10 (+ 2 3) "hello, world" (format t "hello, world~%") (defun hello-world () (format t "hello, world~%")) (hello-world)
178
Common Lisp
.lisp
8
20.125
49
0.650307
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
914ac65b2923e106d21dfa0a0102ca46442b3a77b169eb2e585020092b318167
41,340
[ -1 ]
41,341
10.lisp
fayelee0_practical-common-lisp/10.lisp
;;;; 10 number, character, and string #x1024 #b1010110 #o1010 #36r123abf (characterp #\世) (char-code #\世)
113
Common Lisp
.lisp
7
14.142857
37
0.737374
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
ea9c557de2de9c27f51d3d4d1037c6f3898d155945145dc88944065a58a8b223
41,341
[ -1 ]
41,342
03.lisp
fayelee0_practical-common-lisp/03.lisp
;;;; 03 practical, a simple database ;; normal list (list 1 2 3 4) ;; plist (list :a 1 :b 2 :c 3 :d 4) (getf (list :a 1 :b 2 :c 3 :d 4) :a) (getf (list :a 1 :b 2 :c 3 :d 4) :c) ;; make cd (defun make-cd (title artist rating ripped) (list :title title :artist artist :rating rating :ripped ripped)) (make-cd "Roses" "Kathy Mattea" 7 t) ;; global store ;; 全局变量请使用 ** 来包围,因为 CL 里动态作用域和词法作用域,有时会到导致奇怪的问题 (defvar *db* nil) (defun add-record (cd) (push cd *db*)) (add-record (make-cd "Roses" "Kathy Mattea" 7 t)) (add-record (make-cd "Fly" "Dixie Chicks" 8 t)) (add-record (make-cd "Home" "Dixie Chicks" 9 t)) *db* (defun dump-db () (dolist (cd *db*) (format t "~{~a:~10t~a~%~}~%" cd))) (dump-db) ;;; prompt read (defun prompt-read (prompt) (format *query-io* "~a: " prompt) (force-output *query-io*) (read-line *query-io*)) (defun prompt-for-cd () (make-cd (prompt-read "Title") (prompt-read "Artist") ;; (prompt-read "Rating") (or (parse-integer (prompt-read "Rating") :junk-allowed t) 0) ;; (prompt-read "Ripped [y/n]") (y-or-n-p "Ripped [y/n]: "))) (defun add-cds () (loop (add-record (prompt-for-cd)) (if (not (y-or-n-p "Another? [y/n]: ")) (return)))) ;;; save *db* (defun save-db (filename) (with-open-file (out filename :direction :output :if-exists :supersede) (with-standard-io-syntax (print *db* out)))) (save-db "my-cds.db") (defun load-db (filename) (with-open-file (in filename) (with-standard-io-syntax (setf *db* (read in))))) ;;; query db ;; (remove-if-not #'evenp '(1 2 3 4 5 6 7 8 9 0)) (remove-if (complement #'evenp) '(1 2 3 4 5 6 7 8 9 0)) ;; (remove-if-not #'(lambda (x) (zerop (mod x 2))) ;; '(1 2 3 4 5 6 7 8 9 0)) (remove-if (complement #'(lambda (x) (zerop (mod x 2)))) '(1 2 3 4 5 6 7 8 9 0)) ;; (remove-if-not #'(lambda (cd) (equal (getf cd :artist) "Dixie Chicks")) ;; *db*) (remove-if (complement #'(lambda (cd) (equal (getf cd :artist) "Dixie Chicks"))) *db*) (defun select-by-artist (artist) (remove-if (complement #'(lambda (cd) (equal (getf cd :artist) artist))) *db*)) (select-by-artist "Dixie Chicks") (defun artist-selector (artist) #'(lambda (cd) (equal (getf cd :artist) artist))) (defun select (selector-fn) (remove-if (complement selector-fn) *db*)) (select (artist-selector "Dixie Chicks")) (defun where (&key title artist rating (ripped nil ripped-p)) #'(lambda (cd) (and (if title (equal (getf cd :title) title) t) (if artist (equal (getf cd :artist) artist) t) (if rating (equal (getf cd :rating) rating) t) (if ripped-p (equal (getf cd :ripped) ripped) t)))) (select (where :artist "Dixie Chicks")) (select (where :rating 10 :ripped nil)) ;;; update db (defun update (selector-fn &key title artist rating (ripped nil ripped-p)) (setf *db* (mapcar #'(lambda (row) (when (funcall selector-fn row) (if title (setf (getf row :title) title)) (if artist (setf (getf row :artist) artist)) (if rating (setf (getf row :rating) rating)) (if ripped-p (setf (getf row :ripped) ripped))) row) *db*))) (update (where :artist "Dixie Chicks") :rating 11) (dump-db) ;;; delete db (defun delete-rows (selector-fn) (setf *db* (remove-if selector-fn *db*))) (delete-rows (where :artist "Dixie Chicks")) (dump-db) ;;; defmacro (reverse '(1 2 3)) (defmacro backwards (expr) (reverse expr)) (backwards ("hello, world" t format)) (defun make-comparison-expr (field value) (list 'equal (list 'getf 'cd field) value)) (make-comparison-expr :rating 10) (make-comparison-expr :title "Give US a Break") `(+ 1 2 (+ 1 2)) `(+ 1 2 ,(+ 1 2)) (defun make-comparison-expr (field value) `(equal (getf cd ,field) ,value)) (make-comparison-expr :rating 10) (make-comparison-expr :title "Give US a Break") (defun make-comparison-list (fields) (loop while fields collecting (make-comparison-expr (pop fields) (pop fields)))) (defmacro where (&rest clauses) `#'(lambda (cd) (and ,@(make-comparison-list clauses)))) `(and ,(list 1 2 3)) `(and ,@(list 1 2 3)) `(and ,@(list 1 2 3) 4) (macroexpand-1 '(where :title "Give Us a Break" :ripped t)) (select (where :title "Give Us a Break" :ripped t))
4,484
Common Lisp
.lisp
128
30.4375
74
0.614023
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
e2fec025e4f8b22e89aa51f4d9f7ac86287c47d7fdfe27166e1c7fe8165c73c1
41,342
[ -1 ]
41,343
04.lisp
fayelee0_practical-common-lisp/04.lisp
;;;; 04 syntax and semantics ;;; A typical division is to split the processor into three phases ;;; 1. a lexical analyzer breaks up the stream of characters into tokens ;;; 2. feeds them to a parser that builds a tree representing the expressions in the program, according to the language's grammar <AST> ;;; 3. fed to an evaluator that either interprets it directly or compiles it inot some other language such as machine code ;;; Common Lisp defines two black boxes ;;; 1. *Reader* translates text into Lisp objects ;;; >> The reader defines how strings of characters can be translated inot Lisp objects called *s-expressions*. ;;; 2. *Evaluator* implements the semantics of the language in terms of those objects ;;; >> The evaluator then defines a syntax of Lisp forms that can be built out of s-expressions. ;;; ;;; This split of the black box has a couple of consequences ;;; 1. You can use s-expressions as an externalizable data format for data other than source code, using *READ* to read it and *PRINT* to print it. ;;; 2. Since the semantics of the language are defined in terms of trees of objects rather than strings of characters, ;;; it's easier to generate code within the language thant it would be if you had to generate code as text. ;;; the syntax of s-expressions understood by the reader ;;; the syntax of Lisp forms understood by the evaluator ;;; Lists are delimited by parentheses and can contain any number of whitespace-separated elements. ;;; Atoms are everything else. (type-of 12345678901234567890) (typecase 12345678901234567890) (type-of 123) (type-of 3/7) (type-of 1.0) (type-of 1.0e0) (type-of 1.0d0) (type-of 1.0e-4) (type-of +42) (type-of -42) (type-of -1/4) (type-of -2/8) (type-of 246/2) "foo" "fo\o" "fo\\o" "fo\"o" ;;; Then characters that serve other syntactic purposes can't appear in names: ;;; ( ) ;;; " ' ;;; ` , ;;; : ; ;;; \ | ;;; ;;; Standard style, these days, is to write code in all lowercase and let the reader chagne names to uppercase. ;;; variable -> hello-world ;;; global variable -> *query-io* ;;; constant -> +pi+ (quote (+ 1 2)) (list '+ 1 2) '(+ 1 2) #| The evaluation of a macro form proceeds in two phase: 1. the elements of the macro form are passed, unevaluated, to the macro function 2. the form returned by the macro function -- called its expansion -- is evaluated according to the normal evaluation rules |# (defvar x 20) (let ((x 10)) x) (= 1 1) (= 1 1.0) (char= #\a #\b) (char= #\a #\a) (eq 'a 'b) (eq 'a 'a) (eq 2 1) (eq 1 1.0) (eq 1 1) (eql 'a 'b) (eql 'a 'a) (eql 2 1) (eql 1 1.0) (eql 1 1) (eql "hello" "hello") (equal "hello" "hello") (eql '(1 2 3) '(1 2 3)) (equal '(1 2 3) '(1 2 3)) (equalp "hello" "HELLO") (equal "hello" "HELLO") (equalp 1 1.0) ;;;; package comment ;;; function coment ;; code coment ;; -- ; line coment
2,854
Common Lisp
.lisp
82
33.439024
147
0.706783
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
4e70e06e31d0ebae34edf546c721c2f17253c8225993ecc10a7a67ed50d7ccef
41,343
[ -1 ]
41,344
05.lisp
fayelee0_practical-common-lisp/05.lisp
;;;; 05 functions ;;; Different flavors of parameters handle required, optional, multiple, and keyword arguments. (defun verbose-sum (x y) "Sum any two numbers after printing a message." (format t "Summing ~d and ~d.~%" x y) (+ x y)) (defun bar (a b &optional c d) (list a b c d)) (bar 1 2) (bar 1 2 3) (bar 1 2 3 4) (defun baz (a &optional (b 10)) (list a b)) (baz 1 2) (baz 1) (defun make-rectangle (width &optional (height width)) (cons width height)) (make-rectangle 1) (make-rectangle 1 2) ;; (make-rectangle 1 2 3) (defun bazz (a b &optional (c 3 c-supplied-p)) (list a b c c-supplied-p)) (bazz 1 2) (bazz 1 2 3) (defun bzz (&key a b c) (list a b c)) (bzz) (bzz :a 1) (bzz :a 1 :b 2) (bzz :a 1 :b 2 :c 3) (defun foz (&key (a 0) (b 0 b-supplied-p) (c (+ a b))) (list a b c b-supplied-p)) (foz) (foz :a 1) (foz :b 2) (foz :b 1 :c 4) (foz :a 2 :b 1 :c 4) (defun fzz (&key ((:apple a)) ((:box b) 0) ((:charlie c) 0 c-supplied-p)) (list a b c c-supplied-p)) (fzz :apple 10 :box 20 :charlie 30) ;;; Whenever more than one flavor of parameter is used, they must be declared in the order I've discussed them: ;;; 1. the names of the required parameters; ;;; 2. the optional parameters ;;; 3. the rest parameter ;;; 4. the keyword parameters (defun fooo (x &optional y &key z) (list x y z)) (fooo 1 2 :z 3) (fooo 1) ;; (fooo 1 :z 3) (defun barr (&rest rest &key a b c) (list rest a b c)) (barr :a 1 :b 2 :c 3) ;; (barr 10 20 30 :a 1 :b 2 :c 3) ;;; *RETURN-FROM* special operator to immediately return any value from the function ;;; When you define a function with *DEFUN*, you're really doing two things: ;;; 1. creating a new function object ;;; 2. and giving it a name ;;; FUNCTION ;;; #' ;;; FUNCALL is the one to use when you know the number of arguments you're going to pass to the function at the time you write the code. ;;; APPLY receives a list ;; (documentation #'verbose-sum) (defun foo (n) (dotimes (i 10) (dotimes (j 10) (when (> (* i j) n) (return-from foo (list i j)))))) (function foo) (defun foo (x) (* 2 x)) (funcall #'foo 100) (defun plot (fn min max step) (loop for i from min to max by step do (loop repeat (funcall fn i) do (format t "*")) (format t "~%"))) (plot #'exp 0 4 1/2)
2,297
Common Lisp
.lisp
77
27.558442
136
0.643446
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
4c835608a33f19b067c7a23335984ca07aecc571ccf1033b30081008ae3bb7bc
41,344
[ -1 ]
41,345
09.lisp
fayelee0_practical-common-lisp/09.lisp
;;;; a unit test framework (= (+ 1 2) 3) (= (+ 1 2 3) 6) (= (+ -1 -3) -4) (defun test-+ () (and (= (+ 1 2) 3) (= (+ 1 2 3) 6) (= (+ -1 -3) -4))) (test-+) (defun test-+ () (format t "~:[FAIL~;PASS~] ... ~a~%" (= (+ 1 2) 3) '(= (+ 1 2) 3)) (format t "~:[FAIL~;PASS~] ... ~a~%" (= (+ 1 2 3) 5) '(= (+ 1 2 3) 6)) (format t "~:[FAIL~;PASS~] ... ~a~%" (= (+ -1 -3) -4) '(= (+ -1 -3) -4))) (test-+) (defun report-result (result form) (format t "~:[FAIL~;PASS~] ... ~a~%" result form)) (defun test-+ () (report-result (= (+ 1 2) 3) '(= (+ 1 2) 3)) (report-result (= (+ 1 2 3) 5) '(= (+ 1 2 3) 6)) (report-result (= (+ -1 -3) -4) '(= (+ -1 -3) -4))) (test-+) (defmacro check (form) `(report-result ,form ',form)) (defun test-+ () (check (= (+ 1 2) 3)) (check (= (+ 1 2 3) 5)) (check (= (+ -1 -3) -4))) (test-+) (defmacro check (&body form) `(progn ,@(loop for f in form collect `(report-result ,f ',f)))) (defun test-+ () (check (= (+ 1 2) 3) (= (+ 1 2 3) 5) (= (+ -1 -3) -4))) (test-+) (defun report-result (result form) (format t "~:[FAIL~;PASS~] ... ~a~%" result form) result) (defun test-+ () (check (= (+ 1 2) 3) (= (+ 1 2 3) 5) (= (+ -1 -3) -4))) (test-+) (defmacro combine-results (&body forms) (with-gensyms (result) `(let ((,result t)) ,@(loop for f in forms collect `(unless ,f (setf ,result nil))) ,result))) (defmacro with-gensyms ((&rest names) &body body) `(let ,(loop for n in names collect `(,n (gensym))) ,@body)) (defmacro check (&body forms) `(combine-results ,@(loop for f in forms collect `(report-result ,f ',f)))) (defun test-+ () (check (= (+ 1 2) 3) (= (+ 1 2 3) 5) (= (+ -1 -3) -4))) (test-+) (defun test-* () (check (= (* 2 2) 4) (= (* 3 5) 15))) (test-*) (defun test-arithmetic () (combine-results (test-+) (test-*))) (test-arithmetic) (defvar *test-name* nil) (defun report-result (result form) (format t "~:[FAIL~;PASS~] ... ~a: ~a~%" result *test-name* form)) (test-arithmetic) (defun test-+ () (let ((*test-name* 'test-+)) (check (= (+ 1 2) 3) (= (+ 1 2 3) 5) (= (+ -1 -3) -4)))) (test-+) (defun test-* () (let ((*test-name* 'test-*)) (check (= (* 2 2) 4) (= (* 3 5) 15)))) (test-*) (test-arithmetic) (defmacro deftest (name parameters &body body) `(defun ,name ,parameters (let ((*test-name* ',name)) ,@body))) (deftest test-+ () (check (= (+ 1 2) 3) (= (+ 1 2 3) 5) (= (+ -1 -3) -4))) (test-+) (defmacro deftest (name parameters &body body) `(defun ,name ,parameters (let ((*test-name* (append *test-name* (list ',name)))) ,@body))) (deftest test-+ () (check (= (+ 1 2) 3) (= (+ 1 2 3) 5) (= (+ -1 -3) -4))) (test-+) (deftest test-* () (check (= (* 2 2) 4) (= (* 3 5) 15))) (test-*) (deftest test-arithmetic () (combine-results (test-+) (test-*))) (test-arithmetic) (deftest test-math () (test-arithmetic)) (test-math)
3,065
Common Lisp
.lisp
125
20.952
75
0.488526
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
4c52ce00547e11139ec3dbd6845686291ae37e0a5369a0ffa1c903201bfc2e94
41,345
[ -1 ]
41,346
07.lisp
fayelee0_practical-common-lisp/07.lisp
;;;; 07 Macros: standard control constructs (if (> 2 3) "Yup" "Nope") (if (> 2 3) "Yup") (if (> 3 2) "Yup" "Nope") (defmacro ^when (condition &rest body) `(if ,condition (progn ,@body))) (macroexpand-1 '(^when (spam-p current-message) (file-in-spam-folder current-message) (update-spam-database current-message))) (defmacro ^unless (condition &rest body) `(if (not ,condition) (progn ,@body))) (macroexpand-1 `(and 1 2 3)) (macroexpand-1 '(dolist (x '(1 2 3 4 5)) (format t ".~a~%" x))) (dolist (x '(1 2 3 4)) (print x)) (dolist (x '(1 2 3 4)) (print x) (if (evenp x) (return))) (dotimes (i 4) (print i)) (dotimes (i 4) (print i) (if (oddp i) (return))) (dotimes (x 20) (dotimes (y 20) (format t "~3d " (* (1+ x) (1+ y)))) (format t "~%")) ;; n c nx ;; 0 0 1 ;; 1 1 1 ;; 2 1 2 ;; 3 2 3 ;; ... (do ((n 0 (1+ n)) (cur 0 next) (next 1 (+ cur next))) ; let ((= 10 n) cur)) (do ((i 0 (1+ i))) ((>= i 4)) (print i)) (do ((nums nil) (i 1 (1+ i))) ((> i 10) (nreverse nums)) (push i nums)) (loop for i from 1 to 10 collecting i) (loop for x from 1 to 10 summing (expt x 2)) (loop for x across "the quick brown fox jumps over the lazy dog" counting (find x "aeiou")) (loop for i below 10 and a = 0 then b and b = 1 then (+ b a) finally (return a))
1,374
Common Lisp
.lisp
58
20.568966
64
0.556327
fayelee0/practical-common-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:01 AM (Europe/Amsterdam)
481d9d9ac4e070e5bdc14dc31fbf5d7736aee28b396469c9e9945fb9c190f093
41,346
[ -1 ]
41,372
sequence-flange-bolts-lisp.org
roscoe-tw_sequence-flange-bolts-lisp/sequence-flange-bolts-lisp.org
* The license #+begin_src text 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 <https://www.gnu.org/licenses/>. #+end_src * sequence-flange-bolts-lisp.lsp/ reload #+begin_src lisp :tangle sequence-flange-bolts-lisp.lsp :padline no ;;; -*- coding:big5 -*- ;;; author: Each Application Mechanical Design Studio ([email protected]) ;;; version: 0.0.1 (defun c:RRR () (load "sequence-flange-bolts-lisp.lsp") (alert "Loaded!")) (defun xx:MyError (st) (if (not (member st (list "Function cancelled" "quit/ exit abort"))) (vl-bt)) (princ)) (defun dxf (i l) (cdr (assoc i l))) #+end_src ** 螺栓鎖固順序 - block/ 圖塊 - n - OO - number - circle -- r - point #+begin_src lisp :tangle sequence-flange-bolts-lisp.lsp ;;; 螺栓鎖固順序 (defun screw-sequence (OO r n / *error* blockname rr points) (setq *error* xx:MyError) ;; (setq n 4) (setq ;; OO (getpoint "set OO point\n") ;; r 15 blockname "螺絲編號" rr (+ r 10)) (command "_.circle" OO rr) (setq points (insert-point OO n r)) (mapcar '(lambda (x) (command "_.insert" blockname (cdr x) "" "" "" (car x))) points) (princ)) ;;; 圖塊插入點列表,附上螺栓編號 (defun insert-point (OO n r / list1 radian1 n1 num-l) (setq radian1 (* pi (/ (/ 360.0 n) 180.0))) (setq list1 nil n1 0) (cond ((= n 4) (setq num-l '("3" "1" "4" "2"))) ((= n 8) (setq num-l '("3" "5" "1" "8" "4" "6" "2" "7"))) ((= n 12) (setq num-l '("3" "9" "5" "1" "12" "8" "4" "10" "6" "2" "11" "7"))) ((= n 16) (setq num-l '("3" "13" "9" "5" "1" "16" "12" "8" "4" "14" "10" "6" "2" "15" "11" "7"))) ((= n 20) (setq num-l '("3" "17" "13" "9" "5" "1" "20" "16" "12" "8" "4" "18" "14" "10" "6" "2" "19" "15" "11" "7"))) ((= n 24) (setq num-l '("3" "21" "17" "13" "9" "5" "1" "24" "20" "16" "12" "8" "4" "22" "18" "14" "10" "6" "2" "23" "19" "15" "11" "7"))) (t (setq num-l nil))) (if num-1 nil (repeat n (progn (setq list1 (append list1 (list (cons (nth n1 num-l) (polar OO (+ 0 (* radian1 n1)) r))))) (setq n1 (1+ n1))))) list1) ;;; 繪製螺栓固鎖順序圖 (defun c:screw-sequence (/ *error* old_env-set OO list1) (setq *error* xx:MyError) (setq old_env-set (get-old_env-set)) (command "_.undo" "m" "") (set-env (list '(cmdecho . 0) '(clayer . "0") '(osmode . 0) '(attdia . 0))) (setq OO (getpoint "設定一個定點") list1 '((4 15) (8 35) (12 55) (16 75) (20 95) (24 115) )) (mapcar '(lambda (x) (screw-sequence OO (cadr x) (car x))) list1) (set-env old_env-set) (princ)) ;;; 取得執行程式前的環境 (defun get-old_env-set (/ old_env) (setq old_env (list (cons 'cmdecho (getvar "cmdecho")) (cons 'clayer (getvar "clayer")) (cons 'osmode (getvar "osmode")) (cons 'attdia (getvar "attdia")))) old_env) ;;; 設定程式執行環境 (defun set-env (env-set) (mapcar '(lambda (x) (cond ((equal (car x) 'cmdecho) (setvar "cmdecho" (cdr x))) ((equal (car x) 'clayer) (setvar "clayer" (cdr x))) ((equal (car x) 'osmode) (setvar "osmode" (cdr x))) ((equal (car x) 'attdia) (setvar "attdia" (cdr x))) (t nil))) env-set) (princ)) #+end_src
4,197
Common Lisp
.lisp
115
28.382609
244
0.532891
roscoe-tw/sequence-flange-bolts-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
2cc1986fd3f07b87c622d08c42cc85f235c739ca5ac2268353118b256c65b177
41,372
[ -1 ]
41,373
sequence-flange-bolts-lisp.lsp
roscoe-tw_sequence-flange-bolts-lisp/sequence-flange-bolts-lisp.lsp
;;; -*- coding:big5 -*- ;;; author: Each Application Mechanical Design Studio ([email protected]) ;;; version: 0.0.1 (defun c:RRR () (load "sequence-flange-bolts-lisp.lsp") (alert "Loaded!")) (defun xx:MyError (st) (if (not (member st (list "Function cancelled" "quit/ exit abort"))) (vl-bt)) (princ)) (defun dxf (i l) (cdr (assoc i l))) ;;; 螺栓鎖固順序 (defun screw-sequence (OO r n / *error* blockname rr points) (setq *error* xx:MyError) ;; (setq n 4) (setq ;; OO (getpoint "set OO point\n") ;; r 15 blockname "螺絲編號" rr (+ r 10)) (command "_.circle" OO rr) (setq points (insert-point OO n r)) (mapcar '(lambda (x) (command "_.insert" blockname (cdr x) "" "" "" (car x))) points) (princ)) ;;; 圖塊插入點列表,附上螺栓編號 (defun insert-point (OO n r / list1 radian1 n1 num-l) (setq radian1 (* pi (/ (/ 360.0 n) 180.0))) (setq list1 nil n1 0) (cond ((= n 4) (setq num-l '("3" "1" "4" "2"))) ((= n 8) (setq num-l '("3" "5" "1" "8" "4" "6" "2" "7"))) ((= n 12) (setq num-l '("3" "9" "5" "1" "12" "8" "4" "10" "6" "2" "11" "7"))) ((= n 16) (setq num-l '("3" "13" "9" "5" "1" "16" "12" "8" "4" "14" "10" "6" "2" "15" "11" "7"))) ((= n 20) (setq num-l '("3" "17" "13" "9" "5" "1" "20" "16" "12" "8" "4" "18" "14" "10" "6" "2" "19" "15" "11" "7"))) ((= n 24) (setq num-l '("3" "21" "17" "13" "9" "5" "1" "24" "20" "16" "12" "8" "4" "22" "18" "14" "10" "6" "2" "23" "19" "15" "11" "7"))) (t (setq num-l nil))) (if num-1 nil (repeat n (progn (setq list1 (append list1 (list (cons (nth n1 num-l) (polar OO (+ 0 (* radian1 n1)) r))))) (setq n1 (1+ n1))))) list1) ;;; 繪製螺栓固鎖順序圖 (defun c:screw-sequence (/ *error* old_env-set OO list1) (setq *error* xx:MyError) (setq old_env-set (get-old_env-set)) (command "_.undo" "m" "") (set-env (list '(cmdecho . 0) '(clayer . "0") '(osmode . 0) '(attdia . 0))) (setq OO (getpoint "設定一個定點") list1 '((4 15) (8 35) (12 55) (16 75) (20 95) (24 115) )) (mapcar '(lambda (x) (screw-sequence OO (cadr x) (car x))) list1) (set-env old_env-set) (princ)) ;;; 取得執行程式前的環境 (defun get-old_env-set (/ old_env) (setq old_env (list (cons 'cmdecho (getvar "cmdecho")) (cons 'clayer (getvar "clayer")) (cons 'osmode (getvar "osmode")) (cons 'attdia (getvar "attdia")))) old_env) ;;; 設定程式執行環境 (defun set-env (env-set) (mapcar '(lambda (x) (cond ((equal (car x) 'cmdecho) (setvar "cmdecho" (cdr x))) ((equal (car x) 'clayer) (setvar "clayer" (cdr x))) ((equal (car x) 'osmode) (setvar "osmode" (cdr x))) ((equal (car x) 'attdia) (setvar "attdia" (cdr x))) (t nil))) env-set) (princ))
2,973
Common Lisp
.lisp
96
24.854167
83
0.510762
roscoe-tw/sequence-flange-bolts-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
d63b12d35c5c86a06388c697ffeed86f077d70074058b7db6f1423f19f997345
41,373
[ -1 ]
41,392
let-alist.lisp
zellerin_let-alist/let-alist.lisp
;; Original copyright (C) 2014-2022 Free Software Foundation, Inc. ;; This is modified (translated from emacs lisp to Common Lisp) let-alist.el ;; file from GNU Emacs. As such, it is under GNU GPL. (defpackage #:let-alist (:use #:cl) (:export #:let-alist #:let-dolist-alist)) (in-package #:let-alist) (defun remove-dot (symbol) "Return SYMBOL, sans an initial dot." (let ((name (symbol-name symbol))) (if (eq #\. (char name 0)) (intern (subseq name 1) 'keyword) symbol))) (defun deep-dot-search (body) "Return alist of symbols inside BODY that start with a `.'. Perform a deep search and return an alist where each car is the symbol, and each cdr is the same symbol without the `.'." (cond ((symbolp body) (let ((name (symbol-name body))) (when (eq (char name 0) #\.) ;; Return the cons cell inside a list, so it can be appended ;; with other results in the clause below. (list (cons body (intern (subseq name 1) 'keyword)))))) ((vectorp body) (apply #'nconc (map 'list #'deep-dot-search body))) ((not (consp body)) nil) ((eq (car body) 'let-alist) ;; For nested ‘let-alist’ forms, ignore symbols appearing in the ;; inner body because they don’t refer to the alist currently ;; being processed. (deep-dot-search (cadr body))) (t (append (deep-dot-search (car body)) (deep-dot-search (cdr body)))))) (defun access-sexp (symbol variable) "Return a sexp used to access SYMBOL inside VARIABLE." (let* ((clean (remove-dot symbol)) (name (symbol-name clean))) (if (eq #\. (char name 0)) clean (list-to-sexp (mapcar (lambda (name) (intern name 'keyword)) (nreverse (split-sequence:split-sequence #\. name))) variable)))) (defun list-to-sexp (list var) "Turn symbols LIST into recursive calls to `cdr' `assoc' on VAR." `(cdr (assoc ',(car list) ,(if (cdr list) (list-to-sexp (cdr list) var) var)))) ;;; The actual macro. (defmacro let-alist (alist &rest body) "Let-bind dotted symbols to their cdrs in ALIST and execute BODY. Dotted symbol is any symbol starting with a `.'. Only those present in BODY are let-bound and this search is done at compile time." (let ((var (make-symbol "alist"))) `(let ((,var ,alist)) (let ,(mapcar (lambda (x) `(,(car x) ,(access-sexp (car x) var))) (remove-duplicates (deep-dot-search body) :key 'car)) ,@body)))) (defmacro let-dolist-alist (list &body body) "Perform LET-ALIST on each member of LIST (evaluated)." (let ((varname (gensym "ALIST"))) `(dolist (,varname ,list) (with-simple-restart (continue "Skip to next alist") (let-alist ,varname ,@body)))))
2,778
Common Lisp
.lisp
65
37.246154
76
0.639733
zellerin/let-alist
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
683072dc90f58fd80a9bc24989cf8fb9676f2f27d7786ce4234cc60f8b50e580
41,392
[ -1 ]
41,393
let-alist.asd
zellerin_let-alist/let-alist.asd
(asdf:defsystem #:let-alist :description "Common Lisp macro let-alist modeled by Emacs lisp macro of same name." :author "Tomáš Zellerin <[email protected]>" :license "GNU GPL" :version "0.9" :depends-on ("split-sequence") :components ((:file "let-alist")))
273
Common Lisp
.asd
7
36
86
0.712121
zellerin/let-alist
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
0490e06f2a2a73e7e0472d75e52fe9b501e4735e05825f30636c2c57e33cf214
41,393
[ -1 ]
41,411
dsss-transfer.lisp
glv2_cl-dsss-transfer/dsss-transfer.lisp
;;; This file is part of cl-dsss-transfer ;;; Copyright 2022 Guillaume LE VAILLANT ;;; Distributed under the GNU GPL v3 or later. ;;; See the file LICENSE for terms of use and distribution. (defpackage :dsss-transfer (:use :cl) (:import-from :cffi #:callback #:defcallback #:defcfun #:define-foreign-library #:mem-aref #:null-pointer #:null-pointer-p #:use-foreign-library) (:import-from :cl-octet-streams #:with-octet-input-stream #:with-octet-output-stream) (:export #:free-transfer #:make-transfer #:start-transfer #:stop-all-transfers #:stop-transfer #:transmit-buffer #:transmit-file #:transmit-stream #:receive-buffer #:receive-callback #:receive-file #:receive-stream #:verbosity)) (in-package :dsss-transfer) ;;; ;;; Bindings to libdsss-transfer ;;; (define-foreign-library dsss-transfer (:unix (:or "libdsss-transfer.so" "libdsss-transfer.so.1")) (t (:default "libdsss-transfer"))) (use-foreign-library dsss-transfer) (defcfun ("dsss_transfer_set_verbose" dsss-transfer-set-verbose) :void "Set the verbosity level." (v :unsigned-char)) (defcfun ("dsss_transfer_is_verbose" dsss-transfer-is-verbose) :unsigned-char "Get the verbosity level.") (defcfun ("dsss_transfer_create" dsss-transfer-create) :pointer "Initialize a new transfer." (radio-driver :string) (emit :unsigned-char) (file :string) (sample-rate :unsigned-long) (bit-rate :unsigned-int) (frequency :unsigned-long) (frequency-offset :long) (gain :string) (ppm :float) (spreading-factor :unsigned-int) (inner-fec :string) (outer-fec :string) (id :string) (dump :string) (timeout :unsigned-int) (audio :unsigned-char)) (defcfun ("dsss_transfer_create_callback" dsss-transfer-create-callback) :pointer "Initialize a new transfer using a callback." (radio-driver :string) (emit :unsigned-char) (data-callback :pointer) (callback-context :pointer) (sample-rate :unsigned-long) (bit-rate :unsigned-int) (frequency :unsigned-long) (frequency-offset :long) (gain :string) (ppm :float) (spreading-factor :unsigned-int) (inner-fec :string) (outer-fec :string) (id :string) (dump :string) (timeout :unsigned-int) (audio :unsigned-char)) (defcfun ("dsss_transfer_free" dsss-transfer-free) :void "Cleanup after a finished transfer." (transfer :pointer)) (defcfun ("dsss_transfer_start" dsss-transfer-start) :void "Start a transfer and return when finished." (transfer :pointer)) (defcfun ("dsss_transfer_stop" dsss-transfer-stop) :void "Interrupt a transfer." (transfer :pointer)) (defcfun ("dsss_transfer_stop_all" dsss-transfer-stop-all) :void "Interrupt a transfer.") (defcfun ("dsss_transfer_print_available_radios" dsss-transfer-print-available-radios) :void "Print list of detected software defined radios.") (defcfun ("dsss_transfer_print_available_forward_error_codes" dsss-transfer-print-available-forward-error-codes) :void "Print list of supported forward error codes.") ;;; ;;; Lisp API ;;; (defun verbosity () "Get the verbosity level." (dsss-transfer-is-verbose)) (defun (setf verbosity) (value) "Set the verbosity level." (dsss-transfer-set-verbose value) value) (defun make-transfer (&key (radio-driver "") emit file data-callback callback-context (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump timeout audio) "Initialize a transfer." (when (or (and file data-callback) (and (not file) (not data-callback))) (error "Either FILE or DATA-CALLBACK must be specified.")) (let ((transfer (if file (dsss-transfer-create radio-driver (if emit 1 0) (namestring file) sample-rate bit-rate frequency frequency-offset (if (stringp gain) gain (format nil "~d" gain)) ppm spreading-factor inner-fec outer-fec id (if dump (namestring dump) (null-pointer)) (or timeout 0) (if audio 1 0)) (dsss-transfer-create-callback radio-driver (if emit 1 0) data-callback (or callback-context (null-pointer)) sample-rate bit-rate frequency frequency-offset (if (stringp gain) gain (format nil "~d" gain)) ppm spreading-factor inner-fec outer-fec id (if dump (namestring dump) (null-pointer)) (or timeout 0) (if audio 1 0))))) (if (null-pointer-p transfer) (error "Failed to initialize transfer.") transfer))) (defun free-transfer (transfer) "Cleanup after a finished transfer." (dsss-transfer-free transfer)) (defun start-transfer (transfer) "Start a transfer and return when finished." (float-features:with-float-traps-masked t (dsss-transfer-start transfer))) (defun stop-transfer (transfer) "Interrupt a transfer." (dsss-transfer-stop transfer)) (defun stop-all-transfers () "Interrupt all transfers." (dsss-transfer-stop-all)) (defun transmit-file (file &key (radio-driver "") (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump audio (final-delay 0.0)) "Transmit the data from FILE." (let ((transfer (make-transfer :emit t :file file :radio-driver radio-driver :sample-rate sample-rate :bit-rate bit-rate :frequency frequency :frequency-offset frequency-offset :gain gain :ppm ppm :spreading-factor spreading-factor :inner-fec inner-fec :outer-fec outer-fec :id id :dump dump :audio audio))) (unwind-protect (progn (start-transfer transfer) (unless (zerop final-delay) (sleep final-delay))) (free-transfer transfer)) t)) (defun receive-file (file &key (radio-driver "") (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump timeout audio) "Receive data into FILE." (let ((transfer (make-transfer :emit nil :file file :radio-driver radio-driver :sample-rate sample-rate :bit-rate bit-rate :frequency frequency :frequency-offset frequency-offset :gain gain :ppm ppm :spreading-factor spreading-factor :inner-fec inner-fec :outer-fec outer-fec :id id :dump dump :timeout timeout :audio audio))) (unwind-protect (start-transfer transfer) (free-transfer transfer)) t)) (defparameter *data-stream* nil) (defparameter *buffer* nil) (defcallback read-data-from-stream :int ((context :pointer) (payload :pointer) (payload-size :unsigned-int)) (declare (ignore context)) (handler-case (labels ((copy-data (total) (let* ((size (min (length *buffer*) (- payload-size total))) (n (read-sequence *buffer* *data-stream* :end size))) (cond ((zerop n) (if (zerop total) -1 total)) (t (dotimes (i n) (setf (mem-aref payload :unsigned-char (+ total i)) (aref *buffer* i))) (copy-data (+ total n))))))) (copy-data 0)) (error () -1))) (defcallback write-data-to-stream :int ((context :pointer) (payload :pointer) (payload-size :unsigned-int)) (declare (ignore context)) (handler-case (labels ((copy-data (total) (let ((size (min (length *buffer*) (- payload-size total)))) (cond ((zerop size) payload-size) (t (dotimes (i size) (setf (aref *buffer* i) (mem-aref payload :unsigned-char (+ total i)))) (write-sequence *buffer* *data-stream* :end size) (copy-data (+ total size))))))) (copy-data 0)) (error () -1))) (defun transmit-stream (stream &key (radio-driver "") (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump audio (final-delay 0.0)) "Transmit the data from STREAM." (let* ((*data-stream* stream) (*buffer* (make-array 1024 :element-type '(unsigned-byte 8))) (transfer (make-transfer :emit t :data-callback (callback read-data-from-stream) :callback-context (null-pointer) :radio-driver radio-driver :sample-rate sample-rate :bit-rate bit-rate :frequency frequency :frequency-offset frequency-offset :gain gain :ppm ppm :spreading-factor spreading-factor :inner-fec inner-fec :outer-fec outer-fec :id id :dump dump :audio audio))) (unwind-protect (progn (start-transfer transfer) (unless (zerop final-delay) (sleep final-delay))) (free-transfer transfer)) t)) (defun receive-stream (stream &key (radio-driver "") (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump timeout audio) "Receive data to STREAM." (let* ((*data-stream* stream) (*buffer* (make-array 1024 :element-type '(unsigned-byte 8))) (transfer (make-transfer :emit nil :data-callback (callback write-data-to-stream) :callback-context (null-pointer) :radio-driver radio-driver :sample-rate sample-rate :bit-rate bit-rate :frequency frequency :frequency-offset frequency-offset :gain gain :ppm ppm :spreading-factor spreading-factor :inner-fec inner-fec :outer-fec outer-fec :id id :dump dump :timeout timeout :audio audio))) (unwind-protect (start-transfer transfer) (free-transfer transfer)) t)) (defun transmit-buffer (buffer &key (start 0) end (radio-driver "") (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump audio (final-delay 0.0)) "Transmit the data between START and END in BUFFER." (with-octet-input-stream (stream buffer start (or end (length buffer))) (transmit-stream stream :radio-driver radio-driver :sample-rate sample-rate :bit-rate bit-rate :frequency frequency :frequency-offset frequency-offset :gain gain :ppm ppm :spreading-factor spreading-factor :inner-fec inner-fec :outer-fec outer-fec :id id :dump dump :audio audio :final-delay final-delay))) (defun receive-buffer (&key (radio-driver "") (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump timeout audio) "Receive data into a new octet vector and return it." (with-octet-output-stream (stream) (receive-stream stream :radio-driver radio-driver :sample-rate sample-rate :bit-rate bit-rate :frequency frequency :frequency-offset frequency-offset :gain gain :ppm ppm :spreading-factor spreading-factor :inner-fec inner-fec :outer-fec outer-fec :id id :dump dump :timeout timeout :audio audio))) (defparameter *user-function* nil) (defcallback call-user-function :int ((context :pointer) (payload :pointer) (payload-size :unsigned-int)) (declare (ignore context)) (handler-case (let ((data (make-array payload-size :element-type '(unsigned-byte 8)))) (dotimes (i payload-size) (setf (aref data i) (mem-aref payload :unsigned-char i))) (funcall *user-function* data) payload-size) (error () -1))) (defun receive-callback (function &key (radio-driver "") (sample-rate 2000000) (bit-rate 100) (frequency 434000000) (frequency-offset 0) (gain 0) (ppm 0.0) (spreading-factor 64) (inner-fec "h128") (outer-fec "none") (id "") dump timeout audio) "Receive data and call a FUNCTION on it. The FUNCTION must take one octet vector as argument." (let* ((*user-function* function) (transfer (make-transfer :emit nil :data-callback (callback call-user-function) :callback-context (null-pointer) :radio-driver radio-driver :sample-rate sample-rate :bit-rate bit-rate :frequency frequency :frequency-offset frequency-offset :gain gain :ppm ppm :spreading-factor spreading-factor :inner-fec inner-fec :outer-fec outer-fec :id id :dump dump :timeout timeout :audio audio))) (unwind-protect (start-transfer transfer) (free-transfer transfer)) t))
18,839
Common Lisp
.lisp
427
25.35363
81
0.451429
glv2/cl-dsss-transfer
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
c571c3936901377b197e6500af0a401df23eb271dae3af52c77e2f3046e58558
41,411
[ -1 ]
41,412
tests.lisp
glv2_cl-dsss-transfer/tests.lisp
;;; This file is part of cl-dsss-transfer ;;; Copyright 2022 Guillaume LE VAILLANT ;;; Distributed under the GNU GPL v3 or later. ;;; See the file LICENSE for terms of use and distribution. (defpackage :dsss-transfer-tests (:use :cl :fiveam :dsss-transfer) (:import-from :uiop #:with-temporary-file)) (in-package :dsss-transfer-tests) (def-suite dsss-transfer-tests :description "Tests for dsss-transfer.") (in-suite dsss-transfer-tests) (defparameter *message* (asdf:system-relative-pathname "dsss-transfer" "README.org")) (defun same-files-p (path-1 path-2) (with-open-file (file-1 path-1 :element-type '(unsigned-byte 8)) (with-open-file (file-2 path-2 :element-type '(unsigned-byte 8)) (let ((buffer-1 (make-array 1024 :element-type '(unsigned-byte 8))) (buffer-2 (make-array 1024 :element-type '(unsigned-byte 8)))) (labels ((same-p () (let ((i (read-sequence buffer-1 file-1)) (j (read-sequence buffer-2 file-2))) (cond ((not (= i j)) nil) ((zerop i) t) ((mismatch buffer-1 buffer-2 :end1 i :end2 i) nil) (t (same-p)))))) (same-p)))))) (test transmit-and-receive-file (with-temporary-file (:pathname samples) (with-temporary-file (:pathname decoded) (let ((radio (format nil "file=~a" (namestring samples)))) (transmit-file (namestring *message*) :radio-driver radio :bit-rate 2400) (receive-file (namestring decoded) :radio-driver radio :bit-rate 2400) (is (same-files-p *message* decoded)))))) (test transmit-and-receive-file-audio (with-temporary-file (:pathname samples) (with-temporary-file (:pathname decoded) (let ((radio (format nil "file=~a" (namestring samples)))) (transmit-file (namestring *message*) :radio-driver radio :audio t :sample-rate 48000 :frequency 1500 :bit-rate 120 :spreading-factor 16) (receive-file (namestring decoded) :radio-driver radio :audio t :sample-rate 48000 :frequency 1500 :bit-rate 120 :spreading-factor 16) (is (same-files-p *message* decoded)))))) (test transmit-and-receive-stream (with-temporary-file (:pathname samples) (with-temporary-file (:pathname decoded :stream decoded-stream :direction :output :element-type '(unsigned-byte 8)) (with-open-file (message-stream *message* :element-type '(unsigned-byte 8)) (let ((radio (format nil "file=~a" (namestring samples)))) (transmit-stream message-stream :radio-driver radio :bit-rate 2400) (receive-stream decoded-stream :radio-driver radio :bit-rate 2400))) :close-stream (is (same-files-p *message* decoded))))) (test transmit-and-receive-buffer (with-temporary-file (:pathname samples) (let ((data #(0 1 2 4 9 16 25 36 49 64 81 100 121 144 169 196 225)) (radio (format nil "file=~a" (namestring samples)))) (transmit-buffer data :radio-driver radio) (let ((decoded (receive-buffer :radio-driver radio))) (is (equalp data decoded)))))) (test receive-callback (with-temporary-file (:pathname samples) (let ((data #(0 1 2 4 9 16 25 36 49 64 81 100 121 144 169 196 225)) (radio (format nil "file=~a" (namestring samples))) (decoded nil)) (transmit-buffer data :radio-driver radio :bit-rate 600) (receive-callback (lambda (data) (setf decoded (concatenate 'vector decoded data))) :radio-driver radio :bit-rate 600) (is (equalp data decoded)))))
4,252
Common Lisp
.lisp
84
36.416667
78
0.548232
glv2/cl-dsss-transfer
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
973b117ecfcafdea0ca6460f8a79c2b67c7f7933715cc58a6e9aded69d392e39
41,412
[ -1 ]
41,413
echo-server.lisp
glv2_cl-dsss-transfer/examples/echo-server.lisp
;;; Example of use of cl-dsss-transfer's API to make a server receiving ;;; messages from clients and sending them back in reverse order. ;;; ;;; Copyright 2022 Guillaume LE VAILLANT ;;; ;;; 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/>. (asdf:load-system "dsss-transfer") (defpackage :echo-server (:use :cl) (:export #:client #:server)) (in-package :echo-server) (defparameter *radio-driver* "driver=hackrf") (defparameter *sample-rate* 4000000) (defparameter *transmission-gain* 36) (defparameter *reception-gain* 60) (defparameter *frequency-offset* 100000) (defparameter *bit-rate* 1200) (defparameter *inner-fec* "rs8") (defparameter *outer-fec* "rs8") (defun transmit (data frequency) (dsss-transfer:transmit-buffer data :radio-driver *radio-driver* :sample-rate *sample-rate* :gain *transmission-gain* :frequency frequency :frequency-offset *frequency-offset* :bit-rate *bit-rate* :inner-fec *inner-fec* :outer-fec *outer-fec* :final-delay 1)) (defun receive (callback frequency) (dsss-transfer:receive-callback callback :radio-driver *radio-driver* :sample-rate *sample-rate* :gain *reception-gain* :frequency frequency :frequency-offset *frequency-offset* :bit-rate *bit-rate* :inner-fec *inner-fec* :outer-fec *outer-fec*)) (defun receive-1 (frequency) (let* ((received nil) (callback (lambda (data) (setf received data) (dsss-transfer:stop-all-transfers)))) (receive callback frequency) received)) (defun process-request (data) (reverse data)) (defun server (frequency) (unwind-protect (loop :do (let* ((data (receive-1 frequency)) (processed (process-request data))) (format t "~%Received: ~a~%" data) (sleep 1) (format t "Sending: ~a~%" processed) (transmit processed frequency))) (dsss-transfer:stop-all-transfers))) (defun client (frequency data) (unwind-protect (progn (format t "~%Sending: ~a~%" data) (transmit data frequency) (let ((data (receive-1 frequency))) (format t "Received: ~a~%" data) data)) (dsss-transfer:stop-all-transfers)))
3,369
Common Lisp
.lisp
80
31.0625
73
0.57622
glv2/cl-dsss-transfer
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
e39f5a32a67c2ca4596fffc6b25470991b7dc9c9f33e77b79194fecb3242b1fc
41,413
[ -1 ]
41,414
dsss-transfer.asd
glv2_cl-dsss-transfer/dsss-transfer.asd
;;; This file is part of cl-dsss-transfer ;;; Copyright 2022 Guillaume LE VAILLANT ;;; Distributed under the GNU GPL v3 or later. ;;; See the file LICENSE for terms of use and distribution. (defsystem "dsss-transfer" :name "dsss-transfer" :description "Send and receive data with SDRs using DSSS modulation" :version "1.1" :author "Guillaume LE VAILLANT" :license "GPL-3" :depends-on ("cffi" "cl-octet-streams" "float-features") :in-order-to ((test-op (test-op "dsss-transfer/tests"))) :components ((:file "dsss-transfer"))) (defsystem "dsss-transfer/tests" :name "dsss-transfer/tests" :description "Tests fot dsss-transfer" :version "1.1" :author "Guillaume LE VAILLANT" :license "GPL-3" :depends-on ("fiveam" "dsss-transfer" "uiop") :in-order-to ((test-op (load-op "dsss-transfer/tests"))) :perform (test-op (o s) (let ((tests (uiop:find-symbol* 'dsss-transfer-tests :dsss-transfer-tests))) (uiop:symbol-call :fiveam 'run! tests))) :components ((:file "tests")))
1,074
Common Lisp
.asd
26
36.115385
70
0.662524
glv2/cl-dsss-transfer
0
0
0
GPL-3.0
9/19/2024, 11:50:09 AM (Europe/Amsterdam)
b53002cce71c90e41939268b7b71c5e7c412d0bd49e97262fc9488a09f15fac6
41,414
[ -1 ]
41,433
neteng.lisp
schlesix_networkengineering-lisp/neteng.lisp
; Funktionen für Network Engineers ;(ql:quickload "iterate") ;(use-package :iterate) (ql:quickload "alexandria") (defun cidr2ddn(cidr-number) "Gibt einen CIDR-Wert im DDN-Format zurück" (case cidr-number (32 (return-from cidr2ddn "255.255.255.255")) (31 (return-from cidr2ddn "255.255.255.254")) (30 (return-from cidr2ddn "255.255.255.252")) (29 (return-from cidr2ddn "255.255.255.248")) (28 (return-from cidr2ddn "255.255.255.240")) (27 (return-from cidr2ddn "255.255.255.224")) (26 (return-from cidr2ddn "255.255.255.192")) (25 (return-from cidr2ddn "255.255.255.128")) (24 (return-from cidr2ddn "255.255.255.0")) (23 (return-from cidr2ddn "255.255.254.0")) (22 (return-from cidr2ddn "255.255.252.0")) (21 (return-from cidr2ddn "255.255.248.0")) (20 (return-from cidr2ddn "255.255.240.0")) (19 (return-from cidr2ddn "255.255.224.0")) (18 (return-from cidr2ddn "255.255.192.0")) (17 (return-from cidr2ddn "255.255.128.0")) (16 (return-from cidr2ddn "255.255.0.0")) (15 (return-from cidr2ddn "255.254.0.0")) (14 (return-from cidr2ddn "255.252.0.0")) (13 (return-from cidr2ddn "255.248.0.0")) (12 (return-from cidr2ddn "255.240.0.0")) (11 (return-from cidr2ddn "255.224.0.0")) (10 (return-from cidr2ddn "255.192.0.0")) (9 (return-from cidr2ddn "255.128.0.0")) (8 (return-from cidr2ddn "255.0.0.0")) (7 (return-from cidr2ddn "254.0.0.0")) (6 (return-from cidr2ddn "252.0.0.0")) (5 (return-from cidr2ddn "248.0.0.0")) (4 (return-from cidr2ddn "240.0.0.0")) (3 (return-from cidr2ddn "224.0.0.0")) (2 (return-from cidr2ddn "192.0.0.0")) (1 (return-from cidr2ddn "128.0.0.0")) (0 (return-from cidr2ddn "0.0.0.0")) )) (defun ddn2cidr(ddn-string) "Gibt einen CIDR-Wert im DDN-Format zurück" (alexandria:switch (ddn-string :test #'equal) ("255.255.255.255" (return-from ddn2cidr 32)) ("255.255.255.254" (return-from ddn2cidr 31)) ("255.255.255.252" (return-from ddn2cidr 30)) ("255.255.255.248" (return-from ddn2cidr 29)) ("255.255.255.240" (return-from ddn2cidr 28)) ("255.255.255.224" (return-from ddn2cidr 27)) ("255.255.255.192" (return-from ddn2cidr 26)) ("255.255.255.128" (return-from ddn2cidr 25)) ("255.255.255.0" (return-from ddn2cidr 24)) ("255.255.254.0" (return-from ddn2cidr 23)) ("255.255.252.0" (return-from ddn2cidr 22)) ("255.255.248.0" (return-from ddn2cidr 21)) ("255.255.240.0" (return-from ddn2cidr 20)) ("255.255.224.0" (return-from ddn2cidr 19)) ("255.255.192.0" (return-from ddn2cidr 18)) ("255.255.128.0" (return-from ddn2cidr 17)) ("255.255.0.0" (return-from ddn2cidr 16)) ("255.254.0.0" (return-from ddn2cidr 15)) ("255.252.0.0" (return-from ddn2cidr 14)) ("255.248.0.0" (return-from ddn2cidr 13)) ("255.240.0.0" (return-from ddn2cidr 12)) ("255.224.0.0" (return-from ddn2cidr 11)) ("255.192.0.0" (return-from ddn2cidr 10)) ("255.128.0.0" (return-from ddn2cidr 9)) ("255.0.0.0" (return-from ddn2cidr 8)) ("254.0.0.0" (return-from ddn2cidr 7)) ("252.0.0.0" (return-from ddn2cidr 6)) ("248.0.0.0" (return-from ddn2cidr 5)) ("240.0.0.0" (return-from ddn2cidr 4)) ("224.0.0.0" (return-from ddn2cidr 3)) ("192.0.0.0" (return-from ddn2cidr 2)) ("128.0.0.0" (return-from ddn2cidr 1)) ("0.0.0.0" (return-from ddn2cidr 0)) (t (return-from ddn2cidr nil)) )) (defun ip-string-to-number (ip-string) "Wandelt eine IP-Adresse in String-Form in eine Ganzzahl um" (let ((octets nil)(zahl 0)) ; String in Oktette zerlegen. Separator . (setq octets (uiop:split-string ip-string :separator ".")) ; Es müssen vier Oktette sein (if (/= (length octets) 4) nil (progn ; Oktette entspreched wichten und aufaddieren (Setq zahl (+ (ash (Parse-integer (first octets)) 24) (ash (parse-integer (second octets)) 16) (ash (parse-integer (third octets)) 8) (parse-integer (fourth octets)) ) ) )) )) (defun ip-number-to-string (ip-number) "IP-Adresse im Integer-Format in String umwandeln" (let ((ip-string nil) (oktettwert 0)) ; Okttette jeweils isolieren und dann als String zusammenbauen (setq oktettwert (floor ip-number 16777216)) (Setq ip-string (write-to-string oktettwert)) (setq ip-number (- ip-number (* oktettwert 16777216))) (setq oktettwert (floor ip-number 65536)) (setq ip-string (concatenate 'string ip-string "." (write-to-string oktettwert))) (Setq ip-number (- ip-number (* oktettwert 65536))) (setq oktettwert (floor ip-number 256)) (setq ip-string (concatenate 'string ip-string "." (write-to-string oktettwert))) (setq ip-number (- ip-number (* oktettwert 256))) (setq oktettwert ip-number) (setq ip-string (concatenate 'string ip-string "." (write-to-string oktettwert))) )) (defun test () "Diese Funktion tetstet die Library" (let ((ip-wert 0) (ip-string "")) (setq ip-wert (ip-string-to-number "255.254.253.252")) (setq ip-string (ip-number-to-string ip-wert)) ) ) (defun get-subnetdata (subnet-string &optional printout) "Subnet-Kennzahlen für CIDR-String berechnen, z. B. '192.168.2.17/24'" (let ((ip-address nil) (cidr nil) (ip-cut nil) (ip-subnet) (ip-broadcast nil) (i nil) (divisor nil) (hostanteil nil) (invalid-netmask 1)) ; Prüfen auf CIDR (setq ip-cut (uiop:split-string subnet-string :separator "/")) (if (= (length ip-cut) 2) (progn (Setq cidr (parse-integer (second ip-cut))) (setq invalid-netmask 0))) ; Falls kein CIDR gefunden, auf DDN prüfen (if (= invalid-netmask 1) (progn (setq ip-cut (uiop:split-string subnet-string :separator " ")) (if (= (length ip-cut) 2) (progn (setq cidr (ddn2cidr (second ip-cut))) ; Gültigkeit CIDR prüfen (1-32) (if (and (> cidr 0) (< cidr 33)) (setq invalid-netmask 0) ) )) )) ; Falls Netmask ermittelt werden konnte, Kenndaten ausrechnen (if (= invalid-netmask 0) (progn (Setq ip-address (ip-string-to-number (first ip-cut))) (setq divisor (expt 2 31)) (setq i 0) (dotimes (n cidr ) (setq i (+ i divisor)) (setq divisor (/ divisor 2))) (setq ip-subnet (logand ip-address i)) (setq hostanteil (- (expt 2 (- 32 cidr)) 1)) (setq ip-broadcast (+ ip-subnet hostanteil)) (Setq ip-broadcast (ip-number-to-string ip-broadcast)) (setq ip-subnet (ip-number-to-string ip-subnet)) (if (eq printout t) (progn (format t "Subnet...: ~A~%CIR......: /~d~%DDN......: ~d~%Broadcast: ~A~%~%" ip-subnet cidr (cidr2ddn cidr) ip-broadcast) (return-from get-subnetdata nil)) (Values ip-subnet cidr ip-broadcast)) ))) ) (defun format-mac (mac-address) "Formatiert eine MAC-Addresse im Cisco-Format" ; Prüfen, ob String übergeben wurde. Falls nicht: Abbruch (if (not (stringp mac-address)) (return-from format-mac nil)) ; Für den String wird jedes Zeichen durchiteriert. Alles, was zulässig ist (0-9, a-f), wird zu einem neuen String formatted-mac zusammengebaut (let ((formatted-mac nil)) ; Alles in Kleinbuchstaben (setq mac-address (string-downcase mac-address)) ; Gültige Zeichen 0-9 und a-f ausfiltern (loop for c across mac-address do (if (or (and (char>= c #\a) (char<= c #\f)) (and (char>= c (digit-char 0)) (char<= c (digit-char 9)))) (setf formatted-mac (concatenate 'string formatted-mac (list c)))) ) ; Wenn eine gültige MAC-Adresse vorliegt (=12 Zeichen), weitermachen. Ansonsten: Abbruch. (if (/= (length formatted-mac) 12) (return-from format-mac nil) (return-from format-mac (uiop:strcat (subseq formatted-mac 0 4) "." (subseq formatted-mac 4 8) "." (subseq formatted-mac 8 12)))) ) ) (defun get-help () (print "format-mac {mac-adresse} - Formatiert MAC-Adresse im Cisco-Format") (print "get-subnetdata '192.168.2.54/24'") (print "ddn2cidr {DDN netmask} - Wandelt Netmask von DDN zu CIDR um") (print "cidr2ddn {CIDR netmask} - Wandelt Netmask von CIDR zu DDN um") (print "ip-string-to-number {ip-string} - Wandelt IP-Adresse von String in Integer um") (print "ip-number-to-string {interger} - Wandelt Interger in IP-Adresse um") (return-from get-help nil) )
8,496
Common Lisp
.lisp
186
40.290323
147
0.640644
schlesix/networkengineering-lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:18 AM (Europe/Amsterdam)
352275afedaebfa4a660458eaa4020bc83cea477f5bb03abd39423910831dc6e
41,433
[ -1 ]
41,451
c4.lsp
Boerseth_lisp/ansicl/c4.lsp
(load "headers.lsp") (chapter 4 "SPECIALIZED DATA STRUCTURES") (section 4 1 "Arrays") (setf arr (make-array '(2 3) :initial-element nil)) (aref arr 0 0) (setf (aref arr 0 0) 'b) arr (aref arr 0 0) (defun arr-mult (a b) (let ((c (make-array '(2 2) :initial-element 0))) (dolist (i (list 0 1)) (dolist (j (list 0 1)) (setf (aref c i j) (+ (* (aref a i 0) (aref b 0 j)) (* (aref a i 1) (aref b 1 j)))))) c)) (defun arr-from-list (lst) (let ((n (length lst)) (m (length (car lst)))) (let ((a (make-array (list n m) :initial-element 0)) (i 0) (j 0)) (dolist (row lst) (setf j 0) (dolist (elmt row) (setf (aref a i j) elmt) (setf j (+ j 1))) (setf i (+ i 1))) a))) (setf i (arr-from-list (list (list 1 0) (list 0 1)))) i (setf a (arr-from-list (list (list 1 2) (list 3 4)))) a (setf b (arr-from-list (list (list 5 6) (list 7 8)))) b (setf c (arr-from-list (list (list 5 6 4) (list 7 8 2)))) c *print-array* (setf vec (make-array 4 :initial-element nil)) (vector "a" 'b 3) (svref vec 0) (svref (vector "zeroth" 1 2) 0) (section 4 2 "Example: Binary Search") (defun bin-search (obj vec) (let ((len (length vec))) (and (not (zerop len)) (finder obj vec 0 (- len 1))))) (defun finder (obj vec start end) (format t "~A~%" (subseq vec start (+ end 1))) (let ((range (- end start))) (if (zerop range) (if (eql obj (svref vec start)) start nil) (let ((mid (+ start (round (/ range 2))))) (if (eql obj (svref vec mid)) mid (if (> obj (svref vec mid)) (finder obj vec (+ mid 1) end) (finder obj vec start (- mid 1)))))))) (bin-search 8 (vector 0 1 2 3 4 5 6 7 8 9)) (bin-search 3 (vector 0 1 2 3 4 5 6 7 8 9)) (section 4 3 "Strings and Characters") ;(sort "elbow" #'char<) (aref "abc" 1) (char "abc" 1) (let ((str (copy-seq "Merlin"))) (setf (char str 3) #\k) str) (equal "fred" "fred") (equal "fred" "Fred") (string-equal "fred" "Fred") (format nil "~A or ~A" "truth" "dare") (concatenate 'string "not " "to worry") (section 4 4 "Sequences") ;(mirrorp "abba") (elt '(a b c) 1) (defun mirrorp (s) (let ((len (length s))) (and (evenp len) (do ((forward 0 (+ forward 1)) (back (- len 1) (- back 1))) ((or (> forward back) (not (eql (elt s forward) (elt s back)))) (> forward back)))))) (mirrorp "abba") (mirrorp "abcaba") (position #\a "fantasia") (position #\a "fantasia" :start 3 :end 5) (position #\a "fantasia" :from-end t) (position 'a '((c d) (a b)) :key #'car) (position '(c d) '((c d) (a b))) (position '(c d) '((c d) (a b)) :test #'equal) (position 3 '(1 0 7 5) :test #'<) (position 3 '(1 0 7 5) :test #'>) (defun second-word (str) (let ((p1 (position #\ str))) (if (null p1) nil (let ((p2 (position #\ str :start (+ p1 1)))) (if (null p2) (subseq str (+ p1 1)) (subseq str (+ p1 1) p2)))))) (second-word "Form follows function.") (second-word "Form") (find #\a "cat") (find-if #'characterp "ham") (setf lst '((complete 2) (incomplete 1))) (find-if #'(lambda (x) (eql (car x) 'complete)) lst) (find 'complete lst :key #'car) (remove-duplicates "abracadabra") (reduce #'intersection '((b r a d 's) (b a d) (c a t))) (section 4 5 "Example: Parsing Dates") (defun tokens (str test start) (let ((p1 (position-if test str :start start))) (if p1 (let ((p2 (position-if #'(lambda (c) (not (funcall test c))) str :start p1))) (cons (subseq str p1 p2) (if p2 (tokens str test p2) nil))) nil))) (defun constituent (c) (and (graphic-char-p c) (not (char= c #\ )))) (tokens "ab12 3cde.f" #'alpha-char-p 0) (defun parse-date (str) (let ((toks (tokens str #'constituent 0))) (list (parse-integer (first toks)) (parse-month (second toks)) (parse-integer (third toks))))) (defconstant month-names #("jan" "feb" "mar" "apr" "may" "jun" "jul" "aug" "sep" "oct" "nov" "dec")) (defun parse-month (str) (let ((p (position str month-names :test #'string-equal))) (if p (+ p 1) nil))) (parse-date "16 Aug 1980") (defun my-read-integer (str) (if (every #'digit-char-p str) (let ((accum 0)) (dotimes (pos (length str)) (setf accum (+ (* accum 10) (digit-char-p (char str pos))))) accum) nil)) (section 4 6 "Structures") (defun block-height (b) (svref b 0))
4,846
Common Lisp
.l
159
24.320755
56
0.523401
Boerseth/lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:26 AM (Europe/Amsterdam)
704285351e09756f69a127e7fd2b6182019d38706e1f90ead19c5435f407b560
41,451
[ -1 ]
41,452
c2ex.lsp
Boerseth_lisp/ansicl/c2ex.lsp
(load "headers.lsp") (section 2 "" "Exercises") (exercise "1." " Describe what happens when the following expressions are evaluated:") (exercise "[a]" "(+ (- 5 1) (+ 3 7))") (answer "The inner parens evaluate to 4 and 10, and the outer to 14:") (+ (- 5 1) (+ 3 7)) (done) (exercise "[b]" "(list 1 (+ 2 3))") (answer "After the inner paren evals to 5, the outer becomes a list of 1 and 5") (list 1 (+ 2 3)) (done) (exercise "[c]" "(if (listp 1) (+ 1 2) (+ 3 4))") (answer "It returns a 7") (if (listp 1) (+ 1 2) (+ 3 4)) (done) (exercise "[d]" "(list (and (listp 3) t) (+ 1 2))") (answer "It returns a list of NIL and 3") (list (and (listp 3) t) (+ 1 2)) (ddone) (exercise "2." "Give three distinct cons expressions that return (a b c).") (cons 'a '(b c)) (cons 'a (cons 'b '(c))) (cons 'a (cons 'b (cons 'c ()))) (ddone) (exercise "3." "Using car and cdr, define a function to return the fourth element of a list.") (defun my-fourth (lst) (car (cdr (cdr (cdr lst))))) (my-fourth '(a b c d)) (ddone) (exercise "4." "Define a function that takes two arguments and returns the greater of the two.") (defun greater (x y) (if (or (numberp x) (numberp y)) (if (and (numberp x) (numberp y)) (if (> x y) x y) (if (numberp x) x y)) nil)) (greater 5 6) (greater 6 6) (greater 7 6) (greater 'a 6) (greater 7 'a) (greater 7 ()) (greater 7 '(a b)) (ddone) (exercise "5." "What do these functions do?") (exercise "[a]" "") (defun enigma (x) (and (not (null x)) (or (null (car x)) (enigma (cdr x))))) (answer "It checks whether any element in x is NIL") (enigma '(1 2 3)) (enigma '(nil 2 3)) (enigma '(1 2 3 nil 2 3)) (enigma '(1 2 3 2 3 nil)) (enigma nil) (done) (exercise "[b]" "") (defun mystery (x y) (if (null y) nil (if (eql (car y) x) 0 (let ((z (mystery x (cdr y)))) (and z (+ z 1)))))) (answer "It finds the position of x as element in list y") (mystery 5 '(1 2 3 4 5 6)) (mystery 'c '(a b c d)) (mystery 3 '(a b c d)) (mystery 1 nil) (ddone) (exercise "6." "What could occur in place of the x in each of the following exchanges?") (exercise "[a]" "(car (x (cdr '(a (b c) d)))) => B") (car (first (cdr '(a (b c) d)))) (done) (exercise "[b]" "(x 13 (/ 1 0)) => 13") (or 13 (/ 1 0)) (done) (exercise "[c]" "(x #'list 1 nil) => (1)") (apply #'list 1 nil) (ddone) (exercise "7" "Using only operators introduced in this chapter, define a function that takes a list as an argument and returns true if one of its elements is a list") (defun contains-list (lst) (if (null lst) nil (if (listp (car lst)) t (contains-list (cdr lst))))) (contains-list '(a b c)) (contains-list '(a b c '(1 2))) (contains-list nil) (contains-list '('(1 2))) (ddone) (exercise "8." "Give iterative and recursive definitions of a function that") (exercise "[a]" "takes a positive integer an prints that many dots.") (defun iter-dots (n) (do ((i 0 (+ i 1))) ((eql i n)) (format t "."))) (defun rec-dots (n) (if (> n 0) (format t ".")) (if (> (- n 1) 0) (rec-dots (- n 1)))) (iter-dots 4) (rec-dots 4) (done) (exercise "[b]" "takes a list and returns the number of times the symbol a occurs in it.") (defun iter-a-count (lst) (let ((i 0)) (dolist (obj lst) (if (eql 'a obj) (setf i (+ i 1)))) i)) (defun rec-a-count (lst) (if (null lst) 0 (if (eql 'a (car lst)) (+ 1 (rec-a-count (cdr lst))) (rec-a-count (cdr lst))))) (iter-a-count '(a a b a b b a)) (rec-a-count '(a a b a b b a)) (ddone) (exercise "9." "A friend is trying to write a function that returns the sum of all the non-nil elements in a list. He has written two versions of this function, and neither of them work. Explain what's wrong with each, and give a correct version:") (exercise "[a]" " (defun summit (lst) (remove nil lst) (apply #'+ lst)) ") (answer "The problem is that `remove` does not alter the contents of `lst`. It only returns a new list, which is the same as `lst` only with `nil` removed. To fix this, make the `apply` act on the return of the first paren:") (defun summit (lst) (apply #'+ (remove nil lst))) (summit '(1 2 3 4 () 5 6 () 7 8 9)) (done) (exercise "[b]" " (defun summit (lst) (let ((x (car lst))) (if (null x) (summit (cdr lst)) (+ x (summit (cdr lst)))))) ") (answer "Here, the issue is that once in the recursion process `lst` is empty, we end up in an infinite recursion. Both (car ()) and (cdr ()) return NIL, so that the second to last line is called over and over again.") (defun summit (lst) (if (null lst) 0 (if (null (car lst)) (summit (cdr lst)) (+ (car lst) (summit (cdr lst)))))) (summit '(1 2 3 4 () 5 6 () 7 8 9))
4,724
Common Lisp
.l
150
28.933333
248
0.607033
Boerseth/lisp
0
0
0
GPL-3.0
9/19/2024, 11:50:26 AM (Europe/Amsterdam)
c89e8ce87732cdf5f54b7dee89ccb78eac6a755ad8aa8077d3f2553170989c4b
41,452
[ -1 ]