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
23,809
build-it.lisp
cbaggers_spring-lisp-gamejam/build-it.lisp
;; usage at shell prompt: ;; ;; cd ~/myproject ;; sbcl --load "build-it.lisp" --name myproject ;;---------------------------------------------------- ;; Setup #-quicklisp (load #P"~/quicklisp/setup.lisp") (push (merge-pathnames "lib/" *default-pathname-defaults*) asdf:*central-registry*) #+sbcl (progn #+unix(require 'sb-posix) (setf sb-impl::*default-external-format* :utf-8)) ;;---------------------------------------------------- ;; Load Shipshape (asdf:load-system :shipshape :force t) ;;---------------------------------------------------- ;; Do it (shipshape::command-line-invoke)
599
Common Lisp
.lisp
18
31.666667
83
0.513937
cbaggers/spring-lisp-gamejam
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
11c798a7f4a287fcdf168b060e320e4200654cbfe642419572a44f802fb3aa5e
23,809
[ -1 ]
23,810
space-bodies.lisp
cbaggers_spring-lisp-gamejam/space-bodies.lisp
(in-package :vacuum) (defparameter *ring-ratio* 1.3653333s0) (defparameter *corona-ratio* 1.4670488s0) ;; "corona_inner_rgb.png" ;; "corona_outer_rgb.png" ;; "rings_rgb.png" (defparameter *ambient-particles* `(("star_03.png" 0.3 0 2s0 (,(nrgb 107 56 22) ,(nrgb 220 135 25) ,(nrgb 253 221 107))) ("star_03.png" 0.3 0 2s0 (,(nrgb 107 56 22) ,(nrgb 220 135 25) ,(nrgb 253 221 107))) ("star_02.png" 0.7 0 5s0(,(nrgb 107 56 22) ,(nrgb 220 135 25) ,(nrgb 253 221 107))) ("asteroid_rgb.png" 4 0.97 25s0 (,(nrgb 107 56 22) ,(nrgb 220 135 25) ,(nrgb 253 221 107))) ("rocky_planet_rgb.png" 30 0.97 70s0 (,(nrgb 107 56 22) ,(nrgb 220 135 25) ,(nrgb 253 221 107))))) (defparameter *zoom-levels* '((20.0) (30.0 34.0) (48.0 60.0 78.0) (280.0 320.0 400.0 690.0 710.0) (2500.0 2500.0))) (defparameter *space-field-sizes* #(50s0 50s0 200s0 1000s0 12000s0)) (defparameter *player-journey* `(;; title screen ((:mote "star_01.png" :radius 0.5 :mass 2 :speed 20s0)) ;; level 0 ((:tiny-asteroid "asteroid_rgb.png" :radius 1 :mass 2 :speed 20s0) (:medium-asteroid "asteroid_rgb.png" :radius 1.6 :mass 6 :speed 60s0)) ;; level 1 ((:medium-asteroid "asteroid_rgb.png" :radius 2 :mass 10 :speed 60s0) (:large-asteroid "asteroid_rgb.png" :radius 4 :mass 14 :speed 60s0) (:planetoid "rocky_planet_rgb.png" :radius 8 :mass 28 :speed 60s0)) ;; level 2 ((:planetoid "rocky_planet_rgb.png" :radius 12 :mass 100 :speed 100s0) (:small-rocky-planet "rocky_planet_rgb.png" :radius 16 :mass 400 :speed 180s0) (:medium-rocky-planet "rocky_planet_rgb.png" :radius 32 :mass 8000 :speed 180s0) (:gas-planet "jovian_rgb.png" :radius 64 :mass 20000 :speed 180s0) (:gas-giant "jovian_rgb.png" :radius 192 :mass 100000 :speed 180s0)) ;; level 3 ((:small-star "sun_rgb.png" :radius 400 :mass 200000 :speed 550s0 :flare (("corona_inner_rgb.png" 1.4670488s0 :rotation-speed 0.1) ("corona_inner_rgb.png" 1.4670488s0 :rotation-speed -0.1))) (:large-star "sun_rgb.png" :radius 1200 :mass 260000 :speed 350s0 :flare (("corona_inner_rgb.png" 1.4670488s0 :rotation-speed 0.1) ("corona_inner_rgb.png" 1.4670488s0 :rotation-speed -0.1)))) ;; level 4 ;; end of demo )) (defparameter *bodies* `(;; title screen nil ;; level 0 ((10 (:tiny-asteroid "asteroid_rgb.png" :radius 1 :mass 1 :speed (5 . 15) :colors ((,(nrgb 84 63 41) ,(nrgb 150 123 95) ,(nrgb 255 199 140)) (,(nrgb 49 45 42) ,(nrgb 95 91 86) ,(nrgb 156 147 137)) (,(nrgb 41 62 84) ,(nrgb 95 122 150) ,(nrgb 140 196 255)))))) ;; level 1 ((60 (:tiny-asteroid "asteroid_rgb.png" :radius 1 :mass 1 :speed (5 . 15) :colors ((,(nrgb 84 63 41) ,(nrgb 150 123 95) ,(nrgb 255 199 140)) (,(nrgb 49 45 42) ,(nrgb 95 91 86) ,(nrgb 156 147 137)) (,(nrgb 41 62 84) ,(nrgb 95 122 150) ,(nrgb 140 196 255))))) ;;(:medium-asteroid "" 5) (40 (:comet "comet_rgb.png" :radius 1.5 :mass 28 :rotation ,(/ +pi+ 2) :speed (20 . 37) :colors ((,(nrgb 9 83 145) ,(nrgb 94 224 238) ,(nrgb 210 255 253)) (,(nrgb 82 49 137) ,(nrgb 207 105 222) ,(nrgb 244 202 249))))) (3 (:planetoid "rocky_planet_rgb.png" :radius 8 :mass 28 :speed 60 :colors ((,(nrgb 84 63 41) ,(nrgb 150 123 95) ,(nrgb 255 199 140)) (,(nrgb 49 45 42) ,(nrgb 95 91 86) ,(nrgb 156 147 137)) (,(nrgb 41 62 84) ,(nrgb 95 122 150) ,(nrgb 140 196 255)))))) (;; level 2 (30 (:planetoid "rocky_planet_rgb.png" :radius 8 :mass 28 :speed 20 :colors ((,(nrgb 39 61 55) ,(nrgb 97 175 175) ,(nrgb 183 233 96)) (,(nrgb 53 39 61) ,(nrgb 170 97 175) ,(nrgb 96 192 233)) (,(nrgb 61 48 39) ,(nrgb 175 159 97) ,(nrgb 219 181 33))))) (50 (:comet "comet_rgb.png" :radius 8 :mass 30 :rotation ,(/ +pi+ 2) :speed (45 . 60) :colors ((,(nrgb 9 83 145) ,(nrgb 94 224 238) ,(nrgb 210 255 253)) (,(nrgb 82 49 137) ,(nrgb 207 105 222) ,(nrgb 244 202 249))))) (30 (:small-rocky-planet "rocky_planet_rgb.png" :radius 16 :mass 400 :speed 30 :colors ((,(nrgb 39 61 55) ,(nrgb 97 175 175) ,(nrgb 183 233 96)) (,(nrgb 53 39 61) ,(nrgb 170 97 175) ,(nrgb 96 192 233)) (,(nrgb 61 48 39) ,(nrgb 175 159 97) ,(nrgb 219 181 33))))) (10 (:medium-rocky-planet "rocky_planet_rgb.png" :radius 32 :mass 8000 :speed 30 :colors ((,(nrgb 39 61 55) ,(nrgb 97 175 175) ,(nrgb 183 233 96)) (,(nrgb 53 39 61) ,(nrgb 170 97 175) ,(nrgb 96 192 233)) (,(nrgb 61 48 39) ,(nrgb 175 159 97) ,(nrgb 219 181 33))))) (3 (:gas-planet "jovian_rgb.png" :radius 50 :mass 20000 :speed 30 :flare (("rings_rgb.png" 1.3653333s0 :at-back nil)) :flare-chance-in-% 60 :colors ((,(nrgb 107 56 22) ,(nrgb 220 135 25) ,(nrgb 253 221 107)) (,(nrgb 23 22 107) ,(nrgb 144 25 220) ,(nrgb 56 240 241)) (,(nrgb 107 22 70) ,(nrgb 220 25 103) ,(nrgb 253 107 134)) (,(nrgb 63 107 22) ,(nrgb 87 220 25) ,(nrgb 122 253 107)))))) (;; level 3 (10 (:large-rocky-planet "rocky_planet_rgb.png" :radius 70 :mass 1000 :speed 300 :colors ((,(nrgb 39 61 55) ,(nrgb 97 175 175) ,(nrgb 183 233 96)) (,(nrgb 53 39 61) ,(nrgb 170 97 175) ,(nrgb 96 192 233)) (,(nrgb 61 48 39) ,(nrgb 175 159 97) ,(nrgb 219 181 33))))) (100 (:gas-planet "jovian_rgb.png" :radius 200 :mass 2000 :speed 80 :flare (("rings_rgb.png" 1.3653333s0 :at-back nil)) :flare-chance-in-% 60 :colors ((,(nrgb 107 56 22) ,(nrgb 220 135 25) ,(nrgb 253 221 107)) (,(nrgb 23 22 107) ,(nrgb 144 25 220) ,(nrgb 56 240 241)) (,(nrgb 107 22 70) ,(nrgb 220 25 103) ,(nrgb 253 107 134)) (,(nrgb 63 107 22) ,(nrgb 87 220 25) ,(nrgb 122 253 107)))))))) (defun player-stats (level stage) (elt (elt *player-journey* level) stage)) (defun get-zoom-for-stage (level stage) (elt (elt *zoom-levels* level) stage)) (defun stage-bodies-spec (level) (elt *bodies* level)) (defun passive-particle-spec (level) (elt *ambient-particles* level)) (defun field-size (&optional level) (aref *space-field-sizes* (or level (game-state-level *game-state*)))) (defun parse-speed (x) (rotate-v2 (v! 0 (etypecase x (cons (dbind (s . e) x (let ((range (- e s))) (if (> range 0s0) (+ s (random (float range))) (+ s (float range)))))) (number (+ (random (float x)))))) (random (* 2 +pi+))))
7,221
Common Lisp
.lisp
246
22.841463
72
0.544644
cbaggers/spring-lisp-gamejam
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
0966adbf368af29a64fcdafe35df4f20984b59343bd8971dc4a99e256c4ede9e
23,810
[ -1 ]
23,811
game.lisp
cbaggers_spring-lisp-gamejam/game.lisp
(in-package #:vacuum) (in-readtable fn:fn-reader) (defconstant +fps+ 60s0) ;; frames per second (defconstant +spf+ (/ 1s0 +fps+)) ;; seconds per frame (defconstant +sps+ 60s0) ;; update steps per second (defconstant +fts+ (/ 1s0 60s0)) ;; fixed time step (seconds per step) (defvar *camera* nil) (defvar *player* nil) (defvar *rocks* nil) (defvar *misc-draw* nil) (defvar *blend* nil) (defvar *sky-tex* nil) (defvar *dust-tex* nil) (defvar *sky-quad* nil) (defvar *nebula-tex* nil) (defvar *particle-system* nil) (defvar *nebula-falloff* 20s0) (defvar *eat-sound* nil) (defvar *grow-sound* nil) (defvar *shrink-sound* nil) (defvar *collision-sound* nil) (defvar *logo* nil) (defvar *current-nebula-size* 0s0) (defvar *temporal-draw-funcs* (ttm:make-tfunc-pool)) (defun init () (unless *sky-tex* (unless cepl.context:*gl-context* (cepl:repl)) ;; sounds (sdl2-mixer:init :ogg) (sdl2-mixer:open-audio 22050 :s16sys 1 1024) (sdl2-mixer:play-music (load-ogg "Psyonik_-_The_Heavens_Sing.ogg")) (sdl2-mixer:volume-music 15) (setf *eat-sound* (load-wav "eat.wav")) (setf *grow-sound* (load-wav "grow.wav")) (setf *shrink-sound* (load-wav "shrink.wav")) (setf *collision-sound* (load-wav "collision.wav")) ;; graphics (setf *camera* (make-camera)) (setf *blend* (make-blending-params)) ;; game entities (setf *sky-quad* (make-gpu-quad)) (setf *player* (make-player)) ;; particles (init-particles) (setf *particle-system* (make-particle-system)) (populate-velocities-using-func (lambda (ptr x y) (declare (ignorable x y)) (setf (cffi:mem-aref ptr :float 0) (- (random 0.01) 0.005) (cffi:mem-aref ptr :float 1) (- (random 0.01) 0.005) (cffi:mem-aref ptr :float 2) 0s0))) ;; input (skitter:listen-to λ(mouse-listener _ _1) (skitter:mouse 0) :pos) (skitter:listen-to λ(system-listener _ _1) skitter:+system+ :quitting) (skitter:listen-to λ(window-size-callback _ _1) (skitter:window 0) :size) ;; media (setf *logo* (load-texture "logo.png")) (setf *dust-tex* (load-texture "star_02.png")) (setf *nebula-tex* (load-texture "nebula.jpg")) (setf *sky-tex* (load-texture "space_bg.png")) ;; and begin (reset-game 0 0))) ;;---------------------------------------------------------------------- (defun reset-game (&optional level stage) (let ((level (or level (game-state-level *game-state*))) (stage (or stage (game-state-stage *game-state*)))) (setf *game-state* (make-game-state :level level :stage stage)) (reset-player *player* level stage) (setup-level level) (when (= level stage 0) (ttm:add (tlambda () (then (before (seconds 3) (draw-quad *logo* %progress%)) (before (seconds 3) (draw-quad *logo* 1s0)) (before (seconds 1) (draw-quad *logo* (- 1s0 %progress%))) (once (goto-next-stage *player* *game-state*)))) *temporal-draw-funcs*)) t)) (defun reset-player (&optional (player *player*) level stage) (let ((level (or level (game-state-level *game-state*))) (stage (or stage (game-state-stage *game-state*)))) (setf (actoroid-invincible-for-seconds player) 3s0) (setf (player-stuck player) nil) (setf (actoroid-position player) (v! 0 0) (actoroid-velocity player) (v! 0 0)) (update-player-data player level stage))) (defun player-ready-for-next-stage-p (player game-state) (let ((next-stage (calc-next-stage (game-state-level game-state) (game-state-stage game-state)))) (when next-stage (dbind (&key mass &allow-other-keys) (apply #'player-stats next-stage) (>= (mass player) mass))))) (defun update-player-data (player level stage) (dbind (_ tex &key mass speed flare &allow-other-keys) (player-stats level stage) (declare (ignore _)) (setf (player-texture player) (load-texture tex)) (setf (player-max-speed player) speed) (setf (actoroid-mass player) mass) (setf (actoroid-colors player) (get-new-colors (mapcar #'car (player-stuck player)))) ;; flare (setf (actoroid-flare player) (loop :for f :in flare :collect (dbind (tex ratio &key (at-back t) (rotation-speed 0s0)) f (make-instance 'flare :tex (load-texture tex) :ratio ratio :at-back at-back :rotation-speed rotation-speed)))) ;; these two fire off temporal lambdas (resize-player level stage) (when (player-stuck player) (remove-rocks player)) ;; End of game (when (and (= level 4) (= stage 1)) (let ((z (zoom *camera*))) (ttm:add (tlambda () (then (before (seconds 3) nil) (before (seconds 6) (setf (zoom *camera*) (- z (* 2000s0 %progress%)))) (once (reset-game 0 0))))))) ;; done player)) (defun remove-rocks (player) (let* ((rocks (mapcar #'car (player-stuck player))) (offsets (mapcar λ(v2:- (actoroid-position _) (actoroid-position player)) rocks))) (push (mapcar #'rock->spec rocks) (player-collected player)) (setf *misc-draw* (append rocks *misc-draw*)) (setf (player-stuck player) nil) (incf (actoroid-mass player) (reduce #'+ (mapcar #'mass rocks))) (ttm:add (tlambda () (then (before (seconds 0.4) (loop :for r :in rocks :for o :in offsets :do (setf (actoroid-position r) (v2:+ (actoroid-position player) (v2:*s o (- 1s0 (easing-f:in-quad %progress%))))))) (once (setf *misc-draw* (reduce λ(remove _1 _) rocks :initial-value *misc-draw*)))))))) (defun get-new-colors (rocks) (labels ((c= (x y) (every #'v:= x y))) (let* ((colors (mapcar #'actoroid-colors rocks)) (deduped (remove-duplicates colors :test #'c=)) ;; pair up the counts and colors (pairs (mapcar #'cons deduped (mapcar (lambda (x) (count-if λ(c= x _) colors)) deduped))) (sorted (sort pairs #'> :key #'cdr)) (final-colors (mapcar #'car (subseq sorted 0 (min 3 (length sorted)))))) (make-array 3 :initial-contents (case= (length final-colors) (0 (list (nrgb 100 100 100) (nrgb 130 130 130) (nrgb 200 200 200))) (1 (list (elt (first final-colors) 0) (elt (first final-colors) 1) (elt (first final-colors) 2))) (2 (list (elt (first final-colors) 0) (elt (first final-colors) 1) (elt (second final-colors) 2))) (3 (list (elt (first final-colors) 0) (elt (second final-colors) 1) (elt (third final-colors) 2)))))))) ;;---------------------------------------------------------------------- (defun calc-next-stage (level stage) (vbind (level-inc stage) (floor (1+ stage) (length (elt *player-journey* level))) (let ((level (+ level level-inc))) (unless (>= level (length *player-journey*)) (list level stage))))) (defun calc-last-stage (l s) (let* ((nl (if (= s 0) (- l 1) l)) (ns (if (= nl l) (- s 1) (- (length (elt *player-journey* nl)) 1)))) (list nl ns))) (defun setup-level (level) (declare (optimize debug)) ;; {TODO} do something with field size (dbind (ptex psize palpha spread pcol) (passive-particle-spec level) (setf *dust-tex* (load-texture ptex) (particle-system-neg-alpha *particle-system*) palpha (particle-system-colors *particle-system*) (make-array 3 :initial-contents pcol) (particle-system-size *particle-system*) psize (particle-system-spread *particle-system*) spread)) ;; add new bodies from spec ;; {TODO} for now just dump *rocks*, later animate this (setf *rocks* (loop :for (count spec) :in (stage-bodies-spec level) :append (loop :for i :below count :collect (spec->rock level spec)))) (let ((last-neb-size *current-nebula-size*)) (ttm:add (tlambda () (before (seconds 1.8) (setf *current-nebula-size* (+ last-neb-size (* (- (field-size) last-neb-size) (easing-f:linear %progress%))))))))) (defun spec->rock (level spec) (let ((space-field-size (elt *space-field-sizes* level))) (dbind (name tex &key radius mass colors speed rotation flare flare-chance-in-%) spec (let ((vel (parse-speed speed))) (make-actoroid :kind name :texture (if (sampler-p tex) tex (load-texture tex)) :colors (when colors (make-array 3 :initial-contents (alexandria:random-elt colors))) :position (calc-starting-pos radius space-field-size level 0) :velocity vel :rotation (+ +pi+ (- (vec2->angle vel) (or rotation 0s0))) :mass mass :radius radius :flare (when (and flare (< (random 100s0) flare-chance-in-%)) (loop :for f :in flare :collect (dbind (tex ratio &key (at-back t) (rot-speed 0s0)) f (make-instance 'flare :tex (load-texture tex) :ratio ratio :at-back at-back :rotation-speed rot-speed))))))))) (defun rock->spec (rock) (let ((speed (* (v2:length (actoroid-velocity rock)) 2)) (flare (actoroid-flare rock))) (list (actoroid-kind rock) (actoroid-texture rock) :radius (actoroid-radius rock) :mass (actoroid-mass rock) :rotation (actoroid-rotation rock) :speed (cons speed speed) :colors (list (map 'list #'identity (actoroid-colors (first *rocks*)))) :flare (when flare (loop :for f :in flare :collect (with-slots (tex ratio at-back-p rotatation-speed) f (list tex ratio :at-back at-back-p :rotation-speed rotatation-speed)))) :flare-chance-in-% (when flare 100s0)))) (defun calc-starting-pos (rock-radius space-field-size level stage) (dbind (_ _1 &key radius &allow-other-keys) (player-stats level stage) (declare (ignore _ _1)) (let* ((min (* (+ rock-radius radius) 10)) (range (- (float space-field-size) min))) (rotate-v2 (v! 0 (+ min (random range))) (random (* +pi+ 2)))))) (defun goto-next-stage (player game-state) (let ((last-level (game-state-level game-state)) (last-stage (game-state-stage game-state))) (sdl2-mixer:play-channel 0 *grow-sound* 0) (dbind (level stage) (calc-next-stage last-level last-stage) ;; update the game state (setf (game-state-level game-state) level (game-state-stage game-state) stage) ;; update player (update-player-data player level stage) ;; check if we need to do fancy transition (when (= stage 0) (ttm:add (tlambda () (once (setup-level level)))))))) (defun maybe-goto-next-stage (player game-state) (let ((ready (player-ready-for-next-stage-p player game-state))) ;;(break "~a ~a ~a" player (mass player) ready) (if ready (goto-next-stage player game-state) (sdl2-mixer:play-channel 1 *eat-sound* 0)))) (defun go-back-a-stage (player game-state) (let ((last-level (game-state-level game-state)) (last-stage (game-state-stage game-state))) (unless (= last-level last-stage 0) (sdl2-mixer:play-channel 2 *shrink-sound* 0) (dbind (level stage) (calc-last-stage last-level last-stage) ;; update the game state (setf (game-state-level game-state) level (game-state-stage game-state) stage) ;; update player (update-player-data player level stage) ;; (pop-collected-rocks player level) ;; check if we need to do fancy transition (when (< level last-level) (ttm:add (tlambda () (then (once (setup-level level)))))))))) (defun pop-collected-rocks (player level) (let ((released (mapcar λ(spec->rock level _) (pop (player-collected player))))) (loop :for r :in released :do (setf (actoroid-position r) (actoroid-position player) (actoroid-invincible-for-seconds r) 2s0)) (setf *rocks* (append released *rocks*)))) (defun bump (player) (when (<= (actoroid-invincible-for-seconds player) 0s0) (sdl2-mixer:play-channel 3 *collision-sound* 0) (shake-cam) (setf (actoroid-invincible-for-seconds player) 0.5))) (defparameter *game-state* (make-game-state)) (defun resize-player (level stage) (dbind (_ _1 &key radius &allow-other-keys) (player-stats level stage) (declare (ignore _ _1)) (ttm:add (let* ((start-size (actoroid-radius *player*)) (start-zoom (zoom *camera*)) (size-change (- radius start-size)) (zoom-change (- (get-zoom-for-stage level stage) start-zoom))) (tlambda () (then (before (seconds 1) (setf (actoroid-radius *player*) (+ start-size (* size-change (easing-f:out-bounce %progress%))))) (before (seconds 1) (setf (zoom *camera*) (+ start-zoom (* zoom-change (easing-f:out-bounce %progress%))))))))))) ;;---------------------------------------------------------------------- (defun-g actor-vert ((vert g-pt) &uniform (pos :vec2) (rot :mat3) (cam cam-g :ubo) (rad :float) (ymod :float)) (let* ((vpos (* rot (* (pos vert) rad)))) (values (+ (v! (cam-it (+ vpos (v! pos 0)) cam) 1) (v! 0 0 ymod 0)) (tex vert)))) (defun-g actor-replace-frag ((tc :vec2) &uniform (tex :sampler-2d) (rcol :vec3) (gcol :vec3) (bcol :vec3) (field-size :float) (falloff :float) (pos :vec2)) (let ((map (texture tex tc)) (f (/ (min falloff (max 0s0 (- (length pos) (- field-size falloff)))) falloff))) (v! (+ (* rcol (v:x map)) (* gcol (v:y map)) (* bcol (v:z map))) (* (v:w map) (- 1 f))))) (defun-g actor-replace-stuck ((tc :vec2) &uniform (tex :sampler-2d) (rcol :vec3) (gcol :vec3) (bcol :vec3) (neg-alpha :float)) (let ((map (texture tex tc))) (v! (+ (* rcol (v:x map)) (* gcol (v:y map)) (* bcol (v:z map))) (- (v:w map) neg-alpha)))) (def-g-> actor-replace-color-pipeline () #'actor-vert #'actor-replace-frag) (def-g-> actor-replace-color-pipeline2 () #'actor-vert #'actor-replace-stuck) (defun draw-actor (x &optional (ymod 0s0)) (declare (optimize debug)) (map-g #'actor-replace-color-pipeline (actoroid-stream x) :ymod ymod :pos (actoroid-position x) :tex (actoroid-texture x) :rot (m3:rotation-z (actoroid-rotation x)) :cam (camera-ubo *camera*) :rad (actoroid-radius x) :rcol (aref (actoroid-colors x) 0) :gcol (aref (actoroid-colors x) 1) :bcol (aref (actoroid-colors x) 2) :field-size (field-size) :falloff *nebula-falloff*) (draw-flare x ymod)) (defun draw-flare (x &optional (ymod 0s0) (ymod-inc -0.01)) (loop :for flare :in (actoroid-flare x) :do (with-slots (tex ratio at-back-p rot rotatation-speed) flare (map-g #'actor-replace-color-pipeline (actoroid-stream x) :ymod (+ ymod (if at-back-p 0s0 -0.0001)) :pos (v2:- (actoroid-position x) (v! 0 0)) :tex tex :rot (m3:rotation-z rot) :cam (camera-ubo *camera*) :rad (* (actoroid-radius x) ratio) :rcol (aref (actoroid-colors x) 0) :gcol (aref (actoroid-colors x) 1) :bcol (aref (actoroid-colors x) 2) :field-size (field-size) :falloff *nebula-falloff*) (incf ymod ymod-inc)))) (defun draw-player (x) (declare (optimize debug)) (draw-flare x 0.2) (map-g #'actor-replace-color-pipeline2 (actoroid-stream x) :ymod 0.1 :pos (actoroid-position x) :tex (actoroid-texture x) :rot (m3:rotation-z 0s0) :cam (camera-ubo *camera*) :rad (actoroid-radius x) :rcol (aref (actoroid-colors x) 0) :gcol (aref (actoroid-colors x) 1) :bcol (aref (actoroid-colors x) 2) :neg-alpha (if (> (actoroid-invincible-for-seconds x) 0.0) (+ 0.5 (/ (sin (* 30 (actoroid-invincible-for-seconds x))) 2)) 0s0))) (defun draw-stuck (x &optional (ymod 0s0)) (declare (optimize debug)) (map-g #'actor-replace-color-pipeline2 (actoroid-stream x) :ymod ymod :pos (actoroid-position x) :tex (actoroid-texture x) :rot (m3:rotation-z (actoroid-rotation x)) :cam (camera-ubo *camera*) :rad (actoroid-radius x) :rcol (aref (actoroid-colors x) 0) :gcol (aref (actoroid-colors x) 1) :bcol (aref (actoroid-colors x) 2) :neg-alpha 0s0) (draw-flare x ymod)) (defun update-stuck () (loop :for (s . offset) :in (player-stuck *player*) :do (setf (actoroid-position s) (v2:+ (actoroid-position *player*) offset)))) ;;---------------------------------------------------------------------- (defun-g sky-vert ((vert g-pt) &uniform (cam cam-g :ubo) (player-pos :vec2)) (values (v! (s~ (pos vert) :xy) 0.99 1.0) (tex vert) (s~ (pos vert) :xy))) (defun-g sky-frag ((tc :vec2) (pos :vec2) &uniform (tex :sampler-2d) (nebula :sampler-2d) (cam cam-g :ubo) (field-size :float) (nebula-falloff :float)) (let* ((screen-ratio (v! (/ (v:x (cam-g-size cam)) (v:y (cam-g-size cam))) 1)) (pixel-pos (+ (s~ (cam-g-position cam) :xy) (* (* pos screen-ratio) (cam-g-zoom cam)))) (dist (- (length pixel-pos) field-size nebula-falloff)) (factor (/ (min (max dist 0s0) nebula-falloff) nebula-falloff))) (mix (* (texture tex tc) 0.65) (texture nebula tc) factor))) (def-g-> sky-pipeline2 () #'sky-vert #'sky-frag) (defun draw-sky () (map-g #'sky-pipeline2 *sky-quad* :tex *sky-tex* :nebula *nebula-tex* :player-pos (actoroid-position *player*) :cam (camera-ubo *camera*) :field-size *current-nebula-size* :nebula-falloff *nebula-falloff*)) (defun-g splat-vert ((vert g-pt)) (values (v! (s~ (pos vert) :xy) 0.999 1.0) (tex vert))) (defun-g splat-frag ((tc :vec2) &uniform (tex :sampler-2d) (alpha :float)) (let ((col (texture tex tc))) (v! (s~ col :xyz) (* (v:w col) alpha)))) (def-g-> splat () #'splat-vert #'splat-frag) (defun draw-quad (tex &optional (alpha 1s0)) (map-g #'splat *sky-quad* :tex tex :alpha alpha)) ;;---------------------------------------------------------------------- (defun update-player (&optional (player *player*)) (update-flare-for player) (setf (actoroid-position player) (v2:+ (actoroid-position player) (v2:*s (actoroid-velocity player) +fts+))) (decf (actoroid-invincible-for-seconds player) +fts+) (setf (actoroid-velocity player) (v2:- (actoroid-velocity player) (v2:*s (actoroid-velocity player) (* 0.95 +fts+)))) (when (skitter:key-down-p key.escape) (reset-game 0 0)) (when (skitter:key-down-p key.q) (stop-vacuum)) ;; accelerate when mouse down (if (skitter:mouse-down-p mouse.left) ;; accelerate (let* ((target-vel (rotate-v2 (v! 0 (player-max-speed player)) (actoroid-rotation player))) (ease (easing-f:out-cubic (setf (player-accel-ramp player) (min 1s0 (+ (player-accel-ramp player) (* +fts+ 0.4)))))) (old-vel (player-key-up-vel player))) (setf (player-decel-ramp player) 1s0) (setf (player-key-down-vel player) (setf (actoroid-velocity player) (v! (lerp (x old-vel) (x target-vel) ease) (lerp (y old-vel) (y target-vel) ease))))) ;; decelerate (let* ((ease (easing-f:in-cubic (setf (player-decel-ramp player) (max 0s0 (- (player-decel-ramp player) (* +fts+ 0.1)))))) (old-vel (player-key-down-vel player))) (setf (player-accel-ramp player) 0s0) (setf (player-key-up-vel player) (setf (actoroid-velocity player) (v2:*s old-vel ease))))) (nebula-push-back player) (update-stuck) (check-for-player-collisions player)) (defun actor-offset (a b) (v2:- (actoroid-position b) (actoroid-position a))) (defun actors-colliding-p (a b) (let ((o (actor-offset a b))) (<= (v2:length o) (+ (actoroid-radius a) (actoroid-radius b))))) (defun check-for-player-collisions (player) (when (<= (actoroid-invincible-for-seconds player) 0s0) (symbol-macrolet ((stuck (player-stuck player))) (loop :for a :in (cons player (mapcar #'car stuck)) :do (let ((col-with (find-if λ(actors-colliding-p _ a) *rocks*))) (when col-with (if (<= (mass col-with) (mass player)) (unless (> (actoroid-invincible-for-seconds col-with) 0s0) (attach-rock-to-player player col-with a)) (progn (bump player) (if (null stuck) (go-back-a-stage player *game-state*) (if (eq a player) (detach-all-rocks-from-player player) (detach-rock-from-player player a))))))))))) (defun attach-rock-to-player (player rock stick-to) (symbol-macrolet ((stuck (player-stuck player))) (let ((o (actor-offset player rock))) (setf *rocks* (remove rock *rocks*)) (push (cons rock (v2:- o (v2:*s (actor-offset stick-to rock) 0.05) (v2:*s (actor-offset player rock) 0.05))) stuck)) (maybe-goto-next-stage player *game-state*))) (defun detach-all-rocks-from-player (player) (let ((x (mapcar #'car (player-stuck player)))) (loop :for a :in x :do (detach-rock-from-player player a)))) (defun detach-rock-from-player (player rock) (symbol-macrolet ((stuck (player-stuck player)) (vel (actoroid-velocity rock))) (let ((o (actor-offset player rock))) (setf (actoroid-invincible-for-seconds rock) 1s0) (setf stuck (remove rock stuck :key #'car) vel (v2:*s (v2:normalize (v! (y o) (x o))) (* 0.3 60))) (push rock *rocks*))) (remove-any-seperate-rocks)) (defun remove-any-seperate-rocks () (let* ((stuck (mapcar #'car (player-stuck *player*))) (attached (make-array (length stuck) :initial-contents (mapcar λ(actors-colliding-p _ *player*) stuck))) (neighbours (loop :for s :in stuck :collect (loop :for n :in stuck :for i :from 0 :when (and (not (eq s n)) (actors-colliding-p s n)) :collect i)))) (loop :until (every #'identity attached) :for d :from 0 :do (when (> d 500) (loop :for i :below (length attached) :do (setf (aref attached i) :f))) (loop :for s :in stuck :for ns :in neighbours :for i :from 0 :do (unless (aref attached i) (setf (aref attached i) (cond ((null ns) :f) ((some λ(eq t (aref attached _)) ns) t) ((every λ(eq :f (aref attached _)) ns) :f) (t nil)))))) (loop :for s :in stuck :for a :across attached :do (when (eq :f a) (detach-rock-from-player *player* s))))) (defun nebula-push-back (player) (let ((ppos (actoroid-position player))) (setf (actoroid-velocity player) (v2:+ (actoroid-velocity player) (v2:*s (v2:normalize ppos) (* (- (max 0s0 (- (v2:length ppos) (field-size)))) 300s0 +fts+)))))) (defun draw () (clear) (with-blending *blend* (with-viewport (camera-viewport *camera*) (ttm:update *temporal-draw-funcs*) ;; (draw-sky) ;; (draw-passive-particles *particle-system* *camera* *dust-tex*) ;; (when *rocks* (let* ((min 0.4) (max 0.5) (range (- max min)) (mult (/ range (length *rocks*)))) (loop :for a :in *rocks* :for i :from 0 :do (draw-actor a (- max (* i mult))))) ;; (let* ((min 0.3) (max 0.4) (range (- max min)) (mult (/ range (length *rocks*)))) (loop :for s :in (player-stuck *player*) :for i :from 0 :do (draw-stuck (car s) (- max (* i mult)))))) ;; (loop :for a :in *misc-draw* :do (draw-actor a)) ;; (draw-player *player*))) (swap)) (defun update-rocks () (let ((field-size (field-size))) (loop :for r :in *rocks* :do (update-flare-for r) (symbol-macrolet ((pos (actoroid-position r)) (vel (actoroid-velocity r))) (setf pos (v2:+ pos (v2:*s vel +fts+))) (decf (actoroid-invincible-for-seconds r) +fts+) (when (> (v2:length pos) field-size) (setf pos (v2:*s (v2:normalize pos) (- (- field-size 0.1s0))))))))) (defun update-flare-for (x) (let ((flares (actoroid-flare x))) (when flares (loop :for f :in flares :do (with-slots (rot rotatation-speed) f (incf rot (* rotatation-speed +fts+))))))) (defun update () (setf (cam-pos *camera*) (actoroid-position *player*)) (update-player) (update-rocks) (update-particles *particle-system*) (ttm:update)) (defun vacuum () (run-vacuum)) (let ((running nil)) (defun run-vacuum (&optional for-frames force-stepper) (assert (or (null for-frames) (numberp for-frames))) (unwind-protect (progn (format t "-vacuum started-~%") (setf running t) (let ((game-stepper (temporal-functions:make-stepper (seconds +spf+))) (repl-stepper (temporal-functions:make-stepper (seconds (/ 1.0 10.0))))) (init) (loop :while (and running (not (shutting-down-p)) (if for-frames (>= (decf for-frames) 0) t)) :do (continuable (cepl:step-host) (when (or force-stepper (funcall game-stepper)) (update) (draw)) (when (or force-stepper (funcall repl-stepper)) (update-repl-link)))))) (setf running nil) (format t "-vacuum stopped-~%")) t) (defun stop-vacuum () (sdl2-mixer:halt-music) (setf running nil))) ;;---------------------------------------------------------------------- (let ((last-timestamp 0)) (defun mouse-listener (event timestamp) (setf last-timestamp timestamp) (let* ((d (skitter:xy-pos-vec event)) (res (viewport-resolution (camera-viewport *camera*))) (v (v2:normalize (v! (- (v:x d) (/ (v:x res) 2s0)) (- (- (v:y d) (/ (v:y res) 2s0)))))) (a (acos (v2:dot (v! 0 1) v))) (a (if (< (x v) 0) (- a) a))) (setf (actoroid-rotation *player*) (- a))))) (defun system-listener (event timestamp) (declare (ignore event timestamp)) (stop-vacuum)) ;;---------------------------------------------------------------------- (defun shake-cam (&optional (camera *camera*)) (let ((zoom (zoom camera))) (ttm:add (tlambda () (before (seconds 0.5) (setf (cam-pos camera) (v2:+ (cam-pos camera) (v2:*s (v! (* zoom 0.04 (sin (* 10 %progress%))) (* zoom 0.04 (cos (* 20 %progress%)))) (- 1s0 (easing-f:in-quad %progress%)))))))))) ;;---------------------------------------------------------------------- (defun reshape (new-dimensions) (let ((new-dimensions (v! (v:x new-dimensions) (v:y new-dimensions)))) ;;(print new-dimensions) (update-viewport-size *camera* (v! new-dimensions)))) (defun window-size-callback (event timestamp) (declare (ignore timestamp)) (reshape (skitter:size-2d-vec event)))
26,073
Common Lisp
.lisp
707
32.196605
89
0.613245
cbaggers/spring-lisp-gamejam
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
44fc0d4c323712fc7e0279a92673921876eaeaf09b26679f79fc8d46a26b11d2
23,811
[ -1 ]
23,812
passive-particles.lisp
cbaggers_spring-lisp-gamejam/passive-particles.lisp
(in-package :vacuum) (in-readtable fn:fn-reader) (defvar *particle-stream* nil) (defparameter *particle-resolution* '(64 64)) (defparameter *starting-positions* nil) (defparameter *starting-velocities* (make-c-array (make-array *particle-resolution* :initial-element (v! 0 0 0)) :element-type :half-vec3)) (deftclass particle-gbuffer (positions (sample (make-texture *starting-positions* :element-type :rgb32f))) (positions-fbo nil) (velocities (sample (make-texture *starting-velocities* :element-type :rgb16f))) (velocities-fbo nil)) (deftclass (particle-system (:constructor %make-particle-system)) (front-gbuffer (make-particle-gbuffer)) (back-gbuffer (make-particle-gbuffer) :type particle-gbuffer) (front-to-back t :type boolean) (neg-alpha 0s0 :type single-float ) (size 1s0 :type single-float) (colors (make-array 3 :initial-contents (list (nrgb 107 56 22) (nrgb 220 135 25) (nrgb 253 221 107))) :type array) (spread 2s0 :type single-float)) (defun make-particle-system () (let ((result (%make-particle-system))) (let ((front (particle-system-front-gbuffer result)) (back (particle-system-back-gbuffer result))) (setf (particle-gbuffer-positions-fbo front) (make-fbo `(0 ,(sampler-texture (particle-gbuffer-positions front)))) (particle-gbuffer-velocities-fbo front) (make-fbo `(0 ,(sampler-texture (particle-gbuffer-velocities front))))) (setf (particle-gbuffer-positions-fbo back) (make-fbo `(0 ,(sampler-texture (particle-gbuffer-positions back)))) (particle-gbuffer-velocities-fbo back) (make-fbo `(0 ,(sampler-texture (particle-gbuffer-velocities back))))) result))) ;;---------------------------------------------------------------- (defun init-particles () (unless *particle-stream* (setf *particle-stream* (apply #'make-particle-stream *particle-resolution*)) (let ((arr (make-c-array nil :dimensions *particle-resolution* :element-type :vec3))) (labels ((init (ptr x y) (declare (ignore x y)) (setf (cffi:mem-aref ptr :float 0) (+ -500s0 (random 1000s0)) (cffi:mem-aref ptr :float 1) (+ -500s0 (random 1000s0)) (cffi:mem-aref ptr :float 2) 0s0))) (setf *starting-positions* (across-c-ptr #'init arr)))) t)) (defun populate-velocities-using-func (ptr-x-y-func) (with-c-array (arr (make-c-array nil :dimensions *particle-resolution* :element-type :vec3)) (across-c-ptr ptr-x-y-func arr) (push-g arr (sampler-texture (particle-gbuffer-velocities (particle-system-front-gbuffer *particle-system*)))) (push-g arr (sampler-texture (particle-gbuffer-velocities (particle-system-back-gbuffer *particle-system*)))))) ;;---------------------------------------------------------------- (defun-g particle-vert ((vert cepl:g-pt)) (values (v! (pos vert) 1) (* (v! 1 -1) (cepl:tex vert)))) (defun-g update-particle-positions ((tex-coord :vec2) &uniform (positions :sampler-2d) (velocities :sampler-2d) (field-size :float)) (let* ((position (texture positions tex-coord)) (velocity (texture velocities tex-coord)) (new (+ (v! (s~ position :xy) 0 0) (v! (* 3 (s~ velocity :xy)) 0 0)))) (v! (- (mod (+ field-size (v:x new)) (* 2 field-size)) field-size) (- (mod (+ field-size (v:y new)) (* 2 field-size)) field-size)))) (def-g-> move-particles () #'particle-vert #'update-particle-positions) ;;---------------------------------------------------------------- (defun-g update-particle-velocities ((tex-coord :vec2) &uniform (positions :sampler-2d) (velocities :sampler-2d)) (let* ((position (texture positions tex-coord)) (velocity (texture velocities tex-coord))) velocity)) (def-g-> update-velocities-pline () #'particle-vert #'update-particle-velocities) ;;---------------------------------------------------------------- (defun update-particles (particle-system) (let* ((quad (get-gpu-quad)) (f2b (particle-system-front-to-back particle-system)) (source (if f2b (particle-system-front-gbuffer particle-system) (particle-system-back-gbuffer particle-system))) (destination (if f2b (particle-system-back-gbuffer particle-system) (particle-system-front-gbuffer particle-system)))) ;; (setf (particle-system-front-to-back particle-system) (not f2b)) ;; (with-fbo-bound ((particle-gbuffer-velocities-fbo destination) :with-blending nil) (map-g #'update-velocities-pline quad :positions (particle-gbuffer-positions source) :velocities (particle-gbuffer-velocities source))) ;; (with-fbo-bound ((particle-gbuffer-positions-fbo destination) :with-blending nil) (map-g #'move-particles quad :positions (particle-gbuffer-positions source) :velocities (particle-gbuffer-velocities source) :field-size (field-size))))) ;;---------------------------------------------------------------- (defun-g place-particle ((vert :vec4) &uniform (positions :sampler-2d) (cam cam-g :ubo) (field-size :float) (particle-size :float) (spread :float)) (let* ((pos-index (v!int (int (floor (v:z vert))) (int (floor (v:w vert))))) (id (+ (v:x pos-index) (* 128 (v:y pos-index)))) (particle-position (texel-fetch positions pos-index 0)) (corner-pos (s~ vert :xy)) (pos3 (cam-it (+ (v! (* corner-pos particle-size) 0.8) (* (v! (s~ particle-position :xy) 0) spread)) cam))) (values (v! (s~ pos3 :xy) (+ 0.7 (* (/ 0.2 16384.0) id)) 1) (* (+ corner-pos (v! 1 1)) 0.5)))) (defun-g place-particle-frag ((tex-coord :vec2) &uniform (tex :sampler-2d) (rcol :vec3) (gcol :vec3) (bcol :vec3) (neg-alpha :float)) (let ((map (texture tex tex-coord))) ;; (- map (v! 0 0 0 neg-alpha)) (v! (+ (* rcol (v:x map)) (* gcol (v:y map)) (* bcol (v:z map))) (- (v:w map) neg-alpha)))) (def-g-> draw-particles-pline () #'place-particle #'place-particle-frag) (defun draw-passive-particles (psys camera texture) (let* ((f2b (particle-system-front-to-back psys)) (destination (if f2b (particle-system-back-gbuffer psys) (particle-system-front-gbuffer psys)))) (map-g #'draw-particles-pline *particle-stream* :positions (particle-gbuffer-positions destination) :tex texture :particle-size (particle-system-size psys) :cam (camera-ubo camera) :field-size (field-size) :rcol (aref (particle-system-colors psys) 0) :gcol (aref (particle-system-colors psys) 1) :bcol (aref (particle-system-colors psys) 2) :neg-alpha (particle-system-neg-alpha psys) :spread (particle-system-spread psys)))) ;;---------------------------------------------------------------- (defun make-particle-stream (size-x size-y) ;; (v! vert.x vert.y pos.u pos.v) (let* ((quad-verts (vector (v! -1.0 -1.0) (v! 1.0 -1.0) (v! 1.0 1.0) (v! -1.0 1.0))) (verts (with-c-array (arr (make-c-array nil :dimensions (* 4 size-x size-y) :element-type :vec4)) (labels ((put (ptr index) (multiple-value-bind (y x) (floor (floor index 4) size-x) (let ((qv (svref quad-verts (mod index 4)))) (setf (cffi:mem-aref ptr :float 0) (v:x qv) (cffi:mem-aref ptr :float 1) (v:y qv) (cffi:mem-aref ptr :float 2) (+ 0s0 x) (cffi:mem-aref ptr :float 3) (+ 0s0 y)))))) (across-c-ptr #'put arr)) (make-gpu-array arr))) (indices (with-c-array (arr (make-c-array nil :dimensions (* 6 size-x size-y) :element-type :uint)) (let ((indices #(3 0 1 3 1 2))) (labels ((put (ptr x) (multiple-value-bind (quad-num n) (floor x 6) (setf (cffi:mem-aref ptr :uint) (+ (aref indices n) (* quad-num 4)))))) (across-c-ptr #'put arr))) (make-gpu-array arr)))) (make-buffer-stream verts :index-array indices :retain-arrays t))) ;;----------------------------------------------------------------
8,064
Common Lisp
.lisp
195
36.225641
78
0.608108
cbaggers/spring-lisp-gamejam
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
0cd57f91de6de47f8fba2bffcfe7a8dcdc4c6546220b0fa5db4793dd6111df96
23,812
[ -1 ]
23,813
vacuum.asd
cbaggers_spring-lisp-gamejam/vacuum.asd
;;;; vacuum.asd (asdf:defsystem #:vacuum :description "I dun a game :p" :author "Baggers <[email protected]>" :license "GPL v3" :depends-on (#:cepl #:temporal-functions #:cepl.sdl2 #:swank #:livesupport #:cepl.skitter.sdl2 #:dirt #:structy-defclass #:dendrite #:easing #:sdl2-mixer #:shipshape) :serial t :components ((:file "package") (:file "helpers") (:file "types") (:file "passive-particles") (:file "space-bodies") (:file "game") (:file "shipping")))
729
Common Lisp
.asd
25
17.44
43
0.449502
cbaggers/spring-lisp-gamejam
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
c398c23e542c45465e3ef8487258398f963e77a603805204be4a31bd770eb4d2
23,813
[ -1 ]
23,838
guess-my-number.cl
Kyure-A_Land-of-Lisp/chapter-2/guess-my-number.cl
;; defparameter は再度代入可能 (defparameter *small* 0) (defparameter *big* 100) ;; defvar は不可 (defvar *test* -1) (defun guess-my-number () (ash (+ *small* *big*) -1)) ;; ash は bitshift する; 左にするときは 1, 右にするときは -1 (defun smaller () (setf *big* (1- (guess-my-number))) (guess-my-number)) (defun bigger () (setf *small* (1+ (guess-my-number))) (guess-my-number)) (defun start-guess-number () (defparameter *small* 0) (defparameter *big* 100) (guess-my-number)) (defun correct () (defparameter *small* 0) (defparameter *big* 100) (let ((message "Yeah, good!")) (princ message)))
653
Common Lisp
.cl
22
24.772727
73
0.658494
Kyure-A/Land-of-Lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
32b04242b9ab93eb2425de17015fbd01fb6e4251907ef6263c7beb8ebac0ead0
23,838
[ -1 ]
23,839
guess-my-number-local.cl
Kyure-A_Land-of-Lisp/chapter-2/guess-my-number-local.cl
(defun start-guess-my-number () (let ((small 0) (big 100) (game-over-p nil)) (labels ((guess-my-number () ;; labels は flet と違って labels 内で定義した関数を labels 内で使える (ash (+ small big) -1)) (smaller () (setf big (1- (guess-my-number)))) (bigger () (setf small (1+ (guess-my-number)))) (correct () (setf game-over-p t) (print "Thank you! Bye."))) (print "Game start. I guess your number.") (print (guess-my-number)) (loop while (not game-over-p) with user-choice = nil do (setf user-choice (read-line)) (print user-choice) (cond ((string= user-choice "correct") (correct)) ((string= user-choice "bigger") (bigger)) ((string= user-choice "smaller") (smaller)) (t (error "I'm panic!"))) (print (guess-my-number))))))
883
Common Lisp
.cl
24
28.416667
84
0.565164
Kyure-A/Land-of-Lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
7edaee138a0540fd97610427e21e04df761875c20a90f103260cdccbd26cc587
23,839
[ -1 ]
23,840
text-adventure-game.cl
Kyure-A_Land-of-Lisp/chapter-5/text-adventure-game.cl
;; ここでの日本語は symbol 扱いらしい すごい (defparameter *nodes* '((living-room (あなたは居間にいる。魔法使いはソファでいびきをかいている。)) (garden (あなたは美しい庭にいる。目の前に井戸がある。)) (attic (あなたは屋根裏にいる。部屋の隅に巨大な溶接バーナーがある。)))) (defparameter *objects* '(ウイスキー バケツ カエル チェーン)) (defparameter *object-locations* '((ウイスキー living-room) (バケツ living-room) (チェーン garden) (カエル garden))) (defun describe-location (location nodes) (nth 1 (assoc location nodes))) ;; assoc、要は C++ だと map の nodes[location] ってことで (defparameter *edges* '((living-room (garden 西 扉) (attic 上 はしご)) (garden (living-room 東 扉)) (attic (living-room 下 はしご)))) (defun describe-path (edge) `(ここから ,(nth 1 edge) に向かう ,(nth 2 edge) がある。)) ;; (mapcar #'sqrt '(1 2 3 4 5)) -> (1.0 1.4142135 1.7320508 2.0 2.236068) ;; 第二引数の各要素に第一引数の関数を適用して新しい list を返す ;; (append '(hoge) '(fuga)) -> (HOGE FUGA) ;; list を結合 ;; (apply #'append '((hoge) (fuga))) -> (HOGE FUGA) ;; 第二引数に第一引数の関数を適用する ;; mapcar は 1 変数関数, apply は多変数関数? (defun describe-paths (location edges) (apply #'append (mapcar #'describe-path (cdr (assoc location edges))))) (defun objects-at (location objects object-locations) (labels ((at-locations-p (objects) (eq (cadr (assoc objects object-locations)) location))) (remove-if-not #'at-locations-p objects))) (defun describe-objects (location objects object-locations) (labels ((describe-obj (obj) `(床に ,obj がある。))) (apply #'append (mapcar #'describe-obj (objects-at location objects object-locations))))) (defparameter *players-location* 'living-room) (defun look () (append (describe-location *players-location* *nodes*) (describe-paths *players-location* *edges*) (describe-objects *players-location* *objects* *object-locations*))) ;; :key のあとの関数が要素の比較前に適用され、第一引数が第二引数にあるか検索(あったらそれを返す) (defun walk (direction) (let ((next (find direction (cdr (assoc *players-location* *edges*)) :key #'cadr))) (if next (progn (setf *players-location* (nth 0 next)) (look)) '(そっちには進めない。)))) ;; member は 第二引数の list に 第一引数 key があるか確認 (defun pickup (object) (cond ((member object (objects-at *players-location* *objects* *object-locations*)) (push (list object 'body) *object-locations*) `(あなたは ,object を持っている。)) (t '(あなたはそれを入手できない。)))) (defun players-inventory () (cons 'アイテム- (objects-at 'body *objects* *object-locations*)))
3,013
Common Lisp
.cl
59
36.576271
93
0.688869
Kyure-A/Land-of-Lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
a3a3411f58836eff1908bf897ce2fe1d84aa202903fd6f2c35b3d1253295117a
23,840
[ -1 ]
23,841
interface.cl
Kyure-A_Land-of-Lisp/chapter-6/interface.cl
(defun say-hello () (print "名前を入力してくだしあ: ") ;; 表示位置が行頭でなければ改行 (let ((your-name (read))) (prin1 "こんちは!") ;; 改行しない (print your-name))) ;; "" で囲わないと error (defun say-hello-with-exception () (print "名前を入力してくださいあ: ") (let ((your-name (read))) (if (typep your-name 'string) (format t "こんにちは! ~a" your-name) (error "your-name が string ではない")))) (defun say-hello-princ () (princ "名前を入力してくだしあ: ") ;; string に "" がつかず出力される (let ((your-name (read))) (princ "こんちは!") (princ your-name))) (defun game-read () (let ((cmd (read-from-string (concatenate 'string "(" (read-line) ")")))) (flet ((quote-it (x) (list 'quote x))) (cons (car cmd) (mapcar #'quote-it (cdr cmd)))))) (defparameter *allowed-commands* '(look walk pickup players-inventory)) (defun game-eval (sexp) (if (member (car sexp) *allowed-commands*) (eval sexp) '(そんな command しらない!))) ;; ばかでかい (defun tweak-text (lst caps lit) ;; caps は文頭かを示す, (when lst (let ((item (car lst)) (rest (cdr lst))) (cond ;; item が " " なら 自身の後ろの文字列をわたす ((eql item #\space) (cons item (tweak-text rest caps lit))) ;; item が "!", "?", "." のいずれかなら自身の後ろの文字列をわたす ((member item '(#\! #\? #\.)) (cons item (tweak-text rest t lit))) ((eql item #\") (tweak-text rest caps (not lit))) (lit (cons item (tweak-text rest nil lit))) (caps (cons (char-upcase item) (tweak-text rest nil lit))) (t (cons (char-downcase item) (tweak-text rest nil nil))))))) (defun game-print (lst) ;; coerce: 強制する, 脅かすの意らしい 初めてみたけどきもい ;; (coerce object 'result-type) で object を result-type にかえるらしい 便利ね~ (princ (coerce (tweak-text (coerce (string-trim "() " (prin1-to-string lst)) 'list) t nil) 'string)) (fresh-line)) (defun game-repl () (let ((cmd (game-read))) (unless (eq (car cmd) 'quit) (game-print (game-eval cmd)) (game-repl))))
2,245
Common Lisp
.cl
55
30.418182
71
0.618102
Kyure-A/Land-of-Lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
d44c9656cd781b1e5c3f917a55dfd0026cae75cc0bef43612d8306b2ec7bc8b8
23,841
[ -1 ]
23,861
generate-application.lisp
informatimago_hangman-cocoa-lisp/src/generate-application.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: generate-application.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This script generates the Hangman application on CCL on MacOSX. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-06-19 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2015 ;;;; ;;;; 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 "COMMON-LISP-USER") ;;; -------------------------------------------------------------------- ;;; Load quicklisp (format t "~%;;; Loading quicklisp.~%") (finish-output) (load #P"~/quicklisp/setup.lisp") (setf quicklisp-client:*quickload-verbose* t) ;;; -------------------------------------------------------------------- ;;; Load the application: (defparameter *program-name* "Hangman") (defparameter *release-directory* #P"~/Desktop/") (defparameter *version* "1.0.1") (defparameter *copyright* "Copyright 2015 Pascal Bourguignon License: AGPL3") (push (or *load-pathname* #P"./") asdf:*central-registry*) (ql:quickload :com.informatimago.common-lisp.cesarum) (ql:quickload :com.informatimago.hangman) (push (function com.informatimago.hangman.cocoa:main) ccl:*lisp-startup-functions*) ;;; -------------------------------------------------------------------- ;;; Save the application package. #+ccl (require :build-application) (format t "Generating ~A~%" (merge-pathnames (make-pathname :name *program-name* :type "app") *release-directory*)) (defun copy-files (files dest-dir) (ensure-directories-exist (make-pathname :name "test" :type "test" :defaults dest-dir)) (dolist (file (directory files)) (let ((dest-file (make-pathname :name (pathname-name file) :type (pathname-type file) :defaults dest-dir))) (format t "Copying ~A~%" dest-file) (com.informatimago.common-lisp.cesarum.file:copy-file file dest-file :element-type '(unsigned-byte 8) :if-exists :supersede)))) (let ((resources (merge-pathnames (make-pathname :directory (list :relative (format nil "~A.app" *program-name*) "Contents" "Resources")) *release-directory*))) (copy-files (make-pathname :directory (list :relative :up "Resources" "en.lproj") :name :wild :type :wild) (merge-pathnames #P"en.lproj/" resources)) (copy-files (make-pathname :directory (list :relative :up "Resources" "images") :name :wild :type "png") (merge-pathnames #P"images/" resources)) (copy-files (make-pathname :directory (list :relative :up "Resources") :name "AppIcon" :type "icns") resources)) (defun save-hangman-application () ;; ccl::build-application ;; calls ccl::save-application ;; calls ccl::%save-application-interal ;; calls ccl::save-image #+ccl (ccl::build-application ; This doesn't return. :name *program-name* :directory *release-directory* :type-string "APPL" :creator-string "SOSH" :copy-ide-resources nil ; whether to copy the IDE's resources :info-plist (com.informatimago.hangman.cocoa::dictionary :|LSApplicationCategoryType| "public.app-category.word-games" :|CFBundleIconFile| "AppIcon.icns" :|CFBundleIdentifier| "com.informatimago.hangman.lisp" :|CFBundleShortVersionString| (format nil "~A" *version*) :|CFBundleVersion| (format nil "~A ~A" "ccl" (lisp-implementation-version)) :|LSMinimumSystemVersion| "10.7" :|CFBundleDevelopmentRegion| "English" :|NSHumanReadableCopyright| (format nil "Copyright 2015 Pascal Bourguignon~%License: AGPL3") ;; :|CFBundleHelpBookFolder| "Resources" ;; :|CFBundleHelpBookName| "HangmanHelp" ;; :|NSAppleScriptEnabled| nil ; not yet. ;; :|CFBundleDocumentTypes| (cf-bundle-document-types) ;; :|UTExportedTypeDeclarations| (exported-type-utis) ;; (dictionary-version $default-info-dictionary-version) ;; (development-region $default-info-plist-development-region) ;; (executable $default-info-plist-executable) ;; (has-localized-display-name $default-info-plist-has-localized-display-name) ;; overriden by write-info-plist, I assume. :|NSMainNibFile| "MainMenu" ;; overriden by write-info-plist (bundle-name $default-info-plist-bundle-name) ;; overriden by write-info-plist (bundle-package-type $default-info-plist-bundle-package-type) ;; overriden by write-info-plist (bundle-signature $default-info-plist-bundle-signature) :|NSPrincipalClass| "LispApplication") :nibfiles '() ; a list of user-specified nibfiles ; to be copied into the app bundle ;; :main-nib-name "MainMenu" ;; ; the name of the nib that is to be loaded ;; ; as the app's main. this name gets written ;; ; into the Info.plist on the "NSMainNibFile" key :private-frameworks '() :toplevel-function nil :altconsole t)) ; use t for a console for *standard-output*, *error-output*. (save-hangman-application) ;;;; THE END ;;;;
6,784
Common Lisp
.lisp
124
45.717742
110
0.566305
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
e21ec3863878d5b3574625b192fcde6a55346c8843e7ba9b4e796f18c868f068
23,861
[ -1 ]
23,862
hangman.lisp
informatimago_hangman-cocoa-lisp/src/hangman.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: hangman.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; The hangman game. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-06-18 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2015 ;;;; ;;;; 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 "COM.INFORMATIMAGO.HANGMAN.COCOA") (defstruct (hangman (:constructor %make-hangman)) word ; the word to guess, should only contain letters in the alphabet found ; vector of boolean one for each letter in word tried-letters ; vector of letters tried so far (error-count 0) maximum-error-count (missing-letter ".") alphabet) (defun make-hangman (word maximum-error-count &key (alphabet "abcdefghijklmnopqrstuvwxyz")) (let ((found (make-array (length word) :element-type 'boolean :initial-element nil))) (setf (aref found 0) t (aref found (1- (length found))) t) (%make-hangman :word word :found found :alphabet alphabet :missing-letter "." :tried-letters (make-array (length alphabet) :element-type 'character :fill-pointer 0) :maximum-error-count maximum-error-count))) (defun hangman-found-word (hangman) (loop :with found-word = (copy-seq (hangman-word hangman)) :with found = (hangman-found hangman) :for i :below (length found-word) :unless (aref found i) :do (setf (aref found-word i) (character (hangman-missing-letter hangman))) :finally (return found-word))) (defun hangman-try-letter (hangman letter) (let ((tried (position letter (hangman-tried-letters hangman) :test (function char-equal)))) (when tried (return-from hangman-try-letter (if (< (hangman-error-count hangman) (hangman-maximum-error-count hangman)) :already-tried :loses)))) (vector-push letter (hangman-tried-letters hangman)) (loop :with word = (hangman-word hangman) :with found = (hangman-found hangman) :with error = t :for i :below (length word) :when (char-equal letter (aref word i)) :do (setf (aref found i) t error nil) :finally (when (and error (< (hangman-error-count hangman) (hangman-maximum-error-count hangman))) (incf (hangman-error-count hangman))) (return (cond ((not (< (hangman-error-count hangman) (hangman-maximum-error-count hangman))) :loses) ((not (position nil found)) :wins) (error :bad-guess) (t :good-guess))))) (defun test/hangman () (let ((game (make-hangman "Hello" 11))) (assert (string= "Hello" (hangman-word game))) (assert (string= "H...o" (hangman-found-word game))) (assert (eq :good-guess (hangman-try-letter game #\l))) (assert (= 0 (hangman-error-count game))) (assert (eq :already-tried (hangman-try-letter game #\l))) (assert (= 1 (hangman-error-count game))) (assert (eq :bad-guess (hangman-try-letter game #\z))) (assert (= 2 (hangman-error-count game))) (assert (eq :wins (hangman-try-letter game #\e))) (assert (= 2 (hangman-error-count game)))) (let ((game (make-hangman "Hello" 3))) (assert (string= "Hello" (hangman-word game))) (assert (string= "H...o" (hangman-found-word game))) (assert (eq :good-guess (hangman-try-letter game #\l))) (assert (= 0 (hangman-error-count game))) (assert (eq :already-tried (hangman-try-letter game #\l))) (assert (= 1 (hangman-error-count game))) (assert (eq :bad-guess (hangman-try-letter game #\z))) (assert (= 2 (hangman-error-count game))) (assert (eq :loses (hangman-try-letter game #\z))) (assert (= 3 (hangman-error-count game))))) ;;;; THE END ;;;;
4,938
Common Lisp
.lisp
111
38.207207
105
0.598963
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
ace53bfb685f0cbb6b6686caf81907915e1c69a4ca478d5d2c210f923be21672
23,862
[ -1 ]
23,863
nsapi.lisp
informatimago_hangman-cocoa-lisp/src/nsapi.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: nsapi.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Defines a lisp layer above Cocoa. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-06-17 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2015 ;;;; ;;;; 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 "COM.INFORMATIMAGO.HANGMAN.COCOA") (objcl:set-objective-cl-syntax) (defstruct (point (:type list)) x y) (defstruct (size (:type list)) width height) (defstruct (rect (:type list)) x y width height) (defmacro dovector ((var vector &optional result) &body body) (let ((vvector (gensym "vector")) (vindex (gensym "index")) (vlength (gensym "length"))) `(block nil (let* ((,vvector ,vector) (,vlength (length ,vvector)) (,vindex -1)) (tagbody (go :test) :loop (let ((,var (aref ,vvector ,vindex))) ,@body) :test (incf ,vindex) (if (< ,vindex ,vlength) (go :loop)) (return ,result)))))) (declaim (inline nsrect nspoint nssize nsarray)) (defun nsrect (frame) (apply (function ns:make-ns-rect) frame)) (defun nspoint (point) (apply (function ns:make-ns-point) point)) (defun nssize (size) (apply (function ns:make-ns-size) size)) (defun nsarray (sequence) (etypecase sequence (ns:ns-array sequence) (sequence (let ((array [NSMutableArray arrayWithCapacity:(length sequence)])) (map nil (lambda (element) [array addObject:element]) sequence) array)))) (defun nsstring (string) (etypecase string (ns:ns-string string) (string (objcl:objc-string string)) (symbol (objcl:objc-string (symbol-name string))))) (defun nsurl (url) (typecase url (ns:ns-url url) (t [NSURL URLWithString:(nsstring url)]))) (declaim (inline nstimeinterval cgfloat sfloat fontsize coord nsbool)) (defun nstimeinterval (value) (coerce value 'double-float)) (defun cgfloat (value) (coerce value 'ns:cgfloat)) (defun sfloat (value) (coerce value 'single-float)) (defun fontsize (value) (values (round value))) (defun coord (value) (values (round value))) (defconstant yes #$YES) (defconstant no #$NO) (defun nsbool (value) (case value ((1) yes) ((0) no) ((nil) no) (otherwise yes))) (defun ns-matrix-mode (mode) (ecase mode ((:radio #.#$NSRadioModeMatrix) #$NSRadioModeMatrix) ((:highlight #.#$NSHighlightModeMatrix) #$NSHighlightModeMatrix) ((:list #.#$NSListModeMatrix) #$NSListModeMatrix) ((:track #.#$NSTrackModeMatrix) #$NSTrackModeMatrix))) (defun ns-button-type (type) (ecase type ((:momentary-push :momentary-light #.#$NSMomentaryLightButton) #$NSMomentaryLightButton) ((:push-on-push-off #.#$NSPushOnPushOffButton) #$NSPushOnPushOffButton) ((:toggle #.#$NSToggleButton) #$NSToggleButton) ((:switch #.#$NSSwitchButton) #$NSSwitchButton) ((:radio #.#$NSRadioButton) #$NSRadioButton) ((:momentary-change #.#$NSMomentaryChangeButton) #$NSMomentaryChangeButton) ((:on-off #.#$NSOnOffButton) #$NSOnOffButton) ((:momentary-push-in #.#$NSMomentaryPushInButton) #$NSMomentaryPushInButton) #+cocoa-10.10 ((:accelerator #.#$NSAcceleratorButton) #$NSAcceleratorButton) #+cocoa-10.10 ((:multi-level-accelerator #.#$NSMultiLevelAcceleratorButton) #$NSMultiLevelAcceleratorButton))) (defun ns-bezel-style (style) (ecase style ((:rounded #.#$NSRoundedBezelStyle) #$NSRoundedBezelStyle) ((:regular-square #.#$NSRegularSquareBezelStyle :small-icon-button) #$NSRegularSquareBezelStyle) ((:thick-square #.#$NSThickSquareBezelStyle) #$NSThickSquareBezelStyle) ((:thicker-square #.#$NSThickerSquareBezelStyle) #$NSThickerSquareBezelStyle) ((:disclosure #.#$NSDisclosureBezelStyle) #$NSDisclosureBezelStyle) ((:shadowless #.#$NSShadowlessSquareBezelStyle) #$NSShadowlessSquareBezelStyle) ((:circular #.#$NSCircularBezelStyle) #$NSCircularBezelStyle) ((:textured-square #.#$NSTexturedSquareBezelStyle) #$NSTexturedSquareBezelStyle) ((:help-button #.#$NSHelpButtonBezelStyle) #$NSHelpButtonBezelStyle) ((:small-square #.#$NSSmallSquareBezelStyle) #$NSSmallSquareBezelStyle) ((:textured-rounded #.#$NSTexturedRoundedBezelStyle) #$NSTexturedRoundedBezelStyle) ((:round-rect #.#$NSRoundRectBezelStyle) #$NSRoundRectBezelStyle) ((:recessed #.#$NSRecessedBezelStyle) #$NSRecessedBezelStyle) ((:rounded-disclosure #.#$NSRoundedDisclosureBezelStyle) #$NSRoundedDisclosureBezelStyle) #+cocoa-10.10 ((:inline #.#$NSInlineBezelStyle) #$NSInlineBezelStyle))) (defun ns-gradient-type (type) (ecase type ((:none #.#$NSGradientNone) #$NSGradientNone) ((:concave-weak #.#$NSGradientConcaveWeak) #$NSGradientConcaveWeak) ((:concave-strong #.#$NSGradientConcaveStrong) #$NSGradientConcaveStrong) ((:convex-weak #.#$NSGradientConvexWeak) #$NSGradientConvexWeak) ((:convex-strong #.#$NSGradientConvexStrong) #$NSGradientConvexStrong))) (defun ns-text-field-bezel-style (bezel-style) (ecase bezel-style ((:square #.#$NSTextFieldSquareBezel) #$NSTextFieldSquareBezel) ((:rounded #.#$NSTextFieldRoundedBezel) #$NSTextFieldRoundedBezel))) (defun ns-view-layer-contents-placement (placement) (ecase placement ((:scale-axes-independently #.#$NSViewLayerContentsPlacementScaleAxesIndependently) #$NSViewLayerContentsPlacementScaleAxesIndependently) ((:scale-proportionally-to-fit #.#$NSViewLayerContentsPlacementScaleProportionallyToFit) #$NSViewLayerContentsPlacementScaleProportionallyToFit) ((:scale-proportionally-to-fill #.#$NSViewLayerContentsPlacementScaleProportionallyToFill) #$NSViewLayerContentsPlacementScaleProportionallyToFill) ((:center #.#$NSViewLayerContentsPlacementCenter) #$NSViewLayerContentsPlacementCenter) ((:top #.#$NSViewLayerContentsPlacementTop) #$NSViewLayerContentsPlacementTop) ((:top-right #.#$NSViewLayerContentsPlacementTopRight) #$NSViewLayerContentsPlacementTopRight) ((:right #.#$NSViewLayerContentsPlacementRight) #$NSViewLayerContentsPlacementRight) ((:bottom-right #.#$NSViewLayerContentsPlacementBottomRight) #$NSViewLayerContentsPlacementBottomRight) ((:bottom #.#$NSViewLayerContentsPlacementBottom) #$NSViewLayerContentsPlacementBottom) ((:bottom-left #.#$NSViewLayerContentsPlacementBottomLeft) #$NSViewLayerContentsPlacementBottomLeft) ((:left #.#$NSViewLayerContentsPlacementLeft) #$NSViewLayerContentsPlacementLeft) ((:top-left #.#$NSViewLayerContentsPlacementTopLeft) #$NSViewLayerContentsPlacementTopLeft))) (defun ns-view-layer-contents-redraw-policy (policy) (ecase policy ((:never #.#$NSViewLayerContentsRedrawNever) #$NSViewLayerContentsRedrawNever) ((:on-set-needs-display #.#$NSViewLayerContentsRedrawOnSetNeedsDisplay) #$NSViewLayerContentsRedrawOnSetNeedsDisplay) ((:during-view-resize #.#$NSViewLayerContentsRedrawDuringViewResize) #$NSViewLayerContentsRedrawDuringViewResize) ((:before-view-resize #.#$NSViewLayerContentsRedrawBeforeViewResize) #$NSViewLayerContentsRedrawBeforeViewResize) #+cocoa-10.10 ((:crossfade #.#$NSViewLayerContentsRedrawCrossfade) #$NSViewLayerContentsRedrawCrossfade))) (defun ns-text-alignment (alignment) (ecase alignment ((:left #.#$NSLeftTextAlignment) #$NSLeftTextAlignment) ((:right #.#$NSRightTextAlignment) #$NSRightTextAlignment) ((:center #.#$NSCenterTextAlignment) #$NSCenterTextAlignment) ((:justified #.#$NSJustifiedTextAlignment) #$NSJustifiedTextAlignment) ((:natural #.#$NSNaturalTextAlignment) #$NSNaturalTextAlignment))) (defun ns-writing-direction (direction) (ecase direction ((:natural #.#$NSWritingDirectionNatural) #$NSWritingDirectionNatural) ((:left-to-right #.#$NSWritingDirectionLeftToRight) #$NSWritingDirectionLeftToRight) ((:right-to-left #.#$NSWritingDirectionRightToLeft) #$NSWritingDirectionRightToLeft))) (defun ns-cell-image-position (position) (ecase position ((:none #.#$NSNoImage) #$NSNoImage) ((:only #.#$NSImageOnly) #$NSImageOnly) ((:left #.#$NSImageLeft) #$NSImageLeft) ((:right #.#$NSImageRight) #$NSImageRight) ((:below #.#$NSImageBelow) #$NSImageBelow) ((:above #.#$NSImageAbove) #$NSImageAbove) ((:overlaps #.#$NSImageOverlaps) #$NSImageOverlaps))) (defun ns-image-frame-style (style) (ecase style ((:none #.#$NSImageFrameNone) #$NSImageFrameNone) ((:photo #.#$NSImageFramePhoto) #$NSImageFramePhoto) ((:gray-bezel #.#$NSImageFrameGrayBezel) #$NSImageFrameGrayBezel) ((:groove #.#$NSImageFrameGroove) #$NSImageFrameGroove) ((:button #.#$NSImageFrameButton) #$NSImageFrameButton))) (defun ns-image-alignment (alignment) (ecase alignment ((:center #.#$NSImageAlignCenter) #$NSImageAlignCenter) ((:top #.#$NSImageAlignTop) #$NSImageAlignTop) ((:top-left #.#$NSImageAlignTopLeft) #$NSImageAlignTopLeft) ((:top-right #.#$NSImageAlignTopRight) #$NSImageAlignTopRight) ((:left #.#$NSImageAlignLeft) #$NSImageAlignLeft) ((:bottom #.#$NSImageAlignBottom) #$NSImageAlignBottom) ((:bottom-left #.#$NSImageAlignBottomLeft) #$NSImageAlignBottomLeft) ((:bottom-right #.#$NSImageAlignBottomRight) #$NSImageAlignBottomRight) ((:right #.#$NSImageAlignRight) #$NSImageAlignRight))) (defun ns-image-scaling (scaling) (ecase scaling ((:proportionally-down #.#$NSImageScaleProportionallyDown) #$NSImageScaleProportionallyDown) ((:axes-independently #.#$NSImageScaleAxesIndependently) #$NSImageScaleAxesIndependently) ((:none #.#$NSImageScaleNone) #$NSImageScaleNone) ((:proportionally-up-or-down #.#$NSImageScaleProportionallyUpOrDown) #$NSImageScaleProportionallyUpOrDown))) (defun ns-window-style-mask (mask) (let ((result #$NSBorderlessWindowMask)) (cond ((integerp mask) mask) ((or (null mask) (eq :borderless mask)) result) ((atom mask) (ns-window-style-mask (list mask))) (t (when (member :titled mask) (incf result #$NSTitledWindowMask)) (when (member :closable mask) (incf result #$NSClosableWindowMask)) (when (member :miniaturizable mask) (incf result #$NSMiniaturizableWindowMask)) (when (member :resizable mask) (incf result #$NSResizableWindowMask)) (when (member :textured-background mask) (incf result #$NSTexturedBackgroundWindowMask)) result)))) (defun ns-backing-store-type (type) (ecase type ((:retained #.#$NSBackingStoreRetained) #$NSBackingStoreRetained) ((:non-retained #.#$NSBackingStoreNonretained) #$NSBackingStoreNonretained) ((:buffered #.#$NSBackingStoreBuffered) #$NSBackingStoreBuffered))) (defun ns-window-collection-behavior (behavior) (ecase behavior ((:default #.#$NSWindowCollectionBehaviorDefault) #$NSWindowCollectionBehaviorDefault) ((:can-join-all-spaces #.#$NSWindowCollectionBehaviorCanJoinAllSpaces) #$NSWindowCollectionBehaviorCanJoinAllSpaces) ((:move-to-active-space #.#$NSWindowCollectionBehaviorMoveToActiveSpace) #$NSWindowCollectionBehaviorMoveToActiveSpace))) (defun ns-window-sharing-type (type) (ecase type ((:none #.#$NSWindowSharingNone) #$NSWindowSharingNone) ((:read-only #.#$NSWindowSharingReadOnly) #$NSWindowSharingReadOnly) ((:read-write #.#$NSWindowSharingReadWrite) #$NSWindowSharingReadWrite))) (defgeneric configure (object &key &allow-other-keys) (:documentation "Sets the object parameters. The CONFIGURE method provides a lispier API to initialize the Cocoa Objects, since it takes mostly lisp objects as parameter and convert them to the required NS types: string -> NSString, keywords -> NSInteger enums, real -> CGFloat or whatever is needed rect list -> NSRect size list -> NSSize point list -> NSPoint ")) (defmethod configure ((self ns:ns-responder) &key (next-responder nil next-responder-p) (menu nil menu-p) &allow-other-keys) (when (next-method-p) (call-next-method)) (when next-responder-p [self setNextResponder: next-responder]) (when menu-p [self setMenu: menu]) self) (defmethod configure ((self ns:ns-view) &key (superview nil superview-p) (subviews '() subviews-p) (frame nil frame-p) (frame-rotation 0.0 frame-rotation-p) (bounds nil bounds-p) (bounds-rotation 0.0 bounds-rotation-p) add-constraints remove-constraints (layer nil layer-p) (wants-layer nil wants-layer-p) (wants-update-layer nil wants-update-layer-p) (layer-contents-placement nil layer-contents-placement-p) (layer-contents-redraw-policy nil layer-contents-redraw-policy-p) (can-draw-subviews-into-layer nil can-draw-subviews-into-layer-p) (layer-uses-core-image-filters nil layer-uses-core-image-filters-p) (alpha-value nil alpha-value-p) (frame-center-rotation nil frame-center-rotation-p) (background-filters nil background-filters-p) (compositing-filter nil compositing-filter-p) (content-filters nil content-filters-p) (shadow nil shadow-p) &allow-other-keys) (declare (ignorable add-constraints remove-constraints wants-update-layer wants-update-layer-p can-draw-subviews-into-layer can-draw-subviews-into-layer-p layer-uses-core-image-filters layer-uses-core-image-filters-p)) (when (next-method-p) (call-next-method)) (when frame-p [self setFrame:(nsrect frame)]) (when frame-rotation-p [self setFrameRotation:(cgfloat frame-rotation)]) (when bounds-p [self setBounds:(nsrect bounds)]) (when bounds-rotation-p [self setBoundsRotation:(cgfloat bounds-rotation)]) (when subviews-p [self setSubviews:(nsarray subviews)]) (when wants-layer-p [self setWantsLayer:(nsbool wants-layer)]) #+cocoa-10.10 (when wants-update-layer-p [self setWantsUpdateLayer:(nsbool wants-update-layer)]) (when layer-p [self setLayer:layer]) (when layer-contents-placement-p [self setLayerContentsPlacement:(ns-view-layer-contents-placement layer-contents-placement)]) (when layer-contents-redraw-policy-p [self setLayerContentsRedrawPolicy:(ns-view-layer-contents-redraw-policy layer-contents-redraw-policy)]) #+cocoa-10.10 (when can-draw-subviews-into-layer-p [self setCanDrawSubviewsIntoLayer:(nsbool can-draw-subviews-into-layer)]) #+cocoa-10.10 (when layer-uses-core-image-filters-p [self setLayerUsesCoreImageFilters:(nsbool layer-uses-core-image-filters)]) (when alpha-value-p [self setAlphaValue:(cgfloat alpha-value)]) (when frame-center-rotation-p [self setFrameCenterRotation: (cgfloat frame-center-rotation)]) (when background-filters-p [self setBackgroundFilters:(nsarray background-filters)]) (when compositing-filter-p [self setCompositingFilter:(nsarray compositing-filter)]) (when content-filters-p [self setContentFilters:(nsarray content-filters)]) (when shadow-p [self setShadow:shadow]) #+cocoa-10.10 (when remove-constraints [self removeConstraints:(nsarray remove-constraints)]) #+cocoa-10.10 (when add-constraints [self addConstraints:(nsarray add-constraints)]) (when superview-p [superview addSubview:self]) self) (defmethod configure ((self ns:ns-control) &key (enabled nil enabled-p) (double-value nil double-value-p) (float-value nil float-value-p) (int-value nil int-value-p) (integer-value nil integer-value-p) (object-value nil object-value-p) (string-value nil string-value-p) (attributed-string-value nil attributed-string-value-p) (alignment nil alignment-p) (font nil font-p) (formatter nil formatter-p) (base-writing-direction nil base-writing-direction-p) (allows-expansion-tool-tips nil allows-expansion-tool-tips-p) (action nil action-p) (target nil target-p) (continuous nil continuous-p) (tag nil tag-p) (refuses-first-responder nil refuses-first-responder-p) &allow-other-keys) (declare (ignorable allows-expansion-tool-tips allows-expansion-tool-tips-p)) (when (next-method-p) (call-next-method)) (when enabled-p [self setEnabled: (nsbool enabled)]) (when double-value-p [self setDoubleValue: (coerce double-value 'double-float)]) (when float-value-p [self setFloatValue: (coerce float-value 'single-float)]) (when int-value-p [self setIntValue: (coerce int-value 'integer)]) (when integer-value-p [self setIntegerValue: (coerce integer-value 'integer)]) (when object-value-p [self setObjectValue: object-value]) (when string-value-p [self setStringValue: (nsstring string-value)]) (when attributed-string-value-p [self setAttributedStringValue: attributed-string-value]) (when alignment-p [self setAlignment: (ns-text-alignment alignment)]) (when font-p [self setFont: font]) (when formatter-p [self setFormatter: formatter]) (when base-writing-direction-p [self setBaseWritingDirection: (ns-writing-direction base-writing-direction)]) #+cocoa-10.10 (when allows-expansion-tool-tips-p [self setAllowsExpansionToolTips: allows-expansion-tool-tips]) (when action-p [self setAction: action]) (when target-p [self setTarget: target]) (when continuous-p [self setContinuous: (nsbool continuous)]) (when tag-p [self setTag: tag]) (when refuses-first-responder-p [self setRefusesFirstResponder: (nsbool refuses-first-responder)]) self) (defmethod configure ((self ns:ns-button) &key (button-type nil button-type-p) (alternate-title nil alternate-title-p) (attributed-title nil attributed-title-p) (title nil title-p) (sound nil sound-p) (spring-loaded nil spring-loaded-p) (max-accelerator-level nil max-accelerator-level-p) (image nil image-p) (alternate-image nil alternate-image-p) (image-position nil image-position-p) (bordered nil bordered-p) (transparent nil transparent-p) (bezel-style nil bezel-style-p) (shows-border-only-while-mouse-inside nil shows-border-only-while-mouse-inside-p) (allows-mixed-state nil allows-mixed-state-p) (state nil state-p) (key-equivalent nil key-equivalent-p) (key-equivalent-modifier-mask nil key-equivalent-modifier-mask-p) &allow-other-keys) (declare (ignore spring-loaded spring-loaded-p max-accelerator-level max-accelerator-level-p)) (when (next-method-p) (call-next-method)) (when button-type-p [self setButtonType: (ns-button-type button-type)]) (when alternate-title-p [self setAlternateTitle: (nsstring alternate-title)]) (when attributed-title-p [self setAttributedTitle: attributed-title]) (when title-p [self setTitle: (nsstring title)]) (when sound-p [self setSound: sound]) #+cocoa-10.10 (when spring-loaded-p [self setSpringLoaded: spring-loaded]) #+cocoa-10.10(when max-accelerator-level-p [self setMaxAcceleratorLevel: max-accelerator-level]) (when image-p [self setImage: image]) (when alternate-image-p [self setAlternateImage: alternate-image]) (when image-position-p [self setImagePosition: (ns-cell-image-position image-position)]) (when bordered-p [self setBordered: (nsbool bordered)]) (when transparent-p [self setTransparent: (nsbool transparent)]) (when bezel-style-p [self setBezelStyle: (ns-bezel-style bezel-style)]) (when shows-border-only-while-mouse-inside-p [self setShowsBorderOnlyWhileMouseInside: (nsbool shows-border-only-while-mouse-inside)]) (when allows-mixed-state-p [self setAllowsMixedState: (nsbool allows-mixed-state)]) (when state-p [self setState: state]) (when key-equivalent-p [self setKeyEquivalent: (nsstring key-equivalent)]) (when key-equivalent-modifier-mask-p [self setKeyEquivalentModifierMask: key-equivalent-modifier-mask]) self) (defmethod configure ((self ns:ns-image-view) &key (image nil image-p) (image-frame-style nil image-frame-style-p) (image-alignment nil image-alignment-p) (image-scaling nil image-scaling-p) (animates nil animates-p) (editable nil editable-p) (allows-cut-copy-paste nil allows-cut-copy-paste-p) &allow-other-keys) (when (next-method-p) (call-next-method)) (when image-p [self setImage: image]) (when image-frame-style-p [self setImageFrameStyle: (ns-image-frame-style image-frame-style)]) (when image-alignment-p [self setImageAlignment: (ns-image-alignment image-alignment)]) (when image-scaling-p [self setImageScaling: (ns-image-scaling image-scaling)]) (when animates-p [self setAnimates: (nsbool animates)]) (when editable-p [self setEditable: (nsbool editable)]) (when allows-cut-copy-paste-p [self setAllowsCutCopyPaste: (nsbool allows-cut-copy-paste)]) self) (defmethod configure ((self ns:ns-text-field) &key (editable nil editable-p) (selectable nil selectable-p) (allows-editing-text-attributes nil allows-editing-text-attributes-p) (imports-graphics nil imports-graphics-p) (text-color nil text-color-p) (background-color nil background-color-p) (draws-background nil draws-background-p) (preferred-max-layout-width nil preferred-max-layout-width-p) (bezeled nil bezeled-p) (bezel-style nil bezel-style-p) (bordered nil bordered-p) (delegate nil delegate-p) &allow-other-keys) (declare (ignorable preferred-max-layout-width preferred-max-layout-width-p)) (when (next-method-p) (call-next-method)) (when editable-p [self setEditable: (nsbool editable)]) (when selectable-p [self setSelectable: (nsbool selectable)]) (when allows-editing-text-attributes-p [self setAllowsEditingTextAttributes: (nsbool allows-editing-text-attributes)]) (when imports-graphics-p [self setImportsGraphics: (nsbool imports-graphics)]) (when text-color-p [self setTextColor: text-color]) (when background-color-p [self setBackgroundColor: background-color]) (when draws-background-p [self setDrawsBackground: draws-background]) #+cocoa-10.10 (when preferred-max-layout-width-p [self setPreferredMaxLayoutWidth: (cgfloat preferred-max-layout-width)]) (when bezeled-p [self setBezeled: (nsbool bezeled)]) (when bezel-style-p [self setBezelStyle: (ns-bezel-style bezel-style)]) (when bordered-p [self setBordered: (nsbool bordered)]) (when delegate-p [self setDelegate: delegate]) self) (defmethod configure ((self ns:ns-window) &key (title nil title-p) (represented-filename nil represented-filename-p) (represented-url nil represented-url-p) (movable nil movable-p) (movable-by-window-background nil movable-by-window-background-p) (one-shot nil one-shot-p) (style-mask nil style-mask-p) (works-when-modal nil works-when-modal-p) (alpha-value nil alpha-value-p) (background-color nil background-color-p) (color-space nil color-space-p) (content-view nil content-view-p) (can-hide nil can-hide-p) (hides-on-deactivate nil hides-on-deactivate-p) (collection-behavior nil collection-behavior-p) (opaque nil opaque-p) (has-shadow nil has-shadow-p) (invalidate nil invalidate-p) (delegate nil delegate-p) (initial-first-responder nil initial-first-responder-p) (prevents-application-termination-when-modal nil prevents-application-termination-when-modal-p) (sharing-type nil sharing-type-p) (can-become-visible-without-login nil can-become-visible-without-login-p) (backing-type nil backing-type-p) (preferred-backing-location nil preferred-backing-location-p) (depth-limit nil depth-limit-p) (dynamic-depth-limit nil dynamic-depth-limit-p) (window-controller nil window-controller-p) (aspect-ratio nil aspect-ratio-p) (min-size nil min-size-p) (max-size nil max-size-p) (shows-resize-indicator nil shows-resize-indicator-p) (resize-increments nil resize-increments-p) (preserves-content-during-live-resize nil preserves-content-during-live-resize-p) (content-min-size nil content-min-size-p) (content-max-size nil content-max-size-p) (content-resize-increments nil content-resize-increments-p) (level nil level-p) (frame-using-name nil frame-using-name-p) (frame-autosave-name nil frame-autosave-name-p) (frame-from-string nil frame-from-string-p) (toolbar nil toolbar-p) (default-button-cell nil default-button-cell-p) (excluded-from-windows-menu nil excluded-from-windows-menu-p) (shows-toolbar-button nil shows-toolbar-button-p) (allows-tool-tips-when-application-is-inactive nil allows-tool-tips-when-application-is-inactive-p) (accepts-mouse-moved-events nil accepts-mouse-moved-events-p) (restorable nil restorable-p) (restoration-class nil restoration-class-p) (autodisplay nil autodisplay-p) (allows-concurrent-view-drawing nil allows-concurrent-view-drawing-p) (animation-behavior nil animation-behavior-p) (miniwindow-image nil miniwindow-image-p) (miniwindow-title nil miniwindow-title-p) (anchor-attribute-for-orientation nil anchor-attribute-for-orientation-p) &allow-other-keys) (declare (ignorable invalidate invalidate-p restorable restorable-p restoration-class restoration-class-p animation-behavior animation-behavior-p anchor-attribute-for-orientation anchor-attribute-for-orientation-p)) (when (next-method-p) (call-next-method)) (when title-p [self setTitle: (nsstring title)]) (when represented-filename-p [self setRepresentedFilename: (nsstring represented-filename)]) (when represented-url-p [self setRepresentedURL: (nsurl represented-url)]) (when movable-p [self setMovable: (nsbool movable)]) (when movable-by-window-background-p [self setMovableByWindowBackground: (nsbool movable-by-window-background)]) (when one-shot-p [self setOneShot: (nsbool one-shot)]) (when style-mask-p [self setStyleMask: (ns-window-style-mask style-mask)]) (when works-when-modal-p [self setWorksWhenModal: (nsbool works-when-modal)]) (when alpha-value-p [self setAlphaValue: (cgfloat alpha-value)]) (when background-color-p [self setBackgroundColor: background-color]) (when color-space-p [self setColorSpace: color-space]) (when content-view-p [self setContentView: content-view]) (when can-hide-p [self setCanHide: (nsbool can-hide)]) (when hides-on-deactivate-p [self setHidesOnDeactivate: (nsbool hides-on-deactivate)]) (when collection-behavior-p [self setCollectionBehavior: (ns-window-collection-behavior collection-behavior)]) (when opaque-p [self setOpaque: (nsbool opaque)]) (when has-shadow-p [self setHasShadow: (nsbool has-shadow)]) #+cocoa-10.10 (when invalidate-p [self setInvalidate: (nsbool invalidate)]) (when delegate-p [self setDelegate: delegate]) (when initial-first-responder-p [self setInitialFirstResponder: initial-first-responder]) (when prevents-application-termination-when-modal-p [self setPreventsApplicationTerminationWhenModal: (nsbool prevents-application-termination-when-modal)]) (when sharing-type-p [self setSharingType: (ns-window-sharing-type sharing-type)]) (when can-become-visible-without-login-p [self setCanBecomeVisibleWithoutLogin: (nsbool can-become-visible-without-login)]) (when backing-type-p [self setBackingType: backing-type]) (when preferred-backing-location-p [self setPreferredBackingLocation: preferred-backing-location]) (when depth-limit-p [self setDepthLimit: depth-limit]) (when dynamic-depth-limit-p [self setDynamicDepthLimit: dynamic-depth-limit]) (when window-controller-p [self setWindowController: window-controller]) (when aspect-ratio-p [self setAspectRatio: (cgfloat aspect-ratio)]) (when min-size-p [self setMinSize: (nssize min-size)]) (when max-size-p [self setMaxSize: (nssize max-size)]) (when shows-resize-indicator-p [self setShowsResizeIndicator: shows-resize-indicator]) (when resize-increments-p [self setResizeIncrements: resize-increments]) (when preserves-content-during-live-resize-p [self setPreservesContentDuringLiveResize: preserves-content-during-live-resize]) (when content-min-size-p [self setContentMinSize: (nssize content-min-size)]) (when content-max-size-p [self setContentMaxSize: (nssize content-max-size)]) (when content-resize-increments-p [self setContentResizeIncrements: content-resize-increments]) (when level-p [self setLevel: level]) (when frame-using-name-p [self setFrameUsingName: (nsstring frame-using-name)]) (when frame-autosave-name-p [self setFrameAutosaveName: (nsstring frame-autosave-name)]) (when frame-from-string-p [self setFrameFromString: (nsstring frame-from-string)]) (when toolbar-p [self setToolbar: toolbar]) (when default-button-cell-p [self setDefaultButtonCell: default-button-cell]) (when excluded-from-windows-menu-p [self setExcludedFromWindowsMenu: (nsbool excluded-from-windows-menu)]) (when shows-toolbar-button-p [self setShowsToolbarButton: (nsbool shows-toolbar-button)]) (when allows-tool-tips-when-application-is-inactive-p [self setAllowsToolTipsWhenApplicationIsInactive: (nsbool allows-tool-tips-when-application-is-inactive)]) (when accepts-mouse-moved-events-p [self setAcceptsMouseMovedEvents: (nsbool accepts-mouse-moved-events)]) #+cocoa-10.10 (when restorable-p [self setRestorable: (nsbool restorable)]) #+cocoa-10.10 (when restoration-class-p [self setRestorationClass: restoration-class]) (when autodisplay-p [self setAutodisplay: (nsbool autodisplay)]) (when allows-concurrent-view-drawing-p [self setAllowsConcurrentViewDrawing: (nsbool allows-concurrent-view-drawing)]) #+cocoa-10.10 (when animation-behavior-p [self setAnimationBehavior: animation-behavior]) (when miniwindow-image-p [self setMiniwindowImage: miniwindow-image]) (when miniwindow-title-p [self setMiniwindowTitle: (nsstring miniwindow-title)]) #+cocoa-10.10 (when anchor-attribute-for-orientation-p [self setAnchorAttributeForOrientation: anchor-attribute-for-orientation]) self) (defun make-view (frame &rest keys &key &allow-other-keys) (let ((view [[NSView alloc] initWithFrame:(nsrect frame)])) (when keys (apply (function configure) view keys)) view)) (defun make-image-view (frame &rest keys &key &allow-other-keys) (let ((view [[NSImageView alloc] initWithFrame:(nsrect frame)])) (when keys (apply (function configure) view keys)) view)) (defun make-text-field (frame &rest keys &key &allow-other-keys) (let ((view [[NSTextField alloc] initWithFrame:(nsrect frame)])) (when keys (apply (function configure) view keys)) view)) (defun make-button (frame &rest keys &key &allow-other-keys) (let ((view [[NSButton alloc] initWithFrame:(nsrect frame)])) (when keys (apply (function configure) view keys)) view)) (defun make-window (frame style-mask backing defer &rest keys &key &allow-other-keys) (let ((window [[NSWindow alloc] initWithContentRect: (nsrect frame) styleMask: (ns-window-style-mask style-mask) backing: (ns-backing-store-type backing) defer: (nsbool defer)])) (apply (function configure) window keys) window)) (defun ns-key-equivalent-modifier-mask (keywords) (loop :with m = 0 :for k :in keywords :do (setf m (logior m (ecase k ((:shift) #$NSShiftKeyMask) ((:option :alternate) #$NSAlternateKeyMask) ((:command) #$NSCommandKeyMask) ((:control) #$NSControlKeyMask)))) :finally (return m))) (defmacro item (title &optional selector key-equivalent) (cond ((null key-equivalent)) ((stringp key-equivalent)) ((listp key-equivalent) (assert (= 1 (count-if (function stringp) key-equivalent)) (key-equivalent) "Invalid key-equivalent: ~S~%Must be a string or a list containing a string and modifier keywords." key-equivalent) (assert (every (lambda (k) (or (stringp k) (member k '(:shift :option :alternate :command :control)))) key-equivalent) (key-equivalent) "Invalid key-equivalent: ~S~%Must be a string or a list containing a string and modifier keywords." key-equivalent)) (t (error "Invalid key-equivalent: ~S~%Must be a string or a list containing a string and modifier keywords." key-equivalent))) (let ((item `(let ((title (objcl:objc-string ,title)) (action ,(if (null selector) 'oclo:*null* `(oclo:@selector ,selector))) (key-equivalent ,(cond ((null key-equivalent) `(objcl:objc-string "")) ((stringp key-equivalent) `(objcl:objc-string ,key-equivalent)) ((listp key-equivalent) `(objcl:objc-string ,(find-if (function stringp) key-equivalent)))))) [[[NSMenuItem alloc] initWithTitle: title action: action keyEquivalent: key-equivalent] autorelease]))) (if (consp key-equivalent) `(let ((item ,item) (mask ,(ns-key-equivalent-modifier-mask (remove-if-not (function keywordp) key-equivalent)))) [item setKeyEquivalentModifierMask: mask] item) item))) (defmacro menu (title &body items) `(let* ((menu-title ,(if title `(objcl:objc-string ,title) `(objcl:objc-string ""))) (menu [[[NSMenu alloc] initWithTitle:menu-title] autorelease])) ,@(mapcar (lambda (item-form) `(let ((item ,(cond ((and (or (symbolp item-form) (stringp item-form)) (string= "-" item-form)) `[NSMenuItem separatorItem]) ((atom item-form) (error "Invalid item: ~S" item-form)) (t (ecase (first item-form) (menu `(let ((item (item ,(second item-form))) (menu ,item-form)) [item setSubmenu:menu] item)) (item item-form)))))) [menu addItem: item])) items) menu)) (defun dictionary (&rest key-values &key &allow-other-keys) (flet ((objclize (object) (typecase object (null (objcl:objc-string "NO")) ((member t) (objcl:objc-string "YES")) (string (objcl:objc-string object)) (symbol (objcl:objc-string (symbol-name object))) (t object)))) (loop :with dict = [NSMutableDictionary dictionaryWithCapacity: (truncate (length key-values) 2)] :for (key value) :on key-values :by (function cddr) :do (let ((key (objclize key)) (value (objclize value))) [dict setObject:value forKey:key]) :finally (return dict)))) ;;; THE END;;;
41,539
Common Lisp
.lisp
686
48.801749
162
0.614603
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
6fedeb019c89ace88819ca25477d7353a867194e3f33aec7e655ab179701a8fe
23,863
[ -1 ]
23,864
generate-cli.lisp
informatimago_hangman-cocoa-lisp/src/generate-cli.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: generate-cli.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This script generates the Hangman CLI with CCL. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2018-08-06 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2018 ;;;; ;;;; 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 "COMMON-LISP-USER") ;;; -------------------------------------------------------------------- ;;; Load quicklisp (format t "~%;;; Loading quicklisp.~%") (finish-output) (load #P"~/quicklisp/setup.lisp") (setf quicklisp-client:*quickload-verbose* t) ;;; -------------------------------------------------------------------- ;;; Load the application: (defparameter *program-name* "hangman") (defparameter *release-directory* #P"/usr/local/bin/") (defparameter *program-pathname* (merge-pathnames *program-name* *release-directory*)) (defparameter *version* "1.0.1") (defparameter *copyright* "Copyright 2018 Pascal Bourguignon License: AGPL3") (push (or *load-pathname* #P"./") asdf:*central-registry*) (ql:quickload :com.informatimago.common-lisp.cesarum) (ql:quickload :com.informatimago.hangman.tui) ;; (push (function com.informatimago.hangman.cocoa:play) ccl:*lisp-startup-functions*) ;;; -------------------------------------------------------------------- ;;; Save the application package. (format t "Generating ~A~%" *program-pathname*) (shadow 'copy-file) (defun copy-file (source destination) (ensure-directories-exist destination) (format t "Copying ~A~%" destination) (com.informatimago.common-lisp.cesarum.file:copy-file source destination :element-type '(unsigned-byte 8) :if-exists :supersede)) (copy-file #P"~/src/public/games/hangman-cocoa-lisp/src/hangman.states" #P"/usr/local/games/hangman/hangman.sexp") (defun save-hangman-program () ;; ccl::save-application ;; calls ccl::%save-application-interal ;; calls ccl::save-image #+ccl (ccl::save-application ; This doesn't return. *program-pathname* :toplevel-function (function com.informatimago.hangman.cocoa::play) :init-file nil :error-handler :quit :purify t :mode #o755 :prepend-kernel t)) (save-hangman-program) ;;;; THE END ;;;;
3,403
Common Lisp
.lisp
80
39.0375
88
0.590209
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
25ca9b678529a7419d334c798543801556797f5a2e1a362c8de8e97853a38434
23,864
[ -1 ]
23,865
cocoa.lisp
informatimago_hangman-cocoa-lisp/src/cocoa.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: cocoa.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This file loads Cocoa interfaces. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2014-05-02 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; GPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2014 - 2014 ;;;; ;;;; 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/>. ;;;;************************************************************************** #+(and ccl darwin) (eval-when (:compile-toplevel :load-toplevel :execute) (require :cocoa) (pushnew :cocoa *features*)) ;;;; THE END ;;;;
1,484
Common Lisp
.lisp
38
37.263158
78
0.57133
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
302ba7361f05e48f886e2bcb1923f104f6d9d05f943540b1596fee86faeef6c3
23,865
[ -1 ]
23,866
packages.lisp
informatimago_hangman-cocoa-lisp/src/packages.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: packages.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Defines the packages. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-06-17 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2013 - 2015 ;;;; ;;;; 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/>. ;;;;************************************************************************** (defpackage "COM.INFORMATIMAGO.HANGMAN.COCOA" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.FILE") (:export "MAIN") (:documentation " The hangman game with user interface implemented on Cocoa. ")) ;;;; THE END ;;;;
1,574
Common Lisp
.lisp
41
36.97561
83
0.595425
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
1136d2e1e47b2cc01cbab290edc5dabfa438af757d9f7267e42ac4c83383444b
23,866
[ -1 ]
23,867
hangman-tui.lisp
informatimago_hangman-cocoa-lisp/src/hangman-tui.lisp
(in-package "COM.INFORMATIMAGO.HANGMAN.COCOA") (eval-when (:compile-toplevel :load-toplevel :execute) (defun configure () (setf (logical-pathname-translations "RESOURCES") (list (list "RESOURCES:WORDS" #P"/usr/share/dict/words") (list "RESOURCES:STATES" #+DEBUGGING #P"~/src/public/games/hangman-cocoa-lisp/src/hangman.states" #-DEBUGGING #P"/usr/local/games/hangman/hangman.sexp") (list "RESOURCES:**;*.*" #P"/usr/local/games/hangman/**/*.*")))) (configure)) (defparameter *alphabet* "abcdefghijklmnopqrstuvwxyz") (defun satisfactory-word-p (word &optional (alphabet *alphabet*)) (and (< 2 (length word)) (every (lambda (letter) (find letter alphabet :test (function char-equal))) word))) (defun load-words () (remove-if-not (function satisfactory-word-p) (string-list-text-file-contents #P"RESOURCES:WORDS"))) (defun choose-random-word (words) (elt words (random (length words)))) (defun play () (configure) (let* ((words (load-words)) (states (sexp-file-contents #P"RESOURCES:STATES")) (max-error-count (1- (length states)))) (loop :for game := (make-hangman (choose-random-word words) max-error-count) :do (loop :do (format t "~A~%~A~%" (elt states (hangman-error-count game)) (hangman-found-word game)) (finish-output) (when (<= max-error-count (hangman-error-count game)) (format t "~%You're hung!~%") (finish-output) (loop-finish)) (format *query-io* "Choose a letter: ") (let ((letter (ignore-errors (aref (string-trim " " (read-line *query-io*)) 0)))) (when letter (let ((try (hangman-try-letter game letter))) (format t "~&~A~%" (case try (:good-guess "Yay!") (:already-tried "You already tried this letter!") (:bad-guess "Aiaiai!") (:wins "Pffuit!"))) (when (eq try :wins) (format t "~%~A~%You're saved!~%" (hangman-found-word game)) (finish-output) (loop-finish)))))) :while (y-or-n-p "Again? ")))) ;;;; THE END ;;;;
2,543
Common Lisp
.lisp
52
34.788462
97
0.505844
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
9516d886f46a534c9511224a84b2bce3e27a0a94842cdc45a302df2d228f9a1b
23,867
[ -1 ]
23,868
com.informatimago.hangman.tui.asd
informatimago_hangman-cocoa-lisp/src/com.informatimago.hangman.tui.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.hangman.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Hangman Cocoa Application ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-06-17 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2015 ;;;; ;;;; 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/>. ;;;;************************************************************************** (asdf:defsystem "com.informatimago.hangman.tui" :description "A Hangman game with a Text User Interface." :author "Pascal J. Bourguignon" :version "1.0.0" :license "AGPL3" :depends-on ("com.informatimago.common-lisp.cesarum") :components ( (:file "packages" :depends-on ()) (:file "hangman" :depends-on ("packages")) (:file "hangman-tui" :depends-on ("packages" "hangman"))) ;; :in-order-to ((asdf:test-op (asdf:test-op "com.informatimago.editor.test"))) ) ;;;; THE END ;;;;
1,925
Common Lisp
.asd
45
40.4
87
0.583156
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
2784e9692d89d27df9adb2493cc30afa68984817f0cc150026b96d8fa826ebdc
23,868
[ -1 ]
23,869
com.informatimago.hangman.asd
informatimago_hangman-cocoa-lisp/src/com.informatimago.hangman.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.hangman.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Hangman Cocoa Application ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-06-17 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2015 ;;;; ;;;; 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/>. ;;;;************************************************************************** (asdf:defsystem "com.informatimago.hangman" :description "A Hangman game Cocoa application." :author "Pascal J. Bourguignon" :version "1.0.0" :license "AGPL3" :depends-on (#+ccl "com.informatimago.objcl" "com.informatimago.common-lisp.cesarum") :components ( (:file "packages" :depends-on ()) #+ccl (:file "cocoa" :depends-on ()) #+ccl (:file "nsapi" :depends-on ("packages")) #+ccl (:file "hangman" :depends-on ("packages")) #+ccl (:file "hangman-controller" :depends-on ("packages" "cocoa" "nsapi"))) ;; :in-order-to ((asdf:test-op (asdf:test-op "com.informatimago.editor.test"))) ) ;;;; THE END ;;;;
2,108
Common Lisp
.asd
48
40.958333
93
0.57122
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
eebbde5c6179aca237a7a47e69b37eac7c2f2bb273c87d50529d94148470e30d
23,869
[ -1 ]
23,874
Makefile
informatimago_hangman-cocoa-lisp/src/Makefile
all:application application: ccl -norc < generate-application.lisp cli: ccl -norc < generate-cli.lisp
104
Common Lisp
.l
5
19.4
38
0.808081
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
0c30f725f1994b17c5fdd1f9fb603c128559b92c4680c7d17a4624dea728605d
23,874
[ -1 ]
23,875
utils.el
informatimago_hangman-cocoa-lisp/src/utils.el
(defun pjb-camel-to-lisp (name &optional capitalize) (mapconcat (let ((capitalize capitalize)) (lambda (token) (if capitalize (progn (capitalize token) (setf capitalize nil)) (downcase token)))) (jde-split-by-camel-notation (etypecase name (string name) (symbol (symbol-name name)))) "-")) (defun gen-key-arg (name) (let* ((name (etypecase name (string name) (symbol (symbol-name name)))) (parname (intern (pjb-camel-to-lisp name))) (parnamep (intern (format "%s-p" parname)))) `(,parname nil ,parnamep))) (defun gen-set-arg (name) (let* ((name (etypecase name (string name) (symbol (symbol-name name)))) (parname (intern (pjb-camel-to-lisp name))) (parnamep (intern (format "%s-p" parname)))) `(when ,parnamep [self ,(intern (format "set%c%s:" (capitalize (aref name 0)) (subseq name 1))) ,parname]))) (defun gen-key-args-and-set-msgs (names) (let* ((args (mapcar (function gen-key-arg) names)) (sets (mapcar (function gen-set-arg) names))) (insert "(&key\n") (dolist (arg args) (insert (format "%S\n" arg))) (insert "&allow-other-keys)\n") (insert "(when (next-method-p) (call-next-method))\n") (dolist (set sets) (insert (format "%S\n" set))) (insert "self")))
1,608
Common Lisp
.l
42
26.761905
58
0.506086
informatimago/hangman-cocoa-lisp
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
9f0762125a8a3335200e11a3d48bf87c7d203aaca5e3ef83e1e7379634b6668f
23,875
[ -1 ]
23,895
multithreading.lisp
equwal_lisp-multithreaded-internet/code/multithreading.lisp
(in-package :multi) ;;; Work on DEFGLOBAL global lexical variables for SBCL, it is requested! Let-pseudoglobals was on the right track, but it looks like the compiler must be modified. (defmacro collect (var-and-list &body body) (let ((collector (gensym))) `(let ((,collector nil)) (dolist (,(car var-and-list) ,(car (cdr var-and-list))) (setf ,collector (cons (progn ,@body) ,collector))) (reverse ,collector)))) (defun drakma-no-octets (url) (let ((result (drakma:http-request url))) (if (stringp result) result (drakma::octets-to-string result)))) (defun getpage (uri) "Uri should be 'http(s)://domainname.blah.toplevel/blah/blah/blah'" (drakma-no-octets uri)) (defun multiuri (&rest urilist) "Deprecated function, use `uri' instead!" (progn (warn "Multiuri is deprecated, use `uri' instead. Consider: multi::multiuri vs multi:uri. Isn't that a better name?") (apply #'uri urilist))) (defun uri (&rest urilist) (let ((lock (gensym)) (list (gensym)) (uri (gensym))) (setf lock (make-lock)) ;a gensym (setf list nil) (let ((thread-list (collect (var urilist) (setf uri var) (make-thread (lambda () (let ((result (getpage uri))) (with-lock-held (lock) (setf list (cons result list))))) :name uri)))) (dolist (thread thread-list list) (join-thread thread)))))
1,369
Common Lisp
.lisp
36
34
164
0.663916
equwal/lisp-multithreaded-internet
1
1
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
8e86865271458f29e32589726d7431cacd510523dea0ad34325373b73ed37abb
23,895
[ -1 ]
23,896
packages.lisp
equwal_lisp-multithreaded-internet/code/packages.lisp
(in-package :cl-user) (defpackage :multi (:use :cl) (:import-from :bordeaux-threads :make-thread :make-lock :join-thread) (:export :uri))
159
Common Lisp
.lisp
8
16.25
33
0.642384
equwal/lisp-multithreaded-internet
1
1
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
2de8a9cb81fba1962102375011754b4941b4e302e1ad148befab3180e04010bc
23,896
[ -1 ]
23,897
multi.asd
equwal_lisp-multithreaded-internet/multi.asd
(defsystem :multi :description "Multithreaded internet" :version "0.0.2" :author "Spenser Truex <[email protected]>" :license "GNU GPL v3" :depends-on (:drakma :uiop :bordeaux-threads) :serial t :components ((:file "packages") (:file "multithreading")))
285
Common Lisp
.asd
9
27.555556
48
0.681159
equwal/lisp-multithreaded-internet
1
1
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
7c3242f3bd85ed4e0c938e5c2133e72acd573bad6853e907d2d64ce98c745552
23,897
[ -1 ]
23,916
sudoku-solver.lisp
thecodingdoc_adventures-in-lisp/sudoku-solver.lisp
;;; A depth-first search sudoku solver ;;; ;;; Last updated: 20180127 ;;; ;;; Instructions: check out the example in sudoku-example.lisp ;;; and either load the puzzle in the example or ;;; input your own. ;;; Example: ;;; (load "sudoku-example.lisp") ;;; (load "sudoku-solver.lisp") ;;; (print-board *sudoku-example*) ;;; (print-board (solve-sudoku *sudoku-example*)) (defun print-board (b) (let ((n 0)) (loop for x in b do (cond ((or (= n 27) (= n 54)) (format t "~%---------+---------+---------~%")) ((= (mod n 9) 0) (format t "~%")) ((= (mod n 3) 0) (princ "|")) ((= (mod n 9) 0) (format t "~%"))) (setf n (1+ n)) (format t " ~S " x)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun board-has-duplicates-p (b) ;; T if there is a duplicate number in a row, column, or square (labels ((find-duplicates (x l) (cond ((null x) '()) ((and (numberp (car x)) (member (car x) l)) t) (t (find-duplicates (cdr x) (cons (car x) l))))) ;; check whether there are duplicates in a given row (check-row (n b) (find-duplicates (subseq b (* n 9) (+ (* n 9) 9)) '())) ;; check whether there are duplicates in a given column (check-column (n b) (let ((column (mapcar (lambda (x) (nth (+ n (* x 9)) b)) '(0 1 2 3 4 5 6 7 8)))) (find-duplicates column '()))) ;; check whether there are duplicates in a given square (check-square (n b) (let* ((beg (* 2 (truncate (/ n 3)))) (beg-1 (+ (* 3 n) (* beg 9))) (beg-2 (+ beg-1 9)) (beg-3 (+ beg-2 9)) (square (append (append (subseq b beg-1 (+ 3 beg-1)) (subseq b beg-2 (+ 3 beg-2))) (subseq b beg-3 (+ 3 beg-3))))) (find-duplicates square '())))) ;; check all rows, columns, and squares (loop for n from 0 to 8 do (print (check-row 8 b)) (cond ((or (check-row n b) (check-column n b) (check-square n b)) (return-from board-has-duplicates-p t)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun solve-sudoku (b) (with-open-stream (*standard-output* (make-broadcast-stream)) (labels ((depth-first (b n) (cond ((= n 81) (return-from solve-sudoku b)) ((eq (nth n b) '-) (loop for x from 1 to 9 do (let ((newb (append (subseq b 0 n) (cons x (subseq b (1+ n) 81))))) (cond ((not (board-has-duplicates-p newb)) (depth-first newb (1+ n))))))) (t (depth-first b (1+ n)))))) (depth-first b 0))))
2,732
Common Lisp
.lisp
78
29.423077
70
0.485682
thecodingdoc/adventures-in-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
bd2fd8874c103516a1980d5941be281f47d4adbfbbc4e41a91a2db13562f42bb
23,916
[ -1 ]
23,917
tic-tac-toe.lisp
thecodingdoc_adventures-in-lisp/tic-tac-toe.lisp
;;; A simple game of Tic-Tac-Toe, using the minimax algorithm to ;;; choose the optimal move by Dario Ghersi (github: thecodingdoc) ;;; ;;; Last updated: 20180120 ;;; ;;; Instructions: type '(play-against-ai)' to start. ;;; X is the human player, O is the AI ;; identify the playable empty cells on a board (defun find-empty-cells (b) (let ((empty)) (loop for x from 0 to 9 do (if (eq (nth x b) '-) (push x empty))) empty)) ;; print out the board (defun print-board (b) (format t "~% ~d ~d ~d 0 1 2~% ~d ~d ~d 3 4 5~% ~d ~d ~d 6 7 8~%~%" (nth 0 b) (nth 1 b) (nth 2 b) (nth 3 b) (nth 4 b) (nth 5 b) (nth 6 b) (nth 7 b) (nth 8 b))) ;; check whether 'player' has won the game (defun won? (b player) (flet ((winRow (row) (every #'identity (mapcar (lambda (x) (eq x player)) row)))) (or (winRow (subseq b 0 3)) ; top row (winRow (subseq b 3 6)) ; middle row (winRow (subseq b 6 9)) ; bottom row (winRow (list (nth 0 b) (nth 3 b) (nth 6 b))) ; left column (winRow (list (nth 1 b) (nth 4 b) (nth 7 b))) ; middle column (winRow (list (nth 2 b) (nth 5 b) (nth 8 b))) ; right column (winRow (list (nth 0 b) (nth 4 b) (nth 8 b))) ; left diag (winRow (list (nth 2 b) (nth 4 b) (nth 6 b)))))) ; right diag ;; check the current state (defun check-state (b) (cond ((won? b 'X) -10) ((won? b 'O) 10) ((null (find-empty-cells b)) 0) (t NIL))) ;; generate the current game tree (defun get-game-tree (b players) (let ((state (check-state b))) (cond ((null state) (mapcar (lambda (x) (get-game-tree (append (subseq b 0 x) (cons (car players) (subseq b (1+ x) 9))) (reverse players))) (find-empty-cells b))) (t state)))) ;; check whether the list has a nested list (defun has-list-p (l) (cond ((null l) '()) ((not (listp l)) '()) (t (or (listp (car l)) (has-list-p (cdr l)))))) ;; minimax algorithm (defun minimax (game-tree max-min-l) (declare (special max-min-l)) (cond ((null game-tree) '()) ((not (listp game-tree)) game-tree) ((not (has-list-p game-tree)) (apply (eval '(car max-min-l)) game-tree)) ((null (cdr game-tree)) (minimax (car game-tree) (reverse max-min-l))) (t (apply (eval '(car max-min-l)) (mapcar (lambda (x) (minimax x (reverse max-min-l))) game-tree))))) ;; evaluate move (defun evaluate-move (b x) (minimax (get-game-tree (append (subseq b 0 x) (cons 'O (subseq b (1+ x) 9))) '(X O)) '(min max))) ;; play human against AI (defun play-against-AI () (let ((n 1) (human-move '()) (ai-move '()) (allowed '()) (result '((0 ("Tie!")) (10 ("I win!")) (-10 ("You win!")))) (b (copy-list '(- - - - - - - - -))) (allowed (copy-list '(0 1 2 3 4 5 6 7 8)))) (flet ((check-move (b move) (if (and (member move allowed) (eq (nth move b) '-)) t '()))) (print-board b) (loop until (check-state b) do (loop until (check-move b human-move) do (princ "Your move: ") ; let the human play (setf human-move (read))) ;; show the current move (setf (nth human-move b) 'X) ;; remove the move from the allowed (setf allowed (remove human-move allowed)) (print-board b) ;; AI's first move (if (= n 1) (cond ((= human-move 4) (setf ai-move (nth (random 4) '(0 2 6 8)))) ((member human-move '(0 2 6 8)) (setf ai-move 4)) (t (setf ai-move 4))) ;; AI's moves after 2nd (use minimax) (loop for x in allowed do (cond ((>= (evaluate-move b x) 0) (setf ai-move x) (return))))) (setf (nth ai-move b) 'O) (setf allowed (remove ai-move allowed)) (print-board b) (setf n (1+ n)))) ; increment the current move ;; return the outcome (caadr (assoc (check-state b) result))))
3,843
Common Lisp
.lisp
102
32.872549
75
0.570774
thecodingdoc/adventures-in-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
f5ce3432cdf02f47ebcceb9509cbf6c04d4077444496bb8a4498c8054c0b07ec
23,917
[ -1 ]
23,918
sudoku-example.lisp
thecodingdoc_adventures-in-lisp/sudoku-example.lisp
(defparameter *sudoku-game '(- 7 5 - 1 3 2 - - 4 - - - - - 6 - 1 - - - 2 8 - - - - - - - - 7 2 5 - 3 - 5 7 - - - 9 4 - 8 - 3 9 4 - - - - - - - - 5 8 - - - 5 - 6 - - - - - 7 - - 1 6 3 - 4 2 -))
425
Common Lisp
.lisp
9
20.444444
48
0.129808
thecodingdoc/adventures-in-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
b6d35325acd2fb58c66f43330bb64321356d312e5ed19090fbb0dc37bdda12c4
23,918
[ -1 ]
23,937
rotation.lisp
xdvom03_3d-lisp/rotation.lisp
(defun sq (a) (* a a)) (defun transpose (mat) ;;Returns a transposed matrix ;;Requires a list of lists (apply #'mapcar #'list mat)) (defun mv-multiply (mat vec) ;;Matrix-vector multiplication for square matrices ;;Behaviour unspecified for non-matching sizes (reduce #'(lambda (a b) (mapcar #'+ a b)) (mapcar #'(lambda (num vec) (mapcar #'(lambda (element) (* num element)) vec)) vec mat))) (defun pythagoras (list) ;;Any number of dimensions (sqrt (reduce #'+ (mapcar #'sq list)))) (defun distance (point1 point2) ;;Any number of dimensions (pythagoras (mapcar #'- point1 point2))) (defun perpendicular-base (point line-point) ;;s for slope ;;foot of perpendicular line to [0; line-point] going through point (let* ((sx (first line-point)) (sy (second line-point)) (sz (third line-point)) (px (first point)) (py (second point)) (pz (third point)) (a (/ (+ (* sx px) (* sy py) (* sz pz)) (+ (sq sx) (sq sy) (sq sz))))) (list (* sx a) (* sy a) (* sz a)))) (defun vector-divide (v1 v2) ;;The two vectors must have the same direction, else behavior is unspecified ;;Returns a scalar (let ((x1 (first v1)) (x2 (first v2)) (y1 (second v1)) (y2 (second v2)) (z1 (third v1)) (z2 (third v2))) (if (or (zerop x1) (zerop x2)) (if (or (zerop y1) (zerop y2)) (if (or (zerop z1) (zerop z2)) 0 (/ z1 z2)) (/ y1 y2)) (/ x1 x2)))) (defun cross-product (v1 v2) ;;Returns the cross product of vector 1 and vector 2 ;;3D dependent (let ((x1 (first v1)) (x2 (first v2)) (y1 (second v1)) (y2 (second v2)) (z1 (third v1)) (z2 (third v2))) (list (- (* y1 z2) (* z1 y2)) (- (* z1 x2) (* x1 z2)) (- (* x1 y2) (* y1 x2))))) (defun turn (point line-point angle) ;;Clockwise when looking from the origin towards line-point ;;Returns destination of point when turned "angle" radians around the line given by the origin and "line-point" ;;C is the center of the circle on which the point rotates (let ((C (perpendicular-base point line-point))) (if (equal C point) point (let* ((CO (mapcar #'- (list 0 0 0) (if (= (distance C (list 0 0 0)) 0) line-point C))) (CP (mapcar #'- point C)) (up (cross-product CO CP)) (up-scaled (mapcar #'(lambda (a) (* a (/ (pythagoras CP) (pythagoras up)))) up)) (one-way (mapcar #'+ (if (equal C (list 0 0 0)) (list 0 0 0) C) (mapcar #'(lambda (a) (* a (sin angle))) up-scaled) (mapcar #'(lambda (a) (* a (cos angle))) CP))) (other-way (mapcar #'+ (if (equal C (list 0 0 0)) (list 0 0 0) C) (mapcar #'(lambda (a) (* a (sin (- angle)))) up-scaled) (mapcar #'(lambda (a) (* a (cos angle))) CP))) (middle (mapcar #'(lambda (a) (/ a 2)) (mapcar #'+ one-way other-way))) (first-signed (vector-divide (mapcar #'- middle one-way) (cross-product (mapcar #'- point C) line-point)))) (if (or (equal one-way other-way) (equal (> first-signed 0) (> (mod angle 6.283185307179) 3.14159265358979))) one-way other-way))))) (defun rotated-loc (point x-dir y-dir z-dir) (let* ((cam-dir (list x-dir y-dir z-dir)) (inverse-cam (transpose cam-dir))) (mv-multiply inverse-cam point))) (defun rotate-around-point (point center x-dir y-dir z-dir) (mapcar #'+ center (rotated-loc (mapcar #'- point center) x-dir y-dir z-dir)))
4,175
Common Lisp
.lisp
98
30.663265
122
0.48955
xdvom03/3d-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
09b608540e96a9442729677c1170e422c3e2f22fe17e4500ac9cc6b7ce73bb94
23,937
[ -1 ]
23,938
grav-3d.lisp
xdvom03_3d-lisp/grav-3d.lisp
(defun start-program () (defparameter *particles* nil) (defparameter *G* 100) (defparameter *step* 0.04) (add-particle '(0 0 500) '(0 0 0) 1000 1000) (add-particle '(100 0 500) '(0 30 0) 1 1) (add-particle '(0 200 500) '(0 0 10) 1 1)) (defun add-particle (position speed mass charge) (push (list position speed mass charge) *particles*)) (defun move-particles () (let ((new-particles nil)) (dolist (p *particles*) (let ((net-Fx 0) (net-Fy 0) (net-Fz 0)) (dolist (p2 *particles*) (if (not (equal p p2)) (let* ((dst (sqrt (reduce #'+ (mapcar #'(lambda (a) (* a a)) (mapcar #'- (first p) (first p2)))))) (force (/ (* (fourth p) (fourth p2) *G* -1) (* dst dst))) (dst-x (- (first (first p)) (first (first p2)))) (dst-y (- (second (first p)) (second (first p2)))) (dst-z (- (third (first p)) (third (first p2)))) (force-x (* force (/ dst-x dst))) (force-y (* force (/ dst-y dst))) (force-z (* force (/ dst-z dst)))) (incf net-Fx force-x) (incf net-Fy force-y) (incf net-Fz force-z)))) (push (list (mapcar #'(lambda (pos spd) (+ pos (* spd *step*))) (first p) (second p)) (mapcar #'(lambda (spd acc) (+ spd (* acc *step*))) (second p) (list (/ net-Fx (third p)) (/ net-Fy (third p)) (/ net-Fz (third p)))) (third p) (fourth p)) new-particles))) (setf *particles* (reverse new-particles)))) (defun create-objects (time) (move-particles) (setf *lines* nil) (dotimes (i (length *particles*)) (let* ((p-new (nth i *particles*)) (pos-new (first p-new))) (add-cube (mapcar #'+ pos-new (list 10 10 10)) 20 "#000"))))
2,308
Common Lisp
.lisp
52
27.923077
71
0.403906
xdvom03/3d-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
6a1f1327851cc7409cc7769433cf47c2a193f27a1f3ce7e48e436eb36bbdd9f2
23,938
[ -1 ]
23,939
3d.lisp
xdvom03_3d-lisp/3d.lisp
;;TBD: General cleanup, check what can be delegated to 3D-util.lisp ;;TBD: Adapt mouse control for Linux ;;TBD: Make init simpler to use - libraries :( ;;POSSIBLE BUG: Lots of rotation in one direction causes everything to behave oddly (investigate) (defun init (&optional (compile-p t)) ;;Constants (defparameter *triangles* nil) ;All triangles to be redrawn each tick (defparameter *lines* nil) ;All lines to be redrawn each tick (if compile-p (progn (setf *wish-pathname* "/usr/bin/wish") (in-package :ltk) (defparameter *view-center* (list 0 0 0)) ;Position of camera in space (defparameter *canvas-center* '(450 450)) ;Middle of the actual canvas (defparameter *screen-size* 900) ;Canvas dimensions (defparameter *fog* 0.5) ;Start of fog (division by zero protection) (defparameter *fov* 1) ;FOV in radians (defparameter *move-step* 30) ;How fast the camera moves (defparameter *rot-step* 0.02) ;How fast the camera rotates - radians per button press (defparameter *x-dir* (list 1 0 0)) (defparameter *y-dir* (list 0 1 0)) (defparameter *z-dir* (list 0 0 1)) (defparameter *norm* (/ *screen-size* (* 2 (tan (/ *fov* 2))))) ;Distance of projective plane ))) ;;;-----------------------------------------------------------------------------------------------------------------;;; ;;GLOBAL FUNCTIONS - CHANGING THE ENVIRONMENT (defun add-line (start end color) ;;Adds a line to the global list (push (list start end color) *lines*)) (defun add-cube (bottom-left-front size color) ;;Adds the lines forming a cube (with diagonals) to the global list (let ((lbf (mapcar #'+ bottom-left-front (list 0 0 0))) (lbb (mapcar #'+ bottom-left-front (list 0 0 size))) (ltf (mapcar #'+ bottom-left-front (list 0 size 0))) (ltb (mapcar #'+ bottom-left-front (list 0 size size))) (rbf (mapcar #'+ bottom-left-front (list size 0 0))) (rbb (mapcar #'+ bottom-left-front (list size 0 size))) (rtf (mapcar #'+ bottom-left-front (list size size 0))) (rtb (mapcar #'+ bottom-left-front (list size size size)))) (add-line lbf rbf color) (add-line ltf rtf color) (add-line ltf lbf color) (add-line rtf rbf color) (add-line lbb rbb color) (add-line ltb rtb color) (add-line ltb lbb color) (add-line rtb rbb color) (add-line lbf lbb color) (add-line ltf ltb color) (add-line rtf rtb color) (add-line rbf rbb color))) (defun add-triangle (p1 p2 p3 color outline-colors) ;;If color is nil, the outline isn't printed ;;Colors in order p1p2, p2p3, p3p1 (labels ((outline-part (point-a point-b color) (if color (add-line point-a point-b color)))) (push (list p1 p2 p3 color) *triangles*) (outline-part p1 p2 (first outline-colors)) (outline-part p2 p3 (second outline-colors)) (outline-part p3 p1 (third outline-colors))) (push (list p1 p2 p3 color) *triangles*) (if (first outline-colors) (add-line p1 p2 (first outline-colors)))) ;;;-----------------------------------------------------------------------------------------------------------------;;; ;;RENDERING UTILITIES & RENDER (defun render (c) (dolist (i *triangles*) (apply #'draw-triangle (append (list c) (rotate-coords (remove-last i)) (last i)))) (dolist (i *lines*) (apply #'draw-line (append (list c) (rotate-coords (remove-last i)) (last i))))) (defun rotate-coords (coords) ;;Accepts list of points and returns their rotated new locations (mapcar #'(lambda (point) (rotate-around-point point (mapcar #'- *view-center*) *x-dir* *y-dir* *z-dir*)) coords)) (defun draw-line (c p1 p2 color) ;;Draws a line segment given two points (if (not (and (in-fog-p p1 *fog*) (in-fog-p p2 *fog*))) (itemconfigure c (create-line c (real-locs p1 p2)) :fill color))) ;;;-----------------------------------------------------------------------------------------------------------------;;; ;;TRIANGLE FOG AND RENDERING (defun sort-by-fog (points) (let ((in nil) (out nil)) (dolist (point points (list in out)) (if (in-fog-p point *fog*) (push point in) (push point out))))) (defun draw-triangle (c p1 p2 p3 color) (let ((points-in-fog (count t (mapcar #'(lambda (a) (in-fog-p a *fog*)) (list p1 p2 p3))))) (case points-in-fog (3 nil) ;May be unnecessary (2 (let* ((sorted (sort-by-fog (list p1 p2 p3))) (in (first sorted)) (out (second sorted)) (fog-borders (list (fog-cutoff-loc (first in) (first out)) (fog-cutoff-loc (second in) (first out))))) (itemconfigure c (create-polygon c (append (apply #'real-loc (first out)) fog-borders)) :fill color))) (1 (let* ((sorted (sort-by-fog (list p1 p2 p3))) (in (first sorted)) (out (second sorted)) (fog-borders (list (fog-cutoff-loc (first in) (first out)) (fog-cutoff-loc (first in) (second out))))) (itemconfigure c (create-polygon c (append (apply #'real-loc (second out)) (apply #'real-loc (first out)) fog-borders)) :fill color))) (0 (itemconfigure c (create-polygon c (list (apply #'real-loc p1) (apply #'real-loc p2) (apply #'real-loc p3))) :fill color))))) ;;;-----------------------------------------------------------------------------------------------------------------;;; ;;RUNNING, UPDATING, CREATING WIDGETS (defun tick-compute (num widgets) ;;Creates new widgets and calls main functions (let ((c (make-instance 'canvas :width *screen-size* :height *screen-size*)) (b (make-instance 'button :text num))) ;;Binding forces a parameter I don't want, hence the identities (bind c "<Left>" #'(lambda (a) (identity a) (setf *view-center* (mapcar #'+ *view-center* (mapcar #'(lambda (a) (* a *move-step*)) *x-dir*))))) (bind c "<Right>" #'(lambda (a) (identity a) (setf *view-center* (mapcar #'- *view-center* (mapcar #'(lambda (a) (* a *move-step*)) *x-dir*))))) (bind c "<Shift_L>" #'(lambda (a) (identity a) (setf *view-center* (mapcar #'+ *view-center* (mapcar #'(lambda (a) (* a *move-step*)) *y-dir*))))) (bind c "<Control_L>" #'(lambda (a) (identity a) (setf *view-center* (mapcar #'- *view-center* (mapcar #'(lambda (a) (* a *move-step*)) *y-dir*))))) (bind c "<Down>" #'(lambda (a) (identity a) (setf *view-center* (mapcar #'+ *view-center* (mapcar #'(lambda (a) (* a *move-step*)) *z-dir*))))) (bind c "<Up>" #'(lambda (a) (identity a) (setf *view-center* (mapcar #'- *view-center* (mapcar #'(lambda (a) (* a *move-step*)) *z-dir*))))) (bind c "<w>" #'(lambda (a) (identity a) (rot-cam-x *rot-step*))) (bind c "<s>" #'(lambda (a) (identity a) (rot-cam-x (- *rot-step*)))) (bind c "<e>" #'(lambda (a) (identity a) (rot-cam-y *rot-step*))) (bind c "<d>" #'(lambda (a) (identity a) (rot-cam-y (- *rot-step*)))) (bind c "<r>" #'(lambda (a) (identity a) (rot-cam-z *rot-step*))) (bind c "<f>" #'(lambda (a) (identity a) (rot-cam-z (- *rot-step*)))) (focus c) (create-objects num) ;Must be provided, uses time as parameter (render c) (pack c) (pack b) (dolist (i widgets) (destroy i)) (list c b))) (defun tick (a widgets) ;;Main recursive function ;;Keeps updating (let ((new (tick-compute a widgets))) (after 0 #'(lambda () (tick (1+ a) new))))) (defun run () (init t) (load (first (print ext:*args*))) (start-program) ;Must be provided, serves as init for the program provided (with-ltk () (tick 0 nil)))
8,086
Common Lisp
.lisp
170
40.064706
145
0.551085
xdvom03/3d-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
eb3193aaf52f8ae37fececed49844a9c004c10d479e7b30ea80f58094c4b9991
23,939
[ -1 ]
23,940
3D-util.lisp
xdvom03_3d-lisp/3D-util.lisp
(defun canvas-loc (x y z) ;;Input 3D relative to camera ;;Output 2D coords on canvas (let ((abs-xy (mapcar #'(lambda (a) (/ a (/ z *norm*))) (list x y)))) (mapcar #'+ abs-xy *canvas-center*))) (defun real-locs (point1 point2) ;;Accounts for fog ;;Input two points in 3D space ;;Output 2D coords on canvas ;;Breaks if both points are in fog (if (in-fog-p point1 *fog*) (append (fog-cutoff-loc point1 point2) (apply #'real-loc point2)) (if (in-fog-p point2 *fog*) (append (apply #'real-loc point1) (fog-cutoff-loc point2 point1)) (append (apply #'real-loc point1) (apply #'real-loc point2))))) (defun real-loc (x y z) ;;Input 3D coords absolute (not adjusted for camera) ;;Output 2D canvas coords (let* ((rel-loc (mapcar #'+ (list x y z) *view-center*)) (rel-x (first rel-loc)) (rel-y (second rel-loc)) (rel-z (third rel-loc)) (abs-xy (mapcar #'(lambda (a) (/ a (/ rel-z *norm*))) (list rel-x rel-y)))) (mapcar #'+ abs-xy *canvas-center*))) (defun in-fog-p (point fog) ;;Returns T if the point is not in the visible range (< (+ (third point) (third *view-center*)) fog)) (defun fog-cutoff-loc (in out) ;;Returns the point where the line should be cut off by fog ;;Returns a point on the canvas ;;in means coords of the point in the fog, out the point outside the fog (let* ((rel-in (mapcar #'+ *view-center* in)) (rel-out (mapcar #'+ *view-center* out)) (outZ (- (third rel-out) *fog*)) (inZ (- *fog* (third rel-in))) (dx (- (first rel-in) (first rel-out))) (dy (- (second rel-in) (second rel-out)))) (canvas-loc (+ (first rel-out) (* dx (/ outZ (+ outZ inZ)))) (+ (second rel-out) (* dy (/ outZ (+ outZ inZ)))) *fog*))) (defun remove-nth (n lst) ;;returns list without nth element (indexing from 0) (append (subseq lst 0 n) (nthcdr (1+ n) lst))) (defun remove-last (lst) ;;returns list without last element (remove-nth (1- (length lst)) lst)) (defun rot-cam-x (angle) (let ((old-y *y-dir*) (old-z *z-dir*)) (setf *y-dir* (turn old-y *x-dir* angle)) (setf *z-dir* (turn old-z *x-dir* angle)))) (defun rot-cam-y (angle) (let ((old-x *x-dir*) (old-z *z-dir*)) (setf *x-dir* (turn old-x *y-dir* angle)) (setf *z-dir* (turn old-z *y-dir* angle)))) (defun rot-cam-z (angle) (let ((old-x *x-dir*) (old-y *y-dir*)) (setf *x-dir* (turn old-x *z-dir* angle)) (setf *y-dir* (turn old-y *z-dir* angle)))) (defun rot-cam-absolute (angle axis) ;;Rotates camera about a line not relative to current rotation (let ((old-x *x-dir*) (old-y *y-dir*) (old-z *z-dir*)) (setf *x-dir* (turn old-x axis angle)) (setf *y-dir* (turn old-y axis angle)) (setf *z-dir* (turn old-z axis angle))))
2,994
Common Lisp
.lisp
71
35.140845
85
0.567717
xdvom03/3d-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
1f7401cd44cba18dcd3175a9daab436df5094ce21e89f8b31ca2993379981f74
23,940
[ -1 ]
23,960
package.lisp
K1D77A_hyperborean-markdown/src/package.lisp
;;;; package.lisp (defpackage #:hyperborean-markdown (:use #:cl) (:nicknames #:hm) (:export #:parse-to-md #:with-markdown #:with-markdown-to-string #:with-markdown-to-file #:def-syntax #:def-special #:def-inline-syntax #:initiate-environment #:initiate-spacing ))
373
Common Lisp
.lisp
14
17.857143
36
0.532394
K1D77A/hyperborean-markdown
1
1
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
dacb2c6468f270d9a2a57fc2afbc2384226b3ee38723990801f7f63c0899a2f7
23,960
[ -1 ]
23,961
readme-gen.lisp
K1D77A_hyperborean-markdown/src/readme-gen.lisp
(with-markdown-to-file ("./README.md" :if-exists :supersede) `((:h1 "Hyperborean Markdown") "This is a library that has taken a stab at creating a *Lisp* -> *MD* library. So that you can translate Lisp objects into Markdown, perhaps you wish to create MD templates based off of some lisp objects you have, idk its up to you." (:h2 "Current Problems") (:unordered-list "Currently references aren't implemented." "There is a bug where extra - get added when you start trying to make fancy nested unordered lists. If you simply nest with simple strings there are no problems") (:h2 "Usage") (:h3 "There are 4 main methods to invoke the parser:") (:code-block :lang "lisp" "(with-markdown STREAM BODY)") (:code-block :lang "lisp" "(with-markdown-to-string BODY)") (:code-block :lang "lisp" "(with-markdown-to-file (PATHNAME KEYS) BODY)") (:code-block :lang "lisp" "(parse-to-md STREAM LIST)") "" (:h2 "List of keys") (:ordered-list "h1" "h2" "h3" "h4" "h5" "h6" "br" "bold" "italic" "bold-and-italic" "blockquote" "blockquote1" "ordered-list" "unordered-list" "code-block" "image" "link" "hrule" "linked-image") "" "Keys are CL Keywords." (:h3 "Key options") "A few keys have special options:" (:ordered-list "**image**" (:ordered-list "href") "**link**" (:ordered-list "href" "title") "**linked-image**" (:ordered-list "path" "description" "href") "**code-block**" (:ordered-list "lang")) "" "To provide arguments to these keys you have to use keyword arguments like so" (:code-block :lang "lisp" " (:linked-image :path '~/oof.jpg' :description 'an oof image' :href 'imgur.com/oof' 'an oof image')") (:h2 "Extra") "If you put \"\" at your top level a newline will be added" "" (:h2 "The code used to generate this README.md") "" "" (:code-block :lang "lisp" "(with-markdown-to-file (\"./README.md\" :if-exists :supersede) `((:h1 \"Hyperborean Markdown\") \"This is a library that has taken a stab at creating a *Lisp* -> *MD* library. So that you can translate Lisp objects into Markdown, perhaps you wish to create MD templates based off of some lisp objects you have, idk its up to you.\" (:h2 \"Current Problems\") (:unordered-list \"Currently references aren't implemented.\" \"There is a bug where extra - get added when you start trying to make fancy nested unordered lists. If you simply nest with simple strings there are no problems\") (:h2 \"Usage\") (:h3 \"There are 4 main methods to invoke the parser:\") (:code-block :lang \"lisp\" \"(with-markdown STREAM BODY)\") (:code-block :lang \"lisp\" \"(with-markdown-to-string BODY)\") (:code-block :lang \"lisp\" \"(with-markdown-to-file (PATHNAME KEYS) BODY)\") (:code-block :lang \"lisp\" \"(parse-to-md STREAM LIST)\") \"\" (:h2 \"List of keys\") (:ordered-list \"h1\" \"h2\" \"h3\" \"h4\" \"h5\" \"h6\" \"br\" \"bold\" \"italic\" \"bold-and-italic\" \"blockquote\" \"blockquote1\" \"ordered-list\" \"unordered-list\" \"code-block\" \"image\" \"link\" \"hrule\" \"linked-image\") \"\" \"Keys are CL Keywords.\" (:h3 \"Key options\") \"A few keys have special options:\" (:ordered-list \"**image**\" (:ordered-list \"href\") \"**link**\" (:ordered-list \"href\" \"title\") \"**linked-image**\" (:ordered-list \"path\" \"description\" \"href\") \"**code-block**\" (:ordered-list \"lang\")) \"\" \"To provide arguments to these keys you have to use keyword arguments like so\" (:code-block :lang \"lisp\" \" (:linked-image :path '~/oof.jpg' :description 'an oof image' :href 'imgur.com/oof' 'an oof image')\") \"If you put \"\" at your top level a newline will be added\" \"\))\" ")))
4,162
Common Lisp
.lisp
92
37.5
242
0.579115
K1D77A/hyperborean-markdown
1
1
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
951ffb05f99362f787acbbee1e8f20b2c4fe156c85870423f6645cede5398f06
23,961
[ -1 ]
23,962
hyperborean-markdown.lisp
K1D77A_hyperborean-markdown/src/hyperborean-markdown.lisp
;;;; hyperborean-markdown.lisp (in-package #:hyperborean-markdown) (defparameter *default-spacing* 1 "The default spacing applies after executing a syntax function.") (defparameter *default-tab-size* 4 "Inserted when adding spacing for lists") (defparameter *syntax* () "A plist of plists associating information regarding how to parse lisp to md.") (defparameter *specials* (make-hash-table :test #'equal) "A hash table of lambdas associated with strings, these strings are special strings that have their own execution rules.") (defparameter *inline-syntax* () "A plist of plists associating before and after functions used to perform calls that wrap around other transformation. The plists look like '(:syntax <key> :before <before> :after <after>") (define-condition hyper-condition () ((message :accessor message :initarg :message :type string :documentation "A message sent with each condition")) (:documentation "the toplevel conditions for all of hyperborean-markdowns conditions")) (define-condition key-missing-fun (hyper-condition) ((key :accessor key :initarg :key :type keyword :documentation "The key used for lookup.") (where :accessor where :initarg :where :type string :documentation "The name of the location where lookup happened")) (:documentation "Signalled when a lookup was performed for a key that does't exist.") (:report (lambda (obj stream) (format stream "Key: ~A. Where: ~A~%Message: ~A" (key obj) (where obj) (message obj))))) (define-condition unknown-option (hyper-condition) ((key :accessor key :initarg :key :type keyword :documentation "A keyword that is supposed to be an option, but isn't.") (syntax :accessor syntax :initarg :syntax :type keyword :documentation "The syntax you tried to find key for.") (options :accessor options :initarg :options :type list :documentation "The list of valid options.")) (:documentation "This is signalled when the user has provided an option that doesnt exist for that markdown") (:report (lambda (obj stream) (format stream "That option doesn't exist for that syntax.~%Syntax: ~A. Key: ~A. ~ Valid options: ~A.~%Message: ~A." (syntax obj) (key obj) (options obj) (message obj))))) (defun new-inline-syntax (key before-fun after-fun) "Associate a before and after function with the KEY within *inline-syntax*. If KEY is not first found within *syntax* then signals 'key-missing-fun." (if (getf *syntax* key) (setf (getf *inline-syntax* key) (list :syntax key :before before-fun :after after-fun)) (error 'key-missing-fun :where "*syntax*" :key key :message "Trying to create a new inline-syntax for a key that doesn't exist."))) (defun get-inline (key) (let ((inline (getf *inline-syntax* key))) (if inline inline (getf *inline-syntax* :%default)))) (defmacro def-inline-syntax ((key arg-name environment-name) before-fun after-fun) `(new-inline-syntax ,key (lambda (stream ,arg-name ,environment-name) (declare (ignorable stream ,arg-name ,environment-name)) (locally ,before-fun)) (lambda (stream ,arg-name ,environment-name) (declare (ignorable stream ,arg-name ,environment-name)) (locally ,after-fun)))) (defun new-special (string fun) "Associated FUN with STRING in the hash-table *specials*" (setf (gethash string *specials*) fun)) (defmacro def-special ((special environment-name) &body body) "Defines a new special string SPECIAL, these strings are used to invoke special behaviour when they are seen within the list used to parse MD. The most basic example is the \"\" special which is used to insert a carriage return into the stream." `(new-special ,special (lambda (stream ,environment-name) (declare (ignorable stream ,environment-name)) (locally ,@body)))) (defun new-syntax (key options fun) "Associate the list (list :fun FUN :options OPTIONS) with KEY within the plist *syntax*." (setf (getf *syntax* key) (list :fun fun :options options))) (defmacro def-syntax ((key arg-name environment-name &optional (options ())) &body body) "Define a new 'syntax' this is an association between a KEY something like :h1 and the function that is going to be executed when that key is found while iterating through the list data structure used for converting lists to markdown. OPTIONS is a list of keywords that is used to provide special data to the parser, some markdown options like images require a url, so the key :href would be provided within the OPTIONS list so that special processing can take place. When OPTIONS is non nil then the keys within OPTIONS are automatically destructured and can be referenced as arguments within the body of def-syntax." `(new-syntax ,key ',options (lambda (stream ,arg-name ,environment-name) (declare (ignorable stream ,arg-name ,environment-name)) ,(if options `(destructuring-bind (&key ,@(mapcar (lambda (key) (intern (string-upcase key))) options) &allow-other-keys) (getf ,environment-name :options) (locally ,@body)) `(locally ,@body))))) (defun execute (key stream list-or-string environment) "Uses KEY to find a plist within *syntax*. If the plist is found then calls the function associated with STREAM LIST-OR-STRING and ENVIRONMENT as arguments. If no plist is found then signals the condition 'key-missing-fun." (let ((fun (getf (getf *syntax* key) :fun))) (if fun (funcall fun stream list-or-string environment) (error 'key-missing-fun :where "syntax" :key key :message "couldn't find key. Perhaps your List is invalid.")))) (defun add-spacing (stream env) (let ((current-depth (getf env :current-depth))) (unless (<= current-depth 1) (format stream "~A" (make-string *default-tab-size* :initial-element #\Space))))) (defun increase-depth (env) "Increment :current-depth by 1." (incf (getf env :current-depth))) (defun decrease-depth (env) "Unless :current-depth is already 0, remove 1." (unless (zerop (getf env :current-depth)) (decf (getf env :current-depth)))) (defmacro with-increased-depth (env &body body) "Evaluates BODY after incrementing :current-depth by 1, after evaluation decrements :current-depth by ." `(unwind-protect (progn (increase-depth ,env) (locally ,@body)) (decrease-depth ,env))) ;;;a list of all the syntax rules that I'm aware of so far. (def-syntax (:%default string env) (format stream "~A" string)) (def-syntax (:h1 string env) (format stream "# ~A" string)) (def-syntax (:h2 string env) (format stream "## ~A" string)) (def-syntax (:h3 string env) (format stream "### ~A" string)) (def-syntax (:h4 string env) (format stream "#### ~A" string)) (def-syntax (:h5 string env) (format stream "##### ~A" string)) (def-syntax (:h6 string env) (format stream "###### ~A" string)) (def-syntax (:br string env) (format stream " ~A" string)) (def-syntax (:bold string env) (format stream "**~A**" string)) (def-syntax (:italic string env) (format stream "*~A*" string)) (def-syntax (:bold-and-italic string env) (format stream "***~A***" string)) (def-syntax (:blockquote string env) (format stream ">~A" string)) (def-syntax (:blockquote1 string env) (format stream ">>~A" string)) (def-syntax (:ordered-list string env) ;; (setf (getf env :disable-before-p) t) (let ((item-n (getf env :item-n))) (format stream "~D. ~A" item-n string) (incf (getf env :item-n)))) (def-syntax (:unordered-list string env) ;;(setf (getf env :disable-before-p) t) (format stream "- ~A" string)) (def-syntax (:code-block string env (:lang)) (if lang (format stream "```~A~% ~A~%```" lang string) (format stream "```~%~A~%```" string))) (def-syntax (:image string env (:href)) (format stream "![~A](~A)" string href)) (def-syntax (:link string env (:href :title)) (if title (format stream "[~A](~A \"~A\")" string href title) (format stream "[~A](~A)" string href))) (def-syntax (:hrule string env) (format stream "***")) (def-syntax (:linked-image string env (:path :description :href)) (print path *debug-io*) (format stream "[![~A](~A \"~A\")](~A)" string path description href)) (def-syntax (:%special string env ()) (funcall (gethash string *specials*) stream env)) (def-special ("" env) (format stream "~%")) (def-special ("**" env) (format stream "**")) (def-inline-syntax (:bold form env) (format stream "**") (format stream "**")) (def-inline-syntax (:italic form env) (format stream "*") (format stream "*")) (def-inline-syntax (:ordered-list form env) (add-spacing stream env) (format stream "")) (def-inline-syntax (:unordered-list form env) (progn (add-spacing stream env)) ;;(format stream "- ")) (format stream "")) (def-inline-syntax (:bold-and-italic form env) (format stream "***") (format stream "***")) (def-inline-syntax (:blockquote form env) (format stream "> ") (format stream "")) (def-inline-syntax (:blockquote1 form env) (format stream ">> ") (format stream "")) (def-inline-syntax (:code-block form env) (format stream "``` ") (format stream " ```")) (def-inline-syntax (:%default form env) nil (format stream "~A" (make-string *default-spacing* :initial-element #\Newline))) ;;;last one we need to do is references but this requires special processing rules ;;;as references have to be collected and added onto the end. (defun contains-options-p (list) "Checks if the key at (first LIST) has options associated with it, and if it does then searches for those options within LIST. If it has no options returns nil." (destructuring-bind (&key fun options) (getf *syntax* (first list)) (declare (ignore fun)) (when options (some (lambda (ele) (some (lambda (option) (eql ele option)) options)) list)))) (defun extract-options (list) "Attempts to extract the options keys and their values from LIST. For example a list like (:link :href \"https://oof.com\" \"ooga\") should eval to a list like: '(:href \"https://oof.com\")." (let ((keys (getf (getf *syntax* (first list)) :options))) (loop :for (key val) :on (rest list) :by #'cddr :if (and (keywordp key) (find key keys)) :appending (list key val) :into options :else :if (stringp key) :collect key :into remainder :else :do (error 'unknown-option :syntax (first list) :key key :options keys :message "Bad key") :finally (return (values options remainder))))) (defmacro with-resetting-keys (environment keys &body body) "Stores the values associated with KEYS found in the plist ENVIRONMENT, stores them before the evaluation of BODY then resets the keys back to their previous values." (let* ((vals-keys (loop :for key :in keys :collect (list (gensym) key))) (genned-setf (loop :for (sym key) :in vals-keys :collect `(setf (getf ,environment ,(intern (string key) :keyword)) ,sym)))) `(destructuring-bind (&key ,@keys &allow-other-keys) ,environment (let (,@vals-keys) (unwind-protect (locally ,@body)) ,@genned-setf)))) (defgeneric initiate-environment (list) (:documentation "This method is used to generate the initial environment plist that is passed to every syntax function within the parser. If you wish to modify the environment for your own syntax or specials, or you want to modify some of the default values then you can just create your own version of this that is specialized on a list, perform the modifications with (setf (getf ...)..) and finally return the list.")) (defmethod initiate-environment :around ((list list)) "Sets up the default environment with the keys :current-depth :options :item-n :current-syntax and :references." (let ((environment (list :current-depth 0 :options () :current-inline (list (get-inline :%default)) :item-n 1 :add-spacing-p t :add-newline-p t :current-syntax (getf *syntax* :%default) :references ()))) (call-next-method environment))) (defmethod initiate-environment ((list list)) list) (defgeneric initiate-spacing (list) (:documentation "Sets up the association between a key and the spacing applied after its execution. The default values are (:h1 1) and (:blockquote 1). If you wish to customize this then you can change the defaults by specializing your own version with ((list list)) and making sure you return the list.")) (defmethod initiate-spacing :around ((list list)) (let ((spacing ())) (call-next-method spacing))) (defmethod initiate-spacing ((list list)) (setf (getf list :h1) 1 (getf list :blockquote) 1) list) (defmacro destructuring-environment (environment &body body) "Destructure the keys that you can see in the plist generated by initiate-environment. Each of the keys becomes a variable you can reference within BODY." `(destructuring-bind (&key current-depth options current-inline item-n add-spacing-p add-newline-p current-syntax references &allow-other-keys) ,environment (declare (ignorable current-depth options current-inline item-n add-spacing-p add-newline-p current-syntax references)) (locally ,@body))) (defun parse-to-md (stream list) "Parse LIST and generate md in STREAM" (let ((environment (initiate-environment ())) (*spacing* (initiate-spacing ()))) (declare (special *spacing*)) (%process-list stream list environment))) (defun %process-list (stream list environment) "Steps through the markdown LIST and executes calls to generate the appropriate md in a recursive fashion. ENVIRONMENT is normally a list generated with initiate-environment." (destructuring-environment environment (let ((item (first list)) (remainder (rest list))) (typecase item (null (pop (getf environment :current-inline)) nil) (string (%execute-inlines stream item environment (or (rest current-inline) current-inline)) (%process-list stream remainder environment)) (list (if (or (eql (first item) :ordered-list) (eql (first item) :unordered-list)) (with-resetting-keys environment (item-n current-depth) (when (eql (first item) :ordered-list) (setf (getf environment :item-n) 1));reset when inside a new ordered-list (increase-depth environment) (%process-list stream item environment)) (progn (%process-list stream item environment))) (%process-list stream remainder environment)) (keyword (with-resetting-keys environment (current-syntax options item-n) (push (get-inline item) (getf environment :current-inline)) (let ((syn (getf *syntax* item))) (unless syn (error 'key-missing-fun :where "syntax" :key item :message "No function found for that key")) (setf (getf environment :current-syntax) syn)) (if (contains-options-p list) (multiple-value-bind (options remainder) (extract-options list) (setf (getf environment :options) options) (%process-list stream remainder environment)) (%process-list stream remainder environment)))))))) (defun clean-inlines (list) list) ;; (loop :for inline :in list ;; :unless (or (eql (second inline) :ordered-list) ;; (eql (second inline) :unordered-list)) ;; :collect inline)) (defun %execute-inlines (stream item environment inlines) "Having collected the inline calls into a list, executes the before and after INLINE functions around the call to item." (destructuring-bind (&key fun options &allow-other-keys) (getf environment :current-syntax) (declare (ignorable options)) (mapc (lambda (inline) (destructuring-bind (&key before &allow-other-keys) inline (unless (getf environment :disable-before-p) (funcall before stream item environment)))) (reverse (clean-inlines inlines))) (funcall fun stream item environment) (mapc (lambda (inline) (destructuring-bind (&key after &allow-other-keys) inline (unless (getf environment :disable-after-p) (funcall after stream item environment)))) (clean-inlines inlines)))) (defmacro with-markdown ((stream) &body body) "Process BODY and output it to STREAM." `(parse-to-md ,stream ,@body)) (defmacro with-markdown-to-string (&body body) "Process BODY and output it to a string." (alexandria:with-gensyms (stream) `(with-output-to-string (,stream) (parse-to-md ,stream ,@body)))) (defmacro with-markdown-to-file ((pathname &rest keys &key &allow-other-keys) &body body) "Process BODY and output it to PATHNAME. use KEYS to pass keyword args to alexandria:write-string-into-file" `(alexandria:write-string-into-file (with-markdown-to-string ,@body) ,pathname ,@keys))
18,891
Common Lisp
.lisp
410
37.463415
93
0.62721
K1D77A/hyperborean-markdown
1
1
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
9de17d7c522f296a18e111483c25d090431bc43fe074c4ba0029991a45157496
23,962
[ -1 ]
23,963
hyperborean-markdown.asd
K1D77A_hyperborean-markdown/hyperborean-markdown.asd
;;;; hyperborean-markdown.asd (asdf:defsystem #:hyperborean-markdown :description "A simple lisp -> markdown converter." :author "K1D77A" :license "GPL3" :version "0.0.1" :serial t :depends-on (#:alexandria) :components ((:module "src" :serial t :components ((:file "package") (:file "hyperborean-markdown")))))
393
Common Lisp
.asd
13
23.076923
53
0.585752
K1D77A/hyperborean-markdown
1
1
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
a557f9fcf72ca241a37533e1dbcb4dca585baa2e4963438b1f7fd3c61ca77f21
23,963
[ -1 ]
23,982
tests.lisp
genenetwork_cl-gn/tests.lisp
(require :asdf) ;; Load genenetwork.asd from the current directory. (asdf:load-asd (merge-pathnames #P"genenetwork.asd" (directory-namestring *load-truename*))) (asdf:load-system :genodb/tests)
228
Common Lisp
.lisp
5
37.8
72
0.669683
genenetwork/cl-gn
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
027fd4459066b5ea51ec53599df2c731e3832050a140a24fbfd92bce82f4ca9a
23,982
[ -1 ]
23,983
run.lisp
genenetwork_cl-gn/run.lisp
(require :asdf) ;; Load genenetwork.asd from the current directory. (asdf:load-asd (merge-pathnames #P"genenetwork.asd" (directory-namestring *load-truename*))) ;; Load the genenetwork system and start the web server (asdf:load-system :genenetwork) (asdf:load-system :genodb) (genenetwork:main) ;; Start the REPL server (asdf:load-system :slynk) (slynk:create-server :port 4005)
414
Common Lisp
.lisp
11
33.454545
72
0.7225
genenetwork/cl-gn
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
84de9fda09e822350999c1aa9b9ba7cc9d52b8fdfc93b5b005ba4b5edf566eb1
23,983
[ -1 ]
23,984
genenetwork.lisp
genenetwork_cl-gn/genenetwork.lisp
(defpackage :genenetwork (:use :common-lisp :cl-who :hunchentoot :parenscript) (:import-from :legit :current-commit) (:import-from :cl-json :encode-json-to-string) (:export :main)) (in-package :genenetwork) (hunchentoot:define-easy-handler (version :uri "/api/version") () (setf (hunchentoot:content-type*) "application/json; charset=utf-8") (encode-json-to-string `((version . ,(asdf:system-version (asdf:find-system :genenetwork))) (commit . ,(let ((repository (make-instance 'legit:repository :location (sb-posix:getcwd)))) (current-commit repository)))))) (hunchentoot:define-easy-handler (home :uri "/") () (setf (hunchentoot:content-type*) "text/plain; charset=utf-8") "Hello World!") ;; parenscript puts strings within single quotes. So, use double quote ;; for HTML attributes. (setq cl-who:*attribute-quote-char* #\") (hunchentoot:define-easy-handler (home-ps :uri "/ps") () (with-html-output-to-string (str) (:html (:head (:title "Parenscript hello world")) (:body (:h2 "Parenscript hello world") "Please click the link: " (:a :href "#" :onclick (ps (alert "Hello World!")) "Hello World!"))))) (defvar *acceptor* (make-instance 'hunchentoot:easy-acceptor :address "localhost" :port 8080)) (defun main () (hunchentoot:start *acceptor*))
1,454
Common Lisp
.lisp
34
35.647059
79
0.629158
genenetwork/cl-gn
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
ef2d8fc23214ae9adc3ba5b30c214bfa5e29c414027232621765b098dd072426
23,984
[ -1 ]
23,985
genodb.lisp
genenetwork_cl-gn/genodb.lisp
(defpackage :genodb (:use :common-lisp) (:import-from :alexandria :iota :once-only :with-gensyms) (:import-from :ironclad :with-octet-input-stream :with-octet-output-stream) (:import-from :listopia :all :any :split-at) (:import-from :str :concat :contains? :join :s-rest :split :starts-with? :trim-right :words) (:import-from :trivia :lambda-match :match) (:import-from :trivial-utf-8 :string-to-utf-8-bytes) (:export :genotype-db-current-matrix :genotype-db-matrix :genotype-db-matrix-ref :genotype-db-matrix-row-ref :genotype-db-matrix-column-ref :main :read-geno-file :with-genotype-db)) (in-package :genodb) ;;; ;;; Utilities ;;; (defun matrix-row (matrix n) "Return the Nth row of MATRIX." (let ((ncols (array-dimension matrix 1))) (make-array ncols :element-type (array-element-type matrix) :displaced-to matrix :displaced-index-offset (* n ncols)))) (defun matrix-column (matrix n) "Return the Nth column of MATRIX." (let ((column (make-array (array-dimension matrix 0)))) (dotimes (i (length column)) (setf (aref column i) (aref matrix i n))) column)) (defmacro save-excursion (stream &body body) "Evaluate BODY, and restore STREAM to the position it was in before evaluation of BODY." (with-gensyms (position) (once-only (stream) `(let* ((,position (file-position ,stream))) (unwind-protect (progn ,@body) (file-position ,stream ,position)))))) (defun unget-line (line stream) "Unget LINE to STREAM." (file-position stream (- (file-position stream) (1+ (length line))))) (defun for-each-indexed (function list &optional (start 0)) "Apply FUNCTION successively on every element of LIST. FUNCTION is invoked as (FUNCTION INDEX ELEMENT) where ELEMENT is an element of LIST and INDEX is its index. START is the index to use for the first element." (match list ((list* head tail) (funcall function start head) (for-each-indexed function tail (1+ start))))) (defun assoc-ref (alist key &key (test #'equalp)) "Return the value associated with KEY in ALIST. KEYS are compared using TEST." (match (assoc key alist :test test) ((cons _ value) value))) (defun count-lines (stream) "Return the number of lines in STREAM starting from the current position." (labels ((count-lines-loop (result) (if (read-line stream nil) (count-lines-loop (1+ result)) result))) (save-excursion stream (count-lines-loop 0)))) (defun repeat (thunk n) "Run THUNK N times and return the result as a list." (labels ((repeat-tail (thunk n result) (if (zerop n) result (repeat-tail thunk (1- n) (cons (funcall thunk) result))))) (reverse (repeat-tail thunk n (list))))) (defun repeat-indexed (function n) "Run FUNCTION N times and return the result as a list. FUNCTION is invoked as (FUNCTION INDEX) for INDEX = 0, 1, 2, ..., n-1." (labels ((repeat-tail (function i n result) (if (= i n) result (repeat-tail function (1+ i) n (cons (funcall function i) result))))) (reverse (repeat-tail function 0 n (list))))) (defun find-index (function n) "Return the index between 0 and n-1 (both inclusive) for which FUNCTION returns non-nil. If no such index exists, return nil. FUNCTION is invoked as (FUNCTION INDEX). The order of invocation of FUNCTION is unspecified." (unless (zerop n) (if (funcall function (1- n)) (1- n) (find-index function (1- n))))) ;;; ;;; Genotype database and matrix ;;; (defstruct genotype-matrix matrix metadata) (defstruct genotype-db-matrix db hash nrows ncols row-pointers column-pointers array transpose) (defmacro with-genotype-db ((db database-directory &key write) &body body) (with-gensyms (env) (once-only (database-directory write) `(lmdb:with-env (,env ,database-directory :if-does-not-exist :create :map-size (* 100 1024 1024)) (let ((,db (lmdb:get-db nil :env ,env))) (lmdb:with-txn (:env ,env :write ,write) ,@body)))))) (defun metadata-key (hash key) "Return the database key to retrieve metadata KEY associated with blob of HASH." (concatenate '(vector (unsigned-byte 8)) hash (string-to-utf-8-bytes (concat ":" key)))) (defvar *blob-hash-digest* :sha256) (defun write-bytevector-with-length (bv stream) "Write length of BV followed by BV itself to STREAM. The length is written as a little endian 64-bit unsigned integer." (write-sequence (lmdb:uint64-to-octets (length bv)) stream) (write-sequence bv stream)) (defun bv-hash (bv &optional metadata) "Return hash of BV + METADATA. METADATA is an association list mapping string keys to string, uint64 or bytevector values." (ironclad:with-digesting-stream (stream *blob-hash-digest*) ;; Write bytevector. (write-bytevector-with-length bv stream) ;; Write metadata. (mapc (lambda-match ((cons key value) (write-bytevector-with-length (string-to-utf-8-bytes key) stream) (write-bytevector-with-length (etypecase value (string (string-to-utf-8-bytes value)) ((unsigned-byte 64) (lmdb:uint64-to-octets value)) ((vector (unsigned-byte 8)) value)) stream))) metadata))) (defun hash-vector-length (hash-vector) "Return the number of hashes in HASH-VECTOR." (/ (length hash-vector) (ironclad:digest-length *blob-hash-digest*))) (defun hash-vector-ref (hash-vector n) "Return the Nth hash in HASH-VECTOR." (let ((hash-length (ironclad:digest-length *blob-hash-digest*))) (make-array hash-length :element-type '(unsigned-byte 8) :displaced-to hash-vector :displaced-index-offset (* n hash-length)))) (defun genotype-db-get (db key) "Get bytevector with KEY from genotype DB. KEY may be a hash or a string. If it is a string, it is encoded into octets before querying the database." (lmdb:g3t db (if (stringp key) (string-to-utf-8-bytes key) key))) (defun genotype-db-put (db bv &optional metadata) "Put BV, a bytevector, into DB. Associate METADATA, an association list of metadata, with BV. Return the hash." (let ((hash (bv-hash bv metadata))) ;; Put bytevector and metadata into db. Do nothing if it is ;; already in db. (unless (genotype-db-get db hash) (lmdb:put db hash bv) (mapc (lambda-match ((cons key value) (lmdb:put db (metadata-key hash key) value))) metadata)) hash)) (defun genotype-db-metadata-get (db hash key) "Get metadata associated with KEY, HASH from genotype DB." (genotype-db-get db (metadata-key hash key))) (defun genotype-db-current-matrix-hash (db) "Return the hash of the current matrix in genotype matrix DB." (hash-vector-ref (genotype-db-get db "versions") 0)) (defun (setf genotype-db-current-matrix-hash) (hash db) "Set HASH as the current matrix in genotype matrix DB." ;; Prepend hash onto versions array. (lmdb:put db (string-to-utf-8-bytes "versions") (concatenate '(vector (unsigned-byte 8)) hash (genotype-db-get db "versions"))) ;; Write a read-optimized copy of current matrix into the database. (let ((matrix (genotype-db-matrix db hash))) (lmdb:put db (string-to-utf-8-bytes "current") (genotype-db-put db (with-octet-output-stream (stream) (dotimes (i (genotype-db-matrix-nrows matrix)) (write-sequence (genotype-db-matrix-row-ref matrix i) stream)) (dotimes (i (genotype-db-matrix-ncols matrix)) (write-sequence (genotype-db-matrix-column-ref matrix i) stream))) `(("matrix" . ,hash)))))) (defun genotype-db-all-matrices (db) "Return a list of all matrices in DB, newest first." (let ((all-matrix-hashes (genotype-db-get db "versions"))) (mapcar (lambda (i) (genotype-db-matrix db (hash-vector-ref all-matrix-hashes i))) (iota (hash-vector-length all-matrix-hashes))))) (defun genotype-db-matrix (db hash) "Return the matrix identified by HASH from genotype matrix DB." (let ((nrows (lmdb:octets-to-uint64 (genotype-db-metadata-get db hash "nrows"))) (ncols (lmdb:octets-to-uint64 (genotype-db-metadata-get db hash "ncols"))) (hash-length (ironclad:digest-length *blob-hash-digest*))) (make-genotype-db-matrix :db db :hash hash :nrows nrows :ncols ncols :row-pointers (make-array (* nrows hash-length) :element-type '(unsigned-byte 8) :displaced-to (genotype-db-get db hash)) :column-pointers (make-array (* ncols hash-length) :element-type '(unsigned-byte 8) :displaced-to (genotype-db-get db hash) :displaced-index-offset (* nrows hash-length))))) (defun genotype-db-matrix-put (db matrix) "Put genotype MATRIX into DB and return the hash." (let ((matrix (genotype-matrix-matrix matrix))) (match (array-dimensions matrix) ((list nrows ncols) (genotype-db-put db (with-octet-output-stream (stream) (dotimes (i nrows) (write-sequence (genotype-db-put db (matrix-row matrix i)) stream)) (dotimes (j ncols) (write-sequence (genotype-db-put db (matrix-column matrix j)) stream))) `(("nrows" . ,nrows) ("ncols" . ,ncols))))))) (defun genotype-db-current-matrix (db) "Return the latest version of the matrix in DB." (let* ((read-optimized-blob (genotype-db-get db (genotype-db-get db "current"))) (current-matrix-hash (genotype-db-current-matrix-hash db)) (nrows (lmdb:octets-to-uint64 (genotype-db-metadata-get db current-matrix-hash "nrows"))) (ncols (lmdb:octets-to-uint64 (genotype-db-metadata-get db current-matrix-hash "ncols")))) (make-genotype-db-matrix :db db :nrows nrows :ncols ncols :array (make-array (list nrows ncols) :element-type '(unsigned-byte 8) :displaced-to read-optimized-blob) :transpose (make-array (list ncols nrows) :element-type '(unsigned-byte 8) :displaced-to read-optimized-blob)))) (defun genotype-db-matrix-ref (matrix) "Return MATRIX as a 2-dimensional array." (let ((array (genotype-db-matrix-array matrix))) (if array array (let* ((nrows (genotype-db-matrix-nrows matrix)) (ncols (genotype-db-matrix-ncols matrix)) (array (make-array (list nrows ncols) :element-type '(unsigned-byte 8)))) (dotimes (i nrows) (let ((row (genotype-db-matrix-row-ref matrix i))) (dotimes (j ncols) (setf (aref array i j) (aref row j))))) array)))) (defun genotype-db-matrix-row-ref (matrix i) "Return the Ith row of genotype db MATRIX." (let ((db (genotype-db-matrix-db matrix)) (array (genotype-db-matrix-array matrix))) (if array (matrix-row array i) (genotype-db-get db (hash-vector-ref (genotype-db-matrix-row-pointers matrix) i))))) (defun genotype-db-matrix-column-ref (matrix j) "Return the Jth column of genotype db MATRIX." (let ((db (genotype-db-matrix-db matrix)) (transpose (genotype-db-matrix-transpose matrix))) (if transpose (matrix-row transpose j) (genotype-db-get db (hash-vector-ref (genotype-db-matrix-column-pointers matrix) j))))) ;;; ;;; Geno files ;;; (defun read-geno-file (file) "Read geno FILE and return a genotype-matrix object." (with-open-file (stream file) (let ((file-metadata ;; Read file metadata. (labels ((read-geno-metadata () (let ((line (read-line stream))) (cond ;; Comment line ((starts-with? "#" line) (read-geno-metadata)) ;; Metadata line ((starts-with? "@" line) (match (split ":" (trim-right (s-rest line))) ((list key value) (acons key value (read-geno-metadata))))) ;; Some other line (t (unget-line line stream) (list)))))) (read-geno-metadata)))) ;; Extract metadata column names from table header. (multiple-value-bind (metadata-columns individuals) (match (words (read-line stream)) ((list* "Chr" "Locus" "cM" "Mb" individuals) (values (list "Chr" "Locus" "cM" "Mb") individuals)) ((list* "Chr" "Locus" "cM" individuals) (values (list "Chr" "Locus" "cM" "Mb") individuals))) ;; Read data. (let* ((nrows (count-lines stream)) (ncols (length individuals)) (matrix (make-array (list nrows ncols))) (maternal (assoc-ref file-metadata "mat")) (paternal (assoc-ref file-metadata "pat")) (heterozygous (assoc-ref file-metadata "het")) (unknown (assoc-ref file-metadata "unk"))) (make-genotype-matrix :matrix matrix :metadata ;; Write matrix data by mutation. Return metadata. (repeat-indexed (lambda (i) (match (split-at (length metadata-columns) (words (read-line stream))) ((list metadata data) (for-each-indexed (lambda (j element) (setf (aref matrix i j) (cond ((string= element maternal) 0) ((string= element paternal) 1) ((string= element heterozygous) 2) ((string= element unknown) 3)))) data) (mapcar #'cons metadata-columns metadata)))) nrows))))))) (defun hash-in-hash-vector-p (hash hash-vector) "Return non-nil if HASH is in HASH-VECTOR. Else, return nil." (find-index (lambda (i) (equalp (hash-vector-ref hash-vector i) hash)) (hash-vector-length hash-vector))) (defun live-key-p (db key) "Return non-nil if KEY is live. Else, return nil." (or (equalp key (string-to-utf-8-bytes "current")) (equalp key (string-to-utf-8-bytes "versions")) (equalp key (genotype-db-get db "current")) (let ((versions-hash-vector (genotype-db-get db "versions")) (key-hash-prefix (make-array (ironclad:digest-length *blob-hash-digest*) :element-type '(unsigned-byte 8) :displaced-to key))) (or (hash-in-hash-vector-p key-hash-prefix versions-hash-vector) (find-index (lambda (i) (hash-in-hash-vector-p key-hash-prefix (genotype-db-get db (hash-vector-ref versions-hash-vector i)))) (hash-vector-length versions-hash-vector)))))) (defun collect-garbage (db) "Delete all keys in DB that are not associated with a live hash." (lmdb:with-cursor (cursor db) (lmdb:cursor-first cursor) (lmdb:do-cursor (key value cursor) (unless (live-key-p db key) (lmdb:cursor-del cursor))))) (defun import-into-genotype-db (geno-file genotype-database) "Import GENO-FILE into GENOTYPE-DATABASE." (let ((matrix (read-geno-file geno-file))) ;; Write genotype matrix into genotype database. (with-genotype-db (db genotype-database :write t) (let* ((hash (genotype-db-matrix-put db matrix)) (db-matrix (genotype-db-matrix db hash))) ;; Read written data back and verify. (unless (and (all (lambda (i) (equalp (matrix-row (genotype-matrix-matrix matrix) i) (genotype-db-matrix-row-ref db-matrix i))) (iota (genotype-db-matrix-nrows db-matrix))) (all (lambda (i) (equalp (matrix-column (genotype-matrix-matrix matrix) i) (genotype-db-matrix-column-ref db-matrix i))) (iota (genotype-db-matrix-ncols db-matrix)))) ;; Roll back database updates. (collect-garbage db) ;; Exit with error message. (format *error-output* "Rereading and verifying genotype matrix written to \"~a\" failed. This is a bug. Please report it. " genotype-database) (uiop:quit 1)) ;; Set the current matrix. (setf (genotype-db-current-matrix-hash db) hash))))) (defun print-genotype-db-info (database-directory) (with-genotype-db (db database-directory) (format t "Path: ~a~%Versions: ~a~%Keys: ~a~%~%" database-directory (length (genotype-db-all-matrices db)) (getf (lmdb:db-statistics db) :entries)) (for-each-indexed (lambda (i matrix) (format t "Version ~a Dimensions: ~a × ~a~%" (1+ i) (genotype-db-matrix-nrows matrix) (genotype-db-matrix-ncols matrix))) (genotype-db-all-matrices db)))) (defun main () (match (uiop:command-line-arguments) ((list "import" geno-file genotype-database) (import-into-genotype-db geno-file (fad:pathname-as-directory genotype-database))) ((list "info" genotype-database) (print-genotype-db-info (fad:pathname-as-directory genotype-database))) (_ (format t "Usage: Import GENO-FILE into GENOTYPE-DATABASE: genodb import GENO-FILE GENOTYPE-DATABASE Print info about GENOTYPE-DATABASE: genodb info GENOTYPE-DATABASE ") (uiop:quit 1))))
19,523
Common Lisp
.lisp
445
32.4
94
0.568089
genenetwork/cl-gn
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
89afb1bde4c1923c3df1e8c66d9b8591561f6d3d90db1e6a3ac6156514baf48d
23,985
[ -1 ]
23,986
build.lisp
genenetwork_cl-gn/build.lisp
(require :asdf) ;; Load genenetwork.asd from the current directory. (asdf:load-asd (merge-pathnames "genenetwork.asd" (directory-namestring *load-truename*))) (asdf:make :genodb)
213
Common Lisp
.lisp
5
34.8
72
0.660194
genenetwork/cl-gn
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
88d77c29ca85561b8ee2d3c7af28ebac1772b5dabf7c1610db7d8e21ab86146f
23,986
[ -1 ]
23,987
genodb.lisp
genenetwork_cl-gn/tests/genodb.lisp
(defpackage :genodb/tests (:use :common-lisp :fiveam :genodb) (:import-from :genodb :genotype-matrix-matrix :genotype-matrix-metadata :import-into-genotype-db)) (in-package :genodb/tests) (test test-genodb (let ((actual-genotype-matrix (read-geno-file "tests/test.geno"))) (is (and (equalp (genotype-matrix-matrix actual-genotype-matrix) (make-array (list 7 2) :initial-contents '((0 0) (1 1) (1 1) (0 1) (0 0) (1 0) (1 0)))) (equalp (genotype-matrix-metadata actual-genotype-matrix) '((("Chr" . "1") ("Locus" . "rs31443144") ("cM" . "1.50") ("Mb" . "3.010274")) (("Chr" . "2") ("Locus" . "rs27644551") ("cM" . "93.26") ("Mb" . "173.542999")) (("Chr" . "3") ("Locus" . "rs31187985") ("cM" . "17.12") ("Mb" . "41.921845")) (("Chr" . "4") ("Locus" . "rs30254612") ("cM" . "2.15") ("Mb" . "3.718812")) (("Chr" . "5") ("Locus" . "UNCHS047057") ("cM" . "3.10") ("Mb" . "4.199559")) (("Chr" . "X") ("Locus" . "ChrXp_no_data") ("cM" . "1.40") ("Mb" . "3.231738")) (("Chr" . "X") ("Locus" . "Affy_17539964") ("cM" . "1.40") ("Mb" . "7.947581"))))))) (finishes (let ((test-genodb "tests/test-genodb/")) (unwind-protect (import-into-genotype-db "tests/test.geno" test-genodb) (fad:delete-directory-and-files test-genodb))))) (run! 'test-genodb)
2,347
Common Lisp
.lisp
49
24.204082
100
0.318083
genenetwork/cl-gn
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
69ca7490bdab045ea613d4022a6a99decf73043fbc41f25d2932961bc7790dd5
23,987
[ -1 ]
23,988
genenetwork.asd
genenetwork_cl-gn/genenetwork.asd
(defsystem :genenetwork :class :package-inferred-system :description "GeneNetwork" :version "0.1.0" :author "The GeneNetwork team" :license "GNU Affero General Public License version 3 or later" :depends-on (:genenetwork/genenetwork)) (defsystem :genodb :description "GeneNetwork genotype database tool" :version "0.1.0" :author "The GeneNetwork team" :license "GNU General Public License version 3 or later" :depends-on (:alexandria :cl-fad :ironclad :listopia :lmdb :str :trivia :trivial-utf-8) :components ((:file "genodb")) :build-operation "program-op" :build-pathname "genodb" :entry-point "genodb:main") (defsystem :genodb/tests :description "Tests for GeneNetwork genotype database tool" :version "0.1.0" :author "The GeneNetwork team" :license "GNU General Public License version 3 or later" :depends-on (:cl-fad :fiveam :genodb) :components ((:file "tests/genodb")))
1,056
Common Lisp
.asd
33
25.575758
65
0.652302
genenetwork/cl-gn
1
0
0
AGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
d648302839afe1c2d5a132033b142149f102a2b63f0a54d138966a18070e020f
23,988
[ -1 ]
24,010
b.lisp
Lisprez_lisp_call_c_module/b.lisp
(load "a.lisp") (defun fuck () (let ((result (mc:myfunc 0))) (print result))) (fuck)
95
Common Lisp
.lisp
5
16
33
0.573034
Lisprez/lisp_call_c_module
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
e5a7bf64c3e3b11b301e738f8bcc7efb9b29d70bb72f4840d87f886e5640fbf8
24,010
[ -1 ]
24,011
a.lisp
Lisprez_lisp_call_c_module/a.lisp
(asdf:load-system :cffi) (defpackage :mc (:use :common-lisp :cffi) (:export myfunc)) (in-package :mc) (define-foreign-library libcurl (:unix (:or "/usr/lib64/libcurl.so.4")) (t (:default "/usr/lib64/libcurl.so.4"))) (use-foreign-library libcurl) (defcfun ("curl_global_init" myfunc) :int (flags :long))
321
Common Lisp
.lisp
12
24.25
42
0.693069
Lisprez/lisp_call_c_module
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
74c3db612b8b6cb0ed5cf3644104ffe07aa4d5c094c1b7ee2770ff825bc6dc48
24,011
[ -1 ]
24,029
scheme2common-lisp.lisp
gregcman_scheme2common-lisp/scheme2common-lisp.lisp
(defpackage #:scheme2common-lisp (:use :cl :utility)) (in-package :scheme2common-lisp) (setf *print-case* :downcase) (mapc (lambda (x) (export (cdr x))) '((:export alias0 alias2) (:export atom? symbol? pair? null? eq? equal? integer? for-each assq reverse! remainder modulo quotient assv display eqv? list-ref list-tail memq memv newline set-car! set-cdr! vector-ref vector-set! string-ref string-set! vector-length number? string? list? string-append number->string symbol->string char->integer integer->char list->string string-length) (:export pp) (:export set! begin) (:export named-let make-vector +true+ +false+ letrec call/cc open-input-file close-input-port))) (defun number->string (number &optional radix) ;;radix default to 10, but for some result explicitly ;;providing 10 causes a decimal point to appear. (write-to-string number :radix radix)) (defun string-append (&rest args) (let ((length (reduce #'+ (mapcar #'length args)))) (let ((new (make-array length :element-type 'character)) (count 0)) (dolist (item args) (dotimes (index (length item)) (setf (aref new count) (aref item index)) (incf count))) new))) (defmacro alias0 (scheme-name cl-name) `(eval-always (setf (symbol-function ',scheme-name) (function ,cl-name)))) (alias0 pp pprint) (etouq (cons 'progn (mapcar (lambda (x) (cons 'alias0 x)) '((atom? atom) (symbol? symbolp) (pair? consp) (null? null) (eq? eq) (equal? equal) (integer? integerp) (for-each mapc) (assq (lambda (item alist) (assoc item alist :test 'eq))) (reverse! nreverse) (remainder rem) (modulo mod) (quotient truncate) ;;(assoc (lambda (item alist) (assoc item alist :test equal))) (assv assoc) (display princ) (eqv? eql) (list-ref nth) (list-tail nthcdr) ;;(map mapcar) ;;(member (lambda (item list) (member item list :test equal))) (memq (lambda (item list) (member item list :test 'eq))) (memv member) (newline terpri) (set-car! rplaca) (set-cdr! rplacd) (vector-ref aref) (vector-set! (lambda (array index value) (setf (aref array index) value))) (string-ref aref) (string-set! vector-set!) (vector-length array-total-size) ;;(write prin1) (number? numberp) (string? stringp) (list? alexandria:proper-list-p) ;;(string-append string-append) ;;(number->string number->string) (symbol->string (lambda (x) (string-downcase (string x)))) ;;;;FIXME -> how to convert common lisp symbols to scheme strings? (char->integer char-code) (integer->char code-char) (list->string (lambda (x) (coerce x 'string))) (string-length (lambda (x) (array-total-size x))))))) (defmacro alias2 (scheme-name cl-name) `(defmacro ,scheme-name (&rest rest) `(,',cl-name ,@rest))) (alias2 set! setq) (alias2 begin progn) (defun param-names (params) (mapcar (lambda (x) (if (symbolp x) x (first x))) params)) (defmacro named-let (name params &body body) (let* ((param-names (param-names params)) (rec-param-names (mapcar (lambda (x) (gensym (string x))) param-names))) (with-gensyms (start) `(let ,params (block exit (tagbody ,start (return-from exit (flet ((,name ,rec-param-names (setf (values ,@param-names) (values ,@rec-param-names)) (go ,start))) ,@body)))))))) (defun make-vector (length &optional (obj nil)) (make-array length :initial-element obj)) (defconstant +true+ t) (defconstant +false+ nil) (defmacro letrec (bindings &body body) (let ((vars (param-names bindings)) (acc (list (quote progn)))) (mapc (lambda (binding var) (when (consp binding) (let ((initial-form (cdr binding))) (when initial-form (push `(setf ,var ,@initial-form) acc))))) bindings vars) `(let ,vars ,(nreverse acc) ,@body))) #+nil (letrec ((a 7) (b (* a a)) (c (lambda () (print (list a b))))) (funcall c)) (defun call/cc (function) (block nil (funcall function (lambda (&rest values) (return-from nil (apply (function values) values)))))) (defun close-input-port (stream) (close stream)) (defun open-input-file (file) (open file :direction :input))
4,636
Common Lisp
.lisp
191
19.193717
100
0.614806
gregcman/scheme2common-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
44a5f9d0ab6d220717d254cf26fd4b141877de2c3547ab24999face4f444b4dc
24,029
[ -1 ]
24,030
scheme2common-lisp.asd
gregcman_scheme2common-lisp/scheme2common-lisp.asd
(asdf:defsystem #:scheme2common-lisp :depends-on (#:utility #:alexandria) :serial t :components ((:file "scheme2common-lisp")))
144
Common Lisp
.lisp
6
20.333333
36
0.681159
gregcman/scheme2common-lisp
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
94f5c9212d12ff5b185efdf19a8d4e364c5e55d2b6c067c179c74ec3ac2c84b1
24,030
[ -1 ]
24,050
settings.pl
IAL32_json-parser-lisp-prolog/settings.pl
%% debug only: sbatti ogni volta scrivere [p]. per ricaricare il file r :- make. %% debug only: sbatti scrivere debug ogni volta per fare il trace t :- trace. %% debug only: sbatti scrivere nodebug ogni volta per uscire dal debug(mi esce sia dal trace che dal debug) nd :- nodebug. %% debug only: invece di dover usare ` ogni volta %% %% Disabilitato! Non piu' necessario %:- set_prolog_flag(double_quotes, chars). % NOTARE BENE! PER QUESTIONI DI VISIBILITA' DEL RISULTATO, MANTENERE IL FLAG ATTIVO, COSI COME atom_chars in json_load, ALTRIMENTI SI VEDRANNO I CODES! %% necessario per evitare che prolog mi metta i puntini %% su cose troppo lunghe :- set_prolog_flag(answer_write_options, [ quoted(true), portray(true), spacing(next_argument) ]).
829
Common Lisp
.l
17
42.941176
151
0.683951
IAL32/json-parser-lisp-prolog
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
2cc22b30a6ba1a23a37e8e905803b0ca6fd15c101dd6c457ee99b2a8fdfd1a04
24,050
[ -1 ]
24,051
main.pl
IAL32_json-parser-lisp-prolog/main.pl
:- [settings]. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % INIZIO DEL PROGRAMMA % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% :- [io]. % Input/Output :- [json_decode]. % Json Decode :- [json_encode]. % Json Encode :- [json_get]. % Json Get :- [tests]. % Unit testing
366
Common Lisp
.l
9
39.666667
53
0.305322
IAL32/json-parser-lisp-prolog
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
b3460115ba61d8841671e4f4ef4b4ab36dc3a13127375e1b8ae1d78f976596ec
24,051
[ -1 ]
24,052
json_encode.pl
IAL32_json-parser-lisp-prolog/json_encode.pl
% json_encode(+JsonObject, -String). json_encode(jsonobject([]), '{}') :- !. json_encode(jsonarray([]), '[]') :- !. json_encode(jsonobject(Members), StringObject) :- json_encode_object_members(Members, StringMembers), atomic_list_concat(['{', StringMembers , '}'], StringObject), !. json_encode(jsonarray(Members), StringArray) :- json_encode_array_members(Members, StringMembers), atomic_list_concat(['[', StringMembers, ']'], StringArray). % json_encode_array_members(+JsonArrayMembers, -StringMerged). json_encode_array_members([Member | Members], StringMerged) :- json_encode_value(Member, StringValue), json_encode_array_members(Members, StringMembers), string_concat(StringValue, ',', StringValueComma), string_concat(StringValueComma, StringMembers, StringMerged), !. json_encode_array_members([Member], StringMerged) :- json_encode_value(Member, StringMerged), !. % json_encode_members(+JsonObjectMembers, -StringMerged). json_encode_object_members([Member | Members], StringMerged) :- json_encode_pair(Member, StringPair), json_encode_object_members(Members, StringMembers), string_concat(StringPair, ',', StringPairComma), string_concat(StringPairComma, StringMembers, StringMerged), !. json_encode_object_members([Member], StringMerged) :- json_encode_pair(Member, StringMerged), !. % json_encode_pair(+JsonPair, -StringPair). json_encode_pair((Key, Value), StringPair) :- atomic_list_concat(['"', Key, '"'], StringKey), json_encode_value(Value, StringValue), string_concat(StringKey, ':', StringKeyColon), string_concat(StringKeyColon, StringValue, StringPair). % json_encode_key(+JsonPairKey, -StringKey). json_encode_key(Key, StringKey) :- json_encode_string(Key, StringKey). % json_encode_value(+JsonValue, -StringValue). json_encode_value(Object, StringValue) :- json_encode(Object, StringValue), !. json_encode_value(Number, StringNumber) :- number(Number), atom_number(AtomNumber, Number), atom_chars(AtomNumber, NumberChars), string_chars(StringNumber, NumberChars), !. json_encode_value(String, StringValue) :- json_encode_string(String, StringValue), !. % json_encode_string(+JsonString, -StringValue). json_encode_string(String, StringValue) :- atomic_list_concat(['"', String, '"'], StringValue).
2,346
Common Lisp
.l
50
43.4
68
0.726159
IAL32/json-parser-lisp-prolog
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
1c088f5552486489f9018999d4f256f699a5829ea1715c30708925004f5f653c
24,052
[ -1 ]
24,053
tests.pl
IAL32_json-parser-lisp-prolog/tests.pl
:- use_module(library(plunit)). :- begin_tests(io). test(json_load_1) :- json_load("ex_arthurdent.json", jsonobject([("nome", "Arthur"), ("cognome", "Dent")])). test(json_load_2) :- json_load("ex_emptyobject.json", jsonobject([])). test(json_load_3) :- json_load("ex_emptyarray.json", jsonarray([])). test(json_load_4) :- json_load("ex_superbook.json", jsonobject([("modello", "SuperBook 1234"), ("anno di produzione", 2014), ("processore", jsonobject([("produttore", "EsseTi"), ("velocità di funzionamento (GHz)", jsonarray([1, 2, 4, 8]))]))])). test(json_load_5) :- json_load("ex_wikipedia.json", jsonobject([("type", "menu"), ("value", "File"), ("items", jsonarray([jsonobject([("value", "New"), ("action", "CreateNewDoc")]), jsonobject([("value", "Open"), ("action", "OpenDoc")]), jsonobject([("value", "Close"), ("action", "CloseDoc")])]))])). % write test(json_write_1, [ cleanup(delete_file("test1.json")) ]) :- json_write(jsonobject([]), "test1.json"). test(json_write_2, [ cleanup(delete_file("test2.json")) ]) :- json_write(jsonarray([]), "test2.json"). test(json_write_3, [ cleanup(delete_file("test3.json")) ]) :- Object = jsonobject([("modello", "SuperBook 1234"), ("anno di produzione", 2014), ("processore", jsonobject([("produttore", "EsseTi"), ("velocità di funzionamento (GHz)", jsonarray([1, 2, 4, 8]))]))]), json_write(Object, "test3.json"), json_load("test3.json", Object). :- end_tests(io). :- begin_tests(json_parse). test(json_parse_1) :- json_parse("{}", jsonobject([])). test(json_parse_2) :- json_parse('[]', jsonarray([])). % da email di Lorenzo Aldeghi, sabato 25-11-2017, 13:20 test(json_parse_3) :- json_parse('{"st{rin}ga" : "va[lo]re"}', jsonobject([("st{rin}ga", "va[lo]re")])). % ^ test(json_parse_4) :- json_parse('{\n "confondendo" : "il, riconoscimento, di una coppia, stringa-valore",\n "da:::lle" : "al,,,,,,,,tre"}', jsonobject([("confondendo", "il, riconoscimento, di una coppia, stringa-valore"),("da:::lle", "al,,,,,,,,tre")])). % ^ test(json_parse_5) :- json_parse('["1", "[2]", "{3{{}}}"]', jsonarray(["1", "[2]", "{3{{}}}"])). % email Prof. Antoniotti sabato 25-11-2017, 14:31 test(json_parse_6) :- json_parse('{"fo,32": "43"}', jsonobject([("fo,32", "43")])). test(json_parse_7) :- json_parse('{"fo{32}bar": "43"}', jsonobject([("fo{32}bar", "43")])). % ovviamente mi deve fallire quando la sintassi è sbagliata test(json_parse_8, [fail]) :- json_parse('{', _). :- end_tests(json_parse). :- begin_tests(json_value). test(json_value_1) :- json_value(123.456, `123.456`, []). test(json_value_2) :- json_value(123456, `123456`, []). test(json_value_3) :- json_value("abc{[(,,]èòóö", `"abc{[(,,]èòóö"`, []). test(json_value_4) :- json_value(jsonobject([]), `{}`, []). test(json_value_5) :- json_value(jsonarray([]), `[]`, []). :- end_tests(json_value). :- begin_tests(json_encode). test(json_encode_1) :- json_encode(jsonobject([]), '{}'). test(json_encode_2) :- json_encode(jsonarray([]), '[]'). test(json_encode_3) :- json_encode(jsonobject([(1, 23.45)]), '{"1":23.45}'). :- end_tests(json_encode).
3,208
Common Lisp
.l
71
42.084507
289
0.602126
IAL32/json-parser-lisp-prolog
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
b3f100c7072d246e17d6497e22577fab367af0c16ea2c1f8c6353eb11ee3cae5
24,053
[ -1 ]
24,054
json_decode.pl
IAL32_json-parser-lisp-prolog/json_decode.pl
% json_parse/2 %% Con il primo gestisco il caso in cui il primo %% argomento sia tra apici singoli, eg: %% json_parse('{"a":"b"}', JSON). json_parse(JSONAtom, Object) :- atomic(JSONAtom), atom_codes(JSONAtom, JSONString), json_parse(JSONString, Object), !. %% questi altri due gestiscono le liste di codici %% di caratteri. json_parse(JSONList, Object) :- json_object(Object, JSONList, []), !. json_parse(JSONList, Array) :- json_array(Array, JSONList, []). % json_array/3 json_array(jsonarray([])) --> "[", ws, "]", ws, !. json_array(jsonarray(Array)) --> "[", ws, json_array_members(Array), ws, "]", ws. % json_object/3 json_object(jsonobject([])) --> "{", ws, "}", ws, !. json_object(jsonobject(Object)) --> "{", ws, json_members(Object), ws, "}", ws. % json_array_members/3 json_array_members([Member | Members]) --> json_value(Member), ws, ",", ws, !, json_array_members(Members). json_array_members([Member]) --> json_value(Member). % json_members/3 json_members([Member | Members]) --> json_pair(Member), ws, ",", ws, !, json_members(Members). json_members([Object]) --> json_pair(Object). % json_pair/3 % Pair ::= String ':' Value json_pair((Key, Value)) --> json_string(Key), ws, ":", ws, json_value(Value). % json_value/3 json_value(Value) --> json_string(Value), !. json_value(Value) --> json_object(Value), !. json_value(Value) --> json_array(Value), !. json_value(Value) --> % analizzo la prima parte del numero, json_value_number(Number), ".", !, % analizzo la mantissa json_value_number(Mantissa), % unisco le due liste e ne faccio una sola senza nested lists { flatten([Number, 0'. | Mantissa], Float) }, % converto la lista prima in stringa, e poi in un atomo prolog { string_to_list(Value1, Float), number_chars(Value, Value1) }, !. json_value(Value) --> % un integer json_value_number(Codes), { length(Codes, L), L > 0, number_chars(Value, Codes) }, !. % json_string/3 % definizione di una stringa % String ::= '"' AnyCharSansDQ* '"' | '’' AnyCharSansSQ* '’' % AnyCharSansDQ ::= <qualunque carattere (ASCII) diverso da '"'> % AnyCharSansSQ ::= <qualunque carattere (ASCII) diverso da '’'> json_string(Value) --> ( ("\"", "\"") | ("'", "'") ), { string_codes(Value, "") }, !. json_string(Value) --> ( "\"", !, json_value_string_dq(Codes), { string_codes(Value, Codes) }, "\"" ) | ( "'", !, json_value_string_sq(Codes), { string_codes(Value, Codes) }, "'" ), !. % json_value_number/3 % una stringa composta solo da interi json_value_number([H | T]) --> [H], { char_type(H, digit) }, json_value_number(T), !. json_value_number([]) --> []. % json_value_string_dq/3 % una stringa json inclusa tra ", che non contiene " json_value_string_dq([H | T]) --> [H], { H \= 0'" }, json_value_string_dq(T), !. json_value_string_dq([]) --> []. % json_value_string_sq/3 % una stringa json inclusa tra `, che non contiene ` json_value_string_sq([H | T]) --> [H], { H \= 0'' }, json_value_string_sq(T), !. json_value_string_sq([]) --> []. % ws/2 % consuma gli spazi bianchi ws --> ws_, ws, ! | ws_, ! | []. ws_ --> [W], { char_type(W, space) }.
3,342
Common Lisp
.l
112
26.1875
66
0.592904
IAL32/json-parser-lisp-prolog
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
b03384bae70f87821ef7e2fe7a832f7562718b3f6b3b560d024ca1506493851e
24,054
[ -1 ]
24,055
io.pl
IAL32_json-parser-lisp-prolog/io.pl
% json_load/2 json_load(FileName, JSON) :- open(FileName, read, BufferIn), read_string(BufferIn, _, String), normalize_space(atom(Normalized), String), atom_codes(Normalized, StringList), json_parse(StringList, JSON), close(BufferIn). % json_write/2 % TODO json_write(JSON, FileName) :- json_encode(JSON, String), open(FileName, write, BufferOut), write(BufferOut, String), close(BufferOut).
433
Common Lisp
.l
15
25.133333
46
0.697842
IAL32/json-parser-lisp-prolog
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
3e3bdb0d099edc8c845ab573ed250ac594d5e322f78be499b3e50f3e61f623c5
24,055
[ -1 ]
24,056
json_get.pl
IAL32_json-parser-lisp-prolog/json_get.pl
% json_get/3 json_get(jsonobject(Members), Key, Value) :- %atom_chars(KeyAtom, Key), member((Key, Value), (Members)), !. json_get(Object, [Key], Value) :- json_get(Object, Key, Value), !. json_get(Object, [Key, Nth], Value) :- json_get(Object, Key, jsonarray(Array)), nth0(Nth, Array, Value), !. %json_get_member([(Key, Value) | _Members], Key, Value).
376
Common Lisp
.l
10
34.3
56
0.630854
IAL32/json-parser-lisp-prolog
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
f353fc47d783ba9b8c72295af5fe1fa5cd267b93e89c99f850c677204a2a90ba
24,056
[ -1 ]
24,071
derivatives.lisp
alejandrozf_derivatives/derivatives.lisp
(load "libs.lisp") (defun pair? (x) (not (atom x))) (defun wff (exp) (cond ((atom exp) exp) ;atoms are return it as is ((numberp (car exp)) (cond ((3-term-exp? exp) ;'exp' is a term that is, (3 X 2) or (5 X) (cons 'G exp)) ((2-term-exp? exp) (cons 'G (append exp '(1)))) (list (cadr exp) (car exp) ;'exp' is like (3 + g(x)) (wff (cadr exp))))) ((atom (car exp)) ;'exp' is like (- g(x)) (list (convert-unary (car exp)) (wff (cadr exp)))) (t (aux-res (cadr exp) ;'exp' is like (f(x) + g(x)) or more generally ((... (f(x)) ...)) (wff (car exp)) (wff (caddr exp)))))) (defun 3-term-exp? (exp) (and (numberp (car exp)) (atom (cadr exp)) (numberp (nth 2 exp)))) (defun 2-term-exp? (exp) (and (numberp (car exp)) (atom (cadr exp)) (null (nth 2 exp)))) (defun convert-unary (val) (if (eql val '-) 'U- val)) (defun aux-res (a b c) (cond ((and (null a) (null c)) b) (t (list a b c)))) (defun derg (wff) "wff = (G C X N)" (let* ((c (nth 0 wff)) (n (nth 2 wff))) (if (eql n 1) (* c n) (list 'G (* c n) 'X (- n 1))))) (defun der+ (wff) (list '+ (der-prev (car wff)) (der-prev (nth 1 wff)))) (defun der- (wff) (list '- (der-prev (car wff)) (der-prev (nth 1 wff)))) (defun derU- (wff) (list 'U- (der-prev (car wff)))) (defun der* (wff) (let* ((1st (nth 0 wff)) (2nd (nth 1 wff))) (list '+ `(* ,(der-prev 1st) ,2nd) `(* ,1st ,(der-prev 2nd))))) (defun der/ (wff) (let* ((1st (nth 0 wff)) (2nd (nth 1 wff))) (list '/ `(- (* ,(der-prev 1st) ,2nd) (* ,1st ,(der-prev 2nd))) `(* ,2nd ,2nd)))) (defun dersin (wff) (let ((val (car wff))) (if (atom (car wff)) (list 'COS val) (list '* `(COS ,val) (der-prev val))))) (defun dercos (wff) (let ((val (car wff))) (if (atom (car wff)) (list 'U- `(SIN ,val)) (list '* `(U- (SIN ,val)) (der-prev val))))) (defun der-prev (wff) (cond ((numberp wff) 0) ((atom wff) wff) (t (eval `(,(getp (car wff) DERIVATIVE) ',(cdr wff)))))) (defun simplify (wff) (cond ((atom wff) wff) ((and (eql (car wff) 'G) ;e.g (G 2 X 0) -> 2 (eql (nth 3 wff) 0)) (nth 1 wff)) ((eql (car wff) 'G) wff) ;simple terms ((and (eql (car wff) '-) ;(- exp exp) -> 0 (equal (nth 1 wff) (nth 2 wff))) 0) ((eql (car wff) '+) ;(+ a 0) or (+ 0 a) cases (cond ((eql (nth 1 wff) 0) (simplify (nth 2 wff))) ((eql (nth 2 wff) 0) (simplify (nth 1 wff))) (t (list '+ (simplify (nth 1 wff)) (simplify (nth 2 wff)))))) ((eql (car wff) 'U-) ;(U- (U- wff)) becomes wff (cond ((or (atom (nth 1 wff)) (eql (car (nth 1 wff)) 'G)) wff) ((eql (car (nth 1 wff)) 'U-) (simplify (nth 1 (nth 1 wff)))) (t (list 'U- (simplify (nth 1 wff)))))) ((eql (car wff) '*) (cond ((and (numberp (nth 1 wff)) (numberp (nth 2 wff))) (* (nth 1 wff) (nth 2 wff))) ((and (pair? (nth 1 wff)) ;(* (U- (G 3 X 2)) (G 5 X 3)) -> (U- (* (G 3 X 2) (G 5 X 3))) (eql (car (nth 1 wff)) 'U-)) (simplify `(U- (* ,(nth 1 (nth 1 wff)) ,(nth 2 wff))))) ((and (pair? (nth 2 wff)) ;(* (G 3 X 2) (U- (G 5 X 3)) )) -> (U- (* (G 3 X 2) (G 5 X 3))) (eql (car (nth 2 wff)) 'U-)) (simplify `(U- (* ,(nth 1 (nth 2 wff)) ,(nth 1 wff))))) (t (list '* (simplify (nth 1 wff)) ;normal binary * behaviour (simplify (nth 2 wff)))))) ((eql (car wff) 'SIN) (list 'SIN (simplify (nth 1 wff)))) ((eql (car wff) 'COS) (list 'COS (simplify (nth 1 wff)))) (t (list (car wff) (simplify (nth 1 wff)) (simplify (nth 2 wff)))))) (defun reduce-negatives (wff) (cond ((or (atom wff) (eql (car wff) 'G)) wff) ((eql (car wff) 'U-) (if (and (pair? (nth 1 wff)) (eql (car (nth 1 wff)) 'U-)) (reduce-negatives (nth 1 (nth 1 wff))) (list 'U- (reduce-negatives (nth 1 wff))))) ((or (eql (car wff) 'SIN) (eql (car wff) 'COS)) (list (car wff) (reduce-negatives (nth 1 wff)))) ((or (eql (car wff) '+) (eql (car wff) '-) (eql (car wff) '*) (eql (car wff) '/)) (list (car wff) (reduce-negatives (nth 1 wff)) (reduce-negatives (nth 2 wff)))))) (defun der (wff) (reduce-negatives (simplify (der-prev wff))))
4,538
Common Lisp
.lisp
142
27.34507
116
0.474262
alejandrozf/derivatives
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
712e17f271b8e12056e52bdbe886907175e2b0974d4e59511d93be74564abc17
24,071
[ -1 ]
24,072
tests.lisp
alejandrozf_derivatives/tests.lisp
(load "derivatives.lisp") ;;; Convert the expressions to WFFs ;;; simple polynomials (setf wff1 (wff '(4 X 3) )) (setf wff2 (wff '((2 X 3) + (5 x 2) ) )) (setf wff3 (wff '((3 X 3) + 5) )) (setf wff4 (wff '((4 X 3) + (6 X) ) )) (setf wff5 (wff '((5 x 4) + ((3 X 2) + (5 X))) )) ;;; SIN (setf wff6 (wff '(SIN X) )) (setf wff7 (wff '( SIN ( 7 X 2) ) )) (setf wff8 (wff '( (8 X 3) + (SIN (2 X)) ) )) ;;; diff, product, quotient (setf wff9 (wff '( (9 X 4) - (2 X 3)) )) (setf wff10 (wff '( (10 X 3) * (5 X 2)) )) (setf wff11 (wff '( (11 X 3) / (2 X 1) ) )) (setf wff12 (wff '( (12 X 4) * ( (1 X 5) + (2 X 4)) ) )) ;;; more complex (setf wff13 (wff '(SIN ( (13 X 2) / (2 X 3)) ) )) (setf wff14 (wff '(COS ( 14 X)) )) ;;; others (setf wff15 (wff '( (15 X 1) - (15 X)) )) (setf wff16 (wff '( ((16 X) + 5) * (4 X)) )) ;;; unary (setf wff17 (wff '( - (17 X 2) ) )) (setf wff18 (wff '( - (COS ( 18 X)) ) )) ;;; simple? (setf wff19 (wff '(19 X) )) (setf wff20 (wff '( (20 X 2) - ( 20 x 2)) )) (setf wff21 (wff '(-(cos X)) )) (setf wff22 (wff '(- (sin (- (22 X 2)))) )) (setf wff23 (wff '( (- (23 X 2)) * (- (3 X 3))) )) (setf wff24 (wff '(cos (- (24 X 2))) )) ;;; Take the derivatives (format t "~a <- ~a~%" wff1 'wff1) (format t "~a <- ~a~%" (der wff1) '(der wff1)) (format t "~a <- ~a~%" wff2 'wff2) (format t "~a <- ~a~%" (der wff2) '(der wff2)) (format t "~a <- ~a~%" wff3 'wff3) (format t "~a <- ~a~%" (der wff3) '(der wff3)) (format t "~a <- ~a~%" wff4 'wff4) (format t "~a <- ~a~%" (der wff4) '(der wff4)) (format t "~a <- ~a~%" wff5 'wff5) (format t "~a <- ~a~%" (der wff5) '(der wff5)) ;;; SIN (format t "~a <- ~a~%" wff6 'wff6) (format t "~a <- ~a~%" (der wff6) '(der wff6)) (format t "~a <- ~a~%" wff7 'wff7) (format t "~a <- ~a~%" (der wff7) '(der wff7)) (format t "~a <- ~a~%" wff8 'wff8) (format t "~a <- ~a~%" (der wff8) '(der wff8)) ;;; difference (format t "~a <- ~a~%" wff9 'wff9) (format t "~a <- ~a~%" (der wff9) '(der wff9)) ;;; product (format t "~a <- ~a~%" wff10 'wff10) (format t "~a <- ~a~%" (der wff10) '(der wff10)) ;;; quotient (format t "~a <- ~a~%" wff11 'wff11) (format t "~a <- ~a~%" (der wff11) '(der wff11)) ;;; more complex product (format t "~a <- ~a~%" wff12 'wff12) (format t "~a <- ~a~%" (der wff12) '(der wff12)) ;;; Chain rule with SIN (format t "~a <- ~a~%" wff13 'wff13) (format t "~a <- ~a~%" (der wff13) '(der wff13)) ;;; COS (format t "~a <- ~a~%" wff14 'wff14) (format t "~a <- ~a~%" (der wff14) '(der wff14)) ;;; difference x (format t "~a <- ~a~%" wff15 'wff15) (format t "~a <- ~a~%" (der wff15) '(der wff15)) ;;; producct (format t "~a <- ~a~%" wff16 'wff16) (format t "~a <- ~a~%" (der wff16) '(der wff16)) ;;; unary (format t "~a <- ~a~%" wff17 'wff17) (format t "~a <- ~a~%" (der wff17) '(der wff17)) (format t "~a <- ~a~%" wff18 'wff18) (format t "~a <- ~a~%" (der wff18) '(der wff18)) ;;; simple? (format t "~a <- ~a~%" wff19 'wff19) (format t "~a <- ~a~%" (der wff19) '(der wff19)) (format t "~a <- ~a~%" wff20 'wff20) (format t "~a <- ~a~%" (der wff20) '(der wff20)) (format t "~a <- ~a~%" wff21 'wff21) (format t "~a <- ~a~%" (der wff21) '(der wff21)) (format t "~a <- ~a~%" wff22 'wff22) (format t "~a <- ~a~%" (der wff22) '(der wff22)) (format t "~a <- ~a~%" wff23 'wff23) (format t "~a <- ~a~%" (der wff23) '(der wff23)) (format t "~a <- ~a~%" wff24 'wff24) (format t "~a <- ~a~%" (der wff24) '(der wff24)) (print 'DONE)
3,401
Common Lisp
.lisp
94
34.882979
56
0.51311
alejandrozf/derivatives
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
08c48400a899e518e7b0f58ba86ca7932f8d3435b2e92d0a9b57ee760be58b70
24,072
[ -1 ]
24,073
libs.lisp
alejandrozf_derivatives/libs.lisp
;;; ****** P U T P ****** ;;; (PUTP atm ht value) ;;; atm - atom receiving the property ;;; ht - a hash table representing the property ;;; value - the value for the specified atm ;;; Inserts an entry in the hash-table HT for the specified ;;; atm and value. (defun putp (atm ht value ) (setf (gethash atm ht) value) ) ;;; ****** G E T P ****** ;;; (GETP atm ht) ;;; atm - atom receiving the property ;;; ht - a hash table representing the property ;;; Returns the value for atm as the key in the ;;; hash-table HT (defun getp (atm ht) (gethash atm ht) ) ;;; Define the derivative properties for each function (setf DERIVATIVE (make-hash-table)) (putp 'g DERIVATIVE 'derg ) (putp '+ DERIVATIVE 'der+ ) (putp '- DERIVATIVE 'der-) (putp 'U- DERIVATIVE 'derU-) (putp '* DERIVATIVE 'der*) (putp '/ DERIVATIVE 'der/ ) (putp 'sin DERIVATIVE 'dersin) (putp 'cos DERIVATIVE 'dercos)
913
Common Lisp
.lisp
29
29.896552
60
0.656036
alejandrozf/derivatives
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
b2d4e0babe1bc0a8c27671b101540979f02c6ffe6e0738d7af8659beca5b42f8
24,073
[ -1 ]
24,092
cl-rss-gen.lisp
lukaramishvili_cl-rss-gen/cl-rss-gen.lisp
;;;; Copyright 2012, Luka Ramishvili ;;;; 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 Lesser General Public License ;;;; along with this program. If not, see <http://www.gnu.org/licenses/>. (defun rss-skeleton (&key (title "") (link-self "") (link-alt "") (subtitle "") (class "") (updated "") (id "") entries) (cl-who:with-html-output-to-string (*standard-output* nil :prologue "<?xml version=\"1.0\" encoding=\"utf-8\"?>" :indent t) (:feed :xmlns "http://www.w3.org/2005/Atom" :|xmlns:re| "http://purl.org/atompub/rank/1.0" (:title :type "text" title) (:link :rel "self" :href link-self :type "application/atom+xml") (:link :rel "alternate" :href link-alt :type "text/html") (:subtitle subtitle) (:updated updated) (:id id) (cl-who:str entries)))) (defun rss-entry (&key (id "") (title "") (category-scheme "") (categories nil) (author-name "") (author-uri "") (link-alt "") (published "") (updated "") (summary "")) (cl-who:with-html-output-to-string (*standard-output* nil :prologue nil :indent t) (:entry (:id (cl-who:str id)) (:title :type "text" (cl-who:str title)) (loop for cat in categories do (cl-who:htm (:category :scheme category-scheme :term cat))) (:author (:name (cl-who:str author-name)) (:uri (cl-who:str author-uri))) (:link :rel "alternate" :href link-alt) (:published (cl-who:str published)) (:updated (cl-who:str updated)) (:summary :type "html" (cl-who:str summary))))) (defun rss-entries-from-class (objects &key id title category-scheme categories author-name author-uri link-alt published updated summary) "keyword arguments passed (symbols) will be used as slot names" (reduce #'+s (loop for o in objects collecting (let ((arglist nil)) (progn (if id (setf (getf arglist :id) (slot-value o id))) (if title (setf (getf arglist :title) (slot-value o title))) (if category-scheme (setf (getf arglist :category-scheme) (slot-value o category-scheme))) (if categories (setf (getf arglist :categories) (slot-value o categories))) (if author-name (setf (getf arglist :author-name) (slot-value o author-name))) (if author-uri (setf (getf arglist :author-uri) (slot-value o author-uri))) (if link-alt (setf (getf arglist :link-alt) (slot-value o link-alt))) (if published (setf (getf arglist :published) (slot-value o published))) (if updated (setf (getf arglist :updated) (slot-value o updated))) (if summary (setf (getf arglist :summary) (slot-value o summary))) (apply #'rss-entry arglist))))))
3,151
Common Lisp
.lisp
79
36.227848
77
0.668296
lukaramishvili/cl-rss-gen
1
0
0
LGPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
5eacfce82e7af5238f41f29c861459f96938af567776959b9fe9d5a0ff23664b
24,092
[ -1 ]
24,110
TotalLenght..lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/TotalLenght..lsp
(defun C:TOTLEN (/ ss tl n ent itm obj l) (setq ss (ssget) tl 0 n (1- (sslength ss))) (while (>= n 0) (setq ent (entget (setq itm (ssname ss n))) obj (cdr (assoc 0 ent)) l (cond ((= obj "LINE") (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent)))) ((= obj "ARC") (* (cdr (assoc 40 ent)) (if (minusp (setq l (- (cdr (assoc 51 ent)) (cdr (assoc 50 ent))))) (+ pi pi l) l))) ((or (= obj "CIRCLE")(= obj "SPLINE")(= obj "POLYLINE") (= obj "LWPOLYLINE")(= obj "ELLIPSE")) (command "_.area" "_o" itm) (getvar "perimeter")) (T 0)) tl (+ tl l) n (1- n))) (alert (strcat "Total length of selected objects is " (rtos tl))) (princ) )
911
Common Lisp
.l
25
23.88
69
0.406321
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
ee66a4f14e9ca0c3b2c2cf981db387ace8a9e580c7ceaf800c1fd8473454fc9a
24,110
[ -1 ]
24,111
DrawLineWithWidth.lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/DrawLineWithWidth.lsp
(defun C:KSANITARNA () (setvar 'plinewid (GETREAL "PODAJ SREDNICE") ) (setvar 'clayer "NEWLAYER") (command "_pline") (while (> (getvar "CMDACTIVE") 0) (command pause)) (setvar 'plinewid 0) (princ) )
214
Common Lisp
.l
8
23.875
52
0.665025
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
d27d3f7553d29520c9745d27bd241f2e83b279d516353218f84f09bdbe973e4a
24,111
[ -1 ]
24,112
DrawPipeSection.lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/DrawPipeSection.lsp
(defun c:PROFIL ( / *error* ; *error* has to be always localized !!! clay cmde P1 SLOPE DIST x1 y1 z1 P2 P3 PKT P4 x4 y4 z4 P5 x5 y5 z5 P6) (defun *error* (errmsg) (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end")) (princ (strcat "\nError: " errmsg))) (if clay (setvar 'CLAYER clay)) (if cmde (setvar 'CMDECHO cmde)) (princ)) (setq clay (getvar 'clayer) cmde (getvar 'cmdecho) oldsnap (getvar 'osmode)) (setvar 'cmdecho 0) (command "_.-layer" "_t" "IS_inst ks pod plyta" "_m" "IS_inst ks pod plyta" "_c" 30 "" "_u" "IS_inst ks pod plyta" "") ;!!!! change name of layer for more "international" without special text :p (if (and(setq P1 (getpoint "\nSpecify starting point: ")) (setq P4 (getpoint "\n0 point: ")) (setq P5 (getpoint "\nDown level: "))) (while (and (or (setq SLOPE (getreal "\nSlope <new starting point or exit>: ")) (and (setq P1 (getpoint "\nSpecify starting point <exit>: ")) (setq SLOPE (getreal "\nSlope: ")))) (setq DIST (getdist "\nMeasure distance: ")) (setq PKT (getstring "\nPoint_or_45degree: ")) ) (setq x1 (car P1) y1 (cadr P1) z1 (caddr P1)) (setq x4 (car P4) y4 (cadr P4) z4 (caddr P4)) (setq x5 (car P5) y5 (cadr P5) z5 (caddr P5)) (setq P2 (list (- x1 DIST) (- y1 (* DIST (/ SLOPE 100.))) ; be carefull with integers - always at least one must be real to get real as result. (/ 5 2) see what result is. (but SLOPE is always real so you are good in this) z1)) (setq P3 (list (- x1 DIST) y5 z1)) (setq P6 (list (- x1 DIST) y4 z1)) (command "_.-layer" "_t" "IS_inst ks pod plyta" "_m" "IS_inst ks pod plyta" "_c" 30 "" "_u" "IS_inst ks pod plyta" "") ;!!!! change name of layer for more "international" without special text :p (command "pline" "non" P1 "non" P2 "") ;my instalation (command "pline" "non" P2 "non" P3 "") ;draw line down (command "_.-layer" "_t" "Liczby" "_m" "Liczby" "_c" "white" "" "_u" "Liczby" "") (command "_.text" "BC" "_none" P3 50. 0 PKT) ;write text of sanitary point (command "_.-layer" "_t" "IS_ramka" "_m" "IS_ramka" "_c" "white" "" "_u" "IS_ramka" "") (command "_.dimaligned" P2 P3 P3) (command "_.dimaligned" P2 P6 P6) (setq P1 P2) )) (*error* "end") (setvar 'osmode oldsnap) )
2,409
Common Lisp
.l
53
39.943396
203
0.59569
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
7a47c9fc2cc97aea13128ec29d5e208c3ae49b1d3de726d2a09a0fd70363192c
24,112
[ -1 ]
24,113
ClearFileFromLayer.lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/ClearFileFromLayer.lsp
(defun c:CZYSZCZ (/ aDoc name) (setvar 'Clayer "0") (repeat 4 (vla-purgeall (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))))) (vlax-for itm (vla-get-layers aDoc) (if (and (not (wcmatch (setq name (vla-get-name itm)) "*|*")) (not (eq name "0")) (not (member name '("IS_Armatura_pod³¹czeniowa_grz._dolnozas." "IS_Armatura_Therm" "IS_Text_Odbiornikow_Therm" "IS_Grzejniki_Plan_rzutlayer1" "IS_Grzejniki_Plan_rzut" )))) (progn (vla-put-lock itm :vlax-false) (vl-cmdf "_.-laydel" "_N" name "" "_Y")) ) ) (repeat 4 (vla-purgeall aDoc)) (princ) )
973
Common Lisp
.l
29
18.068966
78
0.390476
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
b6274a6a069db42f7efcde623b03a22935a1151ede8665e32159c3bb1171f0d2
24,113
[ -1 ]
24,114
CreateLayersLegend.lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/CreateLayersLegend.lsp
(defun c:WarstwAll (/ pt dat ln) (setq pt (getpoint "\nSelect insertion point: ")) (while (setq dat (tblnext "layer" (null dat))) (entmake (list '(0 . "line") (cons 10 pt) (cons 11 (mapcar '+ pt '(2.5 0 0))) (cons 8 (setq ln (cdr (assoc 2 dat)))))) (entmake (list '(0 . "text") (cons 10 (mapcar '+ pt '(3.0 0 0))) '(40 . 0.1) (cons 1 ln) (cons 8 ln))) (setq pt (mapcar '- pt '(0 0.15 0)))) (princ))
408
Common Lisp
.l
7
56.142857
120
0.569652
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
418b2975121142d6b5ae5bbb65273411d1ae710df7102d69ef26e26cac2ae0d1
24,114
[ -1 ]
24,115
CreateChooseLayersLegend.lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/CreateChooseLayersLegend.lsp
(defun c:WarstwWyb (/ pt rsp dat ln lst desln) (initget "All Select") (setq pt (getpoint "\nSelect insertion point: ")) (initget "Select All") (setq rsp (getkword "\nSpecify option [Select / All] <All>:")) (cond ((= rsp "Select") (mapcar '(lambda (x) (setq pt (somefunc2 pt x))) (progn (acad_strlsort (mapcar '(lambda (x) (and (null (member x lst)) (setq lst (cons x lst)))) (mapcar '(lambda (x) (cdr (assoc 8 (entget x)))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget))))))) lst))) (t (while (setq dat (tblnext "layer" (null dat))) (setq pt (somefunc2 pt (cdr (assoc 2 dat))))))) (princ)) (defun somefunc2 (pt ln / desln) (entmake (list '(0 . "line") (cons 10 pt) (cons 11 (mapcar '+ pt '(2.5 0))) (cons 8 ln))) (entmake (list '(0 . "text") (cons 10 (mapcar '+ pt '(3.0 0))) '(40 . 0.1) (cons 1 ln) (cons 8 ln))) (if (zerop (strlen (setq desln (getpropertyvalue (tblobjname "layer" ln) "Description")))) () (entmake (list '(0 . "text") (cons 10 (mapcar '+ pt '(4.5 0))) '(40 . 0.1) (cons 1 desln) (cons 8 ln)))) (mapcar '- pt '(0 0.15)))
1,214
Common Lisp
.l
20
51.35
111
0.532218
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
54dff29aa45c6659e4f5484154fb46a8e5505446260f8105035e87b2343117fc
24,115
[ -1 ]
24,116
CreateAlphabeticalLayersLegend.lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/CreateAlphabeticalLayersLegend.lsp
(defun c:WarstwyAlf ( / doc lyrs lst pt) (setq doc (vla-get-activedocument (vlax-get-acad-object)) lyrs (vla-get-layers doc) );end_setq (vlax-for lyr lyrs (setq lst (cons (vlax-get lyr 'name) lst))) (setq lst (vl-sort lst '< ) pt (getpoint "\nSelect insertion point: ") );end_setq (foreach lyr lst (entmakex (list '(0 . "line") (cons 10 pt) (cons 11 (mapcar '+ pt '(2.5 0 0))) (cons 8 lyr))) (entmakex (list '(0 . "text") (cons 10 (mapcar '+ pt '(3.0 0 0))) '(40 . 0.1) (cons 1 lyr) (cons 8 lyr))) (setq pt (mapcar '- pt '(0 0.15 0))) );end_foreach (princ) );end_defun
612
Common Lisp
.l
15
36.933333
109
0.593645
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
4853199f3e53be59080bbf8fef64eb1fc018758f4624ba61fede9dcca03a658a
24,116
[ -1 ]
24,117
LispLayers.lsp
PawelKinczyk_AutoLisp-Automatization-For-Work/Scripts/LispLayers.lsp
(defun c:Layers (/ AcObj ActDoc Cntr Pnt0 e l Pnt1 Pnt2 LyrName LyrLType LyrClr) (vl-load-com) (setq AcObj (vlax-get-Acad-Object)) (setq ActDoc (vla-get-ActiveDocument AcObj)) (vla-EndUndoMark ActDoc) (vla-StartUndoMark ActDoc) (setq Cntr -1) (setq Pnt0 (trans (getpoint "\nBase point")1 0)) (command "_.-style" "LyrNameTxt" "romans.shx" 110 0.8 0 "n" "n" "n") (while (and (setq Lyr (tblnext "LAYER" (null Lyr))) (setq LyrName (cdr (assoc 2 Lyr))) (setq LyrLType (cdr (assoc 6 Lyr))) (setq LyrClr (cdr (assoc 62 Lyr))) ) (if (and (setq Pnt1 (list (+ (car pnt0) 8000) (cadr pnt0) (caddr pnt0))) (setq Pnt2 (list (+ (car pnt0) 8200) (+ (cadr pnt0) 0) (caddr pnt0))) ) (progn (LyrLnType LyrLType LyrName Pnt0 Pnt1 Pnt2 LyrClr) (setq Pnt0 (list (car pnt0) (+ (cadr pnt0) -600) (caddr pnt0))) ) ) (vla-EndUndoMark ActDoc) ) (princ "\n RFTRec.lsp ~ Copyright © by HasanCAD") (princ "\n ...Type LAYERS to Invoke... ") (princ) ) ; q_|_|| _\|| q_|| _\| ; ; Mainroutine End ; ; q_|_|| _\|| q_|| _\| ; ; Subroutine Start ; (defun LyrLnType (LyrLType LyrName Pnt0 Pnt1 Pnt2 LyrClr / ) (entmakex (list (cons 0 "LINE") (cons 6 LyrLType) (cons 8 LyrName) (cons 10 Pnt0) (cons 11 Pnt1) (cons 62 LyrClr) )) (entmakex (list (cons 0 "TEXT") (cons 1 LyrName) (cons 7 "LyrNameTxt") (cons 8 LyrName) (cons 10 Pnt2) (cons 11 Pnt2) (cons 40 220) (cons 41 0. (cons 62 LyrClr) (cons 72 0) (cons 73 2) )) ) ; q_|_|| _\|| q_|| _\| ; ; Subroutine End ;
1,721
Common Lisp
.l
64
22.453125
71
0.55252
PawelKinczyk/AutoLisp-Automatization-For-Work
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
72826613112351e8461655d969278dfab9573c2b272d222d23719bd807b3f7f7
24,117
[ -1 ]
24,140
testframework.lisp
nathangeffen_simple-common-lisp-test-suite/testframework.lisp
; Simple Common Lisp test package :cl-test-suite ; version 1.0 May 2012 ; ; This is a simple generic test package. ; ; Programmer: Nathan Geffen (C) 2012. Licenced under GPL version ; 3.0. See below. ; ; Email queries to nathangeffen at quackdown.info ; ; Exported procedures: ; ; add-test-case - adds a test case to a test suite list, where each ; test case is a an entry in the list ; ; run-tests - takes a test-suite as a parameter, as well as two ; optional parameters to indicate output verbosity, ; and returns the number of failures and number of ; tests. ; ; Six assert functions are supplied for convenience. Failure messages ; are printed if the assertions are not true. ; asserteq - true if the first parameter is equal to the second ; parameter. ; ; assertne - true if the first parameter is not equal to the second ; parameter. ; ; assertge - true if the first parameter is >= the second parameter. ; ; assertgt - true if the first parameter is > the second parameter. ; ; assertle - true if the first parameter is <= the second parameter. ; ; assertlt - true if the first parameter is less than the second ; parameter. ; ; test-this-package - runs a series of tests to see that this test ; suite is working. The function should return ; (0 . 8).; ; ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-test-suite) (defmacro add-test-case (test-function parameter-list result-function expected-value &optional test-suite) "Macro to add a single test-case to a list of test-cases. Parameters: test-function - the function that is being tested parameter-list - list of parameters to the testfunction result-function - a function to apply to the result expected-value - the value you expect (result-function (test-function parameter-list)) to be test-suite - the list containing the test cases (an optional field) The macro returns the test-suite with the new test-case in the car position. If test-suite is not passed, then it just returns the new test-case. E.g: (add-test-case #'cadr ('(1 2 3 4 5 6)) #'identity 2 mytests)" (let* ((copy-test-suite test-suite) (new-test `(cons (list :test-function ,test-function :parameters (list ,@parameter-list) :result-function ,result-function :expected ,expected-value) ,copy-test-suite))) (if copy-test-suite `(setq ,copy-test-suite ,new-test) new-test))) (defun single-test-case (test-function parameters result-function expected) "This applies the function, test-function, with the parameters, test-parameters. It then applies result-function to the result. If the output of that equals test-expected then a list whose first parameter is true is returned (as a list), else nil is returned along with the actual result." (let ((result (funcall result-function (apply test-function parameters)))) (list (equal result expected) result expected))) (defun run-tests (test-cases &optional (verbose t) (failure-messages t)) "This runs a suite of tests defined in the test-cases parameter. Parameters: test-cases - list of cases to test (it's easiest to create these using the add-test-case macro) verbose - optional boolean that if true outputs success messages and final summary messages (defaults to t) failure-messages - optional boolean that if true outputs failure messages (defaults to t)" (let ((num-test-cases 0) (failures 0)) (dolist (test (map 'list (lambda (test-case) (single-test-case (getf test-case :test-function) (getf test-case :parameters) (getf test-case :result-function) (getf test-case :expected))) test-cases)) (when (not (car test)) (setf failures (1+ failures)) (if failure-messages (format t "Test ~D failed. Got ~a. Expected ~a.~%" num-test-cases (nth 1 test) (nth 2 test)))) (setf num-test-cases (1+ num-test-cases))) (if verbose (format t "Test cases: ~D. Failures ~D.~%" num-test-cases failures)) (cons failures num-test-cases))) (defun asserteq (value expected) "Returns true if value = expected else outputs message and returns nil." (if (not (equal value expected)) (progn (format t "ASSERTEQ Error: Got ~a. But expected ~a." value expected) nil) t)) (defun assertne (value expected) "Returns true if value <> expected else outputs message and returns nil." (if (equal value expected) (progn (format t "ASSERTNE Error: Values match but should not: ~a." value) nil) t)) (defun assertgt (value expected) "Returns true if value > expected else outputs message and returns nil." (if (not (> value expected)) (progn (format t "ASSERTGT Error: Values match but should not: ~a." value) nil) t)) (defun assertge (value expected) "Returns true if value >= expected else outputs message and returns nil." (if (not (>= value expected)) (progn (format t "ASSERTGT Error: Values match but should not: ~a." value) nil) t)) (defun assertlt (value expected) "Returns true if value < expected else outputs message and returns nil." (if (not (< value expected)) (progn (format t "ASSERTLT Error: Values match but should not: ~a." value) nil) t)) (defun assertle (value expected) "Returns true if value <= expected else outputs message and returns nil." (if (not (<= value expected)) (progn (format t "ASSERTLE Error: Values match but should not: ~a." value) nil) t)) (defun test-this-package () "Test cases for this package" (let ((test-suite nil) (failures 0) (num-tests 0)) (format t "********************************************~%") (format t "Test package for Simple Lisp Test Framework.~%") (format t "--------------------------------------------~%") ; This should pass. (add-test-case #'car ('(a b c d e f)) #'identity 'a test-suite) ; This should pass too. (add-test-case #'apply ('+ (list 2 3 4)) #'identity '9 test-suite) ; This should fail. The actual is 9. (add-test-case #'apply ('+ (list 2 3 4)) #'identity '7 test-suite) ; This should pass. (add-test-case #'map ('list '+ (list 2 3 4) (list 10 11 12)) #'car '12 test-suite) ; Assert that there has been one failure. (if (asserteq (car (run-tests test-suite nil nil)) 1) (format t "Passed run-tests on standard test cases.~%") (progn (format t "Failed run-tests on standard cases.~%") (incf failures))) (incf num-tests) ; Assert that there have been four tests. (if (asserteq (cdr (run-tests (reverse test-suite) nil nil) ) 4) (format t "Passed run-tests in reverse test.~%") (progn (format t "Failed run-tests in reverse test.~%") (incf failures))) (incf num-tests) ; Assert that has not been 5 tests (if (assertne (cdr (run-tests (reverse test-suite) nil nil) ) 5) (format t "Passed run-tests in reverse test.~%") (progn (format t "Failed run-tests in reverse test.~%") (incf failures))) (incf num-tests) ; Assert that there have been greater than equal to four tests (if (assertge (cdr (run-tests (reverse test-suite) nil nil) ) 4) (format t "Passed assertge test.~%") (progn (format t "Failed assertge test.~%") (incf failures))) (incf num-tests) ; Assert that there have been less than equal to four tests (if (assertle (cdr (run-tests (reverse test-suite) nil nil) ) 4) (format t "Passed assertle test.~%") (progn (format t "Failed assertle test.~%") (incf failures))) (incf num-tests) ; Assert that there have been less than five tests (if (assertgt (cdr (run-tests (reverse test-suite) nil nil) ) 3) (format t "Passed assertgt test.~%") (progn (format t "Failed assertgt test.") (incf failures))) (incf num-tests) ; Assert that there have been more than three tests (if (assertlt (cdr (run-tests (reverse test-suite) nil nil) ) 5) (format t "Passed assertlt test.~%") (progn (format t "Failed assertlt test.~%") (incf failures))) (incf num-tests) ; Test that run-tests works without optional test-suite parameter. (if (asserteq (car (run-tests (add-test-case #'apply ('+ (list 2 3 4)) #'identity '9) nil nil)) 0) (format t "Passed run-tests called without test-suite parm.~%") (progn (format t "Failed run-tests called without test-suite parm.~%") (incf failures))) (incf num-tests) (format t "Ran ~D tests. ~D failures.~%" num-tests failures) (format t "********************************************~%") (cons failures num-tests)))
10,778
Common Lisp
.lisp
266
32.030075
77
0.586059
nathangeffen/simple-common-lisp-test-suite
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
1d16ba2bc96554fbcae6fbb8bb6ffbd5457d9c93b060acc21860b2776a21592b
24,140
[ -1 ]
24,141
packages.lisp
nathangeffen_simple-common-lisp-test-suite/packages.lisp
; Simple Common Lisp test package :cl-test-suite ; version 1.0 May 2012 ; ; This is a simple generic test package. ; ; Programmer: Nathan Geffen (C) 2012. ; ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-user) (defpackage :cl-test-suite (:nicknames :test-suite) (:use :common-lisp) (:export :add-test-case :run-tests :asserteq :assertne :assertge :assertgt :assertle :assertlt :test-this-package))
1,096
Common Lisp
.lisp
32
30.28125
71
0.707707
nathangeffen/simple-common-lisp-test-suite
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
aba3e9748e028859cabe3dc3b30a68c6c8578f449848b64eaaa4870ffb9c1ae5
24,141
[ -1 ]
24,159
package.lisp
rudolfochrist_jasql/package.lisp
;;;; package.lisp (defpackage #:jasql (:use :cl) (:export #:load-sql #:sql #:docstring ;; adapter protocol #:insert-returning #:insert-update-delete #:insert-update-delete-many #:execute-script #:select-one-row #:select #:paramaters))
274
Common Lisp
.lisp
15
14.666667
30
0.649805
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
094f85e44f0d071d564c8bed3db061918903428ab02eca126d334c818a4ac317
24,159
[ -1 ]
24,160
init.lisp
rudolfochrist_jasql/init.lisp
(require 'asdf) #+sbcl (require 'sb-aclrepl) (asdf:initialize-source-registry '(:source-registry (:directory (:here)) (:tree (:here "vendor/")) (:tree (:here "systems/")) :inherit-configuration))
210
Common Lisp
.lisp
8
23.5
32
0.671642
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
265594c5e9996cb9c2f915797ab1747d883147a126f1eda39dd12b486aa0f420
24,160
[ -1 ]
24,161
sqlite.lisp
rudolfochrist_jasql/t/sqlite.lisp
;;;; sqlite.lisp (defpackage #:jasql.sqlite.test (:use :cl :fiveam :fiveam-matchers :jasql.sqlite)) (in-package #:jasql.sqlite.test) (in-suite* :jasql.sqlite.test) (defparameter *test-db-path* (asdf:system-relative-pathname "jasql" "t/test.sqlite3")) (defparameter *test-db* (make-handle :path *test-db-path*)) (defun count-users () (sqlite:with-open-database (db (path *test-db*)) (sqlite:execute-single db "select count(*) from users;"))) ;;; fixtures (defmacro with-test-db (() &body body) `(unwind-protect (progn (create-test-db) ,@body) (when (probe-file *test-db-path*) (delete-file *test-db-path*)))) ;;; tests (jasql:load-sql "t/sqlite-test.sql" :system "jasql.sqlite") (defun create-test-db () (create-users-table *test-db*)) (test test-insert-many (with-test-db () (bulk-insert-users *test-db* (list :username "foo" :firstname "Deborah" :lastname "Miller") (list :username "pfm" :firstname "Percy" :lastname "Miller") (list :username "src" :firstname "Sebastian" :lastname "Christ")) (assert-that (count-users) (equal-to 3)))) (test test-insert-returning (with-test-db () (let* ((id (insert-user-returning *test-db* :username "lol" :firstname "Bob" :lastname "Bobbins")) (user (sqlite:with-open-database (db (path *test-db*)) (sqlite:execute-to-list db "select * from users where _id = ?" id)))) (assert-that (fourth (first user)) (equal-to "Bobbins"))))) (test test-insert-delete (with-test-db () (let ((count (count-users)) (frank (insert-user-returning *test-db* :username "frank"))) (assert-that (count-users) (equal-to (incf count))) (delete-user *test-db* :id frank) (assert-that (count-users) (equal-to (decf count)))))) (defun user-firstname (id) (sqlite:with-open-database (db (path *test-db*)) (sqlite:execute-single db "select firstname from users where _id = ?" id))) (test test-update-user (with-test-db () (let ((id (insert-user-returning *test-db* :username "cool" :firstname "McCool"))) (update-name *test-db* :id id :firstname "SuperCool") (assert-that (user-firstname id) (equal-to "SuperCool"))))) (test test-get-single-user (with-test-db () (assert-that (type-of (first (get-single-user *test-db* :id 1))) (is-not (equal-to 'cons))))) (test test-get-all-by-last-name (with-test-db () (bulk-insert-users *test-db* (list :username "foo" :firstname "Deborah" :lastname "Miller") (list :username "pfm" :firstname "Percy" :lastname "Miller") (list :username "src" :firstname "Sebastian" :lastname "Christ")) (assert-that (length (get-all-by-lastname *test-db* :lastname "Miller")) (equal-to 2)))) (test test-transactions (with-test-db () (ignore-errors (sqlite:with-open-database (db (path *test-db*)) (sqlite:with-transaction db (insert-user db :username "foo") (insert-user db :username "foo")))) (assert-that (count-users) (equal-to 0))))
3,242
Common Lisp
.lisp
76
35.421053
97
0.611217
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
15cd65ead8ffc5b3aa8fc83a208e4531eea490a16977f72d0454591c3fe6cd03
24,161
[ -1 ]
24,162
postgres.lisp
rudolfochrist_jasql/t/postgres.lisp
;;;; postgres.lisp (defpackage #:jasql.postgres.test (:use :cl :fiveam :fiveam-matchers :jasql :jasql.postgres)) (in-package #:jasql.postgres.test) (in-suite* :jasql.postgres.test) (defvar *test-db* (make-handle :database "jasqltest" :username "jasql" :host :unix)) (defun count-users (&optional db) (with-postmodern-connection (or db *test-db*) (pomo:query "select count (*) from users;" :single))) ;;; fixtures (defmacro with-test-db (() &body body) `(progn (create-users-table *test-db*) (unwind-protect (progn ,@body) (with-postmodern-connection *test-db* (pomo:drop-table 'users :if-exists t :cascade t))))) ;;; tests (jasql:load-sql "t/postgres-test.sql" :system "jasql.postgres") (test test-insert-many (with-test-db () (bulk-insert-users *test-db* (list :username "foo" :firstname "Deborah" :lastname "Miller") (list :username "pfm" :firstname "Percy" :lastname "Miller") (list :username "src" :firstname "Sebastian" :lastname "Christ")) (assert-that (count-users) (equal-to 3)))) (pomo:defprepared user-for-id "select lastname from users where _id = $1" :row) (test test-insert-returning (with-test-db () (let* ((id (insert-user-returning *test-db* :username "lol" :firstname "Bob" :lastname "Bobbins")) (user (with-postmodern-connection *test-db* (user-for-id id)))) (assert-that (first user) (equal-to "Bobbins"))))) (test test-insert-delete (with-test-db () (let ((count (count-users)) (id (insert-user-returning *test-db* :username "frank"))) (assert-that (count-users) (equal-to (incf count))) (delete-user *test-db* :id id) (assert-that (count-users) (equal-to (decf count)))))) (test test-update-user (with-test-db () (let* ((id (insert-user-returning *test-db* :username "cool" :lastname "McCool"))) (update-name *test-db* :id id :lastname "SuperCool") (assert-that (first (with-postmodern-connection *test-db* (user-for-id id))) (equal-to "SuperCool"))))) (test test-get-single-user (with-test-db () (insert-user *test-db* :username "foo") (assert-that (type-of (first (get-single-user *test-db* :id 1))) (is-not (equal-to 'cons))))) (test test-get-all-by-last-name (with-test-db () (bulk-insert-users *test-db* (list :username "foo" :firstname "Deborah" :lastname "Miller") (list :username "pfm" :firstname "Percy" :lastname "Miller") (list :username "src" :firstname "Sebastian" :lastname "Christ")) (assert-that (length (get-all-by-lastname *test-db* :lastname "Miller")) (equal-to 2)))) (test test-transactions (with-test-db () (with-postmodern-connection *test-db* (pomo:with-transaction () (insert-user *test-db* :username "foo") (insert-user *test-db* :username "foo"))) (assert-that (count-users) (equal-to 0))))
3,132
Common Lisp
.lisp
76
33.736842
86
0.605541
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
e127ff989ccc73d2086fee48abf971af621cac52c5664e5bf1748f6bbfbf76fb
24,162
[ -1 ]
24,163
protocol.lisp
rudolfochrist_jasql/adapters/protocol.lisp
;;;; protocol.lisp (in-package #:jasql) (defgeneric insert-returning (db sql &optional parameters) (:documentation "Run INSERT statement and return auto-generated value. An auto-generated value can be the (e.g.) ID of the last inserted value.")) (defgeneric insert-update-delete (db sql &optional parameters) (:documentation "Run an INSERT/UPDATE/DELETE statement.")) (defgeneric insert-update-delete-many (db sql &optional parameters-list) (:documentation "Run an INSERT/UPDATE/DELETE statement in bulk. PARAMETERS-LIST is a list of parameters that would have been passed to `insert-update-delete'.")) (defgeneric execute-script (db sql) (:documentation "Run SQL without any variable substitution.")) (defgeneric select-one-row (db sql &optional parameters) (:documentation "Run SELECT and return a single row.")) (defgeneric select (db sql &optional parameters) (:documentation "Run SELECT statement."))
938
Common Lisp
.lisp
19
46.684211
72
0.778024
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
1945c691205a928dd51e45f22e241d42b0b1382b356e214b7563999d9546745d
24,163
[ -1 ]
24,164
sqlite.lisp
rudolfochrist_jasql/adapters/sqlite.lisp
;;;; sqlite.lisp (defpackage #:jasql.sqlite (:use :cl #:jasql) (:import-from #:sqlite #:with-transaction #:with-open-database) (:export #:sqlite-handle #:path #:busy-timeout #:make-handle)) (in-package #:jasql.sqlite) (defclass sqlite-handle () ((path :initarg :path :accessor path :documentation "Path to the SQLite database.") (busy-timeout :initarg :busy-timeout :initform 5000 :accessor busy-timeout :documentation "Busy timeout for this connection.")) (:documentation "Wraps a database connection to a SQLite database.")) (defun make-handle (&key path busy-timeout) "Create a fresh database handle" (make-instance 'sqlite-handle :path path :busy-timeout busy-timeout)) (defun escape-parameters (params) (labels ((recu (params result) (cond ((null params) (reverse result)) ((keywordp (first params)) (recu (rest params) (cons (format nil ":~A" (string-downcase (string (first params)))) result))) ((consp (first params)) (recu (rest params) (cons (recu (first params) '()) result))) (t (recu (rest params) (cons (first params) result)))))) (recu params '()))) (defmacro with-escaped-parameters ((parameters) &body body) (let ((gparams (gensym "params"))) `(let* ((,gparams (escape-parameters ,parameters)) (,(intern (symbol-name parameters)) ,gparams)) ,@body))) (defmethod insert-returning ((handle sqlite-handle) sql &optional parameters) (with-open-database (db (path handle) :busy-timeout (busy-timeout handle)) (with-transaction db (insert-returning db sql parameters)))) (defmethod insert-returning ((handle sqlite:sqlite-handle) sql &optional parameters) (with-escaped-parameters (parameters) (apply #'sqlite:execute-non-query/named handle sql parameters)) (sqlite:last-insert-rowid handle)) (defmethod insert-update-delete ((handle sqlite-handle) sql &optional parameters) (with-open-database (db (path handle) :busy-timeout (busy-timeout handle)) (insert-update-delete db sql parameters))) (defmethod insert-update-delete ((handle sqlite:sqlite-handle) sql &optional parameters) (with-escaped-parameters (parameters) (apply #'sqlite:execute-non-query/named handle sql parameters))) (defmethod insert-update-delete-many ((handle sqlite-handle) sql &optional parameters-list) (with-open-database (db (path handle) :busy-timeout (busy-timeout handle)) (with-transaction db (insert-update-delete-many db sql parameters-list)))) (defmethod insert-update-delete-many ((handle sqlite:sqlite-handle) sql &optional parameters-list) (with-escaped-parameters (parameters-list) (loop for parameters in parameters-list do (apply #'sqlite:execute-non-query/named handle sql parameters)))) (defmethod execute-script ((handle sqlite-handle) sql) (with-open-database (db (path handle) :busy-timeout (busy-timeout handle)) (execute-script db sql))) (defmethod execute-script ((handle sqlite:sqlite-handle) sql) (sqlite:execute-non-query handle sql)) (defun make-keyword (string) (let ((symbol-name (nstring-upcase string))) (or (find-symbol symbol-name :keyword) (intern symbol-name :keyword)))) (defmethod select-one-row ((handle sqlite-handle) sql &optional parameters) (with-open-database (db (path handle) :busy-timeout (busy-timeout handle)) (select-one-row db sql parameters))) (defmethod select-one-row ((handle sqlite:sqlite-handle) sql &optional parameters) (with-escaped-parameters (parameters) (let* ((query (sqlite:prepare-statement handle sql)) (fields (mapcar #'make-keyword (sqlite:statement-column-names query)))) (loop for (pn pv) on parameters by #'cddr do (sqlite:bind-parameter query pn pv)) (when (sqlite:step-statement query) (loop for field in fields for i from 0 nconc (list field (sqlite:statement-column-value query i))))))) (defmethod select ((handle sqlite-handle) sql &optional parameters) (with-open-database (db (path handle) :busy-timeout (busy-timeout handle)) (select db sql parameters))) (defmethod select ((handle sqlite:sqlite-handle) sql &optional parameters) (with-escaped-parameters (parameters) (let* ((query (sqlite:prepare-statement handle sql)) (fields (mapcar #'make-keyword (sqlite:statement-column-names query)))) (loop for (pn pv) on parameters by #'cddr do (sqlite:bind-parameter query pn pv)) (loop for row = (sqlite:step-statement query) while row collect (loop for field in fields for i from 0 nconc (list field (sqlite:statement-column-value query i)))))))
4,964
Common Lisp
.lisp
101
41.633663
98
0.669907
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
d23cf08965675bc36ba6a46737a1680ab019162571355020ef2d98adb5835515
24,164
[ -1 ]
24,165
postgres.lisp
rudolfochrist_jasql/adapters/postgres.lisp
;;;; postgres.lisp (defpackage #:jasql.postgres (:use :cl #:jasql) (:import-from #:postmodern #:query #:prepare) (:export #:postgres-handle #:with-postmodern-connection #:spec #:make-handle)) (in-package #:jasql.postgres) (defclass postgres-handle () ((database :initarg :database :accessor psql-database :documentation "The database name.") (username :initarg :username :initform "postgres" :accessor psql-username :documentation "Username to use for this database connection.") (password :initarg :password :initform "" :accessor psql-password :documentation "Password to use for this database connection.") (host :initarg :host :initform "localhost" :accessor psql-host :documentation "The database host. Use `:unix' to use unix domain sockets. See postmodern documentation for more information") (port :initarg :port :initform 5432 :accessor psql-port :documentation "Post to use for this database connection.") (pooled-p :initarg :pooled-p :initform nil :accessor psql-pooled-p :documentation "Use pooled connection. See postmodern documentation for more information.") (use-ssl :initarg :use-ssl :initform :try :accessor psql-use-ssl :documentation "Use SSL.") (service :initarg :service :initform "postgres" :accessor psql-service :documentation "Service name.") (application-name :initarg :application-name :initform "" :accessor psql-application-name :documentation "Application name") (use-binary :initarg :use-binary :initform nil :accessor psql-use-binary :documentation "User binary protocol for communication.")) (:documentation "Wraps a connection to a PostgreSQL database.")) (defmethod print-object ((handle postgres-handle) stream) (with-accessors ((db psql-database) (role psql-username)) handle (print-unreadable-object (handle stream :type t) (format stream "~A>~A" db role)))) (defun make-handle (&key database (username "postgres") (password "") (host "localhost") (port 5432) pooled-p (use-ssl :try) (service "") (application-name "") use-binary) "Create a fresh database handle" (make-instance 'postgres-handle :database database :username username :password password :host host :port port :pooled-p pooled-p :use-ssl use-ssl :service service :application-name application-name :use-binary use-binary)) (defmethod spec ((db postgres-handle)) "Build a postmodern connection specification for the `postgres-handle' DB." (with-accessors ((database psql-database) (username psql-username) (password psql-password) (host psql-host) (port psql-port) (pooled-p psql-pooled-p) (use-ssl psql-use-ssl) (service psql-service) (application-name psql-application-name) (use-binary psql-use-binary)) db `(,database ,username ,password ,host :port ,port :pooled-p ,pooled-p :use-ssl ,use-ssl :service ,service :application-name ,application-name :use-binary ,use-binary))) (defmacro with-postmodern-connection (db &body body) "Establish a connection to the database DB." `(unless (and pomo:*database* (pomo:connected-p pomo:*database*)) (postmodern:call-with-connection (spec ,db) (lambda () ,@body)))) (defvar *terminals* (list #\Space #\Tab #\Newline #\, #\; #\( #\))) (defun terminalp (char) (member char *terminals*)) (defun make-keyword (string) (intern (string-upcase string) :keyword)) (defun make-string-buffer () (make-array '(0) :element-type 'base-char :fill-pointer 0 :adjustable t)) (defun process-sql (sql) (let ((fstr (make-string-buffer))) (with-output-to-string (s fstr) (loop with mapping = '() with placeholderp = nil with placeholder = nil with num = 1 for c across sql when (eql c #\:) do (setf placeholderp t placeholder (make-string-buffer)) when (and placeholderp (terminalp c)) do (progn (setf placeholderp nil) (push (cons num (make-keyword placeholder)) mapping) (format s "$~D" num) (incf num)) if placeholderp do (unless (eql c #\:) ; skip : (vector-push-extend c placeholder)) else do (write-char c s) finally (return (values fstr (sort mapping #'< :key #'car))))))) (defmacro with-prepared-statement ((statement args) (sql parameters &optional format) &body body) (let ((gstmt (gensym "stmt")) (granking (gensym "ranking"))) `(multiple-value-bind (,gstmt ,granking) (process-sql ,sql) (let ((,statement (prepare ,gstmt ,(when format `,format))) (,args (mapcar (lambda (rank) (getf ,parameters (cdr rank))) ,granking))) ,@body)))) ;;; protocol implementation (defmethod insert-returning ((db postgres-handle) sql &optional parameters) (with-postmodern-connection db (with-prepared-statement (func params) (sql parameters :single) (apply func params)))) (defmethod insert-update-delete ((db postgres-handle) sql &optional parameters) (with-postmodern-connection db (with-prepared-statement (func params) (sql parameters :none) (apply func params)))) (defmethod insert-update-delete-many ((db postgres-handle) sql &optional parameters-list) (with-postmodern-connection db (loop for parameters in parameters-list do (with-prepared-statement (func params) (sql parameters :none) (apply func params))))) (defmethod execute-script ((db postgres-handle) sql) (with-postmodern-connection db (query sql))) (defmethod select-one-row ((db postgres-handle) sql &optional parameters) (with-postmodern-connection db (with-prepared-statement (func params) (sql parameters :plist) (apply func params)))) (defmethod select ((db postgres-handle) sql &optional parameters) (with-postmodern-connection db (with-prepared-statement (func params) (sql parameters :plists) (apply func params))))
7,263
Common Lisp
.lisp
182
28.752747
97
0.574876
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
cc8adb14a8e04dfbaeab58adce072e8ac05be576444c76e903467117e0901870
24,165
[ -1 ]
24,166
documentation.lisp
rudolfochrist_jasql/doc/documentation.lisp
(asdf:load-systems "sb-texinfo" "jasql" "jasql.sqlite" "jasql.postgres") (sb-texinfo:document-packages (list :jasql :jasql.sqlite :jasql.postgres) "jasql" :output-file "doc/dict.texi" :standalone nil :write-backmatter nil :write-menu nil :exclude-node t)
318
Common Lisp
.lisp
4
62.75
100
0.617363
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
4604f700d7862b91965b22012c94f9692a32eaa040522ff5673f3a09395e34be
24,166
[ -1 ]
24,167
jasql.postgres.asd
rudolfochrist_jasql/jasql.postgres.asd
;;;; jasql.postgres.asd (defsystem "jasql.postgres" :author "Sebastian Christ <[email protected]>" :maintainer "Sebastian Christ <[email protected]>" :license "MPL-2.0" :homepage "https://github.com/rudolfochrist/jasql" :version (:read-file-line "version") :depends-on ("cl+ssl" "postmodern" "jasql" "cl-ppcre") :pathname "adapters/" :components ((:file "postgres")) :description "PostgreSQL adadpter for jasql." :long-description #.(uiop:read-file-string (uiop:subpathname *load-pathname* "README.org")) :in-order-to ((test-op (test-op jasql.postgres/test)))) (defsystem "jasql.postgres/test" :depends-on ("uiop" "fiveam" "fiveam-matchers" "jasql.postgres") :pathname "t/" :components ((:file "postgres") (:static-file "postrges-test.sql")) :perform (test-op (op c) (unless (uiop:symbol-call :fiveam :run! :jasql.postgres.test) #-(or slynk swank) (error "Tests faild."))))
1,090
Common Lisp
.asd
30
28.333333
81
0.597538
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
7fb9a2b8719d9c8611f2cebebe9c7e9406e31a88c7fd865c7a38db0ea60ff8cd
24,167
[ -1 ]
24,168
jasql.asd
rudolfochrist_jasql/jasql.asd
;;;; jasql.asd (defsystem "jasql" :author "Sebastian Christ <[email protected]>" :maintainer "Sebastian Christ <[email protected]>" :mailto "[email protected]" :license "MPL-2.0" :homepage "https://github.com/rudolfochrist/jasql" :bug-tracker "https://github.com/rudolfochrist/jasql/issues" :source-control (:git "https://github.com/rudolfochrist/jasql.git") :version (:read-file-line "version") :depends-on ("cl-ppcre" (:require "uiop")) :components ((:file "package") (:file "jasql") (:module "adapters" :components ((:file "protocol")))) :description "Simple SQL in Common Lisp. A direct port of Python's anosql." :long-description #.(uiop:read-file-string (uiop:subpathname *load-pathname* "README.org")))
812
Common Lisp
.asd
20
34.95
77
0.659924
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
d003d6972f6bfb5f003468adc92e3087711e7b1c576c08b3442283e50e133b23
24,168
[ -1 ]
24,169
jasql.sqlite.asd
rudolfochrist_jasql/jasql.sqlite.asd
;;;; jasql.sqlite.asd (defsystem "jasql.sqlite" :author "Sebastian Christ <[email protected]>" :maintainer "Sebastian Christ <[email protected]>" :license "MPL-2.0" :homepage "https://github.com/rudolfochrist/jasql" :version (:read-file-line "version") :depends-on ("sqlite" "jasql") :pathname "adapters/" :components ((:file "sqlite")) :description "Use jasql with SQLite." :long-description #.(uiop:read-file-string (uiop:subpathname *load-pathname* "README.org")) :in-order-to ((test-op (load-op "jasql.sqlite/test"))) :perform (test-op (op c) (unless (uiop:symbol-call :5am :run! :jasql.sqlite.test) #-(or swank slynk) (error "Tests failed.")))) (defsystem "jasql.sqlite/test" :depends-on ("uiop" "fiveam" "fiveam-matchers" "jasql.sqlite") :pathname "t/" :components ((:file "sqlite") (:static-file "test.sql")))
1,005
Common Lisp
.asd
28
28.392857
76
0.598352
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
c479eb6fb147e0b24e2ec14cd85c28f00ff0654d8b548c53ec6a227c09a50ee5
24,169
[ -1 ]
24,175
Makefile
rudolfochrist_jasql/Makefile
# jasql include config.mk .PHONY: clean: -rm -f **/*.fasl -rm -f doc/dict.texi -rm -rf doc/include/ .PHONY: info: jasql.info jasql.info: doc/jasql.texi doc/dict.texi $(MAKEINFO) $(srcdir)/doc/jasql.texi doc/dict.texi: $(SRCS) $(LISP) $(LISPFLAGS) \ --load init.lisp \ --load doc/documentation.lisp .PHONY: check: $(LISP) $(LISPFLAGS) \ --load init.lisp \ --eval '(asdf:test-system "jasql.sqlite")' \ --eval '(asdf:test-system "jasql.postgres")'
462
Common Lisp
.l
21
20.190476
45
0.689655
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
45091bb9f45d7de0cd13eba422ec5fefded33b35723d53b68fa9467e519398c3
24,175
[ -1 ]
24,176
jasql.info
rudolfochrist_jasql/jasql.info
This is jasql.info, produced by makeinfo version 7.1 from jasql.texi. This manual is for jasql (version 0.9.0 , last updated "25 September 2024") Copyright © 2020 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". INFO-DIR-SECTION Software Development START-INFO-DIR-ENTRY * jasql (jasql). Simple SQL in Common Lisp. END-INFO-DIR-ENTRY  File: jasql.info, Node: Top, Next: Defining Queries, Up: (dir) jasql Manual 0.9.0 ****************** This manual is for jasql (version 0.9.0 , last updated "25 September 2024") Copyright © 2020 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". * Menu: * Defining Queries:: * Loading Queries:: * Query Name Semantics:: * Directory:: * GNU Free Documentation License:: * Concept Index:: * Variable Index:: * Function and Macro Index:: * Type Index:: -- The Detailed Node Listing -- Query Name Semantics * Insert returning with <!:: * Insert/Update/Delete with !:: * Bulk operations with *!:: * Execute script with #:: * Select one with ?::  File: jasql.info, Node: Defining Queries, Next: Loading Queries, Prev: Top, Up: Top 1 Defining Queries ****************** Each SQL query (or script) that should be used from you application must have a ‘-- name:’ comment right above the actual query. This name is also used as the function name in your Lisp image. Here's an example query definition: -- name: get-all-articles -- Retrieve all articles. select * from articles ; Every comment between the ‘--name:’ token and the actual SQL query is transformed into the function's docstring.  File: jasql.info, Node: Loading Queries, Next: Query Name Semantics, Prev: Defining Queries, Up: Top 2 Loading Queries ***************** To load the queries into your Lisp image and generate functions for it, use *note load-sql: Macro load-sql. (jasql:load-sql "path/to/sql" :system "blog")  File: jasql.info, Node: Query Name Semantics, Next: Directory, Prev: Loading Queries, Up: Top 3 Query Name Semantics ********************** A query's name can have several suffixes with different semantics about the queries. ‘jasql’ determines how a query should be executes on the basis of that suffix. Without any suffix the statement is a ‘select’ statement returning possibly multiple rows. * Menu: * Insert returning with <!:: * Insert/Update/Delete with !:: * Bulk operations with *!:: * Execute script with #:: * Select one with ?::  File: jasql.info, Node: Insert returning with <!, Next: Insert/Update/Delete with !, Up: Query Name Semantics 3.1 Insert returning with ‘<!’ ============================== A name ending with ‘<!’ defines an insert that returns a specific value. Mostly this is used to return some generated value by the database, such as ‘lastrowid’ (for SQLite). -- name: add-new-article<! -- Inserts a new article and returns the ID. INSERT INTO articles (title, author, content) VALUES (:title, :author, :content) ; PostgesSQL however allows multiple values to be returned with the ‘returning’ clause: -- name: add-new-article<! -- Inserts an new article and returns ID and title. insert into articles (title, author, content) values (:title, :author, :content) returning _id, title ;  File: jasql.info, Node: Insert/Update/Delete with !, Next: Bulk operations with *!, Prev: Insert returning with <!, Up: Query Name Semantics 3.2 Insert/Update/Delete with ‘!’ ================================= Any operation of ‘insert’, ‘update’ or ‘delete’ must have a ‘!’ suffix. They don't return anything. -- name: insert-article-for-src! -- Insert an article with src as author INSERT INTO articles (title, author, content) VALUES (:title, 'src', :content) ; Or with delete: -- name: delete-article! -- Deletes an article DELETE FROM articles WHERE article_id = :article_id ;  File: jasql.info, Node: Bulk operations with *!, Next: Execute script with #, Prev: Insert/Update/Delete with !, Up: Query Name Semantics 3.3 Bulk operations with ‘*!’ ============================= For statements that insert/update/delete many values use the ‘*!’ suffix. The generated function expected a list of lists of arguments. -- name: delete-many*! -- Delete a bunch of articles DELETE FROM articles WHERE article_id = :article_id ; And on the lisp side, execute the function like this: (delete-many *db* '((:article_id 5) (:article_id 24) (:article_id 43) (:article_id 334)))  File: jasql.info, Node: Execute script with #, Next: Select one with ?, Prev: Bulk operations with *!, Up: Query Name Semantics 3.4 Execute script with ‘#’ =========================== Sometimes a statements doesn't take any parameters (e.g. ‘create table’) then use the ‘#’ suffix. -- name: create-articles-table# -- Creates the articles table CREATE TABLE articles ( article_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, author TEXT NOT NULL, content TEXT NOT NULL ) ;  File: jasql.info, Node: Select one with ?, Prev: Execute script with #, Up: Query Name Semantics 3.5 Select one with ‘?’ ======================= Sometimes a query produces a single result. Every query with a ‘?’ suffix returns a single row.  File: jasql.info, Node: Directory, Next: GNU Free Documentation License, Prev: Query Name Semantics, Up: Top 4 Directory *********** -- Generic Function: execute-script db sql Run ‘sql’ without any variable substitution. -- Generic Function: insert-update-delete db sql &optional parameters Run an ‘insert/update/delete’ statement. -- Generic Function: insert-update-delete-many db sql &optional parameters-list Run an ‘insert/update/delete’ statement in bulk. ‘parameters-list’ is a list of parameters that would have been passed to 'insert-update-delete'. -- Macro: load-sql path &key system Load ‘sql’ and generate ‘db’ access functions. ‘path’ is either a ‘sql’ file or a directory that contains ‘sql’ files. If ‘path’ is relative, it is assumed to be relative to ‘system’. -- Function: docstring symbol Return docstring of ‘symbol’. -- Generic Function: insert-returning db sql &optional parameters Run ‘insert’ statement and return auto-generated value. An auto-generated value can be the (e.g.) ‘id’ of the last inserted value. -- Function: paramaters symbol Parameters used in ‘sql’ for ‘symbol’. -- Generic Function: select db sql &optional parameters Run ‘select’ statement. -- Generic Function: select-one-row db sql &optional parameters Run ‘select’ and return a single row. -- Function: sql symbol Return ‘sql’ used by ‘symbol’. -- Class: sqlite-handle Class precedence list: ‘sqlite-handle, standard-object, t’ Slots: • ‘path’ -- initarg: ‘:path’; reader: ‘jasql.sqlite:path’; writer: ‘(setf jasql.sqlite:path)’ Path to the SQLite database. • ‘busy-timeout’ -- initarg: ‘:busy-timeout’; reader: ‘jasql.sqlite:busy-timeout’; writer: ‘(setf jasql.sqlite:busy-timeout)’ Busy timeout for this connection. Wraps a database connection to a SQLite database. -- Function: make-handle &key path busy-timeout Create a fresh database handle -- Class: postgres-handle Class precedence list: ‘postgres-handle, standard-object, t’ Slots: • ‘database’ -- initarg: ‘:database’; reader: ‘jasql.postgres::psql-database’; writer: ‘(setf jasql.postgres::psql-database)’ The database name. • ‘username’ -- initarg: ‘:username’; reader: ‘jasql.postgres::psql-username’; writer: ‘(setf jasql.postgres::psql-username)’ Username to use for this database connection. • ‘password’ -- initarg: ‘:password’; reader: ‘jasql.postgres::psql-password’; writer: ‘(setf jasql.postgres::psql-password)’ Password to use for this database connection. • ‘host’ -- initarg: ‘:host’; reader: ‘jasql.postgres::psql-host’; writer: ‘(setf jasql.postgres::psql-host)’ The database host. Use ':unix' to use unix domain sockets. See postmodern documentation for more information • ‘port’ -- initarg: ‘:port’; reader: ‘jasql.postgres::psql-port’; writer: ‘(setf jasql.postgres::psql-port)’ Post to use for this database connection. • ‘pooled-p’ -- initarg: ‘:pooled-p’; reader: ‘jasql.postgres::psql-pooled-p’; writer: ‘(setf jasql.postgres::psql-pooled-p)’ Use pooled connection. See postmodern documentation for more information. • ‘use-ssl’ -- initarg: ‘:use-ssl’; reader: ‘jasql.postgres::psql-use-ssl’; writer: ‘(setf jasql.postgres::psql-use-ssl)’ Use ‘ssl’. • ‘service’ -- initarg: ‘:service’; reader: ‘jasql.postgres::psql-service’; writer: ‘(setf jasql.postgres::psql-service)’ Service name. • ‘application-name’ -- initarg: ‘:application-name’; reader: ‘jasql.postgres::psql-application-name’; writer: ‘(setf jasql.postgres::psql-application-name)’ Application name • ‘use-binary’ -- initarg: ‘:use-binary’; reader: ‘jasql.postgres::psql-use-binary’; writer: ‘(setf jasql.postgres::psql-use-binary)’ User binary protocol for communication. Wraps a connection to a PostgreSQL database. -- Macro: with-postmodern-connection db &body body Establish a connection to the database ‘db’. -- Function: make-handle &key database username password host port pooled-p use-ssl service application-name use-binary Create a fresh database handle  File: jasql.info, Node: GNU Free Documentation License, Next: Concept Index, Prev: Directory, Up: Top Appendix A GNU Free Documentation License ***************************************** GNU Free Documentation License Version 1.3, 3 November 2008 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 1. PREAMBLE The purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. 1. APPLICABILITY AND DEFINITIONS This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque". Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. The "publisher" means any person or entity that distributes copies of the Document to the public. A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. 1. VERBATIM COPYING You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. 1. COPYING IN QUANTITY If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. 1. MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. C. State on the Title page the name of the publisher of the Modified Version, as the publisher. D. Preserve all the copyright notices of the Document. E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. H. Include an unaltered copy of this License. I. Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. J. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. K. For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. M. Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version. N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section. O. Preserve any Warranty Disclaimers. If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties-for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. 1. COMBINING DOCUMENTS You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements". 1. COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. 1. AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate. 1. TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. 1. TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License. However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it. 1. FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See <https://www.gnu.org/licenses/>. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Document. 1. RELICENSING "Massive Multiauthor Collaboration Site" (or "MMC Site") means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A "Massive Multiauthor Collaboration" (or "MMC") contained in the site means any set of copyrightable works thus published on the MMC site. "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization. "Incorporate" means to publish or republish a Document, in whole or in part, as part of another Document. An MMC is "eligible for relicensing" if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008. The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing. ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: Copyright (c) YEAR YOUR NAME. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this: with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.  File: jasql.info, Node: Concept Index, Next: Variable Index, Prev: GNU Free Documentation License, Up: Top B Concept Index *************** [index] * Menu: * -name:: Defining Queries. (line 6) * -name: <1>: Query Name Semantics. (line 6) * !: Insert/Update/Delete with !. (line 6) * ?: Select one with ?. (line 6) * *!: Bulk operations with *!. (line 6) * #: Execute script with #. (line 6) * <!: Insert returning with <!. (line 6) * bulk operation: Bulk operations with *!. (line 6) * Defining Queries: Defining Queries. (line 6) * execute script: Execute script with #. (line 6) * insert returning: Insert returning with <!. (line 6) * insert update delete many: Insert/Update/Delete with !. (line 6) * insert update delete many <1>: Bulk operations with *!. (line 6) * Loading queries: Loading Queries. (line 6) * naming semantics: Query Name Semantics. (line 6) * select: Query Name Semantics. (line 6) * select on row: Select one with ?. (line 6) * SQL: Defining Queries. (line 6)  File: jasql.info, Node: Variable Index, Next: Function and Macro Index, Prev: Concept Index, Up: Top C Variable Index ****************  File: jasql.info, Node: Function and Macro Index, Next: Type Index, Prev: Variable Index, Up: Top D Function and Macro Index ************************** [index] * Menu: * docstring: Directory. (line 26) * docstring <1>: Directory. (line 26) * execute-script: Directory. (line 6) * execute-script <1>: Directory. (line 6) * insert-returning: Directory. (line 29) * insert-returning <1>: Directory. (line 29) * insert-update-delete: Directory. (line 9) * insert-update-delete <1>: Directory. (line 9) * insert-update-delete-many: Directory. (line 12) * insert-update-delete-many <1>: Directory. (line 12) * load-sql: Directory. (line 19) * load-sql <1>: Directory. (line 19) * make-handle: Directory. (line 63) * make-handle <1>: Directory. (line 63) * make-handle <2>: Directory. (line 128) * make-handle <3>: Directory. (line 128) * paramaters: Directory. (line 35) * paramaters <1>: Directory. (line 35) * select: Directory. (line 38) * select <1>: Directory. (line 38) * select-one-row: Directory. (line 41) * select-one-row <1>: Directory. (line 41) * sql: Directory. (line 44) * sql <1>: Directory. (line 44) * with-postmodern-connection: Directory. (line 125) * with-postmodern-connection <1>: Directory. (line 125)  File: jasql.info, Node: Type Index, Prev: Function and Macro Index, Up: Top E Type Index ************ [index] * Menu: * postgres-handle: Directory. (line 66) * postgres-handle <1>: Directory. (line 66) * sqlite-handle: Directory. (line 47) * sqlite-handle <1>: Directory. (line 47)  Tag Table: Node: Top731 Node: Defining Queries1769 Node: Loading Queries2362 Node: Query Name Semantics2668 Node: Insert returning with <!3229 Node: Insert/Update/Delete with !4105 Node: Bulk operations with *!4780 Node: Execute script with #5455 Node: Select one with ?6019 Node: Directory6277 Ref: Generic-Function execute-script6418 Ref: Generic-Function insert-update-delete6517 Ref: Generic-Function insert-update-delete-many6639 Ref: Macro load-sql6901 Ref: Function docstring7173 Ref: Generic-Function insert-returning7244 Ref: Function paramaters7468 Ref: Generic-Function select7553 Ref: Generic-Function select-one-row7644 Ref: Function sql7757 Ref: Class jasql.sqlite:sqlite-handle7827 Ref: Function jasql.sqlite:make-handle8377 Ref: Class jasql.postgres:postgres-handle8463 Ref: Macro jasql.postgres:with-postmodern-connection10899 Ref: Function jasql.postgres:make-handle11006 Node: GNU Free Documentation License11174 Node: Concept Index34359 Node: Variable Index36314 Node: Function and Macro Index36457 Node: Type Index38537  End Tag Table  Local Variables: coding: utf-8 End:
40,089
Common Lisp
.l
720
51.565278
144
0.726665
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
0ce498fae2eb6c7354680b1603a36d5d87defce17938d597342bf0a7bcb06495
24,176
[ -1 ]
24,178
sqlite-test.sql
rudolfochrist_jasql/t/sqlite-test.sql
-- name: create-users-table# -- Create the users table create table users ( _id integer primary key autoincrement, username text not NULL unique, firstname text, lastname text ) ; -- name: bulk-insert-users*! -- Insert many users insert into users ( username, firstname, lastname ) values ( :username, :firstname, :lastname ) ; -- name: insert-user-returning<! -- Insert a user insert into users ( username, firstname, lastname ) values ( :username, :firstname, :lastname ) ; -- name: insert-user! -- Insert a user insert into users ( username, firstname, lastname ) values ( :username, :firstname, :lastname ) ; -- name: update-name! -- Updates a user's name update users set firstname = :firstname, lastname = :lastname where _id = :id ; -- name: delete-user! -- Delete user with id delete from users where _id = :id ; -- name: get-single-user? -- Return single user select _id, username, firstname, lastname from users where _id = :id ; -- name: get-all-by-lastname -- List all users with the same lastname select username, firstname, lastname from users where lastname = :lastname ;
1,144
Common Lisp
.l
79
12.759494
41
0.739583
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
8e59ec505a49b104e7e2220b7a4c8c9753676a423ac8183d5200d807f06e96be
24,178
[ -1 ]
24,180
postgres-test.sql
rudolfochrist_jasql/t/postgres-test.sql
-- name: create-users-table# -- Create the users table create table users ( _id serial primary key, username text not NULL unique, firstname text, lastname text ) ; -- name: bulk-insert-users*! -- Insert many users insert into users ( username, firstname, lastname ) values ( :username, :firstname, :lastname ) ; -- name: insert-user-returning<! -- Insert a user insert into users ( username, firstname, lastname ) values ( :username, :firstname, :lastname ) returning _id ; -- name: insert-user! -- Insert a user insert into users ( username, firstname, lastname ) values ( :username, :firstname, :lastname ) ; -- name: update-name! -- Updates a user's name update users set firstname = :firstname, lastname = :lastname where _id = :id ; -- name: delete-user! -- Delete user with id delete from users where _id = :id ; -- name: get-single-user? -- Return single user select _id, username, firstname, lastname from users where _id = :id ; -- name: get-all-by-lastname -- List all users with the same lastname select username, firstname, lastname from users where lastname = :lastname ;
1,143
Common Lisp
.l
80
12.575
41
0.73814
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
b26d293de8910bdf6a82171eb7362c83667da8cefa8cbf2e6cfe67891c4986af
24,180
[ -1 ]
24,186
jasql.texi
rudolfochrist_jasql/doc/jasql.texi
\input texinfo @c -*- texinfo -*- @c %**start of header @setfilename jasql.info @settitle jasql Manual 0.9.0 @documentencoding UTF-8 @documentlanguage en @c ------------------------------------------- @c MACHINE GENERATED FILE! DON'T EDIT BY HAND. @c ------------------------------------------- @c %**end of header @copying This manual is for jasql (version 0.9.0 , last updated ``25 September 2024'') Copyright @copyright{} 2020 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. @end quotation @end copying @dircategory Software Development @direntry * jasql (jasql). Simple SQL in Common Lisp. @end direntry @finalout @titlepage @title jasql Manual 0.9.0 @author Sebastian Christ (@email{rudolfo.christ@@pm.me}) @page @vskip 0pt plus 1filll @insertcopying @end titlepage @contents @ifnottex @node Top @top jasql Manual 0.9.0 @insertcopying @end ifnottex @menu * Defining Queries:: * Loading Queries:: * Query Name Semantics:: * Directory:: * GNU Free Documentation License:: * Concept Index:: * Variable Index:: * Function and Macro Index:: * Type Index:: @detailmenu --- The Detailed Node Listing --- Query Name Semantics * Insert returning with @code{<!}:: * Insert/Update/Delete with @code{!}:: * Bulk operations with @code{*!}:: * Execute script with @code{#}:: * Select one with @code{?}:: @end detailmenu @end menu @node Defining Queries @chapter Defining Queries @cindex Defining Queries @cindex --name: @cindex SQL Each SQL query (or script) that should be used from you application must have a @samp{-- name:} comment right above the actual query. This name is also used as the function name in your Lisp image. Here's an example query definition: @example -- name: get-all-articles -- Retrieve all articles. select * from articles ; @end example Every comment between the @samp{--name:} token and the actual SQL query is transformed into the function's docstring. @node Loading Queries @chapter Loading Queries @cindex Loading queries To load the queries into your Lisp image and generate functions for it, use @ref{Macro load-sql,,load-sql}. @lisp (jasql:load-sql "path/to/sql" :system "blog") @end lisp @node Query Name Semantics @chapter Query Name Semantics @cindex --name: @cindex naming semantics @cindex select A query's name can have several suffixes with different semantics about the queries. @samp{jasql} determines how a query should be executes on the basis of that suffix. Without any suffix the statement is a @code{select} statement returning possibly multiple rows. @menu * Insert returning with @code{<!}:: * Insert/Update/Delete with @code{!}:: * Bulk operations with @code{*!}:: * Execute script with @code{#}:: * Select one with @code{?}:: @end menu @node Insert returning with @code{<!} @section Insert returning with @code{<!} @cindex insert returning @cindex <! A name ending with @code{<!} defines an insert that returns a specific value. Mostly this is used to return some generated value by the database, such as @samp{lastrowid} (for SQLite). @example -- name: add-new-article<! -- Inserts a new article and returns the ID. INSERT INTO articles (title, author, content) VALUES (:title, :author, :content) ; @end example PostgesSQL however allows multiple values to be returned with the @code{returning} clause: @example -- name: add-new-article<! -- Inserts an new article and returns ID and title. insert into articles (title, author, content) values (:title, :author, :content) returning _id, title ; @end example @node Insert/Update/Delete with @code{!} @section Insert/Update/Delete with @code{!} @cindex insert update delete many @cindex ! Any operation of @code{insert}, @code{update} or @code{delete} must have a @samp{!} suffix. They don't return anything. @example -- name: insert-article-for-src! -- Insert an article with src as author INSERT INTO articles (title, author, content) VALUES (:title, 'src', :content) ; @end example Or with delete: @example -- name: delete-article! -- Deletes an article DELETE FROM articles WHERE article_id = :article_id ; @end example @node Bulk operations with @code{*!} @section Bulk operations with @code{*!} @cindex insert update delete many @cindex *! @cindex bulk operation For statements that insert/update/delete many values use the @code{*!} suffix. The generated function expected a list of lists of arguments. @example -- name: delete-many*! -- Delete a bunch of articles DELETE FROM articles WHERE article_id = :article_id ; @end example And on the lisp side, execute the function like this: @lisp (delete-many *db* '((:article_id 5) (:article_id 24) (:article_id 43) (:article_id 334))) @end lisp @node Execute script with @code{#} @section Execute script with @code{#} @cindex execute script @cindex # Sometimes a statements doesn't take any parameters (e.g. @code{create table}) then use the @code{#} suffix. @example -- name: create-articles-table# -- Creates the articles table CREATE TABLE articles ( article_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, author TEXT NOT NULL, content TEXT NOT NULL ) ; @end example @node Select one with @code{?} @section Select one with @code{?} @cindex select on row @cindex ? Sometimes a query produces a single result. Every query with a @code{?} suffix returns a single row. @node Directory @chapter Directory @include dict.texi @node GNU Free Documentation License @appendix GNU Free Documentation License GNU Free Documentation License Version 1.3, 3 November 2008 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. @uref{https://fsf.org/} Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @enumerate @item PREAMBLE @end enumerate The purpose of this License is to make a manual, textbook, or other functional and useful document ``free'' in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of ``copyleft'', which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. @enumerate @item APPLICABILITY AND DEFINITIONS @end enumerate This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The ``Document'', below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as ``you''. You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A ``Modified Version'' of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A ``Secondary Section'' is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The ``Invariant Sections'' are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The ``Cover Texts'' are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A ``Transparent'' copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not ``Transparent'' is called ``Opaque''. Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, @LaTeX{} input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG@. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The ``Title Page'' means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, ``Title Page'' means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. The ``publisher'' means any person or entity that distributes copies of the Document to the public. A section ``Entitled XYZ'' means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as ``Acknowledgements'', ``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title'' of such a section when you modify the Document means that it remains a section ``Entitled XYZ'' according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. @enumerate @item VERBATIM COPYING @end enumerate You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. @enumerate @item COPYING IN QUANTITY @end enumerate If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. @enumerate @item MODIFICATIONS @end enumerate You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: A@. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. B@. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. C@. State on the Title page the name of the publisher of the Modified Version, as the publisher. D@. Preserve all the copyright notices of the Document. E@. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. F@. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. G@. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. H@. Include an unaltered copy of this License. I@. Preserve the section Entitled ``History'', Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled ``History'' in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. J@. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the ``History'' section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. K@. For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. L@. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. M@. Delete any section Entitled ``Endorsements''. Such a section may not be included in the Modified Version. N@. Do not retitle any existing section to be Entitled ``Endorsements'' or to conflict in title with any Invariant Section. O@. Preserve any Warranty Disclaimers. If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled ``Endorsements'', provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. @enumerate @item COMBINING DOCUMENTS @end enumerate You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled ``History'' in the various original documents, forming one section Entitled ``History''; likewise combine any sections Entitled ``Acknowledgements'', and any sections Entitled ``Dedications''. You must delete all sections Entitled ``Endorsements''. @enumerate @item COLLECTIONS OF DOCUMENTS @end enumerate You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. @enumerate @item AGGREGATION WITH INDEPENDENT WORKS @end enumerate A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an ``aggregate'' if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate. @enumerate @item TRANSLATION @end enumerate Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled ``Acknowledgements'', ``Dedications'', or ``History'', the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. @enumerate @item TERMINATION @end enumerate You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License. However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it. @enumerate @item FUTURE REVISIONS OF THIS LICENSE @end enumerate The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See @uref{https://www.gnu.org/licenses/}. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License ``or any later version'' applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Document. @enumerate @item RELICENSING @end enumerate ``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A ``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the site means any set of copyrightable works thus published on the MMC site. ``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization. ``Incorporate'' means to publish or republish a Document, in whole or in part, as part of another Document. An MMC is ``eligible for relicensing'' if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008. The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing. ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: Copyright (c) YEAR YOUR NAME@. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the ``with@dots{}Texts.'' line with this: with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST@. If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software. @node Concept Index @chapter Concept Index @printindex cp @node Variable Index @chapter Variable Index @printindex vr @node Function and Macro Index @chapter Function and Macro Index @printindex fn @node Type Index @chapter Type Index @printindex tp @bye
29,346
Common Lisp
.l
621
45.975845
120
0.808159
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
9a874a3b024faa9acae6195f08ba086410dc6e86125a63942a96372fa879a143
24,186
[ -1 ]
24,187
jasql.org
rudolfochrist_jasql/doc/jasql.org
# -*- mode: org; -*- #+MACRO: version (eval (with-temp-buffer (insert-file-contents-literally "../version" nil) (buffer-substring-no-properties (point-min) (point-max)))) #+STARTUP: content #+TITLE: jasql Manual {{{version}}} #+AUTHOR: Sebastian Christ #+EMAIL: [email protected] #+OPTIONS: ':t author:t email:t toc:t #+TEXINFO_HEADER: @c ------------------------------------------- #+TEXINFO_HEADER: @c MACHINE GENERATED FILE! DON'T EDIT BY HAND. #+TEXINFO_HEADER: @c ------------------------------------------- #+TEXINFO_DIR_CATEGORY: Software Development #+TEXINFO_DIR_TITLE: jasql (jasql) #+TEXINFO_DIR_DESC: Simple SQL in Common Lisp #+TEXINFO: @insertcopying * Legalese :PROPERTIES: :COPYING: t :END: This manual is for jasql (version {{{version}}}, last updated {{{modification-time("%d %B %4Y")}}}) Copyright @@texinfo:@copyright{}@@ 2020 Free Software Foundation, Inc. #+begin_quote Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". #+end_quote * Defining Queries #+CINDEX: Defining Queries #+CINDEX: --name: #+CINDEX: SQL Each SQL query (or script) that should be used from you application must have a =-- name:= comment right above the actual query. This name is also used as the function name in your Lisp image. Here's an example query definition: #+begin_src sql -- name: get-all-articles -- Retrieve all articles. select * from articles ; #+end_src Every comment between the =--name:= token and the actual SQL query is transformed into the function's docstring. * Loading Queries #+CINDEX: Loading queries To load the queries into your Lisp image and generate functions for it, use [[texiref:Macro load-sql][load-sql]]. #+begin_src lisp (jasql:load-sql "path/to/sql" :system "blog") #+end_src * Query Name Semantics #+cindex: --name: #+cindex: naming semantics #+cindex: select A query's name can have several suffixes with different semantics about the queries. =jasql= determines how a query should be executes on the basis of that suffix. Without any suffix the statement is a ~select~ statement returning possibly multiple rows. ** Insert returning with ~<!~ #+cindex: insert returning #+cindex: <! A name ending with ~<!~ defines an insert that returns a specific value. Mostly this is used to return some generated value by the database, such as =lastrowid= (for SQLite). #+begin_src sql -- name: add-new-article<! -- Inserts a new article and returns the ID. INSERT INTO articles (title, author, content) VALUES (:title, :author, :content) ; #+end_src PostgesSQL however allows multiple values to be returned with the ~returning~ clause: #+begin_src sql -- name: add-new-article<! -- Inserts an new article and returns ID and title. insert into articles (title, author, content) values (:title, :author, :content) returning _id, title ; #+end_src ** Insert/Update/Delete with ~!~ #+cindex: insert update delete many #+cindex: ! Any operation of ~insert~, ~update~ or ~delete~ must have a =!= suffix. They don't return anything. #+begin_src sql -- name: insert-article-for-src! -- Insert an article with src as author INSERT INTO articles (title, author, content) VALUES (:title, 'src', :content) ; #+end_src Or with delete: #+begin_src sql -- name: delete-article! -- Deletes an article DELETE FROM articles WHERE article_id = :article_id ; #+end_src ** Bulk operations with ~*!~ #+cindex: insert update delete many #+cindex: *! #+cindex: bulk operation For statements that insert/update/delete many values use the ~*!~ suffix. The generated function expected a list of lists of arguments. #+begin_src sql -- name: delete-many*! -- Delete a bunch of articles DELETE FROM articles WHERE article_id = :article_id ; #+end_src And on the lisp side, execute the function like this: #+begin_src lisp (delete-many ,*db* '((:article_id 5) (:article_id 24) (:article_id 43) (:article_id 334))) #+end_src ** Execute script with ~#~ #+cindex: execute script #+cindex: # Sometimes a statements doesn't take any parameters (e.g. ~create table~) then use the ~#~ suffix. #+begin_src sql -- name: create-articles-table# -- Creates the articles table CREATE TABLE articles ( article_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, author TEXT NOT NULL, content TEXT NOT NULL ) ; #+end_src ** Select one with ~?~ #+cindex: select on row #+cindex: ? Sometimes a query produces a single result. Every query with a ~?~ suffix returns a single row. * Directory #+TEXINFO: @include dict.texi * GNU Free Documentation License :PROPERTIES: :APPENDIX: t :END: GNU Free Documentation License Version 1.3, 3 November 2008 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 0. PREAMBLE The purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. 1. APPLICABILITY AND DEFINITIONS This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque". Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. The "publisher" means any person or entity that distributes copies of the Document to the public. A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. 2. VERBATIM COPYING You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. 3. COPYING IN QUANTITY If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. 4. MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. C. State on the Title page the name of the publisher of the Modified Version, as the publisher. D. Preserve all the copyright notices of the Document. E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. H. Include an unaltered copy of this License. I. Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. J. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. K. For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. M. Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version. N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section. O. Preserve any Warranty Disclaimers. If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. 5. COMBINING DOCUMENTS You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements". 6. COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. 7. AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate. 8. TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. 9. TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License. However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it. 10. FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See https://www.gnu.org/licenses/. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Document. 11. RELICENSING "Massive Multiauthor Collaboration Site" (or "MMC Site") means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A "Massive Multiauthor Collaboration" (or "MMC") contained in the site means any set of copyrightable works thus published on the MMC site. "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization. "Incorporate" means to publish or republish a Document, in whole or in part, as part of another Document. An MMC is "eligible for relicensing" if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008. The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing. ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: Copyright (c) YEAR YOUR NAME. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this: with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software. * Concept Index :PROPERTIES: :INDEX: cp :END: * Variable Index :PROPERTIES: :INDEX: vr :END: * Function and Macro Index :PROPERTIES: :INDEX: fn :END: * Type Index :PROPERTIES: :INDEX: tp :END:
27,850
Common Lisp
.l
541
50.18854
149
0.807828
rudolfochrist/jasql
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
eafbe07071ea957fa70e1e7cbffcc28cc470d363d9acbc4fced4c62c328222ae
24,187
[ -1 ]
24,202
scratch.lisp
jobez_verdad/scratch.lisp
(ql:quickload :cffi) (cffi:defcallback on-keydown :bool ((viewer :pointer) (key :char) (modifier :int)) (princ key)) (ecl-set-keydown-cb (cffi:callback on-keydown)) (ecl-to-matrixXd 8 3 #(0.0 0.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 1.0 1.0 0.0 1.0 1.0 1.0)) (ecl-to-matrixXi 12 3 #(1 7 5 1 3 7 1 4 3 1 2 4 3 8 7 3 4 8 5 7 8 5 8 6 1 5 6 1 6 2 2 6 8 2 8 4)) (ecl-set-mesh) (ecl-start-igl-viewer)
873
Common Lisp
.lisp
30
13.066667
47
0.310633
jobez/verdad
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
fb31d4c118a0ba1b08f8a1004318574da277a1c2e06f8f5411d470397d3adbac
24,202
[ -1 ]
24,203
init.lisp
jobez_verdad/init.lisp
(time (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))) (when (probe-file quicklisp-init) (load quicklisp-init)))) (load (asdf/system:system-relative-pathname :swank "start-swank.lisp") :verbose t)
303
Common Lisp
.lisp
7
32.857143
71
0.6
jobez/verdad
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
a5d60766a8890360d3889ea513e467efb7972429f7f346d427fe5ad93e878811
24,203
[ -1 ]
24,204
ecl-root.cc.lisp
jobez_verdad/gen/ecl-root.cc.lisp
(use-package :cm-ifs) (load "helpers.lisp") (with-interface (ecl-root) (include <ecl/ecl.h>) (include <chrono>) (include <iostream>) (include <fstream>) (include "myigl.h") (implementation-only (include "ecl-helpers.h") ) (namespace 'ecl-root (function initialize-ecl ((int argc) (char* argv[])) -> void (cl_boot argc argv) (atexit cl_shutdown) (#:myigl::load-ecl-bindings) (load-embed-lisp "init.lisp") ;; (decl ((#:std::chrono::high_resolution_clock::time-point start = (#:std::chrono::high_resolution_clock::now)))) ;; (load-shen) ;; (decl ((#:std::chrono::high_resolution_clock::time-point end = (#:std::chrono::high_resolution_clock::now)))) ;; (<< #:std::cout "shen is ready" #:std::endl) ;; (decl ((auto duration = ((instantiate #:std::chrono::duration_cast (#:std::chrono::microseconds) ) ;; (- end start)) ;; ))) ;; (<< #:std::cout (duration.count) #:std::endl) )))
1,060
Common Lisp
.lisp
29
30.965517
119
0.557073
jobez/verdad
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
d4203a25dab541af5f773ad52a6d2295cdfb084a49a98fcc22b76cc919a21e1f
24,204
[ -1 ]
24,205
ecl-helpers.cc.lisp
jobez_verdad/gen/ecl-helpers.cc.lisp
; -*- mode: Lisp; eval: (cm-mode 1); -*- (use-package :cm-ifs) (load "helpers.lisp") (with-interface (ecl-helpers) (include <ecl/ecl.h>) (include <iostream>) (include <fstream>) (include "cl_bridge_utils.hpp") (namespace 'ecl-helpers ;; (function cl-str-to-str ((cl_object cl-str)) ;; -> #:std::string ;; (decl ((int j = cl-str->string.dim) ;; (ecl_character* selv = cl-str->string.self) ;; (#:std::string str {""})) ;; (for ((int i = 0) ;; (< i j) ;; (set i (+ i 1))) ;; ;; (set str (+ str (+ selv i))) ;; (inject-syntax "str += (*(selv+i));")) ;; (return str))) (function call-lisp ((const #:std:string &call)) -> void (cl_eval (c_string_to_object (call.c_str))))))
809
Common Lisp
.lisp
25
28.28
58
0.500645
jobez/verdad
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
2355785780d6d9210789a6a7e753c7f5f7ee31b28986d2917923b3c096a794e5
24,205
[ -1 ]
24,206
main.cc.lisp
jobez_verdad/gen/main.cc.lisp
; -*- mode: Lisp; eval: (cm-mode 1); -*- (include "cl_bridge_utils.hpp") (include "ecl-root.h") (function main ((int argc) (char *argv[])) -> int (#:ecl-root::initialize-ecl argc argv) (while 1 ))
226
Common Lisp
.lisp
9
20.888889
40
0.562791
jobez/verdad
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
da1227eb8494731f420ca592bdcfa4305168e6afb278f2f70042538d39d74289
24,206
[ -1 ]
24,207
myigl.cc.lisp
jobez_verdad/gen/myigl.cc.lisp
(use-package :cm-ifs) (load "helpers") (with-interface (myigl) (include <igl/viewer/Viewer.h>) (include "cl_bridge_utils.hpp") (typedef bool (fpointer keydown-cb ((#:igl::viewer::Viewer& viewer) (unsigned char key) (int modifier)))) (namespace 'myigl (implementation-only (decl ((#:igl::viewer::Viewer viewer) (#:Eigen::MatrixXd V) (#:Eigen::MatrixXi F)) (gen-ecl-wrapper (function to-matrixXd ((cl_obj rows) (cl_obj columns) (cl_object verts)) -> void (decl ((int rowz = (rows.to_int)) (int colz = (columns.to_int)) (#:Eigen::MatrixXd (v rowz colz))) (for ((int row = 0) (<= row (- rowz 1)) ++row) (for ((int col = 0) (<= col (- colz 1)) ++col) (decl ((int index = (+ (* row colz) col))) (set (v row col) (ecl_to_double (ecl_aref1 verts index)))))) (set V v)))) (gen-ecl-wrapper (function to-matrixXi ((cl_obj rows) (cl_obj columns) (cl_object verts)) -> void (decl ((int rowz = (rows.to_int)) (int colz = (columns.to_int)) (#:Eigen::MatrixXi (f rowz colz))) (for ((int row = 0) (<= row (- rowz 1)) ++row) (for ((int col = 0) (<= col (- colz 1)) ++col) (decl ((int index = (+ (* row colz) col))) (set (f row col) (ecl_to_int (ecl_aref1 verts index)))))) (set F (- (f.array) 1))))) (function array-to-matrixXd ((int rows) (int columns) (double verts[])) -> #:Eigen::MatrixXd (decl ((#:Eigen::MatrixXd (v rows columns))) (for ((int row = 0) (<= row (- rows 1)) ++row) (for ((int col = 0) (<= col (- columns 1)) ++col) (decl ((int index = (+ (* row columns) col))) (cprint index) (set (v row col) verts[index])))) (return v))) (function array-to-matrixXi ((int rows) (int columns) (int faces[])) -> #:Eigen::MatrixXi (decl ((#:Eigen::MatrixXi (f rows columns))) (for ((int row = 0) (<= row (- rows 1)) ++row) (for ((int col = 0) (<= col (- columns 1)) ++col) (decl ((int index = (+ (* row columns) col))) (cprint index) (set (f row col) faces[index])))) (return f))) (function key-down ((#:igl::viewer::Viewer& viewer) (unsigned char key) (int modifier)) -> bool (when (== key (char-code #\1)) (viewer.core.align_camera_center V F) (cprint "hey")) (return false))) (gen-ecl-wrapper (function set-mesh () -> void (viewer.data.clear()) (viewer.data.set_mesh V F) (viewer.data.set_face_based true))) (gen-ecl-wrapper (function set-keydown-cb ((cl-object on-keydown-cb)) -> void (set viewer.callback_key_down (cast keydown-cb (ecl-foreign-data-pointer-safe on-keydown-cb))))) (gen-ecl-wrapper (function start-igl-viewer () -> int (cprint V) (cprint F) (viewer.launch)))) (make-ecl-loader)))
3,786
Common Lisp
.lisp
111
21.387387
67
0.425294
jobez/verdad
1
0
0
MPL-2.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
1b448c9fc40364232abddf277c182e50eeec2f103b4d7ddcb55d3c83866501cc
24,207
[ -1 ]
24,208
main.lisp
icot_cl-ciph/tests/main.lisp
(defpackage cl-ciph/tests/main (:use :cl :cl-ciph :rove)) (in-package :cl-ciph/tests/main) ;; NOTE: To run this test file, execute `(asdf:test-system :cl-ciph)' in your Lisp. (deftest test-target-1 (testing "should (= 1 1) to be true" (ok (= 1 1))))
276
Common Lisp
.lisp
9
26.777778
83
0.630189
icot/cl-ciph
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
9de97c05dcb9f30c5dbc4d85097ae4fcd2105526d1a0e801bac0a92e27334d52
24,208
[ -1 ]
24,209
cl-ciph.asd
icot_cl-ciph/cl-ciph.asd
(defsystem "cl-ciph" :version "0.1.1" :author "icot" :license "GPLv3" :depends-on ("str" "uiop" "unix-opts") :components ((:module "src" :components ((:file "main")))) :description "" :in-order-to ((test-op (test-op "cl-ciph/tests")))) (defsystem "cl-ciph/tests" :author "icot" :license "GPLv3" :depends-on ("cl-ciph" "rove") :components ((:module "tests" :components ((:file "main")))) :description "Test system for cl-ciph" :perform (test-op (op c) (symbol-call :rove :run c))) ;(asdf:defsystem :system-name ;... ;:build-operation "asdf:program-op" ;:build-pathname "my-exe-name-relative-to-the-source-directory" ;:entry-point "my-package:my-launch-function") ;(sb-ext:save-lisp-and-die "myprog" :toplevel #'main :executable t :compression 9)
861
Common Lisp
.asd
26
27.653846
82
0.612981
icot/cl-ciph
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
f658ba660e0fd66308684cb22ad48aa325ddc0b1d7604ba2dd54479a8dd25d4e
24,209
[ -1 ]
24,212
Makefile
icot_cl-ciph/Makefile
clean: rm build.log build: buildapp --output cl-ciph --asdf-path . --asdf-tree ~/quicklisp/dists --load-system cl-ciph --entry cl-ciph:main --logfile build.log
163
Common Lisp
.l
4
39
133
0.734177
icot/cl-ciph
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
4c41fd51e6398488056b2602d959e945ee012be35a624941e57641eda8ef8a42
24,212
[ -1 ]
24,213
cl-ciph.ros
icot_cl-ciph/roswell/cl-ciph.ros
#!/bin/sh #|-*- mode:lisp -*-|# #| exec ros -Q -- $0 "$@" |# (progn ;;init forms (ros:ensure-asdf) (asdf:load-system :unix-opts)) (defpackage :ros/script/cl-ciph (:use :cl)) (in-package :ros/script/cl-ciph) (defun unknown-option (condition) (format t "warning: ~s option is unknown!~%" (opts:option condition)) (invoke-restart 'opts:skip-option)) (defmacro when-option ((options opt) &body body) `(let ((it (getf ,options ,opt))) (when it ,@body))) (opts:define-opts (:name :help :description "This help" :short #\h :long "help") (:name :input :description "Path to file whose contents will be processed as input (e.g ciphertext)" :short #\i :long "input" :arg-parser #'identity :meta-var "FILE")) (defun main (&rest argv) (declare (ignorable argv)) (multiple-value-bind (options free-args) (handler-case (handler-bind ((opts:unknown-option #'unknown-option)) (opts:get-opts argv)) (opts:missing-arg (condition) (format t "fatal: option ~s requires argument~%" (opts:option condition))) (opts:arg-parser-failed (condition) (format t "fatal: Parser failer: ~s/~s~%" (opts:raw-arg condition) (opts:option condition))) (opts:missing-required-option (con) (format t "fatal: required option ~s~%" con) (opts:exit 1))) (when-option (options :help) (opts:describe :usage-of "cl-ciph" :args "[FREE-ARGS]")) (when-option (options :input) (format t "Loading file ~s~%" (getf options :input))) (if free-args (format t "Unused arguments ~s~%" free-args)))
1,986
Common Lisp
.l
52
26.846154
90
0.517134
icot/cl-ciph
1
0
0
GPL-3.0
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
64d0a8a160e7bf8ed7505c0313d5998232710afd85a501a4dc08238885b715d7
24,213
[ -1 ]
24,229
mpi-export.lisp
gorozhin_cl-gcrypt/src/mpi-export.lisp
(in-package #:cl-gcrypt) (export '#.(lispify "gcry_mpi_t" 'type)) (export '#.(lispify "GCRYMPI_FMT_NONE" 'enumvalue)) (export '#.(lispify "GCRYMPI_FMT_STD" 'enumvalue)) (export '#.(lispify "GCRYMPI_FMT_PGP" 'enumvalue)) (export '#.(lispify "GCRYMPI_FMT_SSH" 'enumvalue)) (export '#.(lispify "GCRYMPI_FMT_HEX" 'enumvalue)) (export '#.(lispify "GCRYMPI_FMT_USG" 'enumvalue)) (export '#.(lispify "GCRYMPI_FMT_OPAQUE" 'enumvalue)) (export '#.(namify-function "gcry_mpi_print")) (export '#.(namify-function "gcry_mpi_release"))
526
Common Lisp
.lisp
11
46.545455
53
0.697266
gorozhin/cl-gcrypt
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
3ed22ad1f7168c4f904a9faa88b1ca0f313731768efdcefdcf43e5d0ea3f0205
24,229
[ -1 ]
24,230
md-export.lisp
gorozhin_cl-gcrypt/src/md-export.lisp
(in-package #:cl-gcrypt) (export '#.(lispify "gcry_md_hd_t" 'type)) (export '#.(lispify "gcry_md_handle" 'type)) (export '#.(lispify "gcry_error_t" 'type)) (export '#.(lispify "gcry_buffer_t" 'type)) (export 'size) (export 'off) (export 'len) (export 'buf) ;; algos (export '#.(lispify "GCRY_MD_NONE" 'enumvalue)) (export '#.(lispify "GCRY_MD_MD5" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA1" 'enumvalue)) (export '#.(lispify "GCRY_MD_RMD160" 'enumvalue)) (export '#.(lispify "GCRY_MD_MD2" 'enumvalue)) (export '#.(lispify "GCRY_MD_TIGER" 'enumvalue)) (export '#.(lispify "GCRY_MD_HAVAL" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA256" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA384" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA512" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA224" 'enumvalue)) (export '#.(lispify "GCRY_MD_MD4" 'enumvalue)) (export '#.(lispify "GCRY_MD_CRC32" 'enumvalue)) (export '#.(lispify "GCRY_MD_CRC32_RFC1510" 'enumvalue)) (export '#.(lispify "GCRY_MD_CRC24_RFC2440" 'enumvalue)) (export '#.(lispify "GCRY_MD_WHIRLPOOL" 'enumvalue)) (export '#.(lispify "GCRY_MD_TIGER1" 'enumvalue)) (export '#.(lispify "GCRY_MD_TIGER2" 'enumvalue)) (export '#.(lispify "GCRY_MD_GOSTR3411_94" 'enumvalue)) (export '#.(lispify "GCRY_MD_STRIBOG256" 'enumvalue)) (export '#.(lispify "GCRY_MD_STRIBOG512" 'enumvalue)) (export '#.(lispify "GCRY_MD_GOSTR3411_CP" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA3_224" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA3_256" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA3_384" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA3_512" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHAKE128" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHAKE256" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2B_512" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2B_384" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2B_256" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2B_160" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2S_256" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2S_224" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2S_160" 'enumvalue)) (export '#.(lispify "GCRY_MD_BLAKE2S_128" 'enumvalue)) (export '#.(lispify "GCRY_MD_SM3" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA512_256" 'enumvalue)) (export '#.(lispify "GCRY_MD_SHA512_224" 'enumvalue)) ;; flags (export '#.(lispify "GCRY_MD_FLAG_SECURE" 'enumvalue)) (export '#.(lispify "GCRY_MD_FLAG_HMAC" 'enumvalue)) (export '#.(lispify "GCRY_MD_FLAG_BUGEMU1" 'enumvalue)) ;; functions (export '#.(namify-function "gcry_md_open")) (export '#.(namify-function "gcry_md_close")) (export '#.(namify-function "gcry_md_enable")) (export '#.(namify-function "gcry_md_copy")) (export '#.(namify-function "gcry_md_reset")) (export '#.(namify-function "gcry_md_write")) (export '#.(namify-function "gcry_md_read")) (export '#.(namify-function "gcry_md_hash_buffer")) (export '#.(namify-function "gcry_md_get_algo")) (export '#.(namify-function "gcry_md_get_algo_dlen")) (export '#.(namify-function "gcry_md_is_enabled")) (export '#.(namify-function "gcry_md_is_secure")) (export '#.(namify-function "gcry_md_algo_name")) (export '#.(namify-function "gcry_md_map_name")) (export '#.(namify-function "gcry_md_setkey")) (export '#.(namify-function "gcry_md_algo_info")) (export '#.(namify-function "gcry_md_test_algo")) (export '#.(namify-function "gcry_md_get_asnoid")) (export '#.(namify-function "gcry_md_ctl")) (export '#.(namify-function "gcry_md_final")) (export '#.(namify-function "gcry_md_putc")) (export '#.(namify-function "gcry_md_debug")) (export '#.(namify-function "gcry_md_info")) (export '#.(namify-function "gcry_md_extract")) (export '#.(namify-function "gcry_md_hash_buffers"))
3,685
Common Lisp
.lisp
79
45.582278
56
0.692671
gorozhin/cl-gcrypt
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
baa4ee368b40bd1b6b3bbfae754b97c82f2bdfd647d529046867069eb15970e1
24,230
[ -1 ]
24,231
sexp-binding.lisp
gorozhin_cl-gcrypt/src/sexp-binding.lisp
(in-package #:cl-gcrypt) (cffi:defctype #.(lispify "gcry_sexp_t" 'type) :pointer) (defenum #.(lispify "GCRYSEXP_FMT_DEFAULT" 'enumvalue) #.(lispify "GCRYSEXP_FMT_CANON" 'enumvalue) #.(lispify "GCRYSEXP_FMT_BASE64" 'enumvalue) #.(lispify "GCRYSEXP_FMT_ADVANCED" 'enumvalue)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_new") #.(lispify "gcry_error_t" 'type) "Create an new S-expression object from BUFFER of size LENGTH and return it in RETSEXP. With AUTODETECT set to 0 the data in BUFFER is expected to be in canonized format." (retsexp :pointer '#.(lispify "gcry_sexp_t" 'type)) (buffer :pointer) (length :uint) (autodetect :int)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_create") #.(lispify "gcry_error_t" 'type) #.(format nil "Same as ~a but allows to pass a FREEFNC which has the effect to transfer ownership of BUFFER to the created object." (namify-function "gcry_sexp_new")) (retsexp :pointer '#.(lispify "gcry_sexp_t" 'type)) (buffer :pointer) (length :uint) (autodetect :int) (freefnc :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_sscan") #.(lispify "gcry_error_t" 'type) "Scan BUFFER and return a new S-expression object in RETSEXP. This function expects a printf like string in BUFFER." (retsexp :pointer '#.(lispify "gcry_sexp_t" 'type)) (erroff :pointer) (buffer :pointer) (length :uint)) (defmacro #.(namify-function "gcry_sexp_build") (retsexp erroff format &rest arguments) #.(format nil "Same as ~a but expects a string in FORMAT and can thus only be used for certain encodings." (namify-function "gcry_sexp_sscan")) `(cffi:foreign-funcall "gcry_sexp_build" :pointer ,retsexp :pointer ,erroff :string ,format ,@arguments #.(lispify "gcry_error_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_build_array") #.(lispify "gcry_error_t" 'type) #.(format nil "Like ~a, but uses an array instead of variable function arguments." (namify-function "gcry_sexp_build")) (retsexp :pointer) (erroff :pointer) (format :string) (arg-list :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_release") :void "Release the S-expression object SEXP" (sexp #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_canon_len") :uint "Calculate the length of an canonized S-expression in BUFFER and check for a valid encoding." (buffer :pointer) (length :uint) (erroff :pointer) (errcode :pointer #.(lispify "gcry_error_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_sprint") :uint "Copies the S-expression object SEXP into BUFFER using the format specified in MODE." (sexp #.(lispify "gcry_sexp_t" 'type)) (mode :int) (buffer :pointer) (maxlength :uint)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_dump") :void "Dumps the S-expression object A in a format suitable for debugging to Libgcrypt's logging stream." (a #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_cons") #.(lispify "gcry_sexp_t" 'type) (a #.(lispify "gcry_sexp_t" 'type)) (b #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_alist") #.(lispify "gcry_sexp_t" 'type) (a :pointer #.(lispify "gcry_sexp_t" 'type))) (defmacro #.(namify-function "gcry_sexp_vlist") (a &rest arguments) #.(format nil "Same as ~a but expects a string in FORMAT and can thus only be used for certain encodings." (namify-function "gcry_sexp_sscan")) `(cffi:foreign-funcall "gcry_sexp_build" :pointer ,a ,@(loop for argument in arguments nconcing `(:pointer ,argument)) #.(lispify "gcry_error_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_append") #.(lispify "gcry_sexp_t" 'type) (a #.(lispify "gcry_sexp_t" 'type)) (b #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_prepend") #.(lispify "gcry_sexp_t" 'type) (a #.(lispify "gcry_sexp_t" 'type)) (b #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_find_token") #.(lispify "gcry_sexp_t" 'type) "Scan the S-expression for a sublist with a type (the car of the list) matching the string TOKEN. If TOKLEN is not 0, the token is assumed to be raw memory of this length. The function returns a newly allocated S-expression consisting of the found sublist or `NULL' when not found." (list #.(lispify "gcry_sexp_t" 'type)) (tok :pointer) (toklen :uint)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_length") :int "Return the length of the LIST. For a valid S-expression this should be at least 1." (list #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_nth") #.(lispify "gcry_sexp_t" 'type) "Create and return a new S-expression from the element with index NUMBER in LIST. Note that the first element has the index 0. If there is no such element, `NULL' is returned." (list #.(lispify "gcry_sexp_t" 'type)) (number :int)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_car") #.(lispify "gcry_sexp_t" 'type) "Create and return a new S-expression from the first element in LIST; this called the \"type\" and should always exist and be a string. `NULL' is returned in case of a problem." (list #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_cdr") #.(lispify "gcry_sexp_t" 'type) "Create and return a new list form all elements except for the first one. Note, that this function may return an invalid S-expression because it is not guaranteed, that the type exists and is a string. However, for parsing a complex S-expression it might be useful for intermediate lists. Returns `NULL' on error." (list #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_cadr") #.(lispify "gcry_sexp_t" 'type) (list #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_sexp_nth_data") :pointer "This function is used to get data from a LIST. A pointer to the actual data with index NUMBER is returned and the length of this data will be stored to DATALEN. If there is no data at the given index or the index represents another list, `NULL' is returned. *Note:* The returned pointer is valid as long as LIST is not modified or released." (list #.(lispify "gcry_sexp_t" 'type)) (number :int) (datalen :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_nth_buffer") :pointer "This function is used to get data from a LIST. A malloced buffer to the data with index NUMBER is returned and the length of this data will be stored to RLENGTH. If there is no data at the given index or the index represents another list, `NULL' is returned." (list #.(lispify "gcry_sexp_t" 'type)) (number :int) (rlength :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_nth_string") :string "This function is used to get and convert data from a LIST. The data is assumed to be a Nul terminated string. The caller must release the returned value using `gcry_free'. If there is no data at the given index, the index represents a list or the value can't be converted to a string, `NULL' is returned." (list #.(lispify "gcry_sexp_t" 'type)) (number :int)) (cffi:defcfun #.(namify-function-definition "gcry_sexp_nth_mpi") #.(lispify "gcry_mpi_t" 'type) "This function is used to get and convert data from a LIST. This data is assumed to be an MPI stored in the format described by MPIFMT and returned as a standard Libgcrypt MPI. The caller must release this returned value using `gcry_mpi_release'. If there is no data at the given index, the index represents a list or the value can't be converted to an MPI, `NULL' is returned." (list #.(lispify "gcry_sexp_t" 'type)) (number :int) (mpifmt :int)) (defmacro #.(namify-function "gcry_sexp_extract_param") (sexp path list &rest arguments) "Extract MPIs from an s-expression using a list of parameters. The names of these parameters are given by the string LIST. Some special characters may be given to control the conversion: + :: Switch to unsigned integer format (default). - :: Switch to standard signed format. / :: Switch to opaque format. & :: Switch to buffer descriptor mode - see below. ? :: The previous parameter is optional. In general parameter names are single letters. To use a string for a parameter name, enclose the name in single quotes. Unless in gcry_buffer_t mode for each parameter name a pointer to an MPI variable is expected that must be set to NULL prior to invoking this function, and finally a NULL is expected. Example: _gcry_sexp_extract_param (key, NULL, \"n/x+ed\", &mpi_n, &mpi_x, &mpi_e, NULL) This stores the parameter \"N\" from KEY as an unsigned MPI into MPI_N, the parameter \"X\" as an opaque MPI into MPI_X, and the parameter \"E\" again as an unsigned MPI into MPI_E. If in buffer descriptor mode a pointer to gcry_buffer_t descriptor is expected instead of a pointer to an MPI. The caller may use two different operation modes: If the DATA field of the provided buffer descriptor is NULL, the function allocates a new buffer and stores it at DATA; the other fields are set accordingly with OFF being 0. If DATA is not NULL, the function assumes that DATA, SIZE, and OFF describe a buffer where to but the data; on return the LEN field receives the number of bytes copied to that buffer; if the buffer is too small, the function immediately returns with an error code (and LEN set to 0). PATH is an optional string used to locate a token. The exclamation mark separated tokens are used to via gcry_sexp_find_token to find a start point inside SEXP. The function returns 0 on success. On error an error code is returned, all passed MPIs that might have been allocated up to this point are deallocated and set to NULL, and all passed buffers are either truncated if the caller supplied the buffer, or deallocated if the function allocated the buffer." `(cffi:foreign-funcall "gcry_sexp_extract_param" #.(lispify "gcry_sexp_t" 'type) ,sexp :string ,path :string ,list ,@(loop for argument in arguments nconcing `(:pointer ,argument)) :pointer (cffi:null-pointer) #.(lispify "gcry_error_t" 'type)))
10,613
Common Lisp
.lisp
251
39.055777
97
0.718717
gorozhin/cl-gcrypt
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
2d22ea0a625b0cf7988d38682a75dec2baed185c36ee1542c74b04f0b0f7e5ef
24,231
[ -1 ]
24,232
mpi-binding.lisp
gorozhin_cl-gcrypt/src/mpi-binding.lisp
(in-package #:cl-gcrypt) (cffi:defctype #.(lispify "gcry_mpi_t" 'type) :pointer) (defenum (#.(lispify "GCRYMPI_FMT_NONE" 'enumvalue) 0) (#.(lispify "GCRYMPI_FMT_STD" 'enumvalue) 1) (#.(lispify "GCRYMPI_FMT_PGP" 'enumvalue) 2) (#.(lispify "GCRYMPI_FMT_SSH" 'enumvalue) 3) (#.(lispify "GCRYMPI_FMT_HEX" 'enumvalue) 4) (#.(lispify "GCRYMPI_FMT_USG" 'enumvalue) 5) (#.(lispify "GCRYMPI_FMT_OPAQUE" 'enumvalue) 8)) (cffi:defcfun #.(namify-function-definition "gcry_mpi_print") #.(lispify "gcry_error_t" 'type) "Convert the big integer A into the external representation described by FORMAT and store it in the provided BUFFER which has been allocated by the user with a size of BUFLEN bytes. NWRITTEN receives the actual length of the external representation unless it has been passed as NULL." (format :int) (buffer :pointer) (buflen :uint) (nwritten :pointer) (a #.(lispify "gcry_mpi_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_mpi_release") :void "Release the number A and free all associated resources." (a #.(lispify "gcry_mpi_t" 'type)))
1,104
Common Lisp
.lisp
26
39.692308
68
0.710428
gorozhin/cl-gcrypt
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
fb8b16f2e514e243a3009ebd587ee02d7b84f0dcbe88bd2b9e5358a87f689a0f
24,232
[ -1 ]
24,233
md-binding.lisp
gorozhin_cl-gcrypt/src/md-binding.lisp
(in-package #:cl-gcrypt) ;;;; MD module ;; algos enum (defenum #.(lispify "GCRY_MD_NONE" 'enumvalue) #.(lispify "GCRY_MD_MD5" 'enumvalue) #.(lispify "GCRY_MD_SHA1" 'enumvalue) #.(lispify "GCRY_MD_RMD160" 'enumvalue) (#.(lispify "GCRY_MD_MD2" 'enumvalue) 5) #.(lispify "GCRY_MD_TIGER" 'enumvalue) #.(lispify "GCRY_MD_HAVAL" 'enumvalue) #.(lispify "GCRY_MD_SHA256" 'enumvalue) #.(lispify "GCRY_MD_SHA384" 'enumvalue) #.(lispify "GCRY_MD_SHA512" 'enumvalue) #.(lispify "GCRY_MD_SHA224" 'enumvalue) (#.(lispify "GCRY_MD_MD4" 'enumvalue) 301) #.(lispify "GCRY_MD_CRC32" 'enumvalue) #.(lispify "GCRY_MD_CRC32_RFC1510" 'enumvalue) #.(lispify "GCRY_MD_CRC24_RFC2440" 'enumvalue) #.(lispify "GCRY_MD_WHIRLPOOL" 'enumvalue) #.(lispify "GCRY_MD_TIGER1" 'enumvalue) #.(lispify "GCRY_MD_TIGER2" 'enumvalue) #.(lispify "GCRY_MD_GOSTR3411_94" 'enumvalue) #.(lispify "GCRY_MD_STRIBOG256" 'enumvalue) #.(lispify "GCRY_MD_STRIBOG512" 'enumvalue) #.(lispify "GCRY_MD_GOSTR3411_CP" 'enumvalue) #.(lispify "GCRY_MD_SHA3_224" 'enumvalue) #.(lispify "GCRY_MD_SHA3_256" 'enumvalue) #.(lispify "GCRY_MD_SHA3_384" 'enumvalue) #.(lispify "GCRY_MD_SHA3_512" 'enumvalue) #.(lispify "GCRY_MD_SHAKE128" 'enumvalue) #.(lispify "GCRY_MD_SHAKE256" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2B_512" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2B_384" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2B_256" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2B_160" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2S_256" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2S_224" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2S_160" 'enumvalue) #.(lispify "GCRY_MD_BLAKE2S_128" 'enumvalue) #.(lispify "GCRY_MD_SM3" 'enumvalue) #.(lispify "GCRY_MD_SHA512_256" 'enumvalue) #.(lispify "GCRY_MD_SHA512_224" 'enumvalue)) (defenum (#.(lispify "GCRY_MD_FLAG_SECURE" 'enumvalue) 1) #.(lispify "GCRY_MD_FLAG_HMAC" 'enumvalue) (#.(lispify "GCRY_MD_FLAG_BUGEMU1" 'enumvalue) #x0100)) ;; types and structs (cffi:defcstruct #.(lispify "gcry_md_handle" 'type) (ctx :pointer) (bufpos :int) (bufsize :int) (buf :char :count 1)) (cffi:defctype #.(lispify "gcry_md_hd_t" 'type) :pointer) (cffi:defcstruct #.(lispify "gcry_buffer_t" 'type) (size :size) (off :size) (len :size) (buf :pointer)) ;; functions (cffi:defcfun #.(namify-function-definition "gcry_md_open") #.(lispify "gcry_error_t" 'type) #.(format nil "Create a message digest object for algorithm ALGO. Create a message digest object for algorithm ALGO. FLAGS may be given as an bitwise OR of the ~a values. ALGO may be given as 0 if the algorithms to be used are later set using ~a" (lispify "gcry_md_flag" 'constant) (namify-function "gcry_md_enable")) (handle (:pointer #.(lispify "gcry_error_t" 'type))) (algo :int) (flags :uint)) (cffi:defcfun #.(namify-function-definition "gcry_md_close") :void "Release the message digest object HANDLE." (handle #.(lispify "gcry_md_hd_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_md_enable") #.(lispify "gcry_error_t" 'type) "Add the message digest algorithm ALGO to the digest object HANDLE" (handle #.(lispify "gcry_md_hd_t" 'type)) (algo :int)) (cffi:defcfun #.(namify-function-definition "gcry_md_copy") #.(lispify "gcry_error_t" 'type) "Create a new digest object as an exact copy of the object HD." (bhd :pointer #.(lispify "gcry_md_hd_t" 'type)) (ahd #.(lispify "gcry_md_hd_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_md_reset") :void "Reset the digest object HANDLE to its initial state." (handle #.(lispify "gcry_md_hd_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_md_ctl") #.(lispify "gcry_error_t" 'type) "Perform various operations on the digest object HANDLE" (handle #.(lispify "gcry_md_hd_t" 'type)) (cmd :int) (buffer :pointer) (buflen :size)) (cffi:defcfun #.(namify-function-definition "gcry_md_write") :void "Pass LENGTH bytes of data in BUFFER to the digest object HANDLE so that it can update the digest values. This is the actual hash function." (handle #.(lispify "gcry_md_hd_t" 'type)) (buffer :pointer) (length :size)) (cffi:defcfun #.(namify-function-definition "gcry_md_read") (:pointer :uchar) "Read out the final digest from HANDLE return the digest value for algorithm ALGO." (handle #.(lispify "gcry_md_hd_t" 'type)) (algo :int)) (cffi:defcfun #.(namify-function-definition "gcry_md_extract") #.(lispify "gcry_error_t" 'type) "Read more output from algorithm ALGO to BUFFER of size LENGTH from digest object HANDLE. Algorithm needs to be 'expendable-output function'" (handle #.(lispify "gcry_md_hd_t" 'type)) (algo :int) (buffer :pointer) (length :size)) (cffi:defcfun #.(namify-function-definition "gcry_md_hash_buffer") :void "Convenience function to calculate the hash from the data in BUFFER of size LENGTH using the algorithm ALGO avoiding the creation of a hash object. The hash is returned in the caller provided buffer DIGEST which must be large enough to hold the digest of the given algorithm." (algo :int) (digest :pointer) (buffer :pointer) (length :size)) (cffi:defcfun #.(namify-function-definition "gcry_md_hash_buffers") #.(lispify "gcry_error_t" 'type) "Convenience function to hash multiple buffers." (algo :int) (flags :uint) (digest :pointer) (iov :pointer #.(lispify "gcry_buffer_t" 'type)) (iovcnt :int)) (cffi:defcfun #.(namify-function-definition "gcry_md_get_algo") :int "Retrieve the algorithm used with HANDLE. This does not work reliable if more than one algorithm is enabled in HANDLE." (handle #.(lispify "gcry_md_hd_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_md_get_algo_dlen") :uint "Retrieve the length in bytes of the digest yielded by algorithm ALGO." (algo :int)) (cffi:defcfun #.(namify-function-definition "gcry_md_is_enabled") :boolean "Return true if the the algorithm ALGO is enabled in the digest object HANDLE." (handle #.(lispify "gcry_md_hd_t" 'type)) (algo :int)) (cffi:defcfun #.(namify-function-definition "gcry_md_is_secure") :boolean "Return true if the digest object HANDLE is allocated in \"secure\" memory." (handle #.(lispify "gcry_md_hd_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_md_info") #.(lispify "gcry_error_t" 'type) #.(format nil "Deprecated: Use ~a or ~a." (namify-function "gcry_md_is_enabled") (namify-function "gcry_md_is_secure")) (handle #.(lispify "gcry_md_hd_t" 'type)) (what :int) (buffer :pointer) (nbytes :pointer :size)) (cffi:defcfun #.(namify-function-definition "gcry_md_algo_info") #.(lispify "gcry_error_t" 'type) "Retrieve various information about the algorithm ALGO" (algo :int) (what :int) (buffer :pointer) (nbytes (:pointer :size))) (cffi:defcfun #.(namify-function-definition "gcry_md_algo_name") :string "Map the digest algorithm id ALGO to a string representation of the algorithm name. For unknown algorithms this function returns \"?\"." (algo :int)) (cffi:defcfun #.(namify-function-definition "gcry_md_map_name") :int "Map the algorithm NAME to a digest algorithm Id. Return 0 if the algorithm name is not known." (name :string)) (cffi:defcfun #.(namify-function-definition "gcry_md_setkey") #.(lispify "gcry_error_t" 'type) "For use with the HMAC feature, the set MAC key to the KEY of KEYLEN bytes." (handle #.(lispify "gcry_md_hd_t" 'type)) (key :pointer) (size :size)) (cffi:defcfun #.(namify-function-definition "gcry_md_debug") :void "Start or stop debugging for digest handle HANDLE; i.e. create a file named dbgmd-<n>.<suffix> while hashing. If SUFFIX is NULL, debugging stops and the file will be closed." (handle #.(lispify "gcry_md_hd_t" 'type)) (suffix :string)) (defun #.(namify-function "gcry_md_putc") (handle char) #.(format nil "Update the hash(s) of HANDLE with the character CHAR. This is a buffered version of the ~a function." (namify-function "gcry_md_write")) (cffi:with-foreign-slots ((bufpos bufsize) handle (:struct #.(lispify "gcry_md_handle" 'type))) (when (= bufpos bufsize) (#.(namify-function "gcry_md_write") handle (cffi:null-pointer) 0)) (let ((buf (cffi:foreign-slot-pointer handle '(:struct #.(lispify "gcry_md_handle" 'type)) 'buf))) (setf (cffi:mem-aref buf :char bufpos) char) (incf bufpos)))) (defun #.(namify-function "gcry_md_final") (handle) #.(format nil "Finalize the digest calculation. This is not really needed because ~a does this implicitly" (namify-function "gcry_md_read")) (#.(namify-function "gcry_md_ctl") handle #.(lispify "GCRYCTL_FINALIZE" 'enumvalue) (cffi:null-pointer) 0)) (defun #.(namify-function "gcry_md_test_algo") (algo) "Return 0 if the algorithm A is available for use." (#.(namify-function "gcry_md_algo_info") algo #.(lispify "GCRYCTL_TEST_ALGO" 'enumvalue) (cffi:null-pointer) (cffi:null-pointer))) (defun #.(namify-function "gcry_md_get_asnoid") (algo buffer nbytes) "Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N must point to size_t variable with the available size of buffer B. After return it will receive the actual size of the returned OID" (#.(namify-function "gcry_md_algo_info") algo #.(lispify "GCRYCTL_GET_ASNOID" 'enumvalue) buffer nbytes))
9,485
Common Lisp
.lisp
248
35.052419
102
0.697404
gorozhin/cl-gcrypt
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
5efb556f6aa2108a233a0499f1e6bc0fa6b3f297ba899b327193eabc5c812b91
24,233
[ -1 ]
24,234
pk-binding.lisp
gorozhin_cl-gcrypt/src/pk-binding.lisp
(in-package #:cl-gcrypt) (defenum (#.(lispify "GCRY_PK_RSA" 'enumvalue) 1) #.(lispify "GCRY_PK_RSA_E" 'enumvalue) #.(lispify "GCRY_PK_RSA_S" 'enumvalue) (#.(lispify "GCRY_PK_ELG_E" 'enumvalue) 16) #.(lispify "GCRY_PK_DSA" 'enumvalue) #.(lispify "GCRY_PK_ECC" 'enumvalue) (#.(lispify "GCRY_PK_ELG" 'enumvalue) 20) (#.(lispify "GCRY_PK_ECDSA" 'enumvalue) 301) #.(lispify "GCRY_PK_ECDH" 'enumvalue) #.(lispify "GCRY_PK_EDDSA" 'enumvalue)) (defenum (#.(lispify "GCRY_PK_USAGE_SIGN" 'enumvalue) 1) (#.(lispify "GCRY_PK_USAGE_ENCR" 'enumvalue) 2) (#.(lispify "GCRY_PK_USAGE_CERT" 'enumvalue) 4) (#.(lispify "GCRY_PK_USAGE_AUTH" 'enumvalue) 8) (#.(lispify "GCRY_PK_USAGE_UNKN" 'enumvalue) 128)) (defenum (#.(lispify "GCRY_PK_GET_PUBKEY" 'enumvalue) 1) #.(lispify "GCRY_PK_GET_SECKEY" 'enumvalue)) (cffi:defcfun #.(namify-function-definition "gcry_pk_encrypt") #.(lispify "gcry_error_t" 'type) "Encrypt the DATA using the public key PKEY and store the result as a newly created S-expression at RESULT." (result :pointer #.(lispify "gcry_sexp_t" 'type)) (data #.(lispify "gcry_sexp_t" 'type)) (pkey #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_pk_decrypt") #.(lispify "gcry_error_t" 'type) "Decrypt the DATA using the private key SKEY and store the result as a newly created S-expression at RESULT." (result :pointer #.(lispify "gcry_sexp_t" 'type)) (data #.(lispify "gcry_sexp_t" 'type)) (skey #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_pk_sign") #.(lispify "gcry_error_t" 'type) "Sign the DATA using the private key SKEY and store the result as a newly created S-expression at RESULT." (result :pointer #.(lispify "gcry_sexp_t" 'type)) (data #.(lispify "gcry_sexp_t" 'type)) (skey #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_pk_verify") #.(lispify "gcry_error_t" 'type) "Check the signature SIGVAL on DATA using the public key PKEY." (sigval #.(lispify "gcry_sexp_t" 'type)) (data #.(lispify "gcry_sexp_t" 'type)) (pkey #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_pk_testkey") #.(lispify "gcry_error_t" 'type) "Check that private KEY is sane." (key #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_pk_genkey") #.(lispify "gcry_error_t" 'type) "Generate a new key pair according to the parameters given in S_PARMS. The new key pair is returned in as an S-expression in R_KEY." (r_key :pointer #.(lispify "gcry_sexp_t" 'type)) (s_parms #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_pk_ctl") #.(lispify "gcry_error_t" 'type) "Catch all function for miscellaneous operations." (cmd :int) (buffer :pointer) (buflen :uint)) (cffi:defcfun #.(namify-function-definition "gcry_pk_algo_info") #.(lispify "gcry_error_t" 'type) "Retrieve information about the public key algorithm ALGO." (algo :int) (what :int) (buffer :pointer) (nbytes :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_pk_algo_name") :string "Map the public key algorithm whose ID is contained in ALGORITHM to a string representation of the algorithm name. For unknown algorithm IDs this functions returns \"?\"." (algorithm :int)) (cffi:defcfun #.(namify-function-definition "gcry_pk_map_name") :int "Map the algorithm NAME to a public key algorithm Id. Return 0 if the algorithm name is not known." (name :string)) (cffi:defcfun #.(namify-function-definition "gcry_pk_get_nbits") :uint "Return what is commonly referred as the key length for the given public or private KEY." (key #.(lispify "gcry_sexp_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_pk_get_keygrip") :pointer "Return the so called KEYGRIP which is the SHA-1 hash of the public key parameters expressed in a way depending on the algorithm." (key #.(lispify "gcry_sexp_t" 'type)) (array :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_pk_get_curve") :string "Return the name of the curve matching KEY." (key #.(lispify "gcry_sexp_t" 'type)) (iterator :int) (r_nbits :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_pk_get_param") #.(lispify "gcry_sexp_t" 'type) "Return an S-expression with the parameters of the named ECC curve NAME. ALGO must be set to an ECC algorithm." (algo :int) (name :string)) (defmacro #.(namify-function "gcry_pk_test_algo") (a) "Return 0 if the public key algorithm A is available for use." `(#.(namify-function "gcry_pk_algo_info") ,a #.(lispify "GCRYCTL_TEST_ALGO" 'enumvalue) (cffi:null-pointer) (cffi:null-pointer))) (cffi:defcfun #.(namify-function-definition "gcry_pubkey_get_sexp") #.(lispify "gcry_error_t" 'type) "Return an S-expression representing the context CTX." (sexp :pointer #.(lispify "gcry_sexp_t" 'type)) (mode :int) (ctx #.(lispify "gcry_ctx_t" 'type)))
5,039
Common Lisp
.lisp
120
39.058333
71
0.695918
gorozhin/cl-gcrypt
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
5c2ed9ece54bb02480deaab1a6b255175b112f6635920e54b0d50a29f685ff08
24,234
[ -1 ]
24,235
cipher-binding.lisp
gorozhin_cl-gcrypt/src/cipher-binding.lisp
(in-package #:cl-gcrypt) (cffi:defctype #.(lispify "gcry_cipher_hd_t" 'type) :pointer) (defenum #.(lispify "GCRY_CIPHER_NONE" 'enumvalue) #.(lispify "GCRY_CIPHER_IDEA" 'enumvalue) #.(lispify "GCRY_CIPHER_3DES" 'enumvalue) #.(lispify "GCRY_CIPHER_CAST5" 'enumvalue) #.(lispify "GCRY_CIPHER_BLOWFISH" 'enumvalue) #.(lispify "GCRY_CIPHER_SAFER_SK128" 'enumvalue) #.(lispify "GCRY_CIPHER_DES_SK" 'enumvalue) #.(lispify "GCRY_CIPHER_AES" 'enumvalue) #.(lispify "GCRY_CIPHER_AES192" 'enumvalue) #.(lispify "GCRY_CIPHER_AES256" 'enumvalue) #.(lispify "GCRY_CIPHER_TWOFISH" 'enumvalue) (#.(lispify "GCRY_CIPHER_ARCFOUR" 'enumvalue) 301) #.(lispify "GCRY_CIPHER_DES" 'enumvalue) #.(lispify "GCRY_CIPHER_TWOFISH128" 'enumvalue) #.(lispify "GCRY_CIPHER_SERPENT128" 'enumvalue) #.(lispify "GCRY_CIPHER_SERPENT192" 'enumvalue) #.(lispify "GCRY_CIPHER_SERPENT256" 'enumvalue) #.(lispify "GCRY_CIPHER_RFC2268_40" 'enumvalue) #.(lispify "GCRY_CIPHER_RFC2268_128" 'enumvalue) #.(lispify "GCRY_CIPHER_SEED" 'enumvalue) #.(lispify "GCRY_CIPHER_CAMELLIA128" 'enumvalue) #.(lispify "GCRY_CIPHER_CAMELLIA192" 'enumvalue) #.(lispify "GCRY_CIPHER_CAMELLIA256" 'enumvalue) #.(lispify "GCRY_CIPHER_SALSA20" 'enumvalue) #.(lispify "GCRY_CIPHER_SALSA20R12" 'enumvalue) #.(lispify "GCRY_CIPHER_GOST28147" 'enumvalue) #.(lispify "GCRY_CIPHER_CHACHA20" 'enumvalue) #.(lispify "GCRY_CIPHER_GOST28147_MESH" 'enumvalue) #.(lispify "GCRY_CIPHER_SM4" 'enumvalue)) (defconstant #.(lispify "GCRY_CIPHER_AES128" 'enumvalue) #.(lispify "GCRY_CIPHER_AES" 'enumvalue)) (defconstant #.(lispify "GCRY_CIPHER_RIJNDAEL" 'enumvalue) #.(lispify "GCRY_CIPHER_AES" 'enumvalue)) (defconstant #.(lispify "GCRY_CIPHER_RIJNDAEL128" 'enumvalue) #.(lispify "GCRY_CIPHER_AES128" 'enumvalue)) (defconstant #.(lispify "GCRY_CIPHER_RIJNDAEL192" 'enumvalue) #.(lispify "GCRY_CIPHER_AES192" 'enumvalue)) (defconstant #.(lispify "GCRY_CIPHER_RIJNDAEL256" 'enumvalue) #.(lispify "GCRY_CIPHER_AES256" 'enumvalue)) (defenum #.(lispify "GCRY_CIPHER_MODE_NONE" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_ECB" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_CFB" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_CBC" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_STREAM" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_OFB" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_CTR" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_AESWRAP" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_CCM" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_GCM" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_POLY1305" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_OCB" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_CFB8" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_XTS" 'enumvalue) #.(lispify "GCRY_CIPHER_MODE_EAX" 'enumvalue)) (defenum (#.(lispify "GCRY_CIPHER_SECURE" 'enumvalue) 1) (#.(lispify "GCRY_CIPHER_ENABLE_SYNC" 'enumvalue) 2) (#.(lispify "GCRY_CIPHER_CBC_CTS" 'enumvalue) 4) (#.(lispify "GCRY_CIPHER_CBC_MAC" 'enumvalue) 8)) (defenum (#.(lispify "GCRY_GCM_BLOCK_LEN" 'enumvalue) 16) (#.(lispify "GCRY_CCM_BLOCK_LEN" 'enumvalue) 16) (#.(lispify "GCRY_OCB_BLOCK_LEN" 'enumvalue) 16) (#.(lispify "GCRY_XTS_BLOCK_LEN" 'enumvalue) 16)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_open") #.(lispify "gcry_error_t" 'type) "Create a handle for algorithm ALGO to be used in MODE. FLAGS may be given as an bitwise OR of the gcry_cipher_flags values." (handle :pointer gcry_cipher_hd_t) (algo :int) (mode :int) (flags :uint)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_close") :void "Close the cipher handle HANDLE and release all resource." (handle #.(lispify "gcry_cipher_hd_t" 'type))) (cffi:defcfun #.(namify-function-definition "gcry_cipher_ctl") #.(lispify "gcry_error_t" 'type) "Perform various operations on the cipher object HANDLE." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (cmd :int) (buffer :pointer) (buflen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_info") #.(lispify "gcry_error_t" 'type) "Retrieve various information about the cipher object HANDLE." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (what :int) (buffer :pointer) (nbytes :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_algo_info") #.(lispify "gcry_error_t" 'type) "Retrieve various information about the cipher algorithm ALGO." (algo :int) (what :int) (buffer :pointer) (nbytes :pointer)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_algo_name") :string "Map the cipher algorithm whose ID is contained in ALGO to a string representation of the algorithm name. For unknown algorithm IDs this function returns \"?\"." (algo :int)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_map_name") :int "Map the algorithm name NAME to an cipher algorithm ID. Return 0 if the algorithm name is not known." (name :string)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_mode_from_oid") :int "Given an ASN.1 object identifier in standard IETF dotted decimal format in STRING, return the encryption mode associated with that OID or 0 if not known or applicable." (string :string)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_encrypt") #.(lispify "gcry_error_t" 'type) "Encrypt the plaintext of size INLEN in IN using the cipher handle HANDLE into the buffer OUT which has an allocated length of OUTSIZE. For most algorithms it is possible to pass NULL for in and 0 for INLEN and do a in-place decryption of the data provided in OUT." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (out :pointer) (outsize :size) (in :pointer) (inlen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_decrypt") #.(lispify "gcry_error_t" 'type) #.(format nil "The counterpart to ~a." '#.(namify-function "gcry_cipher_encrypt")) (handle #.(lispify "gcry_cipher_hd_t" 'type)) (out :pointer) (outsize :size) (in :pointer) (inlen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_setkey") #.(lispify "gcry_error_t" 'type) "Set KEY of length KEYLEN bytes for the cipher handle HANDLE." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (key :pointer) (keylen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_setiv") #.(lispify "gcry_error_t" 'type) "Set initialization vector IV of length IVLEN for the cipher handle HANDLE." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (iv :pointer) (ivlen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_authenticate") #.(lispify "gcry_error_t" 'type) "Provide additional authentication data for AEAD modes/ciphers." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (abuf :pointer) (abuflen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_gettag") #.(lispify "gcry_error_t" 'type) "Get authentication tag for AEAD modes/ciphers." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (outtag :pointer) (taglen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_checktag") #.(lispify "gcry_error_t" 'type) "Check authentication tag for AEAD modes/ciphers." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (intag :pointer) (taglen :size)) (defun #.(namify-function "gcry_cipher_reset") (handle) "Reset the handle to the state after open." (#.(namify-function "gcry_cipher_ctl") handle +gcryctl-reset+ (cffi:null-pointer) 0)) (defun #.(namify-function "gcry_cipher_sync") (handle) "Perform the OpenPGP sync operation if this is enabled for the cipher handle HANDLE." (#.(namify-function "gcry_cipher_ctl") handle #.(lispify "GCRYCTL_CFB_SYNC" 'enumvalue) (cffi:null-pointer) 0)) (defun #.(namify-function "gcry_cipher_cts") (handle on) "Enable or disable CTS in future calls to gcry_encrypt(). CBC mode only." (#.(namify-function "gcry_cipher_ctl") handle #.(lispify "GCRYCTL_SET_CBC_CTS" 'enumvalue) (cffi:null-pointer) on)) (defun #.(namify-function "gcry_cipher_set_sbox") (handle oid) (#.(namify-function "gcry_cipher_ctl") handle #.(lispify "GCRYCTL_SET_SBOX" 'enumvalue) oid 0)) (defun #.(namify-function "gcry_cipher_final") (a) "Indicate to the encrypt and decrypt functions that the next call provides the final data. Only used with some modes." (#.(lispify "gcry_cipher_ctl" 'funcation) a #.(lispify "GCRYCTL_FINALIZE" 'enumvalue) (cffi:null-pointer) 0)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_setctr") #.(lispify "gcry_error_t" 'type) "Set counter for CTR mode. (CTR,CTRLEN) must denote a buffer of block size length, or (NULL,0) to set the CTR to the all-zero block." (handle #.(lispify "gcry_cipher_hd_t" 'type)) (ctr :pointer) (ctrlen :size)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_get_algo_keylen") :size "Retrieve the key length in bytes used with algorithm ALGO." (algo :int)) (cffi:defcfun #.(namify-function-definition "gcry_cipher_get_algo_blklen") :size "Retrieve the block length in bytes used with algorithm ALGO." (algo :int)) (defun #.(namify-function "gcry_cipher_test_algo") (algo) "Return 0 if the algorithm ALGO is available for use." (#.(namify-function "gcry_cipher_algo_info") algo #.(lispify "GCRYCTL_TEST_ALGO" 'enumvalue) (cffi:null-pointer) (cffi:null-pointer)))
9,437
Common Lisp
.lisp
232
37.551724
78
0.71061
gorozhin/cl-gcrypt
1
0
0
LGPL-2.1
9/19/2024, 11:28:28 AM (Europe/Amsterdam)
369c2c31e33c784c4fa732610e69d75b38d5027cd6f76c5911593526b98d4581
24,235
[ -1 ]