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
21,033
deoxybyte-unix.lisp
keithj_deoxybyte-unix/src/deoxybyte-unix.lisp
;;; ;;; Copyright (c) 2009-2013 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-unix. ;;; ;;; 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 :uk.co.deoxybyte-unix) (defun maybe-standard-stream (designator) "Returns a standard stream (*standard-input* *standard-output* or *error-output*) if DESIGNATOR is a string that is STRING-EQUAL to one of \"stdin\", \"stdout\" or \"stderr\", otherwise returns DESIGNATOR. (Also works for \"/dev/stdin\" etc.) This function is useful where one of these strings may be given on a command line to indicate a system stream, rather than a file-stream is to be used." (etypecase designator (stream designator) (pathname designator) (string (cond ((or (string-equal "/dev/stdin" designator) (string-equal "stdin" designator)) *standard-input*) ((or (string-equal "/dev/stdout" designator) (string-equal "stdout" designator)) *standard-output*) ((or (string-equal "/dev/stderr" designator) (string-equal "stderr" designator)) *error-output*) (t designator)))))
1,858
Common Lisp
.lisp
40
40.025
73
0.661894
keithj/deoxybyte-unix
2
0
1
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
da216f067f45fc6bb00014cf377aeb5e4cb9f89a987a3283b5df42df66bfbb43
21,033
[ -1 ]
21,034
default.lisp
keithj_deoxybyte-unix/src/default.lisp
;;; ;;; Copyright (c) 2013 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-unix. ;;; ;;; 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 :uk.co.deoxybyte-unix) (defun file-descriptor (stream &optional direction) (declare (ignore stream direction)) (error "FILE-DESCRIPTOR not supported on this implementation."))
966
Common Lisp
.lisp
22
42.636364
73
0.746285
keithj/deoxybyte-unix
2
0
1
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
455a6c1fe5a0a0cf1830dc66b2b4152f73a35c5b7923f68b95df45ed1eceaa59
21,034
[ -1 ]
21,035
deoxybyte-unix-ffi.lisp
keithj_deoxybyte-unix/src/deoxybyte-unix-ffi.lisp
;;; ;;; Copyright (c) 2009-2013 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-unix. ;;; ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of thcoe 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 :uk.co.deoxybyte-unix-ffi) (defctype off-t #-x86-64 :uint32 #+x86-64 :uint64 "Offset type.") (defctype size-t #-x86-64 :uint32 #+x86-64 :uint64 "Site type.") (defcvar ("errno" *c-error-number*) :int "Number of last error.") (defbitfield open-flags (:rdonly #x0000) :wronly ; #x0001 :rdwr ; ... :nonblock :append (:creat #x0200)) (defbitfield protection-flags (:none #x0000) :read :write :exec) (defbitfield map-flags (:shared #x0001) :private (:fixed #x0010)) (defcenum seek-directive :seek-set :seek-cur :seek-end) (defcenum sysconf-arg :sc-arg-max :sc-child-max :sc-clk-tck :sc-ngroups-max :sc-open-max :sc-stream-max :sc-tzname-max :sc-job-control :sc-saved-ids :sc-realtime-signals :sc-priority-scheduling :sc-timers :sc-asynchronous-io :sc-prioritized-io :sc-synchronized-io :sc-fsync :sc-mapped-files :sc-memlock :sc-memlock-range :sc-memory-protection :sc-message-passing :sc-semaphores :sc-shared-memory-objects :sc-aio-listio-max :sc-aio-max :sc-aio-prio-delta-max :sc-delaytimer-max :sc-mq-open-max :sc-mq-prio-max :sc-version :sc-pagesize :sc-rtsig-max :sc-sem-nsems-max :sc-sem-value-max :sc-sigqueue-max :sc-timer-max ;; POSIX2 :sc-bc-base-max :sc-bc-dim-max :sc-bc-scale-max :sc-bc-string-max :sc-coll-weights-max :sc-equiv-class-max :sc-expr-nest-max :sc-line-max :sc-re-dup-max :sc-charclass-name-max :sc-2-version :sc-2-c-bind :sc-2-c-dev :sc-2-fort-dev :sc-2-fort-run :sc-2-sw-dev :sc-2-localedef :sc-pii :sc-pii-xti :sc-pii-socket :sc-pii-internet :sc-pii-osi :sc-poll :sc-select :sc-uio-maxiov :sc-pii-internet-stream :sc-pii-internet-dgram :sc-pii-osi-cots :sc-pii-osi-clts :sc-pii-osi-m :sc-t-iov-max ;; POSIX threads :sc-threads :sc-thread-safe-functions :sc-getgr-r-size-max :sc-getpw-r-size-max :sc-login-name-max :sc-tty-name-max :sc-thread-destructor-iterations :sc-thread-keys-max :sc-thread-stack-min :sc-thread-threads-max :sc-thread-attr-stackaddr :sc-thread-attr-stacksize :sc-thread-priority-scheduling :sc-thread-prio-inherit :sc-thread-prio-protect :sc-thread-process-shared :sc-nprocessors-conf :sc-nprocessors-onln) (defcfun ("close" c-close) :int (file-descriptor :int)) (defcfun ("fileno" c-fileno) :int (stream :pointer)) (defcfun ("lseek" c-lseek) :int (file-descriptor :int) (offset off-t) (whence seek-directive)) (defcfun ("mkstemp" c-mkstemp) :int (template :pointer)) (defcfun ("mmap" c-mmap) :pointer (address :pointer) (length size-t) (protection protection-flags) (flags map-flags) (file-descriptor :int) (offset off-t)) (defcfun ("munmap" c-munmap) :int (address :pointer) (length size-t)) (defcfun ("open" c-open) :int (path :string) (flags open-flags) (mode :unsigned-int)) (defcfun ("strerror" c-strerror) :string (errno :int)) (defcfun ("sysconf" c-sysconf) :long (name sysconf-arg)) (defcfun ("write" c-write) :int (file-descriptor :int) (value :string) (count size-t))
3,993
Common Lisp
.lisp
167
21.02994
74
0.687352
keithj/deoxybyte-unix
2
0
1
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d4e53eac58b419fd8aec19f3cf2a364bc9bd6f9f009b98eaa06b7ccbee682f83
21,035
[ -1 ]
21,036
sbcl.lisp
keithj_deoxybyte-unix/src/sbcl.lisp
;;; ;;; Copyright (c) 2013 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-unix. ;;; ;;; 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 :uk.co.deoxybyte-unix) (defun file-descriptor (stream &optional direction) "Returns the Unix file descriptor associated with STREAM." (declare (ignore direction)) (sb-posix:file-descriptor stream))
990
Common Lisp
.lisp
23
41.695652
73
0.74715
keithj/deoxybyte-unix
2
0
1
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e56f6c8974c1162bcde5b04aedea7fb09c7f7acc329e85e359242fb0264cf753
21,036
[ -1 ]
21,037
deoxybyte-unix.asd
keithj_deoxybyte-unix/deoxybyte-unix.asd
;;; ;;; Copyright (c) 2009-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-unix. ;;; ;;; 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) (asdf:load-system :deoxybyte-systems) (in-package :uk.co.deoxybyte-systems) (defsystem deoxybyte-unix :name "deoxybyte-unix" :version "0.8.0" :author "Keith James" :licence "GPL v3" :in-order-to ((test-op (load-op :deoxybyte-unix :deoxybyte-unix-test)) (doc-op (load-op :deoxybyte-unix :cldoc))) :depends-on ((:version :deoxybyte-systems "1.0.0") :cffi ; (:version :cffi "0.10.3") (:version :deoxybyte-io "0.15.0")) :components ((:module :deoxybyte-unix :serial t :pathname "src/" :components ((:file "package") (:file "deoxybyte-unix-ffi") (:file "conditions") (:file "deoxybyte-unix") (:file "memory-map") #+:sbcl (:file "sbcl") #+:ccl (:file "ccl") #-(or :sbcl :ccl) (:file "default")))) :perform (test-op :after (op c) (maybe-run-lift-tests :deoxybyte-unix "deoxybyte-unix-test.config")) :perform (doc-op :after (op c) (maybe-build-cldoc-docs :deoxybyte-unix "doc/html")))
2,175
Common Lisp
.asd
47
35.06383
75
0.552731
keithj/deoxybyte-unix
2
0
1
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
81343749efae73e94c5f09c62ece54de74b8e32607e30f319318cf53ec5f7252
21,037
[ -1 ]
21,038
deoxybyte-unix-test.asd
keithj_deoxybyte-unix/deoxybyte-unix-test.asd
;;; ;;; Copyright (c) 2009-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-unix. ;;; ;;; 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/>. ;;; (defsystem deoxybyte-unix-test :depends-on ((:version :lift "1.7.0") :deoxybyte-unix) :components ((:module :deoxybyte-unix-test :serial t :pathname "test/" :components ((:file "package") (:file "deoxybyte-unix-test")))))
1,128
Common Lisp
.asd
26
37.423077
73
0.650318
keithj/deoxybyte-unix
2
0
1
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
31120b95321fee722be613d2610b465e90745ae0954687acbb5f699e82e2f8f9
21,038
[ -1 ]
21,066
rx-package.lisp
vlad-km_jscl-rx-src/rx-package.lisp
;;; -*- mode:lisp; coding:utf-8 -*- ;;; JSCL-RX is a Lisp (JSCL) wrapper for RxJS ;;; Copyright © 2018 Vladimir Mezentsev ;;; ;;; JSCL-RX 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. ;;; ;;; JSCL-RX 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 ;;; Version 3 from <http://www.gnu.org/licenses/>. ;;; ;;; ;;; JSCL - Is a Common Lisp to Javascript compiler ;;; https://github.com/jscl-project/jscl ;;; Licensed under GNU General Public License v3.0 ;;; ;;; RxJS - The Reactive Extensions for JavaScript (RxJS) 4.0 ;;; https://github.com/Reactive-Extensions/RxJS ;;; Licensed under the Apache License, Version 2.0 ;;; (eval-when (:compile-toplevel :load-toplevel :execute) (unless (find-package :rx) (make-package :rx :use (list 'cl)))) (in-package :rx) (export '(jscl::new jscl::oget jscl::make-new jscl::concat jscl::fset)) (export '(jscl::list-to-vector)) (in-package :cl-user) ;;; EOF
1,404
Common Lisp
.lisp
34
39.676471
76
0.695812
vlad-km/jscl-rx-src
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
57e15a25b7e89142ef92c90c4c67bbecbbd94b66ad4421c0ac4671e1bf98f975
21,066
[ -1 ]
21,067
finality.lisp
vlad-km_jscl-rx-src/finality.lisp
;;; -*- mode:lisp; coding:utf-8 -*- ;;; JSCL-RX is a lisp (JSCL) wrapper for RxJS ;;; This file is part of the JSCL-RX ;;; Copyright © 2018 Vladimir Mezentsev (in-package :cl-user) (unless (find :jscl-rx *features*) (push :jscl-rx *features*)) ;;; EOF
263
Common Lisp
.lisp
8
30.75
45
0.66
vlad-km/jscl-rx-src
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
fad49c5646b532393be01e2eed51e5b9b4b80b549e1dca8855c40f58e3d5ed2a
21,067
[ -1 ]
21,068
rx-sdf.lisp
vlad-km_jscl-rx-src/rx-sdf.lisp
;;; -*- mode:lisp; coding:utf-8 -*- ;;; JSCL-RX is a lisp (JSCL) wrapper for JSCL-RX ;;; This file is part of the JSCL-RX ;;; Copyright © 2018 Vladimir Mezentsev (lores:defsys :rx :path "git/jscl-rx" :depends (:promise) :components ((:file "rx-package") (:module "static" :depends ("rx-package") (:file "observable")) (:module "instance" :depends ("rx-package") (:file "observable")) (:file "finality"))) ;;; EOF
538
Common Lisp
.lisp
14
28.714286
60
0.524178
vlad-km/jscl-rx-src
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
de4fde1ddf08ae2af9a4d4181dab0e20b2812c0257f2cc60e4cd7b956250c56a
21,068
[ -1 ]
21,069
observable.lisp
vlad-km_jscl-rx-src/instance/observable.lisp
;;; -*- mode:lisp; coding:utf-8 -*- ;;; JSCL-RX is a lisp (JSCL) wrapper for RxJS ;;; This file is part of the JSCL-RX ;;; Copyright © 2018 Vladimir Mezentsev (in-package :rx) ;;; ;;; Observable Instance methods ;;; ;;; SUBSCRIBE ;;; ;;; (defun subscribe (rxo on &optional error complite) (funcall ((oget rxo "subscribe" "bind") rxo on error complite))) (export '(subscribe)) ;;; TAKE ;;; ;;; Returns a specified number of contiguous elements from the start of an observable sequence, ;;; using the specified scheduler for the edge case of take(0). ;;; ;;; Arguments ;;; ;;; count (Number): The number of elements to return. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence that contains the elements before and ;;; including the specified index in the input sequence. (defun take (rxo count) (funcall ((oget rxo "take" "bind") rxo count))) (export '(take)) ;;; TAKE-LAST ;;; ;;; Returns a specified number of contiguous elements from the end of an observable sequence, ;;; using an optional scheduler to drain the queue. ;;; This operator accumulates a buffer with a length enough to store elements count elements. ;;; Upon completion of the source sequence, this buffer is drained on the result sequence. ;;; This causes the elements to be delayed. ;;; ;;; Arguments ;;; ;;; count (Number): Number of elements to bypass at the end of the source sequence. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence containing the source sequence elements ;;; except for the bypassed ones at the end. ;;; ;;; (defun take-last (rxo count) (funcall ((oget rxo "takeLast" "bind") rxo count))) (export '(take-last)) ;;; TAKE-LAST-WITH-TIME ;;; ;;; Returns elements within the specified duration from the end of the observable source sequence, ;;; ;;; Arguments ;;; ;;; duration (Number): Duration for taking elements from the end of the sequence. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence with the elements taken during the specified ;;; duration from the end of the source sequence. (defun take-last-with-time (rxo duration) (funcall ((oget rxo "takeLastWithTime" "bind") rxo duration))) (export '(take-last-with-time)) ;;; TAKE-UNTIL ;;; ;;; Returns the values from the source observable sequence until the other observable sequence ;;; or Promise produces a value. ;;; ;;; Arguments ;;; ;;; other (Observable | Promise): Observable sequence or Promise that terminates ;;; propagation of elements of the source sequence. ;;; Returns ;;; ;;; (Observable): An observable sequence containing the elements of the source sequence ;;; up to the point the other sequence or Promise interrupted further propagation. ;;; ;;; ;;; (rx:take-until (rx:observable-timer 0 1000) (rx:observable-timer 5000)) ;;; => 0,1,2,3,4 ;;; (defun take-until (rxo other) (funcall ((oget rxo "takeUntil" "bind") rxo other))) (export '(take-until)) ;;; TAKE-WHILE ;;; ;;; Returns elements from an observable sequence as long as a specified condition is true. ;;; ;;; Arguments ;;; ;;; predicate (Function): A function to test each source element for a condition. ;;; The callback is called with the following information: ;;; the value of the element ;;; the index of the element ;;; the Observable object being subscribed ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence that contains the elements ;;; from the input sequence that occur before the element at which the test no longer passes. ;;; ;;; (setq twp (lambda (val idx obs) (< val 3))) ;;; (rx:take-while (rx:observable-range 1 5) twp) ;;; => 0,1,2 ;;; (defun take-while (rxo predicate) (funcall ((oget rxo "takeWhile" "bind") rxo predicate))) (export '(take-while)) ;;; SKIP ;;; ;;; Bypasses a specified number of elements in an observable sequence and then returns the remaining elements. ;;; ;;; Arguments ;;; ;;; count (Number): The number of elements to skip before returning the remaining elements. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence that contains the elements that ;;; occur after the specified index in the input sequence. ;;; ;;; (rx:skip (rx:0bservable-range 0 5) 3) ;;; => 3,4 ;;; (defun skip (rxo count) (funcall ((oget rxo "skip" "bind") rxo count))) (export '(skip)) ;;; SKIP-LAST ;;; ;;; Bypasses a specified number of elements at the end of an observable sequence. ;;; This operator accumulates a queue with a length enough to store the first count elements. ;;; As more elements are received, elements are taken from the front of the queue and produced ;;; on the result sequence. This causes elements to be delayed. ;;; ;;; ;;; Arguments ;;; ;;; count (Number): Number of elements to bypass at the end of the source sequence. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence containing the source sequence elements ;;; except for the bypassed ones at the end. ;;; ;;; ;;; (rx:skip-last (rx:observable-range 0 5) 3) ;;; => 0,1 ;;; (defun skip-last (rxo count) (funcall ((oget rxo "skipLast" "bind") rxo count))) (export '(skip-last)) ;;; SKIP-LAST-WITH-TIME ;;; ;;; Bypasses a specified number of elements at the end of an observable sequence. ;;; This operator accumulates a queue with a length enough to store the first count elements. ;;; As more elements are received, elements are taken from the front of the queue and produced ;;; on the result sequence. This causes elements to be delayed. ;;; ;;; Arguments ;;; ;;; duration (Number): Duration for skipping elements from the end of the sequence. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence with the elements skipped during ;;; the specified duration from the end of the source sequence. ;;; ;;; ;;; (rx:skip-last-with-time (rx:take (rx:observable-timer 0 1000) 10) 5000) ;;; => 0,1,2,3,4 ;;; (defun SKIP-LAST-WITH-TIME (rxo duration) (funcall ((oget rxo "skipLastWithTime" "bind") rxo duration))) (export '(skip-last-with-time)) ;;; SKIP-UNTIL ;;; ;;; Returns the values from the source observable sequence only after the other ;;; observable sequence produces a value. ;;; ;;; Arguments ;;; ;;; other (Observable | Promise): The observable sequence or Promise that triggers ;;; propagation of elements of the source sequence. ;;; Returns ;;; ;;; (Observable): An observable sequence containing the elements of the source sequence ;;; starting from the point the other sequence triggered propagation. ;;; ;;; ;;; (rx:skip-until (rx:observable-timer 0 1000) (rx:observable-timer 5000)) ;;; => 6,7,8 ;;; (defun skip-until (rxo other) (funcall ((oget rxo "skipUntil" "bind") rxo other))) (export '(skip-until)) ;;; SKIP-UNTIL-WITH-TIME ;;; ;;; Skips elements from the observable source sequence until the specified ;;; start time ;;; ;;; Errors produced by the source sequence are always forwarded to the result sequence, ;;; even if the error occurs before the start time. ;;; ;;; Arguments ;;; ;;; start (Date | Number): Time to start taking elements from the source sequence. ;;; If this value is less than or equal to current time, no elements will be skipped. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence with the elements skipped until the specified start time. ;;; ;;; (rx:skip-until-with-time (rx:observable-timer 0 1000) 5000) ;;; => 6,7,8 (defun skip-until-with-time (rxo start) (funcall ((oget rxo "skipUntilWithTime" "bind") rxo start))) (export '(skip-until-with-time)) ;;; SKIp-WHILE ;;; ;;; Bypasses elements in an observable sequence as long as a specified condition is true ;;; and then returns the remaining elements. ;;; ;;; Arguments ;;; ;;; predicate (Function): A function to test each source element for a condition. ;;; The callback is called with the following information: ;;; the value of the element ;;; the index of the element ;;; the Observable object being subscribed ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence that contains the elements ;;; from the input sequence starting at the first element in the linear series ;;; that does not pass the test specified by predicate. ;;; ;;; (rx:skip-while (rx:observable-range 1 5) (lambda (x idx obs) (< x 3))) ;;; => 3,4,5 ;;; ;;; (defun skip-while (rxo pred) (funcall ((oget rxo "skipWhile" "bind") rxo pred))) (export '(skip-while)) ;;; DELAY ;;; ;;; Time shifts the observable sequence by dueTime. The relative time intervals ;;; between the values are preserved. ;;; ;;; or ;;; ;;; Time shifts the observable sequence based on a subscription delay and a delay ;;; selector function for each element. ;;; ;;; Arguments ;;; ;;; ;;; Delay with an absolute or relative time: ;;; ;;; time (Date | Number): Absolute (specified as a Date object) ;;; or relative time (specified as an integer denoting milliseconds) ;;; by which to shift the observable sequence. ;;; ;;; Delay with a delay selector function: ;;; ;;; [delays] (Observable): Sequence indicating the delay for the ;;; subscription to the source. ;;; ;;; duration (Function): Selector function to retrieve a sequence indicating ;;; the delay for each given element. ;;; ;;; (defun delay (rxo time &optional duration) (funcall ((oget rxo "delay" "bind") rxo time duration))) (export '(delay)) ;;; SELECT \ ;;; ==> RX:_MAP / RX:SELECT ;;; MAP / ;;; ;;; Projects each element of an observable sequence into a new form by incorporating the element's index. ;;; ;;; ;;; Arguments ;;; ;;; selector (Function | Object): Transform function to apply to each ;;; source element or an element to yield. If selector ;;; is a function, it is called with the following information: ;;; the value of the element ;;; the index of the element ;;; the Observable object being subscribed ;;; ;;; (rx:select (rx:observable-from-event "mousemove") ;;; (lambda (x idx obs) (oget x "clientX")) ) ;;; ;;; (rx:_map (rx:observable-from-event "mousemove") ;;; (lambda (x idx obs) (oget x "clientX")) ) ;;; (defun select (rxo fn) (funcall ((oget rxo "select" "bind") rxo fn))) (fset '_map #'select) (export '(select _map)) ;;; SELECT-MANY ;;; FLAT-MAP ;;; ;;; One of the following: ;;; ;;; i. Projects each element of an observable sequence to an observable sequence and merges ;;; the resulting observable sequences or Promises or array/iterable into one observable sequence. ;;; ;;; ii. Projects each element of an observable sequence or Promise to an observable sequence, ;;; invokes the result selector for the source element and each of the corresponding ;;; inner sequence's elements, and merges the results into one observable sequence. ;;; ;;; iii. Projects each element of the source observable sequence to the other observable ;;; sequence or Promise, or array/iterable and merges the resulting observable ;;; sequences into one observable sequence. ;;; ;;; ;;; Arguments ;;; ;;; selector (Function | Iterable | Promise): An Object to project to the sequence or ;;; a transform function to apply to each element or an observable sequence ;;; to project each element from the source sequence onto. ;;; The selector is called with the following information: ;;; ;;; x: the value of the element ;;; idx: the index of the element ;;; obs: the Observable object being subscribed ;;; ;;; [result] (Function): A transform function to apply to each element of the ;;; intermediate sequence. The resultSelector is called with the ;;; following information: ;;; ;;; x: the value of the outer element ;;; y: the value of the inner element ;;; idx: the index of the outer element ;;; idy: the index of the inner element ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence whose elements are the result of invoking the one-to-many transform ;;; function collectionSelector on each element of the input sequence and then mapping each of those ;;; sequence elements and their corresponding source element to a result element. ;;; ;;; ;;; ;;; (rx:flat-map ;;; (rx:observable-range 1 2) ;;; (lambda (x idx obs) (rx:observable-range x 2))) ;;; => 1,2,2,3 ;;; ;;; ;;; (rx:flat-map (rx:observable-of 1 2 3 4) ;;; (lambda (x idx obs) (promise:resolve (+ x idx)))) ;;; => 1,3,5,7 ;;; ;;; ;;; ;;; (rx:flat-map (rx:observable-of 2 3 5) ;;; (lambda (x idx obs) ;;; (vector (* x x) (* x x x) (* x x x x))) ;;; (lambda (x y idx idy) ;;; (mkjso "outer" x "inner" y "outerIdx" idx "innerIdx" idy))) (defun select-many (rxo selector &optional resulter) (funcall ((oget rxo "selectMany" "bind") rxo selector resulter))) (export '(select-many)) (fset 'flat-map #'select-many) (export '(flat-map)) ;;; JOIN => RX:_JOIN ;;; ;;; Correlates the elements of two sequences based on overlapping durations. ;;; ;;; Arguments ;;; ;;; right (Observable): The right observable sequence to join elements for. ;;; ;;; left (Function): A function to select the duration (expressed as an ;;; observable sequence) of each element of the left observable ;;; sequence, used to determine overlap. ;;; ;;; selector (Function): A function to select the duration ;;; (expressed as an observable sequence) of each ;;; element of the right observable sequence, used to determine overlap. ;;; ;;; result (Any): A function invoked to compute a result element for any two ;;; overlapping elements of the left and right observable ;;; sequences. The parameters are as follows: ;;; (Any) Element from the left source for which the overlap occurs. ;;; (Any) Element from the right source for which the overlap occurs. ;;; Returns ;;; ;;; (Observable): An observable sequence that contains result elements ;;; computed from source elements that have an overlapping duration. ;;; ;;; (setq xs (rx:_map (rx:observable-interval 100) (lambda (x) (concat "First-" x)))) ;;; (setq ys (rx:_map (rx:observable-interval 100) (lambda (x) (concat "Second-" x)))) ;;; (setq src (rx:_join xs ;;; ys ;;; (lambda () (rx:observable-timer 0)) ;;; (lambda () (rx:observable-times 0)) ;;; (lambda (x y) (concat x "-" y)))) ;;; ;;; (rx:subscribe (rx:take src 5) (lambda (x) (print x))) ;;; (defun _join (rxo right left selector result) (funcall ((oget rxo rigth left selector result)))) (export '(_join)) ;;; CONCAT => RX:_CONCAT ;;; ;;; Concatenates all the observable sequences. This takes in either an array or variable ;;; arguments to concatenate. ;;; ;;; Arguments ;;; ;;; args (arguments | Array): An array or arguments of Observable sequences. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence that contains the elements of each given sequence, in sequential order. ;;; ;;; ;;; (setq src (rx:_concat ;;; (rx:observable-just 42) ;;; (rx:observable-just 56) ;;; (rx:observable-just 72))) (defun _concat (rxo &rest args) (funcall ((oget rxo "concat" "bind") rxo (list-to-array args)))) (export '(_concat)) ;;; FIRST => RX:_FIRST ;;; ;;; Returns the first element of an observable sequence that satisfies the condition in the predicate, ;;; or a default value if no such element exists. If no default value is given, then onError will be called. ;;; ;;; Arguments ;;; ;;; Rx.Observable.prototype.first([predicate], [thisArg], [defaultValue]) ;;; ;;; [predicate] (Function): A predicate function to evaluate for elements in the source sequence. ;;; The callback is called with the following information: ;;; the value of the element ;;; the index of the element ;;; the Observable object being subscribed ;;; [thisArg] (Any): Object to use as this when executing the predicate. ;;; [defaultValue] (Any): Default value if no such element exists. ;;; ;;; ;;; ;;; without predicate ;;; ;;; (setq pred (lambda (x idx obs) (if (oddp x) t nil))) ;;; (setq src (rx:_first (rx:observable-range 0 10))) ;;; (rx:subscribe src (lambda (x) (print x))) ;;; => 0 ;;; ;;; with predicate ;;; ;;; (rx:subscribe (rx:_first (rx:observable-range 0 10) :predicate pred) (lambda (x) (print x))) ;;; => 1 ;;; ;;; with default value ;;; ;;; (rx:subscribe (rx:_first (rx:observable-range 0 10) ;;; :predicate (lambda (x idx obs) (> x 10)) ;;; :default 42)) ;;; (lambda (x) (print x))) ;;; => 42 ;;; or ;;; ;;; (rx:subscribe (rx:_first (rx:observable-range 0 10) ;;; :predicate (lambda (x idx obs) (> x 10)) ;;; :default (lambda (x) 42)) ;;; (lambda (x) (print x))) ;;; => 42 ;;; (defun _first (rxo &key predicate default) (rx/fl_common rxo "first" predicate default)) (export '(_first)) ;;; LAST => RX:_LAST ;;; ;;; Returns the last element of an observable sequence that satisfies the condition in the ;;; predicate if specified, else the last element. If no element was found and no default ;;; value is specified, onError is called with an error, however if a default value was specified, ;;; it will be yielded via an onNext call. ;;; ;;; Arguments ;;; ;;;Rx.Observable.prototype.last([predicate], [thisArg], [defaultValue]) ;;; ;;; [predicate] (Function): A predicate function to evaluate for elements in the source sequence. ;;; The callback is called with the following information: ;;; ;;; the value of the element ;;; the index of the element ;;; the Observable object being subscribed ;;; [defaultValue] (Any): Default value if no such element exists. ;;; (defun _last (rxo &key predicate default) (rx/fl_common rxo "last" predicate default)) (export '(_last)) ;;; ;;; first => (rx/fl_common rxo "first" predicate default) ;;; last => (rx/fl_common rxo "last" predicate default) ;;; (defun rx/fl_common (rxo opname predicate default) (if default (let ((defv (list "defaultValue" default))) (funcall ((oget rxo opname "bind") rxo (if predicate (append defv (list "predicate" predicate)) defv)))) (funcall ((oget rxo opname "bind") rxo predicate)))) ;;; THROTTLE ;;; ;;; Returns an Observable that emits only the first item emitted by the source Observable ;;; during sequential time windows of a specified duration. ;;; ;;; Arguments ;;; ;;; windowDuration (Number): Time to wait before emitting another item after emitting ;;; the last item (specified as an integer denoting milliseconds). ;;; ;;; ;;; Returns ;;; ;;; (Observable): An Observable that performs the throttle operation. ;;; ;;; ;;; (setq times ;;; (vector ;;; (mkjso "value" 0 "time" 100) ;;; (mkjso "value" 1 "time" 600) ;;; (mkjso "value" 2 "time" 400) ;;; (mkjso "value" 3 "time" 900) ;;; (mkjso "value" 4 "time" 200))) ;;; ;;; (setq src (rx:flat-map ;;; (rx:observable-from times) ;;; (lambda (x idx obs) ;;; (rx:delay (rx:observable-of (oget x "value")) (oget x "time"))))) ;;; ;;; (rx:throttle src 300) ;;; => 0,2,3 ;;; (defun throttle (rxo duration) (funcall ((oget rxo "throttle" "bind") rxo duration))) (export '(throttle)) ;;; TIME-INTERVAL ;;; ;;; Records the time interval between consecutive values in an observable sequence. ;;; ;;; Arguments ;;; ;;; None ;;; Returns ;;; ;;; (Observable): An observable sequence with time interval information on values. ;;; -> (mkjso "value" seqn "interval" timeinterval) ;;; ;;; (rx:take ;;; (rx:_map (rx:time-interval (rx:observable-timer 0 1000 )) ;;; (lambda (x idx obs) (concat (oget x "value") "-" (oget x "interval")))) ;;; 5) ;;; ;;; => "0-1000", "1-1000", "2-1000", "3-1000", "4-1000" ;;; (defun time-interval (rxo) (funcall ((oget rxo "timeInterval" "bind") rxo))) (export '(time-interval)) ;;; TIMEOUT ;;; ;;; Rx.Observable.prototype.timeout(dueTime, [other], [scheduler]) ;;; ;;; Rx.Observable.prototype.timeout([firstTimeout], timeoutDurationSelector, [other]) ;;; ;;; Returns the source observable sequence or the other observable sequence if dueTime elapses. ;;; ;;; --OR-- ;;; ;;; Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled. ;;; ;;; Arguments ;;; ;;; If using a relative or absolute time: ;;; ;;; dueTime (Date | Number): Absolute (specified as a Date object) or relative time ;;; (specified as an integer denoting milliseconds) when a timeout occurs. ;;; ;;; [other] (Observable | Promise | Error): Observable sequence or Promise to return in case ;;; of a timeout. If a string is specified, then an error will be ;;; thrown with the given error message. ;;; If not specified, a timeout error throwing sequence will be used. ;;; ;;; ;;; If using a timeout duration selector: ;;; ;;; [firstTimeout] (Observable): Observable sequence that represents the timeout for the first element. ;;; If not provided, this defaults to Rx.Observable.never(). ;;; ;;; timeoutDurationSelector (Function): Selector to retrieve an observable sequence ;;; that represents the timeout between the current element and the next element. ;;; ;;; [other] (Scheduler):Sequence to return in case of a timeout. If not provided, this is set to Observable.throw ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence with time interval information on values. ;;; ;;; ;;; (rx:timeout (rx:delay 5000 (rx:observable-just 42)) 200) ;;; => Error:TIMEOUT ;;; ;;; (setq src (rx:delay (rx:observable-just 42) 5000)) ;;; (rx:timeout src 200 (rx:observable-empty)) ;;; => "Completed" ;;; ;;; ;;; (setq src (rx:delay (rx:observable-just 42) 5000)) ;;; (rx:timeout src (promise:resolve 42) 200) ;;; => 42 ;;; ;;; ;;; (setq times (vector 200 300 3550 400)) ;;; (setq src (rx:_map ;;; (rx:observable-for times ;;; (lambda (x idx obs) (rx:observable-timer x) )) ;;; (lambda (x idx obs) idx))) ;;; ;;; without a first timeout ;;; ;;; (rx:timeout src (lambda (x idx bs) ;;; (rx:observable-timer 400))) ;;; => 0,1,2 (defun timeout (rxo due other) (funcall ((oget rxo "timeout" "bind") rxo due other))) (export '(timeout)) ;;; TIMESTAMP ;;; ;;; Records the timestamp for each value in an observable sequence. ;;; ;;; Arguments ;;; ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence with timestamp information on values. ;;; ;;; ;;; ;;; (rx:take (rx:_map (rx:timestamp (rx:observable-timer 0 1000)) ;;; (lambda (x idx obs) (oget x "timestamp"))) ;;; 5) ;;; => 1378690776351, 1378690777313, 1378690778316,1378690779317,1378690780319 (defun timestamp (rxo) (funcall ((oget rxo "timestamp" "bind") rxo))) (export '(timestamp)) ;;; PLUCK ;;; ;;; Returns an Observable containing the value of a specified nested property from all ;;; elements in the Observable sequence. If a property can't be resolved, it will return ;;; undefined for that value. ;;; ;;; Arguments ;;; ;;; property (String): The property or properties to pluck. pluck accepts ;;; an unlimited number of nested property parameters. ;;; ;;; Returns ;;; ;;; (Observable): Returns a new Observable sequence of property values. ;;; ;;; ;;; ;;; (let ((values (vector (mkjso "value" 0) (mkjso "value" 1) (mkjso "value" 2)))) ;;; (subs (rx:pluck (rx:observable-from values) "value" ))) ;;; (defun pluck (rxo property) (funcall ((oget rxo "pluck" "bind") rxo property))) (export '(pluck)) (in-package :cl-user) ;;; EOF
25,930
Common Lisp
.lisp
683
36.452416
119
0.61164
vlad-km/jscl-rx-src
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
8efa62f2859283cb81a6a22f5d0e23d08cc7da1c91f4f03e1cc6cc406de6fded
21,069
[ -1 ]
21,070
units.lisp
vlad-km_jscl-rx-src/tests/units.lisp
;;; -*- mode:lisp; coding:utf-8 -*- (defparameter *debug* nil) (defun subs (rxo) (rx:subscribe rxo (lambda (x) (if *debug* (console "Ok" x)) (print (list 'Ok x))) (lambda (x) (print (list 'Error x))) (lambda () (print 'Complete )) )) ;;;(fset 'mkjso #'make-js-object) ;;; observable-while (let ((*counter* 0)) (subs (rx:observable-while (lambda () (< (incf *counter*) 5)) (rx:observable-just 42)) ) ) ;;; observable-case (let ((sources (mkjso "foo" (rx:observable-just 42) "bar" (rx:observable-just 22))) (default (rx:observable-empty))) (subs (rx:observable-case (lambda () "foo") sources default)) (subs (rx:observable-case (lambda () "bar") sources default)) ) ;;; observable-amb ;;; (subs (rx:observable-amb (rx:select (rx:observable-timer 500) (lambda (x idx obs) "foo")) (rx:select (rx:observable-timer 200) (lambda (x idx obs) "bar"))) ) ;;; CONCAT (subs (rx:observable-concat (rx:observable-just 11) (rx:observable-empty) (rx:observable-just 55))) ;;; generate-with-absolute-time (subs (rx:time-interval (rx:observable-generate-with-absolute-time 1 (lambda (x) (< x 4)) (lambda (x) (1+ x)) (lambda (x) x) (lambda (x) (+ (#j:Date:now (* 100 x)))))) ) ;;; generate with relative time (subs (rx:time-interval (rx:observable-generate-with-relative-time 1 (lambda (x) (< x 4)) (lambda (x) (1+ x)) (lambda (x) x) (lambda (x) (* 100 x))))) ;;; IF (let ((*should-run* t)) (subs (rx:observable-if (lambda () *should-run*) (rx:observable-just 111))) (setq *should-run* nil) (subs (rx:observable-if (lambda () *should-run*) (rx:observable-just 111) (rx:observable-just 999))) ) ;;; PLUCK (let ((values (vector (mkjso "value" 0) (mkjso "value" 1) (mkjso "value" 2)))) (subs (rx:pluck (rx:observable-from values) "value" ))) ;;; MERGE (let ((*src0* (rx:pluck (rx:time-interval (rx:observable-interval 100)) "interval")) (*src1* (rx:pluck (rx:time-interval (rx:observable-interval 150)) "interval") )) (subs (rx:take (rx:observable-merge *src0* *src1*) 5))) ;;; RANGE (subs (rx:observable-range 10 12) ) ;;; FOR (subs (rx:observable-for (vector 1 2 3) (lambda (val idx obj) (rx:observable-just val)))) ;;; FORK-JOIN ;;; ERROR - too many arguments ;;; ERROR: ERROR: source.subscribe is not a function (subs (rx:observable-fork-join (rx:observable-just 42) (rx:observable-range 0 10))) ;;; => #(42 9) ;;; (subs (rx:observable-fork-join #(1 2 3 4) (rx:observable-range 0 10) (lambda (x y z) (+ x y)))) ;;; => 13 ;;; FROM (rx:subscribe (rx:observable-from "abcd") (lambda (x) (princ x))) ;;; error!!! (rx:subscribe (rx:observable-from 1 2 3 4) (lambda (x) (print x))) ;;; FROM-CALLBACK (setf #j:Fs (require "fs")) (fset 'exists (rx::observable-from-callback #j:Fs:exists)) (rx:subscribe (exists "file.txt") (lambda (ok) (if ok (format t "proceed file.txt") (error "file.txt ?")))) ;;; FROM-EVENTS (let ((event-emitter)) (unless #j:EE (setf #j:EE(require "events"))) (setq event-emitter (make_Instance #j:window "EE")) (subs (rx:observable-from-event event-emitter "data" (lambda (foo bar) (mkjso "foo" foo "bar" bar))) ) (funcall ((oget event-emitter "emit" "bind") event-emitter "data" "baz" "quux")) ) ;;; FROM-EVENTS-PATTERN (let ((emitter)) (unless #j:EE (require "events")) (setq emitter (make-new #j:EE)) (setq src (rx:observable-from-event-pattern (lambda (handl) (funcall ((oget emitter "addListener" "bind") emitter "data" handl))) (lambda (handl) (funcall ((oget emitter "removeListener" "bind") emitter "data" handl))) (lambda (foo bar) (mkjso "foo" foo "bar" bar)))) (subs src) (funcall ((oget emitter "emit" "bind") emitter "data" "Baaaz" "Qqqux")) ) ;;; FROM-PROMISE (let ((promise (lambda () (promise:resolve 42)))) (subs (rx:observable-from-promise promise)) (setq promise (promise:resolve "Agree")) (subs (rx:observable-from-promise promise)) (setq promise (promise:reject "Unbound")) (subs (rx:observable-from-promise promise)) ) ;;; FLAT_MAP (subs (rx:flat-map (rx:observable-range 1 2) (lambda (x idx obs) (rx:observable-range x 2))) ) (subs (rx:flat-map (rx:observable-of 1 2 3 4) (lambda (x idx obs) (promise:resolve (+ x idx)))) ) (subs (rx:flat-map (rx:observable-of 2 3 5) (lambda (x idx obs) (vector (* x x) (* x x x) (* x x x x))) (lambda (x y idx idy) (mkjso "outer" x "inner" y "outerIdx" idx "innerIdx" idy)))) ;;; COMBINE-LATEST (let* ((src1 (rx:_map (rx:observable-interval 100) (lambda (x idx obs) (concat "First " x)))) (src2 (rx:_map (rx:observable-interval 100) (lambda (x idx obs) (concat "Second " x)))) (src (rx:take (rx:observable-combine-latest src1 src2) 2))) (subs src )) ;;; TIMER PLUCK (fset 'pluk-interval (lambda (due period) (rx:pluck (rx:time-interval (rx:observable-timer due period)) "interval"))) (fset 'take (lambda (how from) (rx:take from how))) (fset 'subscribe (lambda (source) (rx:subscribe source (lambda (value) (push value someplace)) (lambda (errmsg) (error "wtf ~a?" errmsg)) (lambda () (rx:observable-start-async #'proc:proc-someplace))))) (subscribe (take 3 (pluck-interval 200 100))) ;;; START (let ((context (mkjso "value" 42))) (subs (rx:observable-start (lambda () (print (list 'Async-start (oget context "value"))))))) ;;; START-ASYNC (let ((async (lambda () (promise:resolve 42)))) (subs (rx:observable-start-async async))) ;;; TO-ASYNC (let* ((fn (lambda (x y) (+ x y))) (afn (rx:observable-to-async fn)) (src)) (setq src (funcall afn 11 22)) (subs src)) ;;; TAKE-LAST (subs (rx:take-last (rx:observable-range 0 5) 3)) ;;; TAKE-LAST-WITH-TIME (subs (rx:take-last-with-time (rx:take (rx:observable-timer 0 1000) 10) 5000)) ;;; TAKE-UNTIL (subs (rx:take-until (rx:observable-timer 0 1000) (rx:observable-timer 5000))) ;;; TAKE-WHILE (let ((twp (lambda (val idx obs) (< val 3)))) (subs (rx:take-while (rx:observable-range 1 5) twp) )) ;;; THROTTLE (let* ((times (vector (mkjso "value" 0 "time" 100) (mkjso "value" 1 "time" 600) (mkjso "value" 2 "time" 400) (mkjso "value" 3 "time" 900) (mkjso "value" 4 "time" 200))) (src (rx:flat-map (rx:observable-from times) (lambda (x idx obs) (rx:delay (rx:observable-of (oget x "value")) (oget x "time")))))) ;; => 0,2,3 (subs (rx:throttle src 300)) ) ;;; TIME-INTERVAL ;;; => "0-1000", "1-1000", "2-1000", "3-1000", "4-1000" (subs (rx:take (rx:_map (rx:time-interval (rx:observable-timer 0 1000 )) (lambda (x idx obs) (concat (oget x "value") "-" (oget x "interval")))) 5) ) ;;; TIMESTAMP ;;; => 1378690776351, 1378690777313, 1378690778316,1378690779317,1378690780319 (subs (rx:take (rx:_map (rx:timestamp (rx:observable-timer 0 1000)) (lambda (x idx obs) (oget x "timestamp"))) 5)) ;;; _FIRST (subs (rx:_first (rx:observable-range 0 12) :predicate (lambda (x idx obs) (> x 10)) :default 42)) (let ((pred (lambda (x idx obs) (if (oddp x) t nil))) (src (rx:_first (rx:observable-range 0 10)))) ;; => 0 (subs src)) (let ((pred (lambda (x idx obs) (if (oddp x) t nil)))) ;; => 1 (rx:subscribe (rx:_first (rx:observable-range 0 10) :predicate pred) (lambda (x) (print x)))) ;;; EOF
8,032
Common Lisp
.lisp
245
27.106122
100
0.583431
vlad-km/jscl-rx-src
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
948c04c0e10eac262188ecac32efc1c2c338d29d7044b19d3683fb83012b751f
21,070
[ -1 ]
21,071
observable.lisp
vlad-km_jscl-rx-src/static/observable.lisp
;;; -*- mode:lisp; coding:utf-8 -*- ;;; JSCL-RX is a lisp (JSCL) wrapper for RxJS ;;; This file is part of the JSCL-RX ;;; Copyright © 2018 Vladimir Mezentsev (in-package :rx) ;;; ;;; Observable static methods ;;; ;;; AMB ;;; ;;; Propagates the observable sequence or Promise that reacts first. "amb" stands for ambiguous. ;;; ;;; Arguments ;;; ;;; args (Array|arguments): Observable sources or Promises competing to react first either as an array or arguments. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence that surfaces any of the given sequences, whichever reacted first. ;;; ;;; ;;; ;;; (rx:observable-amb ;;; (rx:select (rx:observable-timer 500) (lambda () "foo")) ;;; (rx:select (rx:observable-timer 200) (lambda () "bar"))) ;;; (defun observable-amb (&rest sources) (apply #j:Rx:Observable:amb sources)) (export '(observable-amb)) ;;; CASE ;;; ;;; Uses selector to determine which source in sources to use. ;;; ;;; Arguments ;;; ;;; selector (Function): The function which extracts the value for to test in a case statement. ;;; ;;; sources (Object): An object which has keys which correspond to the case statement labels. ;;; ;;; else (Observable): The observable sequence that will be run if the sources are not ;;; matched. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence which is determined by a case statement. ;;; ;;; (defparameter sources (mkjso "foo" (rx:observable-just 42) "bar" (rx:observable-just 22))) ;;; (defparameter default (rx:observable-empty)) ;;; (rx:observable-case ;;; (lambda () "foo") ;;; sources ;;; default) (defun observable-case (selector sources &optional else) (#j:Rx:Observable:case selector sources else )) (export '(observable-case)) ;;; CONCAT ;;; ;;; Concatenates all of the specified observable sequences, as long as the previous ;;; observable sequence terminated successfully. ;;; ;;; Arguments ;;; ;;; args (Array | arguments): Observable sequences or Promises to concatenate. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence that contains the elements of each given sequence, ;;; in sequential order. ;;; ;;; (rx:observable-concat ;;; (rx:observable-just 11) ;;; (rx:observable-empty) ;;; (rx:observable-just 55)) ;;; (defun observable-concat (&rest sources) (#j:Rx:Observable:concat (list-to-vector sources))) (export '(observable-concat)) ;;; CREATE ;;; ;;; Creates an observable sequence from a specified subscribe method implementation. ;;; ;;; Arguments ;;; ;;; subscribe (Function): Implementation of the resulting observable sequence's subscribe method, ;;; optionally returning a function that will be wrapped in a disposable object. ;;; This could also be a disposable object. ;;; ;;; Returns ;;; ;;; (Observable): The observable sequence with the specified implementation for the subscribe method. ;;; ;;; ;;; ;;; (rx:observable-create ;;; (lambda (observer) ;;; (rx:on-next-observer observer 42) ;;; (rx:on-completed-observer observer) ;;; (lambda () (format *console* "Disposed~%")))) ;;; ;;; or, if you require no cleanup ;;; ;;; (rx:observable-create ;;; (lambda (observer) ;;; (rx:on-next-observer observer 42) ;;; (rx:on-completed-observer observer) ;;; (values))) ;;; ;;; or ;;; ;;; (rx:observable-create ;;; (lambda (observer) ;;; (rx:on-next-observer observer 42) ;;; (rx:on-completed-observer observer) ;;; (rx:disposable-create (lambda () (format *console* "Disposable<br>"))))) ;;; (defun observable-create (observer) (#j:Rx:Observable:create observer)) (export '(observable-create)) ;;; GENERATE ;;; ;;; Generates an observable sequence in a manner similar to a for loop, using ;;; an optional scheduler to enumerate the values. ;;; ;;; Arguments ;;; ;;; initial (Any): Initial state. ;;; ;;; condition (Function): Condition to terminate generation (upon returning false). ;;; ;;; iterate (Function): Iteration step function. ;;; ;;; selector (Function): Selector function for results produced in the sequence. ;;; ;;; Returns ;;; ;;; (Observable): The generated sequence. (defun observable-generate (initial condition iterate selector) (#j:Rx:Observable:generate initial condition iterate selector)) (export '(observable-generate)) ;;; GENERATE-WITH-ABSOLUTE-TIME ;;; ;;; Generates an observable sequence by iterating a state from an initial state until the condition fails. ;;; ;;; Arguments ;;; ;;; initialState (Any): Initial state. ;;; condition (Function): Condition to terminate generation (upon returning false). ;;; iterate (Function): Iteration step function. ;;; resultSelector (Function): Selector function for results produced in the sequence. ;;; timeSelector (Function): Time selector function to control the speed of values being ;;; produced each iteration, returning Date values. ;;; ;;; Returns ;;; ;;; (Observable): The generated sequence. ;;; ;;; ;;; (rx:time-interval ;;; (rx:observable-generate-with-absolute-time ;;; 1 ;;; (lambda (x) (< x 4)) ;;; (lambda (x) (1+ x)) ;;; (lambda (x) x) ;;; (lambda (x) (+ (#j:Date:now (* 100 x)))))) ;;; (defun observable-generate-with-absolute-time (initial condition iter result time) (#j:Rx:Observable:generateWithAbsoluteTime initial condition iter result time)) (export '(observable-generate-with-absolute-time)) ;;; GENERATE-WITH-RELATIVE-TIME ;;; ;;; Generates an observable sequence by iterating a state from an initial state until the condition fails. ;;; ;;; Arguments ;;; ;;; initial (Any): Initial state. ;;; ;;; condition (Function): Condition to terminate generation (upon returning false). ;;; ;;; iterate (Function): Iteration step function. ;;; ;;; result (Function): Selector function for results produced in the sequence. ;;; ;;; time (Function): Time selector function to control the speed of values being ;;; produced each iteration, returning integer values denoting milliseconds. ;;; Returns ;;; ;;; (Observable): The generated sequence. ;;; ;;; (rx:time-interval ;;; (rx:observable-generate-with-absolute-time ;;; 1 ;;; (lambda (x) (< x 4)) ;;; (lambda (x) (1+ x)) ;;; (lambda (x) x) ;;; (lambda (x) (* 100 x)))) ;;; (defun observable-generate-with-relative-time (initial condition iter result time) (#j:Rx:Observable:generateWithRelativeTime initial condition iter result time)) (export '(observable-generate-with-relative-time)) ;;; IF ;;; ;;; Determines whether an observable collection contains values. ;;; ;;; Arguments ;;; ;;; condition (Function): The condition which determines if the then ;;; or else will be run. ;;; ;;; then (Observable): The observable sequence that will be ;;; run if the condition function returns true. ;;; ;;; else (Observable): The observable sequence that will ;;; be run if the condition function returns false. ;;; If this is not provided ;;; ;;; Returns ;;; ;;; (Observable): The generated sequence. ;;; ;;; ;;; ;;; (defparameter *should-run* t) ;;; ;;; (rx:observable-if ;;; (lambda () *should-run*) ;;; (rx:observable-just 111)) ;;; (defun observable-if (condition then &optional else) (#j:Rx:Observable:if condition then else)) (export '(observable-if)) ;;; MERGE ;;; ;;; Merges all the observable sequences and Promises into a single observable sequence. ;;; ;;; Arguments ;;; ;;; args (Array|arguments): Observable sequences to merge into a single sequence. ;;; Returns ;;; ;;; (Observable): An observable sequence that produces a value after each period. ;;; ;;; ;;; (defparameter *src0* ;;; (rx:pluck (rx:time-interval (rx:observable-interval 100)) "interval")) ;;; ;;; (defparameter *src1* ;;; (rx:take (rx:pluck (rx:time-interval (rx:observable-interval 150)) "interval") 5) ;;; ;;; (rx:observable-merge *src0* *src1*) ;;; (defun observable-merge (&rest args) (#j:Rx:Observable:merge (list-to-vector args))) (export '(observable-merge)) ;;; RANGE ;;; ;;; Generates an observable sequence of integral numbers within a specified range, ;;; ;;; start (Number): The value of the first integer in the sequence. ;;; count (Number): The number of sequential integers to generate. ;;; ;;; (rx:observable-range 10 20) ;;; (defun observable-range (start count) (#j:Rx:Observable:range start count)) (export '(observable-range)) ;;; INTERVAL ;;; ;;; Returns an observable sequence that produces a value after each period. ;;; ;;; period (Number): Period for producing the values in the resulting sequence ;;; (specified as an integer denoting milliseconds). ;;; ;;; (rx:take (rx:time-interval (rx:observable-interval 100)) 3) ;;; (defun observable-interval (period) (#j:Rx:Observable:interval period)) (export '(observable-interval)) ;;; REPEAT ;;; ;;; Generates an observable sequence that repeats the given element the specified ;;; number of times ;;; ;;; value (Any): Element to repeat. ;;; [repeatCount=-1] (Number):Number of times to repeat the element. ;;; If not specified, repeats indefinitely. ;;; ;;; (rx:take (rx:observable-repeat 42 30) 3) (defun observable-repeat (value count) (#j:Rx:Observable:repeat value count)) (export '(observable-repeat)) ;;; EMPTY ;;; ;;; Returns an empty observable sequence ;;; ;;; (rx:observable-empty) ;;; (defun observable-empty () (#j:Rx:Observable:empty )) (export '(observable-empty)) ;;; JUST ;;; RETURN ;;; ;;; Returns an observable sequence that contains a single element, ;;; ;;; value (Any): Single element in the resulting observable sequence. ;;; (defun observable-just (value) (#j:Rx:Observable:just value)) (export '(observable-just)) ;;; TIMER ;;; ;;; Returns an observable sequence that produces a value after dueTime has elapsed ;;; and then after each period. ;;; ;;; due (Date|Number): Absolute (specified as a Date object) or relative time ;;; (specified as an integer denoting milliseconds) ;;; at which to produce the first value. ;;; ;;; period (Number): Period to produce subsequent values ;;; (specified as an integer denoting milliseconds) ;;; If not specified, the resulting timer is not recurring. ;;; ;;; ;;; ;;; (fset 'take #'rx:take) ;;; (fset 'pluck #'rx:pluk) ;;; (fset 'timer0 (curry #'rx:observable-timer 200)) ;;; (fset 'timer1 (rcarry #'rx:observable-timer 100)) ;;; (fset 'from-now (lambda (value) (+ value (#j:Date:now)))) ;;; (take (pluck (rx:time-interval (timer1 (from-now 153))) "interval") 3) ;;; (take (pluck (rx:time-interval (timer0 100)) "interval") 3) ;;; or ;;; ;;; (fset 'pluk-interval ;;; (lambda (due period) ;;; (rx:pluck (rx:time-interval (rx:observable-timer due period)) "interval"))) ;;; (fset 'take (lambda (how from) (rx:take from how))) ;;; (fset 'subscribe (lambda (source) ;;; (rx:subscribe source ;;; (lambda (value) (push value someplace)) ;;; (lambda (errmsg) (error "wtf ~a?" errmsg)) ;;; (lambda () (rx:observable-start-async #'proc:proc-someplace))))) ;;; ;;; (subscribe (take 3 (pluck-interval 200 100))) ;;; ;;; or ;;; ;;; (rx:take (rx:pluck (rx:time-interval (rx:observable-timer 200 100)) "interval") 3) ;;; (defun observable-timer (due &optional period) (#j:Rx:Observable:timer due period)) (export '(observable-timer)) ;;; WHILE ;;; ;;; condition (Function): The condition which determines if the source will be repeated. ;;; source (Observable): The observable sequence that will be run if the condition function returns true. ;;; ;;; (defparameter *counter* 0) ;;; ;;; (rx:subscribe (rx:observable-while ;;; (lambda () (< (incf *counter*) 5)) ;;; (rx:observable-just 42)) ;;; (lambda (x) (print x))) ;;; (defun observable-while (condition source) (#j:Rx:Observable:while condition source)) (export '(observable-while)) ;;; FOR ;;; ;;; Concatenates the observable sequences or Promises obtained by running the specified ;;; result selector for each element in source. ;;; ;;; Arguments ;;; ;;; sources (Array): An array of values to turn into an observable sequence. ;;; ;;; resultSelector (Function): A function to apply to each item in the sources array to turn it ;;; into an observable sequence. The resultSelector is called with the following information: ;;; ;;; the value of the element ;;; the index of the element ;;; the Observable object being subscribed ;;; ;;; resultSelector must have !!! (lambda (value idx obj) ) ;;; ;;; (rx:observable-for ;;; (vector 1 2 3) ;;; (lambda (val idx obj) (rx:observable-just val))) ;;; (defun observable-for (array selector) (#j:Rx:Observable:for array selector)) (export '(observable-for)) ;;; FORK-JOIN ;;; ;;; Runs all observable sequences in parallel and collect their last elements. ;;; ;;; Arguments ;;; ;;; args (Arguments | Array): An array or arguments of Observable sequences ;;; or Promises to collect the last elements for. ;;; ;;; resultSelector: Function - The result selector from all the values produced. ;;; If not specified, forkJoin will return the results as an array. ;;; ;;; ;;; (rx:observable-fork-join (rx:observable-just 42) ;;; (rx:observable-range 0 10)) ;;; => #(42 9) ;;; ;;; (rx:observable-fork-join #(1 2 3 4) ;;; (rx:observable-range 0 10) ;;; (lambda (x y obj) (+ x y))) ;;; => 13 ;;; (defun observable-fork-join (&rest args) (#j:Rx:Observable:forkJoin (list-to-vector args))) (export '(observable-fork-join)) ;;; OF ;;; ;;; Converts arguments to an observable sequence. ;;; ;;; Arguments ;;; ;;; args (Arguments): A list of arguments to turn into an Observable sequence. ;;; ;;; Returns ;;; ;;; (Observable): The observable sequence whose elements are pulled from the given arguments. ;;; (defun observable-of (&rest args) (apply #j:Rx:Observable:of args)) (export '(observable-of)) ;;; FROM ;;; ;;; This method creates a new Observable sequence from an array-like or iterable object. ;;; ;;; Arguments ;;; ;;; iterable (Array | Arguments | Iterable): An array-like or iterable object to convert to an Observable sequence. ;;; [mapFn] (Function): Map function to call on every element of the array. ;;; ;;; ;;; (rx:subscribe (rx:observable-from "abcd") ;;; (lambda (x) (princ x))) ;;; ;;; ;;; (rx:subscribe ;;; (rx:observable-from ;;; (vector 1 2 3 4 5)) ;;; (lambda (x idx) (+ x x)) ;;; (lambda (x) (print x))) ;;; (defun observable-from (Iterable &optional other) (#j:Rx:Observable:from iterable other)) (export '(observable-from)) ;;; FROM-CALLBACK ;;; ;;; Converts a callback function to an observable sequence. ;;; ;;; Arguments ;;; ;;; func (Function): Function with a callback as the last parameter to convert to an Observable sequence. ;;; ;;; Returns ;;; ;;; (Function): A function, when executed with the required parameters minus the callback, ;;; produces an Observable sequence with a single value of the arguments to the callback ;;; as an array if no selector given, else the object created by the selector function. ;;; ;;; ;;; (setf #j:Fs (require "fs")) ;;; (fset 'exists (rx:observable-from-callback #j:Fs:exists)) ;;; (subscribe (exists "file.txt") (lambda (ok) (if ok (proceed-file "file.txt") ;;; (error "file.txt ?")))) ;;; (defun observable-from-callback (fn) (#j:Rx:Observable:fromCallback fn)) (export '(observable-from-callback)) ;;; FROM-EVENT ;;; ;;; Creates an observable sequence by adding an event listener to the matching DOMElement, jQuery element, ;;; Zepto Element, Angular element, Ember.js element or EventEmitter. ;;; ;;; ;;; Arguments ;;; ;;; element (Any): The DOMElement, NodeList, jQuery element, Zepto Element, ;;; Angular element, Ember.js element or EventEmitter to attach a listener. ;;; For Backbone.Marionette this would be the application ;;; or an EventAggregator object. ;;; ;;; eventName (String): The event name to attach the observable sequence. ;;; ;;; [selector] (Function): A selector which takes the arguments from the event emitter so ;;; that you can return a single object. ;;; ;;; [options] ( Object ) An object of event listener options. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence of events from the specified element ;;; and the specified event. ;;; ;;; from DOM ;;; ;;; (rx:observable-from-event #j:window:document "mousemove") ;;; ;;; ;;; from EventEmitter: ;;; ;;; (setf #j:Eve (require "events")) ;;; (setq event-emittter (make-new #j:Eve)) ;;; subscribe (rx:observable-from-event event-emitter ;;; "data" (lambda (foo bar) (mkjso "foo" foo "bar" bar))) ;;; (funcall ((oget event-emitter "emit" "bind") event-emitter "data" "baz" "quux")) ;;; (defun observable-from-event (elt event &optional fn options) (#j:Rx:Observable:fromEvent elt event fn options)) (export '(observable-from-event)) ;;; FROM-EVENT-PATTERN ;;; ;;; Creates an observable sequence by using the addHandler and removeHandler functions ;;; to add and remove the handlers, with an optional selector function to project ;;; the event arguments. ;;; ;;; Arguments ;;; ;;; addHandler (Function): The DOMElement, NodeList or EventEmitter to attach a listener. ;;; ;;; [removeHandler] (Function): The optional function to remove a handler from an emitter. ;;; ;;; [selector] (Function): A selector which takes the arguments from the event handler ;;; to produce a single item to yield on next. ;;; ;;; Returns ;;; ;;; An observable sequence of events from the specified element and the specified event. ;;; ;;; (let ((emitter)) ;;; (unless #j:EventEmitter (require "events")) ;;; (setq emitter (make-new #j:EventEmitter)) ;;; (setq src ;;; (rx:observable-from-event-pattern ;;; (lambda (handl) (funcall ((oget emitter "addListener" "bind") emitter "data" handl))) ;;; (lambda (handl) (funcall ((oget emitter "removeListener" "bind") emitter "data" handl))) ;;; (lambda (foo bar) (mkjso "foo" foo "bar" bar)))) ;;; (subs src) ;;; (funcall ((oget emitter "emit" "bind") emitter "data" "Baaaz" "Qqqux")) ) ;;; ;;; (defun observable-from-event-pattern (add-handl &optional rem-handl selector) (#j:Rx:Observable:fromEventPattern add-handl rem-handl selector)) (export '(observable-from-event-pattern)) ;;; FROM-PROMISE ;;; ;;; Converts a Promises/A+ spec compliant Promise and/or ES2015 compliant Promise ;;; or a factory function which returns said Promise to an Observable sequence. ;;; ;;; Arguments ;;; ;;; promise|Function: Promise - Promises/A+ spec compliant Promise ;;; to an Observable sequence or a function which ;;; returns a Promise. ;;; ;;; Returns ;;; ;;; Observable: An Observable sequence which wraps the existing ;;; promise success and failure. ;;; ;;; ;;; ;;; (let ((promise-fn (lambda () (promise:resolve 42)))) ;;; (subs (rx:observable-from-promise promise-fn)) ;;; ;;; (setq promise-fn (promise:reject "Unbound")) ;;; (subs (rx:observable-from-promise promise-fn)) ) (defun observable-from-promise (promise) (#j:Rx:Observable:fromPromise promise)) (export '(observable-from-promise)) ;;; COMBINE-LATEST ;;; ;;; Merges the specified observable sequences into one observable sequence by using the selector ;;; function whenever any of the observable sequences produces an element. This can be in the form ;;; of an argument list of observables or an array. If the result selector is omitted, ;;; a list with the elements will be yielded. ;;; ;;; Arguments ;;; ;;; args (arguments): An arguments of Observable sequences. ;;; ;;; [resultSelector] (Function): Function to invoke whenever either of the ;;; sources produces an element. ;;; If omitted, a list with the elements will be yielded. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence containing the result of combining elements of the ;;; sources using the specified result selector function. ;;; ;;; ;;; (setq src1 (rx:select (rx:observable-interval 100) (lambda (x idx obs) (concat "First " x)))) ;;; (setq src2 (rx:select (rx:observable-interval 100) (lambda (x idx obs) (concat "Second " x)))) ;;; (setq src (rx:take (rx:observable-combine-latest src1 src2) 2)) ;;; (rx:subscribe src (lambda (x) (print x)))) ;;; (defun observable-combine-latest (&rest args) (apply #j:Rx:Observable:combineLatest args)) (export '(observable-combine-latest)) ;;; START ;;; ;;; Invokes the specified function asynchronously ;;; surfacing the result through an observable sequence. ;;; ;;; Arguments ;;; ;;; func (Function): Function to run asynchronously. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence exposing the function's result value, or an exception. ;;; ;;; ;;; (let ((context (mkjso "value" 42))) ;;; (subs ;;; (rx:observable-start ;;; (lambda () (print (list 'Async-start (oget context "value"))))))) (defun observable-start (fn) (#j:Rx:Observable:start fn)) (export '(observable-start)) ;;; START-ASYNC ;;; ;;; Invokes the asynchronous function, surfacing the result through an observable sequence. ;;; ;;; Arguments ;;; ;;; functionAsync (Function): Asynchronous function which returns a Promise to run. ;;; ;;; Returns ;;; ;;; (Observable): An observable sequence exposing the function's Promises's value or error. ;;; ;;; ;;; (let ((async (lambda () (promise:resolve 42)))) ;;; (subs (rx:observable-start-async async))) (defun observable-start-async (fn) (#j:Rx:Observable:startAsync fn)) (export '(observable-start-async)) ;;; TO-ASYNC ;;; ;;; Converts the function into an asynchronous function. Each invocation of the resulting ;;; asynchronous function causes an invocation of the original synchronous function ;;; on the specified scheduler. ;;; ;;; Arguments ;;; ;;; func (Function): Function to convert to an asynchronous function. ;;; [context] (Any): The context for the func parameter to be executed. If not specified, defaults to undefined. ;;; ;;; Returns ;;; ;;; (Function): Asynchronous function. ;;; ;;; ;;; (let ((fn (lambda (x y) (+ x y))) ;;; (afn (rx:observable-to-async fn)) ;;; (src)) ;;; (setq src (funcall afn 11 22)) ;;; (subs src)) (defun observable-to-async (fn) (#j:Rx:Observable:toAsync fn)) (export '(observable-to-async)) (in-package :cl-user) ;;; EOF
23,941
Common Lisp
.lisp
673
34.228826
122
0.63958
vlad-km/jscl-rx-src
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
febf4cab2bddd14f03c45d8ee2b41e8d6afbbc74723d1e1d7b1352b6a6a66c72
21,071
[ -1 ]
21,093
requests.lisp
gschjetne_cl-arango/src/requests.lisp
;; Copyright © 2014 Grim Schjetne <[email protected]> ;; This file is part of CL-Arango. ;; CL-Arango is free software: you can redistribute it and/or modify ;; it under the terms of the GNU Lesser General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; CL-Arango 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 ;; Lesser General Public License for more details. ;; You should have received a copy of the GNU Lesser General Public ;; License along with CL-Arango. If not, see ;; <http://www.gnu.org/licenses/>. (in-package #:cl-arango-rest) ;; Settings (defvar *arango-host* "localhost") (defvar *arango-port* 8529) (defvar *arango-database* "_system") (defvar *username* nil) (defvar *password* nil) (defvar *parse-result* t) (defmacro with-endpoint ((host port) &body body) "Select the host and port to connect to" `(let ((*arango-host* ,host) (*arango-port* ,port)) ,@body)) (defmacro with-database (name &body body) "Select the database NAME in which to do the operations in" `(let ((*arango-database* ,name)) ,@body)) (defmacro with-user ((username password) &body body) "Authenticate with USERNAME and PASSWORD" `(let ((*username* ,username) (*password* ,password)) ,@body)) ;; Request apparatus (defmacro def-arango-fun (name lambda-list method &rest args) `(defun ,name ,lambda-list ,(cadr (assoc :documentation args)) (send-request :method ,method :uri (format-uri ,@(remove nil (append (assoc :uri args) (assoc :query args))) :database *arango-database*) :username *username* :password *password* :content (aif ,(cadr (assoc :content args)) (jsown:to-json it))))) (defun format-uri (&key uri query database) (concatenate 'string "http://" *arango-host* ":" (write-to-string *arango-port*) (if database (concatenate 'string "/_db/" database)) "/_api" (apply #'concatenate 'string (append (mapcar (lambda (segment) (concatenate 'string "/" segment)) uri))) (if query (apply #'concatenate 'string "?" (mapcar (lambda (pair) (concatenate 'string (car pair) "=" (cond ((eq (cdr pair) t) "true") ((null (cdr pair)) "false") (t (cdr pair))) "&")) (plist-alist query)))))) (defun send-request (&key method uri content username password) (multiple-value-bind (body status header uri stream must-close) (http-request uri :method method :content content :external-format-out :utf-8 :content-type "application/json; charset=utf-8" :basic-authorization (if (and username password) (list username password))) (declare (ignore uri)) (unless must-close (close stream)) (let* ((content-type (cdr (assoc :content-type header))) (body-string (flexi-streams:octets-to-string body :external-format :utf-8)) (result (if (search "application/json" content-type) (jsown:parse body-string)))) (if (and (jsown:keyp result "error") (t-or-jsf-p (jsown:val result "error"))) (restart-case (error 'arango-error :http-status status :error-number (jsown:val result "errorNum") :error-message (jsown:val result "errorMessage")) (return-result () (if *parse-result* result body-string))) (if *parse-result* result body-string))))) ;; Conditions (define-condition arango-error (error) ((http-status :initarg :http-status :reader http-status) (error-number :initarg :error-number :reader error-number) (error-message :initarg :error-message :reader error-message)) (:report (lambda (condition stream) (format stream "ArangoDB failed with status ~D/~D: ~A" (http-status condition) (error-number condition) (error-message condition))))) ;; Utility functions (defun t-or-jsf (x) (if x t :f)) (defun t-or-jsf-p (x) (when (not (or (eq x :f) (eq x :false))) x))
5,360
Common Lisp
.lisp
113
32.283186
83
0.517215
gschjetne/cl-arango
2
1
1
LGPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a6ed646865c1fc6ba9ec28558cc7fbbdc6b7e8712c89de285f017e085628eb46
21,093
[ -1 ]
21,094
package.lisp
gschjetne_cl-arango/src/package.lisp
;; Copyright © 2014 Grim Schjetne <[email protected]> ;; This file is part of CL-Arango. ;; CL-Arango is free software: you can redistribute it and/or modify ;; it under the terms of the GNU Lesser General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; CL-Arango 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 ;; Lesser General Public License for more details. ;; You should have received a copy of the GNU Lesser General Public ;; License along with CL-Arango. If not, see ;; <http://www.gnu.org/licenses/>. (in-package #:cl-user) (defpackage #:cl-arango-rest (:use #:cl #:alexandria #:anaphora #:drakma) (:export #:get-current-database #:list-accessible-databases #:list-databases #:create-database #:drop-database #:read-document #:create-document #:replace-document #:patch-document #:delete-document #:read-document-header #:read-all-documents #:read-edge #:read-all-edges #:create-edge #:patch-edge #:replace-edge #:delete-edge #:read-document-header #:read-in-or-outbound-edges #:aql-query #:create-cursor #:read-cursor #:delete-cursor #:parse-query #:explain-query #:create-user-fun #:delete-user-fun #:list-user-funs #:simple-return-all #:simple-by-example #:simple-first-example #:simple-by-example-hash #:simple-by-example-skiplist #:simple-by-example-bitarray #:simple-by-condition-bitarray #:simple-any #:simple-range #:simple-near #:simple-within #:simple-fulltext #:simple-remove-by-example #:simple-replace-by-example #:simple-update-by-example #:simple-first #:simple-last #:key-options #:create-collection #:delete-collection #:truncate-collection #:read-collection-properties #:read-collection-document-count #:read-collection-statistics #:read-collection-revision-id #:read-collection-checksum #:read-all-collections #:load-collection #:unload-collection #:set-collection-properties #:rename-collection #:collection-rotate-journal #:read-index #:create-index #:cap-constraint #:hash-index #:skip-list #:geo #:full-text #:delete-index #:read-all-indexes #:create-graph #:traverse #:database-user #:create-user #:replace-user #:update-user #:delete-user #:read-user #:create-endpoint #:delete-endpoint #:list-endpoints #:with-endpoint #:with-database #:with-user #:t-or-jsf #:t-or-jsf-p #:arango-error #:http-status #:error-number #:error-message #:*arango-host* #:*arango-port* #:*arango-database* #:*parse-result* #:*username* #:*password*))
3,695
Common Lisp
.lisp
115
21.565217
69
0.546813
gschjetne/cl-arango
2
1
1
LGPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
830122173773613c4f7efc24773eabc18a7c596c0458349999c24b81afe13fc3
21,094
[ -1 ]
21,095
rest.lisp
gschjetne_cl-arango/src/rest.lisp
;; Copyright © 2014 Grim Schjetne <[email protected]> ;; This file is part of CL-Arango. ;; CL-Arango is free software: you can redistribute it and/or modify ;; it under the terms of the GNU Lesser General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; CL-Arango 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 ;; Lesser General Public License for more details. ;; You should have received a copy of the GNU Lesser General Public ;; License along with CL-Arango. If not, see ;; <http://www.gnu.org/licenses/>. (in-package #:cl-arango-rest) ;; Databases (def-arango-fun get-current-database () :get (:documentation "Retrieves information about the current database.") (:uri '("database" "current"))) (def-arango-fun list-accessible-databases () :get (:documentation "Retrieves the list of all databases the current user can access without specifying a different username or password.") (:uri '("database" "user"))) (def-arango-fun list-databases () :get (:documentation "Retrieves the list of all existing databases.") (:uri '("database"))) (def-arango-fun create-database (name &rest users) :post (:documentation "Creates a new database.") (:uri '("database")) (:content (cons :obj (remove nil `(("name" . ,name) ,(if users `("users" . ,users))))))) (def-arango-fun drop-database (name) :delete (:documentation "Deletes the database along with all data stored in it.") (:uri `("database" ,name))) ;; Documents (def-arango-fun read-document (handle) :get (:documentation "Returns the document identified by HANDLE.") (:uri `("document" ,handle))) (def-arango-fun create-document (document collection &key create-collection wait-for-sync) :post (:documentation "Creates a new document in the collection named COLLECTION.") (:uri '("document")) (:query (list "collection" collection "createCollection" create-collection "waitForSync" wait-for-sync)) (:content document)) (def-arango-fun replace-document (document handle &key wait-for-sync rev policy) :put (:documentation "Completely updates (i.e. replaces) the document identified by HANDLE.") (:uri `("document" ,handle)) (:query (append `("waitForSync" ,wait-for-sync) (if rev `("rev" ,rev)) (if policy `("policy" ,policy)))) (:content document)) (def-arango-fun patch-document (document handle &key keep-null wait-for-sync rev policy) :patch (:documentation "Partially updates the document identified by HANDLE.") (:uri `("document" ,handle)) (:query (append `("keepNull" ,keep-null "waitForSync" ,wait-for-sync) (if rev `("rev" ,rev)) (if policy `("policy" ,policy)))) (:content document)) (def-arango-fun delete-document (handle &key wait-for-sync rev policy) :delete (:documentation "Deletes a document.") (:uri `("document" ,handle)) (:query (append `("waitForSync" ,wait-for-sync) (if rev `("rev" ,rev)) (if policy `("policy" ,policy))))) ;; This function always fails. Custom response handler is needed (def-arango-fun read-document-header (handle &key rev) :head (:documentation "Like READ-DOCUMENT, but only returns the header fields and not the body.") (:uri `("document" ,handle)) (:query (if rev `("rev" rev)))) (def-arango-fun read-all-documents (collection) :get (:documentation "Returns a list of all URI for all documents from the collection identified by COLLECTION.") (:uri '("document")) (:query `("collection" ,collection))) ;; Edges (def-arango-fun read-edge (handle) :get (:documentation "Returns the edge identified by HANDLE.") (:uri `("edge" ,handle))) (def-arango-fun read-all-edges (collection) :get (:documentation "Returns a list of all URI for all edges from the collection identified by COLLECTION.") (:uri '("edge")) (:query `("collection" ,collection))) (def-arango-fun create-edge (document collection from-handle to-handle &key create-collection wait-for-sync) :post (:documentation "Creates a new edge document in the collection named COLLECTION") (:uri '("edge")) (:query (list "collection" collection "from" from-handle "to" to-handle "createCollection" create-collection "waitForSync" wait-for-sync)) (:content document)) (def-arango-fun patch-edge (document handle &key keep-null wait-for-sync rev policy) :patch (:documentation "Partially updates the edge document identified by HANDLE.") (:uri `("edge" ,handle)) (:query (append `("keepNull" ,keep-null "waitForSync" ,wait-for-sync) (if rev `("rev" ,rev)) (if policy `("policy" ,policy)))) (:content document)) (def-arango-fun replace-edge (document handle &key wait-for-sync rev policy) :put (:documentation "Completely updates (i.e. replaces) the edge identified by HANDLE.") (:uri `("edge" ,handle)) (:query (append `("waitForSync" ,wait-for-sync) (if rev `("rev" ,rev)) (if policy `("policy" ,policy)))) (:content document)) (def-arango-fun delete-edge (handle &key wait-for-sync rev policy) :delete (:documentation "Deletes an edge.") (:uri `("edge" ,handle)) (:query (append `("waitForSync" ,wait-for-sync) (if rev `("rev" ,rev)) (if policy `("policy" ,policy))))) ;; This function always fails. Custom response handler is needed (def-arango-fun read-edge-header (handle &key rev) :head (:documentation "Like READ-EDGE, but only returns the header fields and not the body.") (:uri `("document" ,handle)) (:query (if rev `("rev" rev)))) (def-arango-fun read-in-or-outbound-edges (collection vertex &key direction) :get (:documentation "Returns the list of edges starting or ending in the vertex identified by VERTEX.") (:uri `("edges" ,collection)) (:query (append `("vertex" ,vertex) (if direction `("direction" ,direction))))) ;; AQL queries (defun aql-query (query-string &key count-results batch-size time-to-live bind-parameters full-count) (cons :obj (remove nil `(("query" . ,query-string) ,(if count-results '("count" . t)) ,(if batch-size `("batchSize" . ,batch-size)) ,(if time-to-live `("ttl" . ,time-to-live)) ,(if bind-parameters `("bindVars" . (:obj ,@bind-parameters))) ,(if full-count '("options" (:obj ("fullCount" . t)))))))) (def-arango-fun create-cursor (query) :post (:documentation "Create a cursor and return the first results") (:uri '("cursor")) (:content query)) (def-arango-fun read-cursor (cursor-id) :put (:documentation "Return the next results from an existing cursor") (:uri `("cursor" ,cursor-id))) (def-arango-fun delete-cursor (cursor-id) :delete (:documentation "Deletes the cursor and frees the resources associated with it.") (:uri `("cursor" ,cursor-id))) (def-arango-fun parse-query (query) :post (:documentation "Parse a query and return information about it") (:uri '("query")) (:content query)) (def-arango-fun explain-query (query) :post (:documentation "Explain a query and return information about it") (:uri '("explain")) (:content query)) (def-arango-fun create-user-fun (name code &key is-deterministic) :post (:documentation "Create a new AQL user function") (:uri '("aqlfunction")) (:content (cons :obj (remove nil `(("name" ,name) ("code" ,code) ,(if is-deterministic '("is-deterministic" t))))))) (def-arango-fun delete-user-fun (name) :delete (:documentation "Remove an existing AQL user function") (:uri `("aqlfunction" ,name))) (def-arango-fun list-user-funs () :get (:documentation "Gets all reqistered AQL user functions") (:uri '("aqlfunction"))) ;; Simple queries (def-arango-fun simple-return-all (collection &key skip limit) :put (:documentation "Returns all documents of a collection.") (:uri '("simple" "all")) (:content (cons :obj (remove nil `(("collection" . ,collection) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-by-example (example collection &key skip limit) :put (:documentation "Finds all documents matching the example given by EXAMPLE.") (:uri '("simple" "by-example")) (:content (cons :obj (remove nil `(("collection" . ,collection) ("example" . ,example) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-first-example (example collection) :put (:documentation "Finds all documents matching the example given by EXAMPLE.") (:uri '("simple" "first-example")) (:content `(:obj ("collection" . ,collection) ("example" . ,example)))) (def-arango-fun simple-by-example-hash (example collection index &key skip limit) :put (:documentation "Finds all documents matching the example given by EXAMPLE.") (:uri '("simple" "by-example")) (:content (cons :obj (remove nil `(("index" . ,index) ("collection" . ,collection) ("example" . ,example) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-by-example-skiplist (example collection index &key skip limit) :put (:documentation "Finds all documents matching the example given by EXAMPLE.") (:uri '("simple" "by-example-skiplist")) (:content (cons :obj (remove nil `(("index" . ,index) ("collection" . ,collection) ("example" . ,example) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-by-example-bitarray (example collection index &key skip limit) :put (:documentation "Finds all documents matching the example given by EXAMPLE.") (:uri '("simple" "by-example-bitarray")) (:content (cons :obj (remove nil `(("index" . ,index) ("collection" . ,collection) ("example" . ,example) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-by-condition-bitarray (condition collection index &key skip limit) :put (:documentation "Finds all documents matching the example given by EXAMPLE.") (:uri '("simple" "by-condition-bitarray")) (:content (cons :obj (remove nil `(("index" . ,index) ("condition" . ,condition) ("collection" . ,collection) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-any (collection) :put (:documentation "Returns a random document from a collection.") (:uri '("simple" "any")) (:content `(:obj ("collection" . ,collection)))) (def-arango-fun simple-range (collection attribute left right &key closed skip limit) :put (:documentation "This will find all documents within a given range. In order to execute a range query, a skip-list index on the queried attribute must be present.") (:uri '("simple" "range")) (:content (cons :obj (remove nil `(("attribute" . ,attribute) ("left" . ,left) ("right" . ,right) ("closed" . ,(t-or-jsf closed)) ("collection" . ,collection) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-near (collection latitude longitude &key distance geo skip limit) :put (:documentation "The default will find at most 100 documents near the given coordinate. The returned list is sorted according to the distance, with the nearest document being first in the list.") (:uri '("simple" "near")) (:content (cons :obj (remove nil `(("latitude" . ,latitude) ("longitude" . ,longitude) ("collection" . ,collection) ,(if distance `("distance" . ,distance)) ,(if geo `("geo" . ,geo)) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-within (collection latitude longitude radius &key distance geo skip limit) :put (:documentation "This will find all documents within a given radius around the coordinate (LATITUDE, LONGITUDE). The returned list is sorted by distance.") (:uri '("simple" "within")) (:content (cons :obj (remove nil `(("latitude" . ,latitude) ("longitude" . ,longitude) ("collection" . ,collection) ("radius" . ,radius) ,(if distance `("distance" . ,distance)) ,(if geo `("geo" . ,geo)) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-fulltext (collection attribute query index &key skip limit) :put (:documentation "This will find all documents from the collection that match the fulltext query specified in QUERY.") (:uri '("simple" "fulltext")) (:content (cons :obj (remove nil `(("attribute" . ,attribute) ("query" . ,query) ("index" . ,index) ("collection" . ,collection) ,(if skip `("skip" . ,skip)) ,(if limit `("limit" . ,limit))))))) (def-arango-fun simple-remove-by-example (example collection &key wait-for-sync limit) :put (:documentation "Finds and removes all documents matching the example given by EXAMPLE.") (:uri '("simple" "remove-by-example")) (:content `(:obj ("collection" . ,collection) ("example" . ,example) ("options" . ,(remove nil (list :obj (if wait-for-sync `("waitForSync" . ,wait-for-sync)) (if limit `("limit" . ,limit)))))))) (def-arango-fun simple-replace-by-example (example collection replacement &key wait-for-sync limit) :put (:documentation "Finds and replaces all documents matching EXAMPLE by REPLACEMENT.") (:uri '("simple" "replace-by-example")) (:content (cons :obj `(("collection" . ,collection) ("example" . ,example) ("replacement" . ,replacement) ("options" . ,(remove nil (list :obj (if wait-for-sync `("waitForSync" . ,wait-for-sync)) (if limit `("limit" . ,limit))))))))) (def-arango-fun simple-update-by-example (example collection replacement &key keep-null wait-for-sync limit) :put (:documentation "Finds all documents matching EXAMPLE and partially updates them with REPLACEMENT.") (:uri '("simple" "update-by-example")) (:content `(:obj ("collection" . ,collection) ("example" . ,example) ("replacement" . ,replacement) ("options" . ,(remove nil (list :obj (if keep-null `("keepNull" . ,keep-null)) (if wait-for-sync `("waitForSync" . ,wait-for-sync)) (if limit `("limit" . ,limit)))))))) (def-arango-fun simple-first (collection &key (count 1)) :put (:documentation "Returns the first document(s) from COLLECTION, in the order of insertion/update time. When the COUNT argument is supplied, the result will be a list of documents, with the oldest document being first in the result list") (:uri '("simple" "first")) (:content `(:obj ("collection" . ,collection) ("count" . ,count)))) (def-arango-fun simple-last (collection &key (count 1)) :put (:documentation "Returns the last document(s) from COLLECTION, in the order of insertion/update time. When the COUNT argument is supplied, the result will be a list of documents, with the latest document being first in the result list") (:uri '("simple" "last")) (:content `(:obj ("collection" . ,collection) ("count" . ,count)))) ;; Collections (defun key-options (type allow-user-keys &key increment offset) "Constructs a hash table of key options suitable for passing to CREATE-COLLECTION" (cons :obj (remove nil (append (ccase type (:traditional '(("type" . "traditional"))) (:autoincrement `(("type" . "autoincrement") ,(if increment `("increment" . ,increment)) ,(if offset `("offset" . ,offset))))) `(("allowUserKeys" . ,(t-or-jsf allow-user-keys))))))) (def-arango-fun create-collection (name &key wait-for-sync do-compact journal-size is-system is-volatile key-options (type :document) number-of-shards (shard-keys '("_key"))) :post (:documentation "Creates an new collection with a given name.") (:uri '("collection")) (:content (cons :obj (remove nil `(("name" . ,name) ("type" . ,(ccase type (:document 2) (:edges 3))) ,(if wait-for-sync `("waitForSync" . ,wait-for-sync)) ,(if do-compact `("doCompact" . ,do-compact)) ,(if journal-size `("journalSize" . ,journal-size)) ,(if is-system `("isSystem" . ,is-system)) ,(if is-volatile `("isVolatile" . ,is-volatile)) ,(if key-options `("keyOptions" . ,key-options)) ,(if number-of-shards `("numberOfShards" . ,number-of-shards)) ,(if number-of-shards `("shardKeys" . ,shard-keys))))))) (def-arango-fun delete-collection (name) :delete (:documentation "Deletes a collection identified by NAME.") (:uri `("collection" ,name))) (def-arango-fun truncate-collection (name) :put (:documentation "Removes all documents from the collection, but leaves the indexes intact.") (:uri `("collection" ,name "truncate"))) (def-arango-fun read-collection-properties (name) :get (:documentation "Read properties of a collection identified by NAME.") (:uri `("collection" ,name "properties"))) (def-arango-fun read-collection-document-count (name) :get (:documentation "Return number of documents in a collection identified by NAME.") (:uri `("collection" ,name "count"))) (def-arango-fun read-collection-statistics (name) :get (:documentation "Return statistics for a collection identified by NAME.") (:uri `("collection" ,name "figures"))) (def-arango-fun read-collection-revision-id (name) :get (:documentation "Return the revision ID of a collection identified by NAME.") (:uri `("collection" ,name "revision"))) (def-arango-fun read-collection-checksum (name) :get (:documentation "Return the checksum of a collection identified by NAME.") (:uri `("collection" ,name "checksum"))) (def-arango-fun read-all-collections () :get (:documentation "Return all collections") (:uri '("collection"))) (def-arango-fun load-collection (name &key count) :put (:documentation "Loads a collection into memory. If COUNT is set to T, number of documents will also be returned, at a performance penalty") (:uri `("collection" ,name "load")) (:query (if count `("count" ,count)))) (def-arango-fun unload-collection (name) :put (:documentation "Removes a collection from memory. This call does not delete any documents.") (:uri `("collection" ,name "unload"))) (def-arango-fun set-collection-properties (name wait-for-sync journal-size) :put (:documentation "Changes the properties of a collection.") (:uri `("collection" ,name "properties")) (:content `(:obj ("waitForSync" . ,(t-or-jsf wait-for-sync)) ("journalSize" . ,journal-size)))) (def-arango-fun rename-collection (name new-name) :put (:document "Renames a collection identified by NAME to NEW-NAME.") (:uri `("collection" ,name "rename")) (:content `(:obj ("name" . ,new-name)))) (def-arango-fun collection-rotate-journal (name) :put (:document "Rotates the journal of a collection. The current journal of the collection will be closed and made a read-only datafile. The purpose of the rotate method is to make the data in the file available for compaction (compaction is only performed for read-only datafiles, and not for journals).") (:uri `("collection" ,name "rotate"))) ;; Indexes (def-arango-fun read-index (handle) :get (:documentation "") (:uri `("index" ,handle))) (def-arango-fun create-index (collection details) :post (:documentation "Creates a new index in the collection COLLECTION.") (:uri '("index")) (:query `("collection" ,collection)) (:content details)) (defun cap-constraint (&key size byte-size) `(:obj ("type" . "cap") ("size" . ,size) ("byteSize" . ,byte-size))) (defun hash-index (fields &key unique) `(:obj ("type" . "hash") ("fields" . ,fields) ("unique" . ,(t-or-jsf unique)))) (defun skip-list (fields &key unique) `(:obj ("type" . "skiplist") ("fields" . ,fields) ("unique" . ,(t-or-jsf unique)))) (defun geo (fields) `(:obj ("type" . "geo") ("fields" ,fields))) (defun full-text (fields min-length) `(:obj ("type" . "fulltext") ("fields" . ,fields) ("minLength" . ,min-length))) (def-arango-fun delete-index (handle) :delete (:documentation "Deletes an index identified by HANDLE.") (:uri `("index" ,handle))) (def-arango-fun read-all-indexes (collection) :get (:documentation "Returns an object with an attribute indexes containing a list of all index descriptions for the given collection.") (:uri '("index")) (:query `("collection" ,collection))) ;; Transactions ;; General Graph (def-arango-fun create-graph (name edge-definitions) :post (:documentation "Create a new graph") (:uri '("gharial")) (:content `(:obj ("name" . ,name) ("edgeDefinitions" . ,edge-definitions)))) ;; Traversals (def-arango-fun traverse (start-vertex graph-name &key filter min-depth max-depth visitor direction init expander sort strategy order item-order uniqueness max-iterations) :post (:documentation "Starts a traversal starting from a given vertex") (:uri '("traversal")) (:content `(:obj ("startVertex" . ,start-vertex) ("graphName" . ,graph-name)))) ;; Replication ;; Bulk Imports ;; Batch Requests ;; Monitoring ;; User Management (defun database-user (username &key password (active t) extra) "Constructs a list defining a user, suitable for passing to CREATE-DATABASE and CREATE-USER." (cons :obj (remove nil `(("username" . ,username) ("active" . ,(t-or-jsf active)) ,(if password `("passwd" . ,password)) ,(if extra `("extra" . ,extra)))))) (def-arango-fun create-user (database-user &key change-password) :post (:documentation "") (:uri '("user")) (:content (append database-user `(("changePassword" . ,(t-or-jsf change-password)))))) (defmacro replace-or-update-user (name method documentation) `(def-arango-fun ,name (username password &key (active t) extra change-password) ,method (:documentation ,documentation) (:uri `("user" ,username)) (:content (cons :obj (remove nil `(("passwd" . ,password) ("active" . ,(t-or-jsf active)) ,(if password `("changePassword" . ,(t-or-jsf change-password))) ,(if extra `("extra" . ,extra)))))))) (replace-or-update-user replace-user :put "Replaces the data of an existing user.") (replace-or-update-user update-user :patch "Updates the data of an existing user.") (def-arango-fun delete-user (username) :delete (:documentation "Removes an existing user, identified by USER.") (:uri `("user" ,username))) (def-arango-fun read-user (username) :get (:documentation "Fetches data about the specified user.") (:uri `("user" ,username))) ;; Async Result ;; Endpoints (def-arango-fun create-endpoint (endpoint &rest databases) :post (:documentation "Add a new endpoint, or reconfigure an existing one. If DATABASES is NIL, all databases present in the server will become accessible via the endpoint, with the _system database being the default database.") (:uri '("endpoint")) (:content `(:obj ("endpoint" . ,endpoint) ("databases" . ,databases)))) (def-arango-fun delete-endpoint (endpoint) :delete (:documentation "This operation deletes an existing endpoint from the list of all endpoints, and makes the server stop listening on the endpoint.") (:uri `("endpoint" ,endpoint))) (def-arango-fun list-endpoints () :get (:documentation "Returns a list of all configured endpoints the server is listening on. For each endpoint, the list of allowed databases is returned too if set.") (:uri '("endpoint"))) ;; Sharding ;; Miscellaneous ;; General Handling
29,160
Common Lisp
.lisp
642
33.579439
95
0.551404
gschjetne/cl-arango
2
1
1
LGPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
2f671aacb4429bb9c8c1289f9404ad8b462d66f89b09ca82d70e88f6edc18b01
21,095
[ -1 ]
21,096
cl-arango.asd
gschjetne_cl-arango/cl-arango.asd
;; Copyright © 2014 Grim Schjetne <[email protected]> ;; This file is part of CL-Arango. ;; CL-Arango is free software: you can redistribute it and/or modify ;; it under the terms of the GNU Lesser General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; CL-Arango 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 ;; Lesser General Public License for more details. ;; You should have received a copy of the GNU Lesser General Public ;; License along with CL-Arango. If not, see ;; <http://www.gnu.org/licenses/>. (defpackage :cl-arango-system (:use :cl :asdf)) (in-package :cl-arango-system) (defsystem cl-arango :name "CL-Arango" :author "Grim Schjetne <[email protected]" :version "unreleased" :description "ArangoDB client library" :long-description "ArangoDB REST client library for Common Lisp" :depends-on (:alexandria :anaphora :drakma :jsown) :components ((:module "src" :serial t :components ((:file "package") (:file "requests" :depends-on ("package")) (:file "rest" :depends-on ("requests"))))))
1,362
Common Lisp
.asd
32
37.53125
69
0.688822
gschjetne/cl-arango
2
1
1
LGPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
97b7bcd036016dc6c99cb74cb02a4296ae75de242321cbb7e02ae6bd8918348a
21,096
[ -1 ]
21,116
package.lisp
keithj_deoxybyte-io/test/package.lisp
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io-test (:use #:common-lisp #:deoxybyte-io #:deoxybyte-utilities #:lift) (:export #:deoxybyte-io-tests) (:documentation "Deoxybyte IO tests."))
978
Common Lisp
.lisp
23
41.173913
73
0.733473
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
35d83e91ae00a6c37985cce9e05abb306bb35a0e96cd81cbbdd1d520e52bae8c
21,116
[ -1 ]
21,117
binary-operations-test.lisp
keithj_deoxybyte-io/test/binary-operations-test.lisp
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io-test) ;; NaN, +Inf and -Inf values serialized by Java (i.e. network byte ;; order). ;; ;; NaN: 7f c0 00 00 ;; +Inf: 7f 80 00 00 ;; -Inf: ff 80 00 00 ;; ;; NaN: 7f f8 00 00 00 00 00 00 ;; +Inf: 7f f0 00 00 00 00 00 00 ;; -Inf: ff f0 00 00 00 00 00 00 (defvar *single-float-nan-bytes* '(#x7f #xc0 #x00 #x00) "NaN serialized by Java.") (defvar *single-float-positive-infinity-bytes* '(#x7f #x80 #x00 #x00) "+Inf serialized by Java.") (defvar *single-float-negative-infinity-bytes* '(#xff #x80 #x00 #x00) "-Inf serialized by Java.") (defvar *double-float-nan-bytes* '(#x7f #xf8 #x00 #x00 #x00 #x00 #x00 #x00) "NaN serialized by Java.") (defvar *double-float-positive-infinity-bytes* '(#x7f #xf0 #x00 #x00 #x00 #x00 #x00 #x00) "+Inf serialized by Java.") (defvar *double-float-negative-infinity-bytes* '(#xff #xf0 #x00 #x00 #x00 #x00 #x00 #x00) "-Inf serialized by Java.") (defun make-byte-array (bytes) (make-array (length bytes) :element-type 'octet :initial-contents bytes)) (defun test-round-trip-int (num-bytes encoder decoder &optional signed) (let ((bytes (make-byte-array (loop repeat num-bytes collect 0))) (max (expt 2 (1- (* 8 num-bytes))))) (loop repeat 1000000 always (let ((x (if signed (- (random max) (/ max 2)) (random max)))) (= (funcall decoder (funcall encoder x bytes)) x))))) (defun test-round-trip-float (size encoder decoder &optional signed) (let ((range (ecase size (4 most-positive-single-float) (8 most-positive-double-float)))) (loop repeat 1000000 always (let ((x (if (and signed (zerop (random 2))) (- (random range)) (random range)))) (= (funcall decoder (funcall encoder x)) x))))) (addtest (deoxybyte-io-tests) decode-unsigned-int-le/1 (let ((bytes (make-byte-array '(#x78 #x56 #x34 #x12)))) (ensure (= #x12345678 (decode-uint32le bytes 0))) (ensure (= #x5678 (decode-uint16le bytes 0))) (ensure (= #x1234 (decode-uint16le bytes 2))))) (addtest (deoxybyte-io-tests) decode-unsigned-int-be/1 (let ((bytes (make-byte-array '(#x12 #x34 #x56 #x78)))) (ensure (= #x12345678 (decode-uint32be bytes 0))) (ensure (= #x1234 (decode-uint16be bytes 0))) (ensure (= #x5678 (decode-uint16be bytes 2))))) (addtest (deoxybyte-io-tests) decode-signed-int-le/1 (let ((bytes (make-byte-array '(#xf8 #xff #xff #xff)))) (ensure (= -8 (decode-int32le bytes 0))) (ensure (= -8 (decode-int16le bytes 0))) (ensure (= -1 (decode-int16le bytes 2))))) (addtest (deoxybyte-io-tests) decode-signed-int-be/1 (let ((bytes (make-byte-array '(#xff #xff #xff #xf8)))) (ensure (= -8 (decode-int32be bytes 0))) (ensure (= -1 (decode-int16be bytes 0))) (ensure (= -8 (decode-int16be bytes 2))))) (addtest (deoxybyte-io-tests) decode-float32-le/1 (mapc (lambda (bytes result) (ensure (eql result (decode-float32le (reverse bytes))))) (mapcar #'make-byte-array (list *single-float-nan-bytes* *single-float-positive-infinity-bytes* *single-float-negative-infinity-bytes*)) '(:not-a-number :positive-infinity :negative-infinity))) (addtest (deoxybyte-io-tests) decode-float32-be/1 (mapc (lambda (bytes result) (ensure (eql result (decode-float32be bytes)))) (mapcar #'make-byte-array (list *single-float-nan-bytes* *single-float-positive-infinity-bytes* *single-float-negative-infinity-bytes*)) '(:not-a-number :positive-infinity :negative-infinity))) (addtest (deoxybyte-io-tests) decode-float64-le/1 (mapc (lambda (bytes result) (ensure (eql result (decode-float64le (reverse bytes))))) (mapcar #'make-byte-array (list *double-float-nan-bytes* *double-float-positive-infinity-bytes* *double-float-negative-infinity-bytes*)) '(:not-a-number :positive-infinity :negative-infinity))) (addtest (deoxybyte-io-tests) decode-float64-be/1 (mapc (lambda (bytes result) (ensure (eql result (decode-float64be bytes)))) (mapcar #'make-byte-array (list *double-float-nan-bytes* *double-float-positive-infinity-bytes* *double-float-negative-infinity-bytes*)) '(:not-a-number :positive-infinity :negative-infinity))) (addtest (deoxybyte-io-tests) round-trip-unsigned-int64-le/1 (ensure (test-round-trip-int 8 #'encode-int64le #'decode-int64le))) (addtest (deoxybyte-io-tests) round-trip-signed-int64-le/1 (ensure (test-round-trip-int 8 #'encode-int64le #'decode-int64le t))) (addtest (deoxybyte-io-tests) round-trip-unsigned-int32-le/1 (ensure (test-round-trip-int 4 #'encode-int32le #'decode-int32le))) (addtest (deoxybyte-io-tests) round-trip-signed-int32-le/1 (ensure (test-round-trip-int 4 #'encode-int32le #'decode-int32le t))) (addtest (deoxybyte-io-tests) round-trip-unsigned-int16-le/1 (ensure (test-round-trip-int 2 #'encode-int16le #'decode-int16le))) (addtest (deoxybyte-io-tests) round-trip-signed-int16-le/1 (ensure (test-round-trip-int 2 #'encode-int16le #'decode-int16le t))) (addtest (deoxybyte-io-tests) round-trip-signed-int8-le/1 (ensure (test-round-trip-int 1 #'encode-int8le #'decode-int8le t))) (addtest (deoxybyte-io-tests) round-trip-unsigned-int64-be/1 (ensure (test-round-trip-int 8 #'encode-int64be #'decode-int64be))) (addtest (deoxybyte-io-tests) round-trip-signed-int64-be/1 (ensure (test-round-trip-int 8 #'encode-int64be #'decode-int64be t))) (addtest (deoxybyte-io-tests) round-trip-unsigned-int32-be/1 (ensure (test-round-trip-int 4 #'encode-int32be #'decode-int32be))) (addtest (deoxybyte-io-tests) round-trip-signed-int32-be/1 (ensure (test-round-trip-int 4 #'encode-int32be #'decode-int32be t))) (addtest (deoxybyte-io-tests) round-trip-unsigned-int16-be/1 (ensure (test-round-trip-int 2 #'encode-int16be #'decode-int16be))) (addtest (deoxybyte-io-tests) round-trip-signed-int16-be/1 (ensure (test-round-trip-int 2 #'encode-int16be #'decode-int16be t))) (addtest (deoxybyte-io-tests) round-trip-signed-int8-be/1 (ensure (test-round-trip-int 1 #'encode-int8be #'decode-int8be t))) (addtest (deoxybyte-io-tests) round-trip-ieee-float32/1 (ensure (test-round-trip-float 4 #'encode-ieee-float32 #'decode-ieee-float32 t)) (mapcar (lambda (n) (ensure (eql n (decode-ieee-float32 (encode-ieee-float32 n))))) '(:not-a-number :positive-infinity :negative-infinity))) (addtest (deoxybyte-io-tests) round-trip-ieee-float64/1 (ensure (test-round-trip-float 4 #'encode-ieee-float64 #'decode-ieee-float64 t)) (mapcar (lambda (n) (ensure (eql n (decode-ieee-float64 (encode-ieee-float64 n))))) '(:not-a-number :positive-infinity :negative-infinity)))
7,953
Common Lisp
.lisp
158
43.664557
75
0.65125
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0756c91a15421033f2489d24d1350a0b6d6654bfdaf659073a7d476be6bc7428
21,117
[ -1 ]
21,118
command-line-interface-test.lisp
keithj_deoxybyte-io/test/command-line-interface-test.lisp
;;; ;;; Copyright (c) 2010-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io-test) (define-cli test-cli (cli) ((a "a" :required-option t :value-type 'string :documentation "Required option A.") (b "b" :required-option t :value-type 'integer :documentation "Required option B.") (c "c" :required-option t :value-type 'character :documentation "Required option C.") (d "d" :required-option t :value-type 'float :documentation "Required option D."))) (define-cli test-cli-subclass (test-cli) ((e "e" :required-option t :value-type 'string-list :documentation "Required option E.") (f "f" :required-option t :value-type 'integer-list :documentation "Required option F.") (g "g" :required-option t :value-type 'character-list :documentation "Required option G.") (h "h" :required-option t :value-type 'float-list :documentation "Required option H."))) (define-cli test-optional-cli (cli) ((a "a" :required-option nil :value-type 'string))) (define-cli test-boolean-cli (cli) ((a "a" :required-option nil :value-type t))) (define-cli test-value-default-cli (cli) ((a "a" :required-option nil :value-type 'string :value-default "foo" :documentation "Option A.") (b "b" :required-option nil :value-type 'integer :value-default 99 :documentation "Option B."))) (addtest (deoxybyte-io-tests) option-slot-p/1 (let ((cli (make-instance 'test-cli))) (ensure (every (lambda (slot) (option-slot-p cli slot)) '(a b c d))))) (addtest (deoxybyte-io-tests) option-slots-of/1 (ensure (equal '(a b c d) (option-slots-of (make-instance 'test-cli))))) (addtest (deoxybyte-io-tests) option-of/1 (let ((cli (make-instance 'test-cli))) (ensure (every #'equal '("a" "b" "c" "d") (mapcar #'name-of (mapcar (lambda (name) (option-of cli name)) '(a b c d))))))) (addtest (deoxybyte-io-tests) option-of/2 (let ((cli (make-instance 'test-cli))) (ensure (every #'equal '("a" "b" "c" "d") (mapcar #'name-of (mapcar (lambda (name) (option-of cli name)) '("a" "b" "c" "d"))))))) (addtest (deoxybyte-io-tests) parse-command-line/1 (ensure (make-instance 'test-cli-subclass)) (let* ((arglist (list "--a" "aaa" "--b" "1" "--c" "c" "--d" "0.1" "--e" "aaa,bbb,ccc" "--f" "1,2,3" "--g" "a,b,c" "--h" "0.1,0.2,0.3")) (super-expected '((D . 0.1) (C . #\c) (B . 1) (A . "aaa"))) (super-parsed (parse-command-line (make-instance 'test-cli) arglist)) (sub-expected '((H 0.1 0.2 0.3) (G #\a #\b #\c) (F 1 2 3) (E "aaa" "bbb" "ccc") (D . 0.1) (C . #\c) (B . 1) (A . "aaa"))) (sub-parsed (parse-command-line (make-instance 'test-cli-subclass) arglist))) (ensure (equalp super-expected super-parsed) :report "Expected ~a but found ~a" :arguments (super-expected super-parsed)) (ensure (equalp sub-expected sub-parsed) :report "Expected ~a but found ~a" :arguments (sub-expected sub-parsed)))) (addtest (deoxybyte-io-tests) parse-command-line/2 (let ((cli (make-instance 'test-cli))) (multiple-value-bind (parsed remaining unknown) (parse-command-line cli (list "--a" "aaa" "--b" "1" "--c" "c" "--d" "0.1" "--w" "x" "y" "z")) (ensure (equal '((D . 0.1) (C . #\c) (B . 1) (A . "aaa")) parsed)) (ensure (equal '("x" "y" "z") remaining)) (ensure (equal '("w") unknown))))) (addtest (deoxybyte-io-tests) parse-command-line/3 (let ((cli (make-instance 'test-cli))) (ensure-condition missing-required-option (parse-command-line cli (list "--a" "aaa" "--b" "1" "--c" "c"))) (ensure-condition missing-required-value (parse-command-line cli (list "--a" "--b" "1" "--c" "c" "--d" "0.1"))))) (addtest (deoxybyte-io-tests) parse-command-line/4 (let ((cli (make-instance 'test-boolean-cli))) (ensure (equal '((A . T)) (parse-command-line cli (list "--a")))) (ensure (equal '((A)) (parse-command-line cli nil))))) (addtest (deoxybyte-io-tests) option-value/1 (let ((parsed (parse-command-line (make-instance 'test-cli) (list "--a" "aaa" "--b" "1" "--c" "c" "--d" "0.1")))) (ensure (equal "aaa" (option-value 'a parsed))) (ensure-condition invalid-argument-error (option-value 'w parsed)))) (addtest (deoxybyte-io-tests) default-value/1 (let ((parsed (parse-command-line (make-instance 'test-value-default-cli) (list "--a" "aaa" "--b" "1")))) (ensure (equal "aaa" (option-value 'a parsed))) (ensure (= 1 (option-value 'b parsed))))) (addtest (deoxybyte-io-tests) default-value/2 (let* ((cli (make-instance 'test-value-default-cli)) (parsed (parse-command-line cli nil))) (ensure (equal (value-default-of (option-of cli "a")) (option-value 'a parsed))) (ensure (= (value-default-of (option-of cli "b")) (option-value 'b parsed)))))
6,704
Common Lisp
.lisp
138
36.637681
78
0.525118
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
5724e86e3ffe7089e2a8ab5c240c60120e3685147054b87a879694bc8bb4c7ac
21,118
[ -1 ]
21,119
deoxybyte-io-test.lisp
keithj_deoxybyte-io/test/deoxybyte-io-test.lisp
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io-test) (deftestsuite deoxybyte-io-tests () ()) (defun test-data-file (filespec) (asdf:system-relative-pathname 'deoxybyte-io filespec)) ;;; Gray-streams methods to be tested ;; input streams ;; sb-gray:stream-clear-input stream ;; sb-gray:stream-read-sequence stream seq &optional start binary ;; end streams ;; sb-gray:stream-read-byte stream ;; sb-gray:stream-write-byte stream integer ;; character input streams ;; sb-gray:stream-peek-char stream ;; sb-gray:stream-read-char-no-hang stream ;; sb-gray:stream-read-char stream ;; sb-gray:stream-read-line stream ;; sb-gray:stream-listen stream ;; sb-gray:stream-unread-char stream character (addtest (deoxybyte-io-tests) gray-common/1 (dolist (elt-type '(base-char octet)) (with-open-file (stream (test-data-file "data/test1.txt") :direction :input :element-type elt-type) (let ((s (make-line-stream stream))) (ensure (subtypep (stream-element-type s) 'string)) (ensure (zerop (stream-file-position s))) (ensure (open-stream-p s)) (ensure (stream-close s)) (ensure (not (open-stream-p s))) (ensure-error (stream-read-line s)))))) (addtest (deoxybyte-io-tests) gray-input/1 (dolist (elt-type '(base-char octet)) (with-open-file (stream (test-data-file "data/test3.txt") :direction :input :element-type elt-type) (let ((s (make-line-stream stream)) (b (make-array 9 :element-type t))) ;; stream-clear-input should empty the line buffer (push-line s "aaaa") (ensure (slot-value s 'deoxybyte-io::line-stack)) (ensure-null (stream-clear-input s)) (ensure (not (slot-value s 'deoxybyte-io::line-stack))) (ensure (= 1 (stream-read-sequence s b 0 1))) (ensure (= 4 (stream-read-sequence s b 1 5))) (ensure (= 4 (stream-read-sequence s b 5))) (ensure (equalp #("abc" "def" "ghi" "jkl" "mno" "pqr" "stu" "vwx" "yz") b)))))) (addtest (deoxybyte-io-tests) stream-read-line/1 (dolist (elt-type '(base-char octet)) (with-open-file (stream (test-data-file "data/test1.txt") :direction :input :element-type elt-type) (let ((s (make-line-stream stream)) (line "abcdefghijklmnopqrstuvwxyz")) (multiple-value-bind (line2 missing-newline-p) (stream-read-line s) (ensure (equal line line2)) (ensure (not missing-newline-p))) (multiple-value-bind (line2 missing-newline-p) (stream-read-line s) (ensure (eql :eof line2)) (ensure missing-newline-p)))))) (addtest (deoxybyte-io-tests) push-line/1 (dolist (elt-type '(base-char octet)) (with-open-file (stream (test-data-file "data/test1.txt") :direction :input :element-type elt-type) (let ((s (make-line-stream stream)) (line "abcdefghijklmnopqrstuvwxyz")) (multiple-value-bind (line2 missing-newline-p) (stream-read-line s) (ensure (equal line line2)) (ensure (not missing-newline-p)) (push-line s line2) (ensure (equal line (stream-read-line s)))))))) (addtest (deoxybyte-io-tests) missing-newline-p/1 (dolist (elt-type '(base-char octet)) (with-open-file (stream (test-data-file "data/test2.txt") :direction :input :element-type elt-type) (let ((s (make-line-stream stream)) (lines '("1234567890" "0987654321" "abcdefghij" "klmnopqrst"))) (dolist (line (butlast lines)) (multiple-value-bind (line2 missing-newline-p) (stream-read-line s) (ensure (equal line line2)) (ensure (not missing-newline-p)))) (multiple-value-bind (line2 missing-newline-p) (stream-read-line s) (ensure (equal (car (last lines)) line2)) (ensure missing-newline-p)))))) (addtest (deoxybyte-io-tests) find-line/1 (dolist (elt-type '(base-char octet)) (with-open-file (stream (test-data-file "data/test3.txt") :direction :input :element-type elt-type) (let ((s (make-line-stream stream)) (lines '("abc" "def" "ghi" "jkl" "mno" "pqr" "stu" "vwx" "yz"))) ;; Success at line 1 of max 1 -> "abc" (multiple-value-bind (line found line-count) (find-line s (lambda (a) (char= (aref a 0) #\a)) 1) (ensure (equal (nth 0 lines) line)) (ensure found) (ensure (= 1 line-count))) ;; Fail at line 1 of max 1 -> "def" (multiple-value-bind (line found line-count) (find-line s (lambda (a) (char= (aref a 0) #\Z)) 1) (ensure (equal (nth 1 lines) line)) (ensure (not found)) (ensure (= 1 line-count))) ;; Success at line 3 of max 4 (multiple-value-bind (line found line-count) (find-line s (lambda (a) (char= (aref a 0) #\m)) 4) (ensure (equal (nth 4 lines) line)) (ensure found) (ensure (= 3 line-count))) ;; Fall through to eof (multiple-value-bind (line found line-count) (find-line s (lambda (a) (declare (ignore a)) nil)) (ensure-same :eof line) (ensure (not found)) (ensure (= 5 line-count))))))) (addtest (deoxybyte-io-tests) make-tmp-directory/1 ;; Test defaults (let ((tmpdir (make-tmp-directory))) (unwind-protect (progn (ensure (pathnamep tmpdir)) (ensure (equalp '(:absolute "tmp") (subseq (pathname-directory tmpdir) 0 2))) (ensure (parse-integer (third (pathname-directory tmpdir)))) (ensure-null (pathname-type tmpdir)) (ensure (fad:directory-exists-p tmpdir)) (ensure (fad:directory-pathname-p tmpdir))) (fad:delete-directory-and-files tmpdir))) ;; Test optional arguments. There need to be more tests in here to ;; check :if-exists arguments (ensure-directories-exist "/tmp/bar/") (let ((tmpdir (make-tmp-directory :tmpdir "/tmp/bar" :basename "foo"))) (unwind-protect (progn (ensure (string= "foo" (fourth (pathname-directory tmpdir)) :end2 3)) (ensure (string= "bar" (third (pathname-directory tmpdir)) :end2 3))) (fad:delete-directory-and-files tmpdir))) ;; Test error conditions (let ((bad-dir "/this-directory-does-not-exist/")) (ensure (not (fad:directory-exists-p bad-dir))) (ensure-condition invalid-argument-error (make-tmp-directory :tmpdir bad-dir)))) (addtest (deoxybyte-io-tests) with-tmp-directory/1 (let ((pathname (with-tmp-directory (tmpdir) (ensure (fad:directory-exists-p tmpdir)) tmpdir))) (ensure (not (fad:directory-exists-p pathname))))) (addtest (deoxybyte-io-tests) with-tmp-directory/2 (handler-bind ((error #'leave-tmp-directory)) (let ((pathname (with-tmp-directory (tmpdir) (error "Error")))) (ensure (fad:directory-exists-p pathname)) (fad:delete-directory-and-files pathname)))) (addtest (deoxybyte-io-tests) with-tmp-directory/3 (handler-bind ((error #'delete-tmp-directory)) (let ((pathname (with-tmp-directory (tmpdir) (error "Error")))) (ensure (not (fad:directory-exists-p pathname)))))) (addtest (deoxybyte-io-tests) with-tmp-pathname/1 (with-tmp-pathname (tmpfile) (ensure (pathnamep tmpfile)))) (addtest (deoxybyte-io-tests) with-tmp-pathname/2 (handler-bind ((error #'leave-tmp-pathname)) (let ((pathname (with-tmp-pathname (tmpfile) (with-open-file (stream tmpfile :direction :output) stream) (ensure (fad:file-exists-p tmpfile)) (error "Error")))) (ensure (fad:file-exists-p pathname)) (delete-file pathname)))) (addtest (deoxybyte-io-tests) with-tmp-pathname/3 (handler-bind ((error #'delete-tmp-pathname)) (let ((pathname (with-tmp-pathname (tmpfile) (with-open-file (stream tmpfile :direction :output) stream) (ensure (fad:file-exists-p tmpfile)) (error "Error")))) (ensure (not (fad:file-exists-p pathname)))))) (addtest (deoxybyte-io-tests) ensure-file-exists/1 (let ((test-file (test-data-file "data/touch_test.txt"))) (ensure (not (probe-file test-file))) (ensure-file-exists test-file) (ensure (probe-file test-file)) (delete-file test-file)))
9,984
Common Lisp
.lisp
228
33.868421
80
0.581921
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
2a68bf8feae68bf8f50ee5953087764b45286734ddbe81401c8cada7300ae3c5
21,119
[ -1 ]
21,120
pathnames-test.lisp
keithj_deoxybyte-io/test/pathnames-test.lisp
;;; ;;; Copyright (c) 2010-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io-test) (addtest (deoxybyte-io-tests) pathstring/1 (ensure (string= "/foo/bar/baz.txt" (pathstring (pathname "/foo/bar/baz.txt")))) ;; These tests ensure that we can unescape all the dots under CCL (ensure (string= "/foo/bar.baz.txt" (pathstring (pathname "/foo/bar.baz.txt")))) (ensure (string= "/foo/bar..baz.txt" (pathstring (pathname "/foo/bar..baz.txt"))))) (addtest (deoxybyte-io-tests) tmp-pathname/1 ;; Test defaults (ensure (pathnamep (tmp-pathname))) (ensure (string= "/tmp/" (directory-namestring (tmp-pathname)))) (ensure (integerp (parse-integer (pathname-name (tmp-pathname))))) (ensure-null (pathname-type (tmp-pathname))) ;; Test optional arguments (ensure (string= "/" (directory-namestring (tmp-pathname :tmpdir "/")))) (ensure (string= "tmp" (pathname-type (tmp-pathname :type "tmp")))) (ensure (string= "foo" (pathname-name (tmp-pathname :tmpdir "/tmp" :basename "foo")) :end2 3)) (ensure (string= "bar" (pathname-type (tmp-pathname :tmpdir "/tmp" :basename "foo" :type "bar")))) ;; Test error condition (let ((bad-dir "/this-directory-does-not-exist/")) (ensure (not (fad:directory-exists-p bad-dir))) (ensure-condition invalid-argument-error (tmp-pathname :tmpdir bad-dir)))) (addtest (deoxybyte-io-tests) absolute-pathname-p/1 (ensure (not (absolute-pathname-p "foo"))) (ensure (absolute-pathname-p "/foo"))) (addtest (deoxybyte-io-tests) relative-pathname-p/1 (ensure (relative-pathname-p "foo")) (ensure (relative-pathname-p "./foo")) (ensure (relative-pathname-p "../foo"))) (addtest (deoxybyte-io-tests) directory-pathname/1 (ensure (equal (pathname "/") (directory-pathname "/foo"))) (ensure (equal (pathname "/foo/") (directory-pathname "/foo/"))) (ensure (equal (pathname "/foo/bar/") (directory-pathname "/foo/bar/")))) (addtest (deoxybyte-io-tests) file-pathname/1 (ensure (equal (pathname "foo") (file-pathname "/foo"))) (ensure (equal (pathname "") (file-pathname "/foo/"))) (ensure (equal (pathname "bar") (file-pathname "/foo/bar")))) (addtest (deoxybyte-io-tests) leaf-directory-pathname/1 (ensure (equal (pathname "/") (leaf-directory-pathname "/foo"))) (ensure (equal (pathname "/foo/") (leaf-directory-pathname "/foo/"))) (ensure (equal (pathname "bar/") (leaf-directory-pathname "/foo/bar/"))))
3,361
Common Lisp
.lisp
66
45.075758
75
0.649224
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
92ca1449c42a0d2ec4a8c795cfe405c92e5053d7e3c4b9629b4135be6a2acf40
21,120
[ -1 ]
21,121
parse-float.lisp
keithj_deoxybyte-io/src/parse-float.lisp
;;; Thu Aug 25 00:56:39 1994 by Mark Kantrowitz <[email protected]> ;;; atof.cl -- 7824 bytes ;;; **************************************************************** ;;; PARSE-FLOAT -- equivalent of C's atof ************************** ;;; **************************************************************** ;;; ;;; This program is based loosely on the CMU Common Lisp implementation ;;; of PARSE-INTEGER. ;;; ;;; ORIGIN: ftp.cs.cmu.edu:/user/ai/lang/lisp/code/math/atof/ ;;; ;;; Copyright (c) 1994 by Mark Kantrowitz ;;; ;;; This material was developed by Mark Kantrowitz of the School of ;;; Computer Science, Carnegie Mellon University. ;;; ;;; Permission to use, copy, modify, and distribute this material is ;;; hereby granted, subject to the following terms and conditions. ;;; ;;; In case it be determined by a court of competent jurisdiction that any ;;; provision herein contained is illegal, invalid or unenforceable, such ;;; determination shall solely affect such provision and shall not affect ;;; or impair the remaining provisions of this document. ;;; ;;; 1. All copies of the software, derivative works or modified versions, ;;; and any portions thereof, must include this entire copyright and ;;; permission notice, without modification. The full notice must also ;;; appear in supporting documentation. ;;; ;;; 2. Users of this material agree to make their best efforts to inform ;;; Mark Kantrowitz of noteworthy uses of this material. Correspondence ;;; should be provided to Mark at: ;;; ;;; Mark Kantrowitz ;;; School of Computer Science ;;; Carnegie Mellon University ;;; 5000 Forbes Avenue ;;; Pittsburgh, PA 15213-3891 ;;; ;;; E-mail: [email protected] ;;; ;;; 3. This software and derivative works may be distributed (but not ;;; offered for sale) to third parties, provided such third parties ;;; agree to abide by the terms and conditions of this notice. If you ;;; modify this software, you must cause the modified file(s) to carry ;;; a change log describing the changes, who made the changes, and the ;;; date of the changes. ;;; ;;; 4. All materials developed as a consequence of the use of this material ;;; shall duly acknowledge such use, in accordance with the usual standards ;;; of acknowledging credit in academic research. ;;; ;;; 5. Neither the name of Mark Kantrowitz nor any adaptation thereof may ;;; be used to endorse or promote products derived from this software ;;; or arising from its use without specific prior written permission ;;; in each case. ;;; ;;; 6. Users of this software hereby grant back to Mark Kantrowitz and ;;; Carnegie Mellon University a non-exclusive, unrestricted, royalty-free ;;; right and license under any changes, enhancements or extensions made ;;; to the core functions of the software, including but not limited to ;;; those affording compatibility with other hardware or software ;;; environments. Users further agree to use their best efforts to return to ;;; Mark Kantrowitz any such changes, enhancements or extensions that they ;;; make. ;;; ;;; THE SOFTWARE IS PROVIDED "AS IS" AND MARK KANTROWITZ DISCLAIMS ALL ;;; EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS MATERIAL (INCLUDING ;;; SOFTWARE CONTAINED THEREIN), INCLUDING, WITHOUT LIMITATION, ALL ;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ;;; PURPOSE. IN NO EVENT SHALL MARK KANTROWITZ BE LIABLE FOR ANY SPECIAL, ;;; DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ;;; RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF ;;; CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN ;;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE (INCLUDING BUT ;;; NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR ;;; LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE PROGRAM TO ;;; OPERATE AS DOCUMENTED). MARK KANTROWITZ IS UNDER NO OBLIGATION TO ;;; PROVIDE ANY SERVICES, BY WAY OF MAINTENANCE, UPDATE, OR OTHERWISE. ;;; ;;; Change Log: ;;; 26-AUG-94 mk Suggestions from Richard Lynch: Check for builtin ;;; whitespacep before defining (MCL, CMU CL), add #\newline ;;; to *whitespace-chars*. ;;; 2008-01-09 kdj Placed this copy within package :uk.co.deoxybyte-io instead ;;; of package "LISP" ; (in-package "LISP") ; (export '(parse-float)) (in-package :uk.co.deoxybyte-io) (eval-when (:compile-toplevel :load-toplevel :execute) (unless (fboundp 'whitespacep) (defparameter *whitespace-chars* '(#\space #\tab #\newline #\return #\linefeed #\page)) (defun whitespacep (char) (find char *whitespace-chars*)))) (defun parse-float (string &key (start 0) end (radix 10) junk-allowed) "Converts a substring of STRING, as delimited by START and END, to a floating point number, if possible. START and END default to the beginning and end of the string. RADIX must be between 2 and 36. A floating point number will be returned if the string consists of an optional string of spaces and an optional sign, followed by a string of digits optionally containing a decimal point, and an optional e or E followed by an optionally signed integer. The use of e/E to indicate an exponent only works for RADIX = 10. Returns the floating point number, if any, and the index for the first character after the number." ;; END defaults to the end of the string ;; We don't accomplish this by sticking (end (length string)) in the ;; lambda list because I've encountered too many implementations that ;; don't handle such properly. Also, this will work ok if somebody calls ;; the function with :end nil. (setq end (or end (length string))) ;; Skip over whitespace. If there's nothing but whitespace, signal an error. (let ((index (or (position-if-not #'whitespacep string :start start :end end) (if junk-allowed (return-from parse-float (values nil end)) (error "no non-whitespace characters in number.")))) (minusp nil) (decimalp nil) (found-digit nil) (before-decimal 0) (after-decimal 0) (decimal-counter 0) (exponent 0) (result 0)) (declare (fixnum index)) ;; Take care of optional sign. (let ((char (char string index))) (cond ((char= char #\-) (setq minusp t) (incf index)) ((char= char #\+) (incf index)))) (loop (when (= index end) (return nil)) (let* ((char (char string index)) (weight (digit-char-p char radix))) (cond ((and weight (not decimalp)) ;; A digit before the decimal point (setq before-decimal (+ weight (* before-decimal radix)) found-digit t)) ((and weight decimalp) ;; A digit after the decimal point (setq after-decimal (+ weight (* after-decimal radix)) found-digit t) (incf decimal-counter)) ((and (char= char #\.) (not decimalp)) ;; The decimal point (setq decimalp t)) ((and (char-equal char #\e) (= radix 10)) ;; E is for exponent (multiple-value-bind (num idx) (parse-integer string :start (1+ index) :end end :radix radix :junk-allowed junk-allowed) (setq exponent (or num 0) index idx) (when (= index end) (return nil)))) (junk-allowed (return nil)) ((whitespacep char) (when (position-if-not #'whitespacep string :start (1+ index) :end end) (error "junk in string: ~S." string)) (return nil)) (t (error "junk in string: ~S." string)))) (incf index)) ;; Cobble up the resulting number (setq result (float (* (+ before-decimal (* after-decimal (expt radix (- decimal-counter)))) (expt radix exponent)))) ;; Return the result (values (if found-digit (if minusp (- result) result) (if junk-allowed nil (error "no digits in string: ~S" string))) index))) ;;; *EOF*
8,448
Common Lisp
.lisp
175
42.314286
79
0.643696
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
5f525748413c6ee438c05b5ecf0934f7c54145555de2e9ff632ccbf040cce1fd
21,121
[ -1 ]
21,122
simple-table-parser.lisp
keithj_deoxybyte-io/src/simple-table-parser.lisp
;;; ;;; Copyright (c) 2008-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) (defparameter *empty-field* (make-array 0 :element-type 'base-char) "The default empty field string.") (defmacro define-line-parser (parser-name delimiter fields &optional constraints) "Defines a line parser function that splits lines and then parses and validates fields according to the FIELDS contraints and validates combinations of fields according to CONSTRAINTS. Arguments: - parser-name (symbol): a symbol naming the new function. - delimiter (character): a character used to split the lines being parsed. - fields (list list): a list of field definition lists. The form of a definition list is ;;; (symbolic-field-name &keys type ignore parser validator null-str) which indicates the symbol to which the parsed field value will be stored in the alist returned by the function - parser-name (symbol): the expected type of the field value ( :string, :integer or :float, defaulting to :string), an optional boolean flag indicating that the field should be ignored, an optional parser function (defaults to a pass-through string parser), an optional validator function that returns T when the parsed field is valid and an optional string to indicate an null field (defaults to {defparameter *empty-field*} ). Optional: - constraints (list list): a list of field constraint definition lists. The form of a constraint definition list is ;;; (symbolic-constraint-name (symbolic-field-name list) validator) The symbolic-field-name list should contain names of one or more fields and the validator must then be a function which accepts the parsed values of those fields in the same order and returns T when those fields have acceptable values." (let ((field-count (length fields)) (field-names `,(mapcar #'car fields)) (field-args (mapcar #'collect-parser-args fields)) (constraint-names `,(mapcar #'car constraints)) (constraint-args (mapcar #'collect-constraint-args constraints))) `(progn (defun ,parser-name (line) (declare (optimize (speed 3))) (declare (type simple-string line)) (multiple-value-bind (field-starts field-ends) (string-split-indices line ,delimiter) (declare (type list field-starts)) (check-record (= ,field-count (length field-starts)) line "invalid line: ~d fields instead of ~d" (length field-starts) ,field-count) (let* ((fargs (list ,@field-args)) (cargs (list ,@constraint-args)) (parsed-fields (loop for name in ',field-names for arg-list in fargs for start in field-starts for end in field-ends unless (key-value :ignore arg-list) collect (cons name (apply #'parse-field name line start end arg-list))))) (let* ((record-constraints (loop for name in ',constraint-names for form in cargs collect (apply #'validate-record name parsed-fields form))) (failed-constraints (loop for (result . nil) in record-constraints when (null (cdr result)) collect (car result)))) (when failed-constraints (error 'record-validation-error :record line :format-control "constraints ~a failed" :format-arguments (list failed-constraints)))) parsed-fields)))))) (declaim (inline default-validator)) (defun default-validator (value) "The default validator always returns T." (declare (ignore value)) t) (defun default-string-parser (field-name str &key (start 0) end (null-str *empty-field*)) "Returns a string subsequence from simple-string record STR between START and END, or NIL if STR is STRING= to NULL-STR between START and END." (declare (optimize (speed 3))) (declare (type simple-string str null-str)) (let ((end (or end (length str)))) (if (string= null-str str :start2 start :end2 end) nil (handler-case (subseq str start end) (parse-error (condition) (signal-malformed-field field-name str start end condition)))))) (defun default-integer-parser (field-name str &key (start 0) end (null-str *empty-field*)) "Returns an integer parsed from simple-base-string record STR between START and END, or NIL if STR is STRING= to NULL-STR between START and END." (declare (optimize (speed 3))) (declare (type simple-string str null-str)) (let ((end (or end (length str)))) (if (string= null-str str :start2 start :end2 end) nil (handler-case (parse-integer str :start start :end end) (parse-error (condition) (signal-malformed-field field-name str start end condition)))))) (defun default-float-parser (field-name str &key (start 0) end (null-str *empty-field*)) "Returns a float parsed from simple-base-string record STR between START and END, or NIL if STR is STRING= to NULL-STR between START and END." (declare (optimize (speed 3))) (declare (type simple-string str null-str)) (let ((end (or end (length str)))) (if (string= null-str str :start2 start :end2 end) nil (handler-case (parse-float str :start start :end end) (parse-error (condition) (signal-malformed-field field-name str start end condition)))))) (defun parse-field (field-name line start end null-str parser &optional (validator #'default-validator)) "Returns a value parsed from LINE between START and END using PARSER and VALIDATOR." (declare (optimize (speed 3))) (declare (type function parser validator) (type simple-string line)) (let ((parsed-value (funcall parser field-name line :start start :end end :null-str (or null-str *empty-field*)))) (if (funcall validator parsed-value) parsed-value (error 'field-validation-error :field field-name :format-control "~s with parsed value ~a" :format-arguments (list (subseq line start end) parsed-value))))) (defun validate-record (name fields validator &rest field-names) "Returns a pair of constraint NAME and either T or NIL, indicating the result of applying VALIDATOR to values from the alist of parsed FIELDS named by FIELD-NAMES." (let ((field-values (mapcar (lambda (key) (assocdr key fields)) field-names))) (cons name (handler-case (apply validator field-values) (error (condition) (error 'record-validation-error :record name :format-control (txt "validator raised an error" "on field values ~a: ~a") :format-arguments (list field-values condition))))))) (defun collect-parser-args (field) "Returns an argument list form for FIELD to be used by PARSE-FIELD which has suitable parsers and validators set up for the standard field types: :string , :integer and :float ." (destructuring-bind (field-name &key ignore (type :string) null-str parser validator) field (declare (ignore field-name)) (if ignore '(list :ignore t) (let ((field-parser (or parser (ecase type (:string '#'default-string-parser) (:integer '#'default-integer-parser) (:float '#'default-float-parser)))) (field-validator (or validator (ecase type (:string '#'default-validator) (:integer '#'default-validator) (:float '#'default-validator))))) `(list ,null-str ,field-parser ,field-validator))))) (defun collect-constraint-args (form) "Returns an argument list form to be used by CROSS-VALIDATE by quoting the field-names in FORM and re-ordering the elements." (destructuring-bind (constraint-name field-names validator) form (declare (ignore constraint-name)) `(list ,validator ,@(mapcar (lambda (n) `(quote ,n)) field-names)))) (defun signal-malformed-field (field str start end reason) "Signals a MALFORMED-FIELD-ERROR for FIELD in STR between START and END for REASON." (error 'malformed-field-error :field field :format-control "invalid field ~a: ~a" :format-arguments (list (subseq str start end) reason)))
9,929
Common Lisp
.lisp
209
37.416268
79
0.622873
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f0ea23e395fc3b0564633bdcec70857c9e7a391c4607c0e0a2bff97160b530bf
21,122
[ -1 ]
21,123
package.lisp
keithj_deoxybyte-io/src/package.lisp
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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) (eval-when (:compile-toplevel :load-toplevel :execute) (defun gray-streams-symbols () "Returns a list of the symbols required for Gray streams." `(;; Classes #:fundamental-stream #:fundamental-input-stream #:fundamental-output-stream #:fundamental-character-stream #:fundamental-binary-stream #:fundamental-character-input-stream #:fundamental-character-output-stream #:fundamental-binary-input-stream #:fundamental-binary-output-stream ;; Common generic functions #:streamp #:input-stream-p #:output-stream-p #:open-stream-p #:stream-element-type ;; #:close ;; Input stream generic functions #:stream-clear-input ;; Output stream generic functions #:stream-finish-output #:stream-force-output #:stream-clear-output ;; Binary stream generic functions #:stream-read-byte #:stream-write-byte ;; Character stream generic functions #:stream-listen #:stream-peek-char #:stream-read-char #:stream-unread-char #:stream-read-char-no-hang #:stream-read-line #:stream-advance-to-column #:stream-fresh-line #:stream-line-column #:stream-write-char #:stream-start-line-p #:stream-write-string #:stream-terpri ;; Extra methods provided by implementations #+:sbcl ,@(list :stream-file-position :stream-read-sequence :stream-write-sequence)))) (defmacro define-deoxybyte-io-package () `(defpackage :uk.co.deoxybyte-io (:use #:common-lisp #:deoxybyte-utilities) (:nicknames #:deoxybyte-io #:dxi) (:shadow #:type-of) (:import-from #+:sbcl :sb-gray #+:ccl :ccl #+:lispworks :stream ,@(gray-streams-symbols)) (:export ;; IO conditions #:io-error #:io-warning ;; Parse conditions #:general-parse-error #:malformed-file-error #:malformed-record-error #:malformed-field-error #:record-validation-error #:field-validation-error #:record-of #:field-of ;; Parse utility macros #:check-record #:check-field ;; Environment variables #:environment-variable ;; Files and directories #:*default-tmpdir* #:*default-tmpfile-defaults* #:absolute-pathname-p #:relative-pathname-p #:file-pathname #:directory-pathname #:leaf-directory-pathname #:ensure-file-exists #:pathstring #:tmp-pathname #:with-tmp-pathname #:delete-tmp-pathname #:leave-tmp-pathname #:make-tmp-directory #:with-tmp-directory #:delete-tmp-directory #:leave-tmp-directory #:pathname-generator #:pathname-extender ;; CLI definition #:cli-error #:cli-option-error #:cli-warning #:cli-option-warning #:unknown-command #:missing-required-option #:missing-required-value #:incompatible-value #:unmatched-option #:unknown-option #:string-list #:integer-list #:character-list #:float-list #:define-cli #:cli #:cli-option #:cli-help #:option-slot-p #:option-slots-of #:options-of #:option-of #:option-help #:option-value #:help-message #:name-of #:required-option-p #:boolean-option-p #:required-value-p #:value-type-of #:value-parser-of #:value-default-of #:documentation-of #:parse-command-line #:print-backtrace #:quit-lisp #:with-argv ,@(gray-streams-symbols) #:stream-open #:stream-close #:stream-file-position #:stream-read-sequence #:stream-write-sequence #:wrapped-stream-mixin #:stream-of #:stream-filter-mixin #:test-of #:io-stream-mixin #:make-line-stream #:line-stream #:line-input-stream #:line-output-stream #:character-line-input-stream #:octet-line-input-stream #:line-stack-of #:pop-line #:push-line #:more-lines-p #:find-line ;; Table parser #:*empty-field* #:define-line-parser #:default-integer-parser #:default-float-parser ;; Binary operations #:encode-uint64le #:encode-uint32le #:encode-uint16le #:encode-uint8le #:encode-int64le #:encode-int32le #:encode-int16le #:encode-int8le #:decode-uint64le #:decode-uint32le #:decode-uint16le #:decode-uint8le #:decode-int64le #:decode-int32le #:decode-int16le #:decode-int8le #:encode-uint64be #:encode-uint32be #:encode-uint16be #:encode-uint8be #:encode-int64be #:encode-int32be #:encode-int16be #:encode-int8be #:decode-uint64be #:decode-uint32be #:decode-uint16be #:decode-uint8be #:decode-int64be #:decode-int32be #:decode-int16be #:decode-int8be #:encode-ieee-float32 #:encode-ieee-float64 #:decode-ieee-float32 #:decode-ieee-float64 #:encode-float64le #:encode-float32le #:decode-float64le #:decode-float32le #:encode-float64be #:encode-float32be #:decode-float64be #:decode-float32be #:define-integer-encoder #:define-integer-decoder ;; Misc #:parse-float ;; External merge sort protocol #:sort-input-stream #:sort-output-stream #:merge-stream #:stream-head-of #:stream-merge #:stream-read-element #:stream-write-element #:external-merge-sort ;; External merge sort by line implementation #:line-sort-input-stream #:line-sort-output-stream #:line-merge-stream #:make-merge-stream) (:documentation "The deoxybyte-io system is a selection of utility code focused on transfer of data between Lisp and its environment. It includes: - IO and parser conditions - File and directory utilities - Command line interface definition utilities - Stream classes and methods - Tabular text parsing - Binary encoding and decoding"))) (define-deoxybyte-io-package)
6,974
Common Lisp
.lisp
254
21.629921
73
0.649438
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
6927ffe87f0b029a8153d69ed24b6f5b34c73368417033570241a94d5074068b
21,123
[ -1 ]
21,124
external-merge-sort.lisp
keithj_deoxybyte-io/src/external-merge-sort.lisp
;;; ;;; Copyright (c) 2009-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) ;;; This external merge sort protocol is slightly slower than the ;;; previous implementation, but is extendable to sort things other ;;; than line-based text files. Speed is roughly 70% of the speed of ;;; Unix sort using SBCL 1.0.30 on X86_64. (defclass sort-input-stream (fundamental-input-stream) () (:documentation "An input stream for reading and sorting the stream contents.")) (defclass sort-output-stream (fundamental-output-stream) () (:documentation "An output stream for sorting and writing the stream contents.")) (defclass merge-stream (io-stream-mixin) ((stream-head :initform nil :initarg :stream-head :accessor stream-head-of :documentation "Returns the next element from MERGE-STREAM without removing it. Part of the external merge sort protocol.")) (:documentation "An IO stream for merging sorted data.")) (defgeneric stream-merge (merge-stream) (:documentation "Returns the next element from MERGE-STREAM as part of the a merging operation between several {defclass merge-stream } s.")) (defgeneric stream-read-element (sort-input-stream) (:documentation "Returns the next element from SORT-INPUT-STREAM.")) (defgeneric stream-write-element (element sort-output-stream) (:documentation "Writes ELEMENT to SORT-OUTPUT-STREAM.")) (defgeneric make-merge-stream (sort-input-stream predicate &key key buffer-size) (:documentation "Returns a new {defclass merge-stream} appropriate to SORT-INPUT-STREAM. The new stream must return sorted elements read from SORT-INPUT-STREAM. Arguments: - sort-input-stream (sort-input-stream): The stream whose elements are to be sorted. - predicate (function designator): The sorting predicate, as in CL:SORT, a function of two arguments that returns a generalized boolean. Key: - key (function designator): A function of one argument, or nil. - buffer-size (fixnum): The size of the in-memory sort buffer and hence the number of elements written to disk in the external merge file. Returns: - a {defclass merge-stream} from which sorted elements may be read.")) (defgeneric external-merge-sort (sort-input-stream sort-output-stream predicate &key key buffer-size) (:documentation "Performs an external merge sort on the elements read from SORT-INPUT-STREAM and writes the sorted elements to SORT-OUTPUT-STREAM. Arguments: - sort-input-stream (sort-input-stream): The stream whose elements are to be sorted. - sort-output-stream (sort-output-stream): A stream whose elements are sorted. - predicate (function designator): The sorting predicate, as in CL:SORT, a function of two arguments that returns a generalized boolean. Key: - key (function designator): A function of one argument, or nil. - buffer-size (fixnum): The size of the in-memory sort buffer and hence the number of elements written to disk in the external merge file. Returns: - The total number of elements sorted (fixnum). - The number of {defclass merge-stream} s used in sorting (fixnum).")) (defmethod stream-delete-file ((stream merge-stream)) (delete-file (stream-of stream))) (defmethod external-merge-sort ((in sort-input-stream) (out sort-output-stream) predicate &key key (buffer-size 100000)) (declare (optimize (speed 3) (safety 0))) (flet ((merge-and-count (streams pred key) (unwind-protect (loop for elt = (merge-element streams pred key) while elt count elt into num-elts do (stream-write-element elt out) finally (return num-elts)) (loop for stream across streams do (progn (when (open-stream-p stream) (stream-delete-file stream) (close stream :abort t))))))) (let* ((merge-streams (loop for stream = (make-merge-stream in predicate :key key :buffer-size buffer-size) while stream collect stream into streams finally (return (make-array (the fixnum (list-length streams)) :initial-contents streams)))) (num-streams (length merge-streams)) (key (cond ((null key) #'identity) ((functionp key) key) (t (fdefinition key))))) (values (if (zerop num-streams) 0 (merge-and-count merge-streams predicate key)) num-streams)))) (declaim (inline merge-element)) (defun merge-element (merge-streams predicate key) "Returns the next element from one of MERGE-STREAMS. The returned element is the on that sorts first according to PREDICATE and KEY, as required by the merge-sort algorithm." (declare (optimize (speed 3))) (declare (type simple-vector merge-streams) (type function predicate key)) (loop with x = (slot-value (svref merge-streams 0) 'stream-head) and x-index = 0 for y-index from 0 below (length merge-streams) for y = (slot-value (svref merge-streams y-index) 'stream-head) when (and y (or (null x) (funcall predicate (funcall key y) x))) do (setf x y x-index y-index) finally (progn (stream-merge (svref merge-streams x-index)) (return x))))
6,396
Common Lisp
.lisp
144
37.104167
79
0.667845
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
98a4bdc5dd9eac53e0f5b27799c4a330367c6d48fd719b480da3df107c8cc2ed
21,124
[ -1 ]
21,125
deoxybyte-io.lisp
keithj_deoxybyte-io/src/deoxybyte-io.lisp
;;; ;;; Copyright (c) 2010-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) (defmacro check-record (test-form record &optional error-message &rest message-arguments) "Checks RECORD. If TEST-FORM returns false a {define-condition malformed-record-error} is raised. The default error message may be refined with an additional ERROR-MESSAGE. Arguments: - test-form (form): A form to be evaluated. If the form returns NIL, an error is raised. - record (form): A form that evaluates to a record. Optional: - error-message (string): An error message string. Rest: - message-arguments (forms): Forms that evaluate to arguments for the error message." `(progn (unless ,test-form (error 'malformed-record-error :record ,record :format-control ,error-message :format-arguments (list ,@message-arguments))) t)) (defmacro check-field (test-form record field &optional error-message &rest message-arguments) "Checks FIELD of RECORD. If TEST-FORM returns false a {define-condition malformed-field-error} is raised. The default error message may be refined with an additional ERROR-MESSAGE. Arguments: - test-form (form): A form to be evaluated. If the form returns NIL, an error is raised. - record (form): A form that evaluates to a record. - field (form): A form that evaluates to a field in RECORD. Optional: - error-message (string): An error message string. Rest: - message-arguments (forms): Forms that evaluate to arguments for the error message." `(progn (unless ,test-form (error 'malformed-field-error :record ,record :field ,field :format-control ,error-message :format-arguments (list ,@message-arguments))) t))
2,552
Common Lisp
.lisp
63
36.174603
73
0.71059
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9975f8fd27a467a45572ecdeeb506781c6511fd83707e08b9c64372384bbc871
21,125
[ -1 ]
21,126
external-line-sort.lisp
keithj_deoxybyte-io/src/external-line-sort.lisp
;;; ;;; Copyright (c) 2009-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) ;;; An implementation of the external merge sort protocol for sorting ;;; lines in text files. (defclass line-sort-input-stream (sort-input-stream wrapped-stream-mixin) ()) (defclass line-sort-output-stream (sort-output-stream wrapped-stream-mixin) ()) (defclass line-merge-stream (merge-stream wrapped-stream-mixin) ()) (defmethod stream-read-element ((stream line-sort-input-stream)) (read-line (stream-of stream) nil nil)) (defmethod stream-write-element ((line string) (stream line-sort-output-stream)) (write-line line (stream-of stream))) (defmethod make-merge-stream ((stream line-sort-input-stream) predicate &key key (buffer-size 100000)) (let ((out (open (tmp-pathname :basename "line-merge-sort") :direction :io :element-type (stream-element-type stream))) (elements (make-array buffer-size :adjustable t :fill-pointer 0))) (loop for i from 0 below buffer-size for elt = (stream-read-element stream) while elt do (vector-push elt elements)) (cond ((plusp (length elements)) (loop for elt across (stable-sort elements predicate :key key) do (write-line elt out) finally (if (file-position out 0) (return (make-instance 'line-merge-stream :stream out)) (error 'file-error :pathname out)))) (t (close out :abort t) nil)))) (defmethod initialize-instance :after ((stream line-merge-stream) &key) (with-accessors ((s stream-of) (h stream-head-of)) stream (setf h (read-line s nil nil)))) (defmethod stream-merge ((stream line-merge-stream)) (with-accessors ((s stream-of) (h stream-head-of)) stream (setf h (read-line s nil nil))))
2,668
Common Lisp
.lisp
61
37.459016
80
0.662048
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
54fa923ed31ae56ba6b860fd8d217b5cdb8ada72e764cdb073fab91f4af6a146
21,126
[ -1 ]
21,127
ccl.lisp
keithj_deoxybyte-io/src/ccl.lisp
;;; ;;; Copyright (c) 2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) ;;; command-line-interface (defun get-system-argv () (rest ccl:*command-line-argument-list*)) (defun print-backtrace (stream &optional (depth 20)) (let ((*debug-io* stream)) (ccl:print-call-history :count depth :detailed-p nil))) (defun quit-lisp (&key (status 0)) (ccl:quit status)) ;;; environment (defun environment-variable (variable-name) "Returns the string value of VARIABLE-NAME, or NIL." (ccl:getenv variable-name)) (defun (setf environment-variable) (value variable-name) "Sets the value of VARIABLE-NAME to VALUE, which maye be a string or a symbol." (ccl:setenv variable-name value))
1,423
Common Lisp
.lisp
35
38.971429
73
0.736614
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
31d70f5b01c4f1b1f90fa29d8ee850acd3a1edb5cba700a47b7011540a03c4f0
21,127
[ -1 ]
21,128
ieee-float.lisp
keithj_deoxybyte-io/src/ieee-float.lisp
;;; ;;; Copyright (c) 2010-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) (defconstant +frac-factor-32+ (expt 2 23) "Mantissa fraction float32 multiplication factor") (defconstant +min-norm-exponent-32+ -126 "Smallest normalized float32 exponent") (defconstant +exponent-bias-32+ 127 "Exponent bias for float32") (defconstant +not-a-number-32+ #b1111111110000000000000000000000) (defconstant +positive-infinity-32+ #b1111111100000000000000000000000) (defconstant +negative-infinity-32+ #b11111111100000000000000000000000) (defconstant +frac-factor-64+ (expt 2 52) "Mantissa fraction float64 multiplication factor") (defconstant +min-norm-exponent-64+ -1022 "Smallest normalized float64 exponent") (defconstant +exponent-bias-64+ 1023 "Exponent bias for float64") (defconstant +not-a-number-64+ #b111111111111000000000000000000000000000000000000000000000000000) (defconstant +positive-infinity-64+ #b111111111110000000000000000000000000000000000000000000000000000) (defconstant +negative-infinity-64+ #b1111111111110000000000000000000000000000000000000000000000000000) ;;; IEEE 754 float to integer conversions with support for reading and ;;; writing NaN and infinity. (defun encode-ieee-float32 (f) "Encodes single-float F as a 32-bit integer using IEEE 754 encoding. NaN, +Inf and -Inf may be represented by using the keywords :not-a-number :positive-infinity or :negative-infinity respectively, as an argument." (etypecase f (symbol (ecase f (:not-a-number +not-a-number-32+) (:positive-infinity +positive-infinity-32+) (:negative-infinity +negative-infinity-32+))) (number (let ((f (coerce f 'single-float))) (multiple-value-bind (significand exponent sign) (decode-float f) (let ((n 0)) (setf (ldb (byte 1 31) n) (if (minusp sign) 1 0)) (if (>= (abs f) least-positive-normalized-single-float) (let ((normalized-signif (* 2 significand)) ; a normalized float (normalized-exp (1- exponent))) (setf (ldb (byte 8 23) n) (+ normalized-exp +exponent-bias-32+) (ldb (byte 23 0) n) (round (* (1- normalized-signif) +frac-factor-32+)))) (setf (ldb (byte 23 0) n) ; a denormalized float (ash (round (* significand +frac-factor-32+)) (- exponent +min-norm-exponent-32+)))) n)))))) (defun decode-ieee-float32 (n) "Decodes an IEEE 754 encoded single-float from 32-bit integer N. NaN, +Inf and -Inf are represented by the keywords :not-a-number :positive-infinity or :negative-infinity respectively." (let ((sign (if (zerop (ldb (byte 1 31) n)) 1.0 -1.0)) (exponent (ldb (byte 8 23) n)) (significand (ldb (byte 23 0) n))) (cond ((= #b11111111 exponent) ; nan or infinity (cond ((zerop significand) (cond ((plusp sign) :positive-infinity) (t :negative-infinity))) (t :not-a-number))) (t (cond ((zerop exponent) ; a denormalized float (setf exponent +min-norm-exponent-32+)) (t ; a normalized float (decf exponent +exponent-bias-32+) (setf (ldb (byte 1 23) significand) 1))) ; replace hidden bit (* sign (scale-float (float significand) (- exponent 23))))))) (defun encode-ieee-float64 (f) "Encodes double-float F as a 64-bit integer using IEEE 754 encoding. NaN, +Inf and -Inf may be represented by using the keywords :not-a-number :positive-infinity or :negative-infinity respectively, as an argument." (etypecase f (symbol (ecase f (:not-a-number +not-a-number-64+) (:positive-infinity +positive-infinity-64+) (:negative-infinity +negative-infinity-64+))) (number (let ((f (coerce f 'double-float))) (multiple-value-bind (significand exponent sign) (decode-float f) (let ((n 0)) (setf (ldb (byte 1 63) n) (if (minusp sign) 1 0)) (if (>= (abs f) least-positive-normalized-double-float) (let ((norm-signif (* 2 significand)) ; a normalized float (norm-exp (1- exponent))) (setf (ldb (byte 11 52) n) (+ norm-exp +exponent-bias-64+) (ldb (byte 52 0) n) (round (* (1- norm-signif) +frac-factor-64+)))) (setf (ldb (byte 52 0) n) ; a denormalized float (ash (round (* significand +frac-factor-64+)) (- exponent +min-norm-exponent-64+)))) n)))))) (defun decode-ieee-float64 (n) "Decodes an IEEE 754 encoded double-float from 64-bit integer N. NaN, +Inf and -Inf are represented by the keywords :not-a-number :positive-infinity or :negative-infinity respectively." (let ((sign (if (zerop (ldb (byte 1 63) n)) 1.0d0 -1.0d0)) (exponent (ldb (byte 11 52) n)) (significand (ldb (byte 52 0) n))) (cond ((= #b11111111111 exponent) ; nan or infinity (cond ((zerop significand) (cond ((plusp sign) :positive-infinity) (t :negative-infinity))) (t :not-a-number))) (t (cond ((zerop exponent) ; a denormalized float (setf exponent +min-norm-exponent-64+)) (t ; a normalized float (decf exponent +exponent-bias-64+) (setf (ldb (byte 1 52) significand) 1))) ; replace hidden bit (* sign (scale-float (float significand 1.0d0) (- exponent 52)))))))
6,946
Common Lisp
.lisp
146
36.90411
80
0.583333
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
1601cd1774a051dd7bc140655ee06ff1ce53830a8774cd082e5aaa64b4868937
21,128
[ -1 ]
21,129
environment.lisp
keithj_deoxybyte-io/src/environment.lisp
;;; ;;; Copyright (c) 2009-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io)
809
Common Lisp
.lisp
19
41.526316
73
0.737643
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
7a20ac5104e708e3a1379f842a2ed7ead2b2481c7f8d24e29ad6058d462c9741
21,129
[ -1 ]
21,130
conditions.lisp
keithj_deoxybyte-io/src/conditions.lisp
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) ;;; General IO error conditions (define-condition io-error (error) () (:documentation "The parent type of all IO error conditions.")) (define-condition io-warning (warning) () (:documentation "The parent type of all IO warning conditions.")) ;;; Command line interface conditions (define-condition cli-error (error) ((cli :initarg :cli :initform nil :reader cli-of :documentation "The CLI object relevant to the error.")) (:documentation "The parent type of all CLI error conditions.")) (define-condition cli-warning (warning) ((cli :initarg :cli :initform nil :reader cli-of :documentation "The CLI object relevant to the warning.")) (:documentation "The parent type of all CLI warning conditions.")) (define-condition cli-option-error (cli-error) ((name :initarg :name :reader name-of :documentation "The option name.")) (:documentation "The parent type of all CLI option error conditions.")) (define-condition cli-option-warning (cli-warning) ((name :initarg :name :reader name-of :documentation "The option name.")) (:documentation "The parent type of all CLI option warning conditions.")) (define-condition unknown-command (cli-error) ((command :initarg :command :reader command-of :documentation "The unknown command.")) (:report (lambda (condition stream) (format stream "Unknown command ~a." (command-of condition)))) (:documentation "An error that is raised when the main command is not recognised.")) (define-condition missing-required-option (cli-option-error) () (:report (lambda (condition stream) (format stream "Missing required option --~a." (name-of condition)))) (:documentation "An error that is raised when a required option is missing.")) (define-condition missing-required-value (cli-option-error) () (:report (lambda (condition stream) (format stream "Missing required value for --~a." (name-of condition)))) (:documentation "An error that is raised when a required value for an option is missing.")) (define-condition incompatible-value (cli-option-error) ((type :initarg :type :reader type-of :documentation "The expected type of option value.") (value :initarg :value :reader value-of :documentation "The invalid value.")) (:report (lambda (condition stream) (format stream "Invalid value ~s supplied for option --~a (~a)." (value-of condition) (name-of condition) (type-of condition)))) (:documentation "An error that is raised when an option is supplied with an invalid value.")) (define-condition unmatched-option (cli-option-warning) () (:report (lambda (condition stream) (format stream "unmatched option --~a" (name-of condition))))) (define-condition unknown-option (cli-option-warning) () (:report (lambda (condition stream) (format stream "unknown option --~a" (name-of condition))))) ;;; Parse conditions (define-condition general-parse-error (io-error formatted-condition) () (:report (lambda (condition stream) (format stream "General parse error~@[: ~a~]" (message-of condition)))) (:documentation "The parent type of all parse error conditions.")) (define-condition malformed-file-error (general-parse-error) ((file :initform nil :initarg :file :reader file-of :documentation "The malformed file.")) (:report (lambda (condition stream) (format stream "Malformed file~@[ ~a ~]~@[: ~a~]" (file-of condition) (message-of condition)))) (:documentation "An error that is raised when a file is malformed for any reason.")) (define-condition malformed-record-error (general-parse-error) ((record :initform nil :initarg :record :reader record-of :documentation "The malformed record.")) (:report (lambda (condition stream) (format stream "Malformed record~@[ ~a ~]~@[: ~a~]" (record-of condition) (message-of condition)))) (:documentation "An error that is raised when a record is malformed for any reason.")) (define-condition record-validation-error (malformed-record-error) () (:report (lambda (condition stream) (format stream "Invalid record~@[ ~a ~]~@[: ~a~]" (record-of condition) (message-of condition)))) (:documentation "An error that is raised when a record fails validation of one or more of its parts.")) (define-condition malformed-field-error (malformed-record-error) ((field :initform nil :initarg :field :reader field-of :documentation "The malformed field.")) (:report (lambda (condition stream) (format stream "Malformed field~@[ ~a~]~@[ in record ~a~]~@[: ~a~]" (field-of condition) (record-of condition) (message-of condition)))) (:documentation "An error that is raised when a field-based record contains a malformed field within it.")) (define-condition field-validation-error (malformed-field-error) () (:report (lambda (condition stream) (format stream "Invalid field~@[ ~a ~]~@[: ~a~]" (field-of condition) (message-of condition)))) (:documentation "An error that is raised when a record field fails validation."))
6,342
Common Lisp
.lisp
145
37.489655
77
0.667098
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
bd52b836996619e7631ca499162a42e17ce87a3896330e467400a9f74a493181
21,130
[ -1 ]
21,131
default.lisp
keithj_deoxybyte-io/src/default.lisp
;;; ;;; Copyright (c) 2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) ;;; command-line-interface (defun get-system-argv () (error "GET-SYSTEM-ARGV not supported on this Lisp implementation.")) (defun print-backtrace (stream) (error "PRINT-BACKTRACE not supported on this Lisp implementation.")) (defun quit-lisp () (error "QUIT-LISP not supported on this Lisp implementation.")) ;;; environment (defun environment-variable (variable-name) "Returns the string value of VARIABLE-NAME, or NIL." (declare (ignore variable-name)) (error "ENVIRONMENT-VARIABLE not supported on this Lisp implementation.")) (defun (setf environment-variable) (value variable-name) "Sets the value of VARIABLE-NAME to VALUE, which maye be a string or a symbol." (declare (ignore value variable-name)) (error "ENVIRONMENT-VARIABLE not supported on this Lisp implementation."))
1,609
Common Lisp
.lisp
36
43
76
0.752874
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
7c15dff7684296102dcd17984e86ac4c4067e65771d76867eff7cfd7f2dcd400
21,131
[ -1 ]
21,132
line-stream.lisp
keithj_deoxybyte-io/src/line-stream.lisp
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) (defconstant +octet-buffer-size+ 4096 "Buffer size for {defclass octet-line-input-stream} internal buffer.") (deftype octet-buffer () "Buffer type for {defclass octet-line-input-stream} internal buffer." `(simple-array (unsigned-byte 8) (,+octet-buffer-size+))) (deftype octet-buffer-index () "Index type for {defclass octet-line-input-stream} internal buffer." `(integer 0 ,+octet-buffer-size+)) (defclass line-stream () () (:documentation "A line-based stream. Useful for building readers and writers for ad-hoc text data sources.")) (defclass line-input-stream (line-stream fundamental-input-stream) ((line-stack :initform nil :accessor line-stack-of :documentation "A list of lines that have been pushed back into the stream to be read again.")) (:documentation "A line-based stream that allows lines to be pushed back into a stack to be re-read.")) (defclass character-line-input-stream (wrapped-stream-mixin line-input-stream) ()) (defclass octet-line-input-stream (wrapped-stream-mixin line-input-stream) ((buffer :initarg :buffer :initform (make-array +octet-buffer-size+ :element-type 'octet :initial-element 0) :documentation "The buffer from which lines are read.") (eol-code :initarg :eol-code :initform (char-code #\Newline) :documentation "The end of line character code. If two characters are used, this is the first of the pair.") (num-bytes :initform 0 :documentation "The number of bytes that were read into the buffer from the stream.") (offset :initform 0 :documentation "The offset in the byte buffer from which the next byte is to be read.")) (:documentation "A {defclass line-input-stream} whose lines are arrays of bytes. Allows buffered reading of lines of (unsigned-byte 8) from a stream.")) (defclass line-output-stream (line-stream fundamental-output-stream) ()) (defclass character-line-output-stream (line-output-stream) ()) (defclass octet-line-output-stream (line-output-stream) ()) (defgeneric make-line-stream (stream) (:method ((stream stream)) (let* ((elt-type (stream-element-type stream)) (class (cond ((input-stream-p stream) (cond ((subtypep elt-type 'character) 'character-line-input-stream) ((subtypep 'octet elt-type) 'octet-line-input-stream))) ((output-stream-p stream) (cond ((subtypep elt-type 'character) 'character-line-output-stream) ((subtypep 'octet elt-type) 'octet-line-output-stream)))))) (check-arguments class (stream) "unable to make a line-input stream from ~a" stream) (make-instance class :stream stream))) (:documentation "Returns a new {defclass line-stream} created from STREAM.")) (defgeneric pop-line (line-input-stream line) (:method ((stream line-input-stream) (line string)) (pop (slot-value stream 'line-stack))) (:documentation "Pops one line from {defclass line-input-stream} .")) (defgeneric push-line (line-input-stream line) (:method ((stream line-input-stream) (line string)) (push line (slot-value stream 'line-stack))) (:documentation "Pushes LINE back onto {defclass line-input-stream} .")) (defgeneric find-line (line-input-stream test &optional max-lines) (:method ((stream line-input-stream) test &optional max-lines) (do* ((line (stream-read-line stream) (stream-read-line stream)) (matching-line-p (and (vectorp line) (funcall test line)) (and (vectorp line) (funcall test line))) (line-count 1 (1+ line-count))) ((or (eql :eof line) matching-line-p (and (not (null max-lines)) (= line-count max-lines))) (values line matching-line-p line-count)))) (:documentation "Iterates through lines read from LINE-INPUT-STREAM until a line matching predicate TEST is found or until a number of lines equal to MAX-LINES have been examined.")) (defgeneric more-lines-p (line-input-stream) (:method ((stream character-line-input-stream)) (with-slots ((s stream) line-stack) stream (or line-stack (not (eql :eof (peek-char nil s nil :eof)))))) (:method ((stream octet-line-input-stream)) (with-slots ((s stream) buffer offset num-bytes line-stack) stream (when (zerop num-bytes) (setf offset 0 num-bytes (read-sequence buffer s))) (or line-stack (not (zerop num-bytes))))) (:documentation "Returns T if {defclass line-input-stream} contains unread data.")) ;;; line-stream-methods (defmethod stream-element-type ((stream line-stream)) 'string) ;;; character-line-input-stream methods (defmethod stream-element-type ((stream character-line-input-stream)) 'string) (defmethod stream-file-position ((stream character-line-input-stream) &optional position) (with-slots ((s stream) line-stack) stream (cond (position (setf line-stack ()) (file-position s position)) (t (let ((buffered-chars (loop for line in line-stack sum (1+ (length line))))) ; eol (- (file-position s) buffered-chars)))))) (defmethod stream-clear-input ((stream character-line-input-stream)) (setf (slot-value stream 'line-stack) nil)) (defmethod stream-read-line ((stream character-line-input-stream)) (with-slots ((s stream) line-stack) stream (if (null line-stack) (multiple-value-bind (line missing-eol-p) (read-line s nil :eof) (values line missing-eol-p)) (pop line-stack)))) ;;; octet-line-input-stream methods (defmethod stream-element-type ((stream octet-line-input-stream)) 'string) (defmethod stream-file-position ((stream octet-line-input-stream) &optional position) (with-slots ((s stream) offset num-bytes line-stack) stream (cond (position (setf num-bytes 0 offset 0 line-stack ()) (file-position s position)) (t (- (file-position s) (- num-bytes offset)))))) (defmethod stream-clear-input ((stream octet-line-input-stream)) (with-slots (offset num-bytes line-stack) stream (setf offset 0 num-bytes 0 line-stack ()))) (defmethod stream-read-line ((stream octet-line-input-stream)) (declare (optimize (speed 3))) (flet ((build-string (chunks) ; this is 3x faster than with-output-to-string (let ((length (if (endp (rest chunks)) (length (the simple-octet-vector (first chunks))) (reduce #'+ chunks :key #'length)))) (declare (type vector-index length)) (loop with line = (make-array length :element-type 'base-char) with offset of-type vector-index = 0 for chunk of-type simple-octet-vector in chunks for clength = (length chunk) do (unless (zerop clength) (copy-vector chunk 0 clength line offset #'code-char) (incf offset clength)) finally (return line))))) (with-slots (line-stack) stream (if (null line-stack) (multiple-value-bind (chunks has-eol-p) (read-octet-line stream) (if (null chunks) (values :eof t) (values (build-string chunks) has-eol-p))) (pop line-stack))))) ;;; line-output-stream methods (defgeneric stream-write-line (string stream &optional start end) (:method ((str string) (stream character-line-output-stream) &optional (start 0) end) (write-line str (slot-value stream 'stream) :start start :end end)) (:method ((str string) (stream octet-line-output-stream) &optional (start 0) end) (let ((end (or end (length str))) (octets (make-array (- end start) :element-type 'octet))) (copy-vector str 0 end octets 0 #'char-code) (write-sequence octets (slot-value stream 'stream))))) (defun read-octet-line (stream) "Reads chunks of bytes up to the next newline or end of stream, returning them in a list. The newline is not included. Returns two values - a list of chunks and either NIL or T to indicate whether a terminating newline was missing. When the stream underlying the buffer is exhausted the list of chunks will be empty." (declare (optimize (speed 3) (safety 0))) (with-slots ((s stream) buffer offset num-bytes eol-code) stream (declare (type octet-buffer buffer) (type octet-buffer-index offset num-bytes)) (labels ((buffer-empty-p () (= offset num-bytes)) (fill-buffer () (setf offset 0 num-bytes (read-sequence buffer s))) (find-eol () (let ((eol-pos (position eol-code buffer :start offset :end num-bytes))) (cond ((and eol-pos (plusp (- eol-pos offset))) ;; There is a newline in the buffer, but not ;; at the zeroth position. Make a chunk up to ;; the newline (let ((chunk (make-array (- eol-pos offset) :element-type 'octet :initial-element 0))) (replace chunk buffer :start2 offset :end2 eol-pos) (setf offset (1+ eol-pos)) (values (list chunk) nil))) ((and eol-pos (zerop (- eol-pos offset))) ;; There is a newline in the buffer at the ;; zeroth position. (setf offset (1+ eol-pos)) (values nil nil)) ((zerop num-bytes) ;; The buffer is empty (values nil t)) (t ;; There is no newline in the buffer. Make a ;; chunk and recurse to find the newline (let ((chunk (make-array (- num-bytes offset) :element-type 'octet :initial-element 0))) (replace chunk buffer :start2 offset :end2 num-bytes) (fill-buffer) (multiple-value-bind (chunks missing-eol-p) (find-eol) (values (cons chunk chunks) missing-eol-p)))))))) (when (buffer-empty-p) (fill-buffer)) (find-eol)))) (defun %stream-read-sequence (stream sequence start end) (loop with n = 0 for i from start below end for line = (stream-read-line stream) until (or (eql :eof line) (= end i)) do (setf (elt sequence i) line n (1+ n)) finally (return n))) (defun %stream-write-sequence (stream sequence start end) (loop for i from start below end do (write-sequence (elt sequence i) stream)))
12,443
Common Lisp
.lisp
271
35.287823
79
0.593099
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
5f4ca714230405bcca60b3a88b036beed10956b0a862390e8c023854ec85ec25
21,132
[ -1 ]
21,133
streams.lisp
keithj_deoxybyte-io/src/streams.lisp
;;; ;;; Copyright (c) 2008-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) (defclass wrapped-stream-mixin () ((stream :initarg :stream :reader stream-of :documentation "The underlying stream from which data are read.")) (:documentation "A Gray-stream wrapping a standard Lisp stream.")) (defclass stream-filter-mixin () ((test :initarg :test :reader test-of :documentation "A function designator for a test that returns T when the next datum read from the stream is to be ignored.")) (:documentation "A mixin that provides a filtering function for streams. Any data encountered while reading or writing for which the test returns T are ignored and skipped.")) (defclass io-stream-mixin (fundamental-input-stream fundamental-output-stream) ()) ;;; Deoxybyte Gray streams generic functions (defgeneric stream-open (filespec class &rest initargs) (:documentation "Returns a Gray stream of CLASS")) (defgeneric stream-close (stream &key abort) (:documentation "Closes STREAM, returning T if STREAM was open. If ABORT is T, attempts to clean up any side effects of having created stream.")) (defgeneric stream-delete-file (stream) (:documentation "Equivalent to CL:DELETE-FILE.")) ;;; Methods common to all Gray streams (defmethod stream-element-type ((stream wrapped-stream-mixin)) (stream-element-type (slot-value stream 'stream))) (defmethod open-stream-p ((stream wrapped-stream-mixin)) (open-stream-p (slot-value stream 'stream))) (defmethod stream-file-position ((stream wrapped-stream-mixin) &optional position) (file-position (slot-value stream 'stream) position)) ;;; Deoxybyte Gray streams methods (defmethod stream-open (filespec class &rest initargs) (make-instance class :stream (apply #'open filespec initargs))) (defmethod stream-close ((stream wrapped-stream-mixin) &key abort) (close (slot-value stream 'stream) :abort abort)) (defmethod stream-delete-file ((stream wrapped-stream-mixin)) (delete-file (slot-value stream 'stream))) ;;; Methods common to Gray input streams (defmethod stream-clear-input ((stream io-stream-mixin)) nil) ;;; Methods common to Gray output streams (defmethod stream-clear-output ((stream io-stream-mixin)) nil) (defmethod stream-finish-output ((stream io-stream-mixin)) nil) (defmethod stream-force-output ((stream io-stream-mixin)) nil) ;;; Initialization (defmethod initialize-instance :after ((stream wrapped-stream-mixin) &key) (check-arguments (streamp (slot-value stream 'stream)) (stream) "expected a stream argument"))
3,376
Common Lisp
.lisp
73
42.849315
78
0.737595
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d93071210605b5dd9531d4b1594d33ca359c1d064dda414bbfa39e0b91480e2c
21,133
[ -1 ]
21,134
binary-operations.lisp
keithj_deoxybyte-io/src/binary-operations.lisp
;;; ;;; Copyright (c) 2009-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) (defmacro define-integer-encoder (name &key (bytes 1) (order :little-endian) signed) "Defines a function NAME with two mandatory arguments, an integer and a simple-array of unsigned-byte 8, and one optional argument, a fixnum index in that array that defaults to 0. The function returns the buffer containing the encoded integer. Key: - bytes (fixnum): the number of bytes that comprise the number. - order (sumbol): the byte order of the array, may be one of :little-endian or :big-endian ( :network-byte-order may be used as a synonym for :big-endian )." (assert (plusp bytes) () "must encode at least 1 byte") (let ((byte-shifts (ecase order (:little-endian (loop for i from 0 to (* 8 (1- bytes)) by 8 collect i)) ((:big-endian :network-byte-order) (loop for i from (* 8 (1- bytes)) downto 0 by 8 collect i)))) (int-type (if (< 0 bytes 5) `(or (signed-byte ,(* 8 bytes)) (unsigned-byte ,(* 8 bytes))) 'integer)) (speed (if (< 0 bytes 5) 3 1))) `(progn (declaim (inline ,name)) (declaim (ftype (function (,int-type simple-octet-vector &optional vector-index) simple-octet-vector) ,name)) (defun ,name (value buffer &optional (index 0)) ,(format nil (txt "Encodes a ~a byte integer as consecutive bytes" "in BUFFER, in ~a byte order, starting at INDEX.") bytes (string-downcase (symbol-name order))) (declare (optimize (speed ,speed) (safety 1))) (declare (type simple-octet-vector buffer) (type vector-index index) (type ,int-type value)) ,@(unless signed `((check-arguments (not (minusp value)) (value) "cannot store a negative number as unsigned"))) (setf ,@(loop for i from 0 below bytes for shift in byte-shifts nconc `((aref buffer (+ index ,i)) (ldb (byte 8 ,shift) value)))) buffer)))) (defmacro define-integer-decoder (name &key (bytes 1) (order :little-endian) signed) "Defines a function NAME with one mandatory argument, a simple-array of unsigned-byte 8, and one optional argument, a fixnum index in that array that defaults to 0. The function returns the Lisp integer whose value is given by the bytes at that index in the byte array. Key: - bytes (fixnum): the number of bytes that comprise the number. - order (sumbol): the byte order of the array, may be one of :little-endian or :big-endian ( :network-byte-order may be used as a synonym for :big-endian ). - signed (boolean): T if the bytes are a two's complement representation of a signed integer." (assert (plusp bytes) () "must decode at least 1 byte") (let ((byte-shifts (ecase order (:little-endian (loop for i from 0 to (* 8 (1- bytes)) by 8 collect i)) ((:big-endian :network-byte-order) (loop for i from (* 8 (1- bytes)) downto 0 by 8 collect i)))) (mask (1- (ash 1 (* 8 bytes)))) (sign-bit (1- (* 8 bytes))) (int-type (if signed `(signed-byte ,(* 8 bytes)) `(unsigned-byte ,(* 8 bytes)))) (speed (if (< 0 bytes 5) 3 1))) `(progn (declaim (inline ,name)) (declaim (ftype (function ((simple-octet-vector) &optional vector-index) ,int-type) ,name)) (defun ,name (buffer &optional (index 0)) ,(format nil (txt "Decodes ~:[an unsigned~;a signed~] ~a byte" "integer stored as consecutive bytes in BUFFER," "in ~a byte order, starting at INDEX.") signed bytes (string-downcase (symbol-name order))) (declare (optimize (speed ,speed) (safety 1))) (declare (type simple-octet-vector buffer) (type vector-index index)) (let ((value (logior ,@(loop for i from 0 below bytes for shift in byte-shifts collect `(ash (aref buffer (+ index ,i)) ,shift))))) ,(if signed `(if (logbitp ,sign-bit value) (- (1+ (logxor value ,mask))) value) 'value)))))) (defmacro define-float-encoder (name &key (bytes 4) (order :little-endian)) "Defines a function NAME with two mandatory arguments, a float and a simple-array of unsigned-byte 8, and one optional argument, a fixnum index in that array that defaults to 0. The function returns the buffer containing the encoded float. Key: - bytes (fixnum): the number of bytes that comprise the number. - order (sumbol): the byte order of the array, may be one of :little-endian or :big-endian ( :network-byte-order may be used as a synonym for :big-endian )." (let ((int-encoder (ecase order (:little-endian (ecase bytes (4 'encode-int32le) (8 'encode-int64le))) (:big-endian (ecase bytes (4 'encode-int32be) (8 'encode-int64be))))) (float-encoder (ecase bytes (4 'encode-ieee-float32) (8 'encode-ieee-float64)))) `(progn (defun ,name (value buffer &optional (index 0)) ,(format nil (txt "Encodes ~a byte float as consecutive bytes in" "BUFFER, in ~a byte order, starting at INDEX.") bytes (string-downcase (symbol-name order))) (,int-encoder (,float-encoder value) buffer index))))) (defmacro define-float-decoder (name &key (bytes 4) (order :little-endian)) "Defines a function NAME with one mandatory argument, a simple-array of unsigned-byte 8, and one optional argument, a fixnum index in that array that defaults to 0. The function returns the Lisp float whose value is given by the bytes at that index in the byte array. Key: - bytes (fixnum): the number of bytes that comprise the number. - order (sumbol): the byte order of the array, may be one of :little-endian or :big-endian ( :network-byte-order may be used as a synonym for :big-endian )." (let ((int-decoder (ecase order (:little-endian (ecase bytes (4 'decode-uint32le) (8 'decode-uint64le))) (:big-endian (ecase bytes (4 'decode-uint32be) (8 'decode-uint64be))))) (float-decoder (ecase bytes (4 'decode-ieee-float32) (8 'decode-ieee-float64)))) `(progn (defun ,name (buffer &optional (index 0)) ,(format nil (txt "Decodes ~a byte float stored as consecutive bytes" "in BUFFER, in ~a byte order, starting at INDEX.") bytes (string-downcase (symbol-name order))) (,float-decoder (,int-decoder buffer index)))))) (define-integer-encoder encode-uint64le :bytes 8 :order :little-endian) (define-integer-encoder encode-uint32le :bytes 4 :order :little-endian) (define-integer-encoder encode-uint16le :bytes 2 :order :little-endian) (define-integer-encoder encode-uint8le :bytes 1 :order :little-endian) (define-integer-encoder encode-int64le :bytes 8 :order :little-endian :signed t) (define-integer-encoder encode-int32le :bytes 4 :order :little-endian :signed t) (define-integer-encoder encode-int16le :bytes 2 :order :little-endian :signed t) (define-integer-encoder encode-int8le :bytes 1 :order :little-endian :signed t) (define-integer-decoder decode-uint64le :bytes 8 :order :little-endian) (define-integer-decoder decode-uint32le :bytes 4 :order :little-endian) (define-integer-decoder decode-uint16le :bytes 2 :order :little-endian) (define-integer-decoder decode-uint8le :bytes 1 :order :little-endian) (define-integer-decoder decode-int64le :bytes 8 :order :little-endian :signed t) (define-integer-decoder decode-int32le :bytes 4 :order :little-endian :signed t) (define-integer-decoder decode-int16le :bytes 2 :order :little-endian :signed t) (define-integer-decoder decode-int8le :bytes 1 :order :little-endian :signed t) (define-integer-encoder encode-uint64be :bytes 8 :order :big-endian) (define-integer-encoder encode-uint32be :bytes 4 :order :big-endian) (define-integer-encoder encode-uint16be :bytes 2 :order :big-endian) (define-integer-encoder encode-uint8be :bytes 1 :order :big-endian) (define-integer-encoder encode-int64be :bytes 8 :order :big-endian :signed t) (define-integer-encoder encode-int32be :bytes 4 :order :big-endian :signed t) (define-integer-encoder encode-int16be :bytes 2 :order :big-endian :signed t) (define-integer-encoder encode-int8be :bytes 1 :order :big-endian :signed t) (define-integer-decoder decode-uint64be :bytes 8 :order :big-endian) (define-integer-decoder decode-uint32be :bytes 4 :order :big-endian) (define-integer-decoder decode-uint16be :bytes 2 :order :big-endian) (define-integer-decoder decode-uint8be :bytes 1 :order :big-endian) (define-integer-decoder decode-int64be :bytes 8 :order :big-endian :signed t) (define-integer-decoder decode-int32be :bytes 4 :order :big-endian :signed t) (define-integer-decoder decode-int16be :bytes 2 :order :big-endian :signed t) (define-integer-decoder decode-int8be :bytes 1 :order :big-endian :signed t) (define-float-encoder encode-float64le :bytes 8 :order :little-endian) (define-float-encoder encode-float32le :bytes 4 :order :little-endian) (define-float-encoder encode-float64be :bytes 8 :order :big-endian) (define-float-encoder encode-float32be :bytes 4 :order :big-endian) (define-float-decoder decode-float64le :bytes 8 :order :little-endian) (define-float-decoder decode-float32le :bytes 4 :order :little-endian) (define-float-decoder decode-float64be :bytes 8 :order :big-endian) (define-float-decoder decode-float32be :bytes 4 :order :big-endian)
11,505
Common Lisp
.lisp
219
42.068493
80
0.616642
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
affb4a0ba98a69b19191a083217e858d70fde5b17c45192ce0bb17123c39fb08
21,134
[ -1 ]
21,135
sbcl.lisp
keithj_deoxybyte-io/src/sbcl.lisp
;;; ;;; Copyright (c) 2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) ;;; command-line-interface (defun get-system-argv () (rest sb-ext:*posix-argv*)) (defun print-backtrace (stream &optional (depth 20)) (sb-debug:backtrace depth stream)) (defun quit-lisp (&key (status 0)) (sb-ext:exit :code status)) ;;; environment (defun environment-variable (variable-name) "Returns the string value of VARIABLE-NAME, or NIL." (sb-posix:getenv (etypecase variable-name (string variable-name) (symbol (symbol-name variable-name))))) (defun (setf environment-variable) (value variable-name) "Sets the value of VARIABLE-NAME to VALUE, which maye be a string or a symbol." (declare (ignore value variable-name)) (error "Not implemented on ~a" (lisp-implementation-type))) ;;; line-stream (defmethod stream-read-sequence ((stream character-line-input-stream) sequence &optional (start 0) end) (let ((end (or end (length sequence)))) (%stream-read-sequence stream sequence start end))) (defmethod stream-read-sequence ((stream octet-line-input-stream) sequence &optional (start 0) end) (let ((end (or end (length sequence)))) (%stream-read-sequence stream sequence start end))) (defmethod stream-write-sequence ((stream line-output-stream) sequence &optional (start 0) end) (let ((end (or end (length sequence)))) (%stream-write-sequence stream sequence start end)))
2,267
Common Lisp
.lisp
50
40.64
73
0.692935
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d7ae58d38c960eeae53a93c161056018f0244478708dc1f87c37672b47eae4ef
21,135
[ -1 ]
21,136
files-and-directories.lisp
keithj_deoxybyte-io/src/files-and-directories.lisp
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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 :uk.co.deoxybyte-io) (defparameter *default-tmpdir* (pathname "/tmp/") "The default temporary file directory pathname.") (defparameter *default-tmpfile-defaults* (make-pathname :directory (pathname-directory *default-tmpdir*)) "The defaults used to fill in temporary file pathnames.") (defmacro with-tmp-pathname ((pathname &rest rest) &body body) "Executes BODY with DIRECTORY bound to a pathname of a temporary file that has been created with the MAKE-TMP-PATHNAME function. If BODY executes without error, any file denoted by the temporary pathname is deleted. If an error occurs, restarts DELETE-TMP-PATHNAME and LEAVE-TMP-PATHNAME are provided to control what happens." `(let ((,pathname (tmp-pathname ,@rest))) (restart-case (multiple-value-prog1 (progn ,@body) (when (fad:file-exists-p ,pathname) (delete-file ,pathname))) (delete-tmp-pathname () :report "Delete temporary pathname" (when (fad:file-exists-p ,pathname) (delete-file ,pathname)) ,pathname) (leave-tmp-pathname () :report "Leave temporary pathname" ,pathname)))) (defun delete-tmp-pathname (condition) "Invokes the DELETE-TMP-PATHNAME restart, if established." (declare (ignore condition)) (let ((restart (find-restart 'delete-tmp-pathname))) (when restart (invoke-restart restart)))) (defun leave-tmp-pathname (condition) "Invokes the LEAVE-TMP-PATHNAME restart, if established." (declare (ignore condition)) (let ((restart (find-restart 'leave-tmp-pathname))) (when restart (invoke-restart restart)))) (defmacro with-tmp-directory ((directory &rest rest) &body body) "Executes BODY with DIRECTORY bound to a temporary directory that has been created with the MAKE-TMP-DIRECTORY function. If BODY executes without error, the temporary directory is deleted. If an error occurs, restarts DELETE-TMP-DIRECTORY and LEAVE-TMP-DIRECTORY are provided to control what happens." `(let ((,directory (make-tmp-directory ,@rest))) (restart-case (multiple-value-prog1 (progn ,@body) (when (fad:directory-exists-p ,directory) (fad:delete-directory-and-files ,directory))) (delete-tmp-directory () :report "Delete temporary directory" (when (fad:directory-exists-p ,directory) (fad:delete-directory-and-files ,directory)) ,directory) (leave-tmp-directory () :report "Leave temporary directory" ,directory)))) (defun delete-tmp-directory (condition) "Invokes the DELETE-TMP-DIRECTORY restart, if established." (declare (ignore condition)) (let ((restart (find-restart 'delete-tmp-directory))) (when restart (invoke-restart restart)))) (defun leave-tmp-directory (condition) "Invokes the LEAVE-TMP-DIRECTORY restart, if established." (declare (ignore condition)) (let ((restart (find-restart 'leave-tmp-directory))) (when restart (invoke-restart restart)))) (defun absolute-pathname-p (pathname) "Returns T if PATHSPEC is a pathname designator for an absolute file or directory, or NIL otherwise." (eql :absolute (first (pathname-directory pathname)))) (defun relative-pathname-p (pathname) "Returns T if PATHSPEC is a pathname designator for a relative file or directory, or NIL otherwise." (or (null (pathname-directory pathname)) (eql :relative (first (pathname-directory pathname))))) (defun file-pathname (pathname) "Returns a new pathname that represents the file component of PATHSPEC." (pathname (file-namestring pathname))) (defun directory-pathname (pathname) "Returns a new pathname that represents the directory component of PATHSPEC." (pathname (directory-namestring pathname))) (defun leaf-directory-pathname (pathname) "Returns a new relative pathname that represents the leaf directory component of PATHSPEC." (flet ((canonical (elts) (let ((x ())) (dolist (elt elts (reverse x)) (if (eql :up elt) (pop x) (push elt x))))) (leading-ups (elts) (subseq elts 0 (position-if #'stringp elts)))) (let* ((dir (pathname-directory pathname)) (canonical (canonical (rest dir)))) (cond ((and (eql :absolute (first dir)) (second canonical)) (make-pathname :directory (cons :relative (last canonical)) :name nil :type nil :defaults pathname)) ((eql :absolute (first dir)) (make-pathname :directory (cons :absolute (last canonical)) :name nil :type nil :defaults pathname)) (t (make-pathname :directory (cons :relative ; leave any :up on relative path (concatenate 'list (leading-ups (rest dir)) (last canonical))) :name nil :type nil :defaults pathname)))))) (defun ensure-file-exists (filespec) "Creates the file designated by FILESPEC, if it does not exist. Returns the pathname of FILESPEC." (with-open-file (stream filespec :direction :output :if-does-not-exist :create :if-exists nil) (declare (ignorable stream))) (pathname filespec)) (defun pathstring (pathname) "Returns a string representing PATHNAME. This function is similar to CL:NAMESTRING, but is designed to be portable whereas the return value of CL:NAMESTRING is implementation-dependent." (labels ((unescape (str) (let ((esc-pos (search "\\." str ))) (if esc-pos (cons (subseq str 0 esc-pos) (unescape (subseq str (1+ esc-pos)))) (list str))))) #+:ccl (apply #'concatenate 'string (unescape (namestring pathname))) #-:ccl (namestring pathname))) (defun merge-pathstrings (pathname &optional (default-pathname *default-pathname-defaults*) (default-version :newest)) "Merges PATHNAME with defaults, using CL:MERGE-PATHNAMES, and calls {defun pathstring} on the result." (pathstring (merge-pathnames (pathname pathname) default-pathname default-version))) (defun tmp-pathname (&key (tmpdir *default-tmpdir*) (basename "") type) "Returns a pathname suitable for use as a temporary file or directory. The directory component of the new pathname is TMPDIR, defaulting to *DEFAULT-TMPDIR*. The NAME component of the new pathname is a concatenation of BASENAME, defaulting to an empty string, and a pseudo-random number. The type component of the new pathname is TYPE, defaulting to NIL." (check-arguments (cl-fad:directory-exists-p tmpdir) (tmpdir) "temporary file directory does not exist") (merge-pathnames (fad:pathname-as-directory tmpdir) (make-pathname :directory '(:relative) :name (format nil "~a~a" basename (random most-positive-fixnum)) :type type))) (defun make-tmp-directory (&key (tmpdir *default-tmpdir*) (basename "") (if-exists :error) mode) "Creates a new temporary directory and returns its pathname. The new directory's pathname is created using {defun tmp-pathname} . The IF-EXISTS keyword argument determines what happens if a directory by that name already exists; options are :error which causes a FILE-ERROR to be raised, :supersede which causes the existing directory to be deleted and a new, empty one created and NIL where no directory is created an NIL is returned to indicate failure." (declare (ignorable mode)) (let ((pathname (tmp-pathname :tmpdir tmpdir :basename basename))) (ecase if-exists (:error (if (fad:directory-exists-p pathname) (error 'file-error :pathname pathname))) (:supersede (if (fad:directory-exists-p pathname) (fad:delete-directory-and-files pathname))) ((nil) nil)) ;; :mode is a non-ANSI extension to ensure-directories-exist in SBCL (ensure-directories-exist (fad:pathname-as-directory pathname)))) (defun pathname-generator (directory name &key type separator generator) "Returns a function of zero arity that generates pathnames when called. The generated pathnames are relative to DIRECTORY and have a namestring composed of NAME, SEPARATOR (defaults to NIL) and a value taken from calling the function GENERATOR (defaults to a numeric generator starting from 0, incrementing by 1). TYPE may be used to specify the type of the new pathnames." (let ((gen (or generator (number-generator)))) (flet ((gen-pname (d n s g y) (merge-pathnames (fad:pathname-as-directory d) (make-pathname :directory '(:relative) :name (format nil "~a~@[~a~]~a" n s (next g)) :type y)))) (let ((current nil)) (defgenerator (more t) (next (let ((pname (gen-pname directory name separator gen type))) (prog1 pname (setf current pname)))) (current current)))))) (defun pathname-extender (pathname &key type separator generator) "Returns a function of zero arity that returns modified copies of a pathname argument. The pathname is modified by extending its namestring. The new namestring is composed of the original namestring SEPARATOR (defaults to NIL) and a value taken from calling the function GENERATOR (defaults to a numeric generator starting from 0, incrementing by 1). TYPE may be used to specify the type of the new pathname, otherwise the original type will be used." (let ((gen (or generator (number-generator)))) (lambda () (make-pathname :directory (pathname-directory pathname) :name (format nil "~a~@[~a~]~a" (pathname-name pathname) separator (next gen)) :type (or type (pathname-type pathname))))))
11,006
Common Lisp
.lisp
230
40.117391
78
0.666574
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
4e14eb6b828a63c8720bc7178c94f95f0ac7f03754c18fad07e08a426adc0f2c
21,136
[ -1 ]
21,137
deoxybyte-io.asd
keithj_deoxybyte-io/deoxybyte-io.asd
;;; ;;; Copyright (c) 2007-2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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) (asdf:load-system :deoxybyte-systems) (in-package :uk.co.deoxybyte-systems) (defsystem deoxybyte-io :name "deoxybyte-io" :version "0.15.0" :author "Keith James" :licence "GPL v3" :in-order-to ((test-op (load-op :deoxybyte-io :deoxybyte-io-test)) (doc-op (load-op :deoxybyte-io :cldoc))) :depends-on ((:version :deoxybyte-systems "1.0.0") (:version :cl-fad "0.6.2") (:version :deoxybyte-utilities "0.11.0") (:version :getopt "1.0")) :components ((:module :core :serial t :pathname "src/" :components ((:file "package") (:file "conditions") (:file "deoxybyte-io") (:file "environment") (:file "parse-float") (:file "ieee-float") (:file "binary-operations") (:file "streams") (:file "line-stream") (:file "command-line-interface") (:file "files-and-directories") (:file "simple-table-parser") (:file "external-merge-sort") (:file "external-line-sort") #+:ccl (:file "ccl") #+:sbcl (:file "sbcl") #-(or :ccl :sbcl) (:file "default")))) :perform (test-op :after (op c) (maybe-run-lift-tests :deoxybyte-io "deoxybyte-io-test.config")) :perform (doc-op :after (op c) (maybe-build-cldoc-docs :deoxybyte-io "doc/html")))
2,588
Common Lisp
.asd
58
31.913793
73
0.525337
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
4beb392d62d1b1b9a262af951d868acc41d38ef317a3c8bdb7983c81055c322c
21,137
[ -1 ]
21,138
deoxybyte-io-test.asd
keithj_deoxybyte-io/deoxybyte-io-test.asd
;;; ;;; Copyright (c) 2007-2013 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-io. ;;; ;;; 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/>. ;;; (defsystem deoxybyte-io-test :depends-on ((:version :lift "1.7.0") :deoxybyte-io) :components ((:module :deoxybyte-io-test :serial t :pathname "test/" :components ((:file "package") (:file "deoxybyte-io-test") (:file "pathnames-test") (:file "binary-operations-test") (:file "command-line-interface-test")))))
1,325
Common Lisp
.asd
29
36.413793
78
0.598456
keithj/deoxybyte-io
2
0
2
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
6b581c481539ef299a37cfe7ff86da3029da75986a38137b442ed913eed8a901
21,138
[ -1 ]
21,177
problem26.lisp
OlegTheCat_project-euler/problem26.lisp
(defun period-starts-from (n) (let ((twos (factorize-by n 2)) (fives (factorize-by n 5))) (values (1+ (max twos fives)) (/ (/ n (expt 2 twos)) (expt 5 fives))))) (defun factorize-by (n factor &key (initial-value 0)) (if (= 0 (mod n factor)) (factorize-by (/ n factor) factor :initial-value (1+ initial-value)) (values initial-value n))) (defun period-length (n) (multiple-value-bind (pos val) (period-starts-from n) (if (= val 1) 0 (do ((j 9 (+ 9 (* j 10)))) ((= 0 (mod j val)) (length (explode j))))))) (defun problem26 () (let ((alist (loop for i from 1 to 999 collect (cons i (period-length i))))) (car (rassoc (reduce #'max (mapcar #'cdr alist)) alist))))
695
Common Lisp
.lisp
19
33.736842
78
0.618128
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
8177402a98b0510c09349a2c563cf7ec8a4aa9ba75d152e092e35cea694ace26
21,177
[ -1 ]
21,178
problem33.lisp
OlegTheCat_project-euler/problem33.lisp
(defun problem33 () (let* ((fractions (loop for i from 10 to 99 nconc (loop for j from 10 to 99 if (< (/ i j) 1) collect (list i j)))) (non-trivial (filter #'(lambda (f) (let* ((expanded-fraction (mapcar #'explode f)) (common-numbers (apply #'intersection expanded-fraction))) (when (and (single common-numbers) (is-non-trivial-p expanded-fraction)) (let* ((cancelled-fraction (cancel-fraction expanded-fraction common-numbers))) (unless (some #'null cancelled-fraction) (let ((simplified-cancelled-fraction (simplify-fraction cancelled-fraction)) (simplified-fraction (simplify-fraction f))) (when (equal simplified-cancelled-fraction simplified-fraction) simplified-fraction))))))) fractions))) (simplify-fraction (reduce #'(lambda (x acc) (list (* (first x) (first acc)) (* (second x) (second acc)))) non-trivial :initial-value '(1 1))))) (defun cancel-fraction (expanded-fraction common-numbers) (mapcar #'stick-num (mapcar #'(lambda (x) (set-exclusive-or x common-numbers)) expanded-fraction))) (defun simplify-fraction (fraction) (let ((fraction-gcd (apply #'gcd fraction))) (mapcar #'(lambda (x) (/ x fraction-gcd)) fraction))) (defun is-non-trivial-p (expanded-fraction) (notevery #'zerop (mapcar #'second expanded-fraction)))
1,847
Common Lisp
.lisp
27
44.740741
118
0.490369
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0bf787fad21f0c7ef2373f270766c5c9502fc2541ac99379d40c70bc35d9b657
21,178
[ -1 ]
21,179
problem17.lisp
OlegTheCat_project-euler/problem17.lisp
(defparameter repr '((1 . "one") (2 . "two") (3 . "three") (4 . "four") (5 . "five") (6 . "six") (7 . "seven") (8 . "eight") (9 . "nine") (10 . "ten") (11 . "eleven") (12 . "twelve") (13 . "thirteen") (14 . "fourteen") (15 . "fifteen") (16 . "sixteen") (17 . "seventeen") (18 . "eighteen") (19 . "nineteen") (20 . "twenty") (30 . "thirty") (40 . "forty") (50 . "fifty") (60 . "sixty") (70 . "seventy") (80 . "eighty") (90 . "ninety"))) (defun num-to-word (num-lst) (and num-lst (case (length num-lst) (1 (transform-digit num-lst)) (2 (transform-decade num-lst)) (3 (transform-hundred num-lst)) (4 (list "one" "thousand"))))) (defun transform-hundred (num-lst) (cons (car (transform-digit (list (car num-lst)))) (cons "hundred" (aand (transform-decade (cdr num-lst)) (cons "and" it))))) (defun transform-decade (num-lst) (case (car num-lst) (0 (transform-digit (cdr num-lst))) (1 (list (cdr-assoc (stick-num num-lst) repr))) (otherwise (cons (cdr-assoc (* 10 (car num-lst)) repr) (transform-digit (cdr num-lst)))))) (defun transform-digit (num-lst) (and (not (= (car num-lst) 0)) (list (cdr-assoc (car num-lst) repr)))) (defun problem17 () (length (apply #'concatenate 'string (loop for i from 1 to 1000 append (num-to-word (explode i))))))
1,316
Common Lisp
.lisp
52
22.846154
102
0.597774
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
4d11266e0b0904862e81d704aedd639c4bed339244dbfd9382ba540cd7b958cf
21,179
[ -1 ]
21,180
problem8.lisp
OlegTheCat_project-euler/problem8.lisp
(defun problem8() (funcall (alambda (lst) (if (null (fifth lst)) 0 (max (apply #'* (subseq lst 0 5)) (self (cdr lst))))) (explode 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450)))
1,147
Common Lisp
.lisp
4
282.5
1,009
0.945757
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9554e089f7142f13ba305692bac81fff9bb687c6dab79dac28cd92e8c59e81d0
21,180
[ -1 ]
21,181
problem12.lisp
OlegTheCat_project-euler/problem12.lisp
(defun problem12() (loop for i from 2 by 1 for num = (* (/ (+ 1 i) 2) i) do (when (> (length (divisors-of num)) 500) (return-from problem12 num))))
156
Common Lisp
.lisp
4
36
58
0.592105
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
95e3d15ce8ecd19e1c43cd8c7555dec9877699f91b05690dc35e91275570e345
21,181
[ -1 ]
21,182
problem2.lisp
OlegTheCat_project-euler/problem2.lisp
(defun sum-of-even-fibos (below &optional (start-from 1)) (let ((num (fibo start-from))) (if (< num below) (+ (if (evenp num) num 0) (sum-of-even-fibos below (1+ start-from))) 0))) (defun problem2() (sum-of-even-fibos 4000000))
261
Common Lisp
.lisp
7
31.571429
79
0.588933
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
05998a05cec12e283195c28f0ff240d3a4bba1132f1ec5ab5d40ad2aea4ccdc0
21,182
[ -1 ]
21,183
problem37.lisp
OlegTheCat_project-euler/problem37.lisp
(defun problem37 () (let ((truncatable-primes nil)) (loop for i from 1 while (< (length truncatable-primes) 11) if (is-truncatable-p i) do (push i truncatable-primes)) (reduce #'+ truncatable-primes))) (defun is-truncatable-p (num) (and (prime-p num) (let ((nums (explode num))) (and (cdr nums) ;; len 2 or more (every #'prime-p (maplist #'(lambda (x) (stick-num x)) (cdr nums))) (every #'prime-p (mapbutlast #'(lambda (x) (stick-num x)) (butlast nums)))))))
526
Common Lisp
.lisp
11
40.727273
92
0.59144
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f4a3fd5fe219073ed61eb12bbac3e7dd91ba9876c96d55e8e1e8bed1fe815475
21,183
[ -1 ]
21,184
problem4.lisp
OlegTheCat_project-euler/problem4.lisp
(defun problem4 () (apply #'max (mapcar #'stick-num (remove-if-not #'palindrome-p (mapcar #'explode (loop for i from 999 downto 100 append (loop for j from 999 downto 100 collect (* i j))))))))
256
Common Lisp
.lisp
5
37.8
76
0.52988
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f11638f5834f8d77330ddecdad133fde4741aec99b705692b0cb3df9826f9e3e
21,184
[ -1 ]
21,185
problem35.lisp
OlegTheCat_project-euler/problem35.lisp
(defun rotations (lst) (labels ((%rotate (lst) (append1 (cdr lst) (car lst))) (%perform (lst number) (if (zerop number) nil (cons lst (%perform (%rotate lst) (1- number)))))) (%perform lst (length lst)))) (defun circular-prime-p (prime) (let ((digits (explode prime))) (every #'prime-p (mapcar #'stick-num (rotations digits))))) (defun problem35 () (let ((primes (primes-below 1000000))) (count-if #'circular-prime-p primes)))
527
Common Lisp
.lisp
13
31.846154
73
0.558824
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
b7031c5c009563d81c42cf722b0a33ccc8f780957cdbdeb63531cfc84a2c0560
21,185
[ -1 ]
21,186
problem29.lisp
OlegTheCat_project-euler/problem29.lisp
(defun problem29 () (let ((combs (loop for i from 2 to 100 nconc (loop for j from 2 to 100 collect (expt i j))))) (length (remove-duplicates combs))))
205
Common Lisp
.lisp
5
29.2
54
0.515
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
447ca498f2d91130c0cdcdb6648b5ecb0dea182f514ea5a048db2e39f07b22c1
21,186
[ -1 ]
21,187
problem15.lisp
OlegTheCat_project-euler/problem15.lisp
(defun problem15() (do ((lst '(0) (let ((new (reduce #'(lambda (x y) (cons (+ (car x) y) x)) (reverse (butlast lst)) :initial-value '(1)))) (cons (* 2 (car new)) new)))) ((> (length lst) 20) (car lst))))
223
Common Lisp
.lisp
5
39.8
94
0.509174
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
fb74ee4ad9bc085309642482d006c3b5357f4e3b4929e960fbfa37fb6b5e4555
21,187
[ -1 ]
21,188
problem36.lisp
OlegTheCat_project-euler/problem36.lisp
(defun double-base-palindrome-p (num) (let ((numbers (explode num)) (bits (bits num))) (and (palindrome-p numbers) (palindrome-p bits)))) (defun problem36 () (loop for i from 0 to 999999 if (double-base-palindrome-p i) sum i))
261
Common Lisp
.lisp
8
27.375
66
0.630952
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9486130504dc9fe2fb43fb981f932c5297924dc31782fcff39a143c14c1ee951
21,188
[ -1 ]
21,189
utils.lisp
OlegTheCat_project-euler/utils.lisp
(defun memoize (fn) (let ((cache (make-hash-table :test #'equal))) #'(lambda (&rest args) (multiple-value-bind (result exists) (gethash args cache) (if exists result (setf (gethash args cache) (apply fn args))))))) (defun map0-n (fn n) (mapa-b fn 0 n)) (defun map1-n (fn n) (mapa-b fn 1 n)) (defun mapa-b (fn a b &optional (step 1)) (do ((i a (+ i step)) (result nil)) ((> i b) (nreverse result)) (push (funcall fn i) result))) (defmacro aif (test-form then-form &optional else-form) `(let ((it ,test-form)) (if it ,then-form ,else-form))) (defmacro aand (&rest args) (cond ((null args) t) ((null (cdr args)) (car args)) (t `(aif ,(car args) (aand ,@(cdr args)))))) (defmacro alambda (parms &body body) `(labels ((self ,parms ,@body)) #'self)) (defmacro awhen (test-form &body body) `(aif ,test-form (progn ,@body))) (defmacro awhile (expr &body body) `(do ((it ,expr ,expr)) ((not it)) ,@body)) (defmacro when-bind ((var expr) &body body) `(let ((,var ,expr)) (when ,var ,@body))) (defmacro acond (&rest clauses) (if (null clauses) nil (let ((cl1 (car clauses)) (sym (gensym))) `(let ((,sym ,(car cl1))) (if ,sym (let ((it ,sym)) ,@(cdr cl1)) (acond ,@(cdr clauses))))))) (defmacro when-bind* (binds &body body) (if (null binds) `(progn ,@body) `(let (,(car binds)) (if ,(caar binds) (when-bind* ,(cdr binds) ,@body))))) (defmacro with-gensyms (syms &body body) `(let ,(mapcar #'(lambda (s) `(,s (gensym))) syms) ,@body)) #|(defmacro do-tuples/o (parms source &body body) (if parms (let ((src (gensym))) `(prog ((,src ,source)) (mapc #'(lambda ,parms ,@body) ,@(map0-n #'(lambda (n) `(nthcdr ,n ,src)) (1- (length parms)))))))) (defmacro do-tuples/c (parms source &body body) (if parms (with-gensyms (src rest bodfn) (let ((len (length parms))) `(let ((,src ,source)) (when (nthcdr ,(1- len) ,src) (labels ((,bodfn ,parms ,@body)) (do ((,rest ,src (cdr ,rest))) ((not (nthcdr ,(1- len) ,rest)) ,@(mapcar #'(lambda (args) `(,bodfn ,@args)) (dt-args len rest src)) nil) (,bodfn ,@(map1-n #'(lambda (n) `(nth ,(1- n) ,rest)) len)))))))))) (defun dt-args (len rest src) (map0-n #'(lambda (m) (map1-n #'(lambda (n) (let ((x (+ m n))) (if (>= x len) `(nth ,(- x len) ,src) `(nth ,(1- x) ,rest)))) len)) (- len 2))) |# (defun mkstr (&rest args) (with-output-to-string (s) (dolist (a args) (princ a s)))) (defun symb (&rest args) (values (intern (apply #'mkstr args)))) (defun mappend (fn &rest lsts) (apply #'append (apply #'mapcar fn lsts))) (defun mapcars (fn &rest lsts) (let ((result nil)) (dolist (lst lsts) (dolist (obj lst) (push (funcall fn obj) result))) (nreverse result))) (defun rmapcar (fn &rest args) (if (some #'atom args) (apply fn args) (apply #'mapcar #'(lambda (&rest args) (apply #'rmapcar fn args)) args))) (proclaim '(inline last1 single append1 conc1 mklist)) (defun last1 (lst) (car (last lst))) (defun single (lst) (and (consp lst) (not (cdr lst)))) (defun append1 (lst obj) (append lst (list obj))) (defun conc1 (lst obj) (nconc lst (list obj))) (defun mklist (obj) (if (listp obj) obj (list obj))) (defun longer (x y) (labels ((compare (x y) (and (consp x) (or (null y) (compare (cdr x) (cdr y)))))) (if (and (listp x) (listp y)) (compare x y) (> (length x) (length y))))) (defun filter (fn lst) (let ((acc nil)) (dolist (x lst) (let ((val (funcall fn x))) (if val (push val acc)))) (nreverse acc))) (defun group (source n) (when (zerop n) (error "zero length")) (labels ((rec (source acc) (let ((rest (nthcdr n source))) (if (consp rest) (rec rest (cons (subseq source 0 n) acc)) (nreverse (cons source acc)))))) (if source (rec source nil) nil))) (defgeneric explode (x)) (defmethod explode ((x string)) (coerce x 'list)) (defmethod explode ((x number)) (and (>= x 1) (append1 (explode (floor (/ x 10))) (mod x 10)))) (defmethod explode ((x symbol)) (map 'list #'(lambda (c) (intern (make-string 1 :initial-element c))) (symbol-name x))) (defun mapbutlast (fun lst) (loop for i from 0 below (length lst) collect (funcall fun (butlast lst i)))) (defun bits (num) (if (< num 2) (list num) (append1 (bits (truncate num 2)) (mod num 2)))) (defun stick-num (lst &key (error nil)) (multiple-value-bind (i n) (parse-integer (apply #'mkstr lst) :junk-allowed (not error)) (declare (ignore n)) i)) (defun cdr-assoc (key alist) (cdr (assoc key alist))) (defun palindrome-p (lst &key (test #'=)) (or (null (cdr lst)) (and (funcall test (car lst) (last1 lst)) (palindrome-p (butlast (cdr lst)))))) (defun make-num-lst (a b &optional (step 1)) (mapa-b #'identity a b step)) (defun fibo (n &key (initial-values '(1 . 2))) (case n (1 (car initial-values)) (2 (cdr initial-values)) (otherwise (+ (fibo (1- n)) (fibo (- n 2)))))) (setf (fdefinition 'fibo) (memoize #'fibo)) (defun find-divisor (n &optional (start-from 2) (inc #'1+) (cond-fun #'(lambda (n s) (<= (* s s) n)))) (and (funcall cond-fun n start-from) (if (= 0 (mod n start-from)) start-from (find-divisor n (funcall inc start-from) inc cond-fun)))) (defun prime-p (n) (and (> n 1) (not (find-divisor n)))) (defun nth-prime(n &optional (start-from 2)) (if (< n 1) (1- start-from) (if (prime-p start-from) (nth-prime (1- n) (1+ start-from)) (nth-prime n (1+ start-from))))) (defun primes-below (n &optional (start-from 2) (lst nil)) (if (< start-from n) (if (prime-p start-from) (primes-below n (1+ start-from) (cons start-from lst)) (primes-below n (1+ start-from) lst)) (reverse lst))) (defun next-prime (start-from) (if (prime-p start-from) start-from (next-prime (1+ start-from)))) (defun sieve (lst) (and lst (cons (car lst) (sieve (delete-if #'(lambda (x) (= 0 (mod x (car lst)))) lst))))) ;Destructive (defun add-factor (factor alst) (aif (assoc factor alst) (progn (rplacd it (1+ (cdr it))) alst) (acons factor 1 alst))) (defun factorial (n) (reduce #'* (make-num-lst 2 n))) (defun factorize (n &optional (lst nil) (start-from 2)) (if (prime-p n) (add-factor n lst) (if (= 0 (mod n start-from)) (factorize (/ n start-from) (add-factor start-from lst) start-from) (factorize n lst (next-prime (1+ start-from)))))) (defun proper-divisors-of (n) (cons 1 (sort (loop for i from 2 to (sqrt n) if (= 0 (mod n i)) append (if (= (* i i) n) (list i) (list i (/ n i)))) #'<))) (defun divisors-of (n) (append1 (proper-divisors-of n) n)) (defun cumsum (lst) (let* ((res nil) (sum (reduce #'(lambda (acc el) (push acc res) (+ el acc)) lst))) (reverse (cons sum res)))) (defun k-sublists (set k) (cond ((minusp k) '()) ((zerop k) (list '())) ((= k 1) (mapcar #'list set)) (t (loop for elems on set nconc (mapcar #'(lambda (set) (cons (car elems) set)) (k-sublists (cdr elems) (- k 1))))))) (defun permutations (l) (if (null l) (list nil) (mapcan #'(lambda (x) (mapcar #'(lambda (y) (cons x y)) (permutations (remove x l :count 1)))) l)))
7,782
Common Lisp
.lisp
243
26.567901
124
0.558765
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
85282a1b9f25bd614e4edea7400179210a731eda70d73412f4a99ad7315e1776
21,189
[ -1 ]
21,190
problem67.lisp
OlegTheCat_project-euler/problem67.lisp
(defun problem67 () (with-open-file (stream "data/problem67.txt" :if-does-not-exist nil) (car (max-path (read-triangle stream)))))
134
Common Lisp
.lisp
3
42.666667
70
0.709924
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
3d6950428ddc02fdef1feb342e5269b8986173b7588e3f53f09028acd97eb4fa
21,190
[ -1 ]
21,191
problem9.lisp
OlegTheCat_project-euler/problem9.lisp
(defun triplet-p (a b c) (and (< a b) (< b c) (= (+ (* a a) (* b b)) (* c c)))) (defun problem9() (loop for i from 1 to 1000 do (loop for j from (1+ i) to 1000 for k = (- 1000 i j) do (and (triplet-p i j k) (return-from problem9 (* i j k))))))
281
Common Lisp
.lisp
6
39.666667
80
0.47619
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
93a9eed12167322c114bc11a195e8673859d746f42ad3cb9a8bd0db7b84d83a5
21,191
[ -1 ]
21,192
problem28.lisp
OlegTheCat_project-euler/problem28.lisp
(defun duplicate-elems (lst times) (mapcan #'(lambda (el) (loop for i from 1 to times collect el)) lst)) (defun problem28 () (let* ((size 1001) (steps (make-num-lst 2 size 2)) (all-steps (cons 1 (duplicate-elems steps 4))) (diagonal-els (cumsum all-steps))) (reduce #'+ diagonal-els)))
311
Common Lisp
.lisp
10
27.6
49
0.646667
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
c9812d2e35af9c282f47048e863f50ff9f7ac1a50d6d61fbf9e2ff033254d629
21,192
[ -1 ]
21,193
problem24.lisp
OlegTheCat_project-euler/problem24.lisp
(defun all-permutations-of (lst) (if lst (let ((perms (all-permutations-of (cdr lst)))) (append (mapcar #'(lambda (x) (cons (car lst) x)) perms) (mapcan #'(lambda (x) (loop for i from 1 to (length x) collect (insert-before x (car lst) i))) perms))) (list nil))) (defun insert-before (lst elem pos) (if (= pos 0) (cons elem lst) (cons (car lst) (insert-before (cdr lst) elem (1- pos))))) (defun problem24 () (nth 999999 (mapcar #'stick-num (p (make-num-lst 0 9)))))
507
Common Lisp
.lisp
17
26.352941
78
0.614754
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
109df128c0b2eda0fc309618541d06d2e60323f23a66f8caba96feaac5038eed
21,193
[ -1 ]
21,194
problem30.lisp
OlegTheCat_project-euler/problem30.lisp
(defun problem30 () (let ((nums (make-num-lst 1 9999999))) (reduce #'+ (delete-if-not #'(lambda (num) (let ((digits (explode num))) (and (cdr digits) ;; 2 or more (= num (reduce #'+ (mapcar #'(lambda (d) (expt d 5)) digits)))))) nums))))
627
Common Lisp
.lisp
11
20.636364
76
0.228896
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
1fbd094db5f3c365af27a45ce8d9f18edf7cb2559834e68bbe4814701dc643c1
21,194
[ -1 ]
21,195
problem3.lisp
OlegTheCat_project-euler/problem3.lisp
(defun largest-prime-factor (n largest) (aif (find-divisor n (1- largest) #'1- #'(lambda (n s) (> s 1))) (if (prime-p it) it (largest-prime-factor n it)))) (defun problem3() (largest-prime-factor 600851475143 (floor (sqrt 600851475143))))
276
Common Lisp
.lisp
7
33.142857
66
0.604478
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
8d7149260c52fd065730acbd97699b5490ae0fb8d87b44f740c86130d940568c
21,195
[ -1 ]
21,196
problem19.lisp
OlegTheCat_project-euler/problem19.lisp
(defun problem19 () (loop for year from 1901 to 2000 sum (loop for month from 1 to 12 sum (multiple-value-bind (second minute hour date month year day-of-week dst-p tz) (decode-universal-time (encode-universal-time 0 0 0 1 month year)) (if (= day-of-week 6) 1 0)))))
290
Common Lisp
.lisp
7
37.142857
70
0.678445
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
609f0f35d5c28f94c4910c584cbf388d5db7152ab8145e20d01e8efdbeacce39
21,196
[ -1 ]
21,197
problem6.lisp
OlegTheCat_project-euler/problem6.lisp
(defun problem6 () (let ((lst (make-num-lst 1 100))) (- (expt (apply #'+ lst) 2) (apply #'+ (mapcar #'(lambda (x) (* x x)) lst)))))
149
Common Lisp
.lisp
3
43
85
0.5
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a53d0346f9a2b50f08eaed69c49326fe4459973b92a2654cd79b281a0aa28841
21,197
[ -1 ]
21,198
problem13.lisp
OlegTheCat_project-euler/problem13.lisp
(defun problem13 () (with-open-file (stream "data/problem13.txt" :if-does-not-exist nil) (stick-num (subseq (explode (funcall (alambda (stream) (aif (read-line stream nil nil) (+ (parse-integer it) (self stream)) 0)) stream)) 0 10))))
302
Common Lisp
.lisp
7
32.571429
70
0.552542
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
ec3a8d875724c5c7acc277e766aa28fbb4596439f593e0f123e5036f6e5c74a0
21,198
[ -1 ]
21,199
problem27.lisp
OlegTheCat_project-euler/problem27.lisp
(defun gen-formula (a b) #'(lambda (n) (+ (* n n) (* a n) b))) (defun problem27 () (labels ((%gen-coeficients (max-abs-a max-abs-b) (loop for i from (- max-abs-a) to max-abs-a append (loop for j from (- max-abs-b) to max-abs-b collect (list i j))))) (do ((i 0 (1+ i)) ;; Not do* (coefs (%gen-coeficients 999 999) (delete-if-not #'(lambda (coef-pair) (prime-p (funcall (gen-formula (first coef-pair) (second coef-pair)) i))) coefs))) ((single coefs) (reduce #'* (car coefs))))))
603
Common Lisp
.lisp
14
33.142857
77
0.5
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f5b0daf17bad132c7810917055852116366640ba2582d6cc07b62770342be967
21,199
[ -1 ]
21,200
problem32.lisp
OlegTheCat_project-euler/problem32.lisp
(defun problem32 () (let ((products (loop for i from 1 to 2000 nconc (loop for j from 1 to 2000 for prod = (* i j) if (pandigital-p (nconc (explode i) (explode j) (explode prod))) collect prod)))) (reduce #'+ (remove-duplicates products)))) (defun pandigital-p (nums &key (range '(1 . 9))) (and (= (length nums) (cdr range)) (equal (sort (copy-list nums) #'<) (make-num-lst (car range) (cdr range)))))
549
Common Lisp
.lisp
11
35.545455
94
0.486034
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d568eba8069f05db42e966e8f2f38835fc19b97cbe8f8851811dbce0edcc4b7b
21,200
[ -1 ]
21,201
problem1.lisp
OlegTheCat_project-euler/problem1.lisp
(defun get-sum-of-3-or-5 (num-below &optional (sum 0)) (if (< num-below 1) sum (get-sum-of-3-or-5 (1- num-below ) (if (or (= (mod num-below 3) 0) (= (mod num-below 5) 0)) (+ sum num-below) sum)))) (defun problem1 () (get-sum-of-3-or-5 999))
259
Common Lisp
.lisp
6
39.166667
123
0.573705
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
14ddbbff9e63d9a6d5a67c04ee2b452fc86fc315989ed3bfabfba75408014fed
21,201
[ -1 ]
21,202
problem18.lisp
OlegTheCat_project-euler/problem18.lisp
(defun read-triangle (stream) (aand (read-line stream nil nil) (cons (mapcar #'parse-integer (cl-utilities:split-sequence #\Space it)) (read-triangle stream)))) ;; Slow algorithm that works by tree traversing #|(defun triangle2tree (triangle &optional (fmake-node #'(lambda (val &optional list-of-nodes) (and val (cons val list-of-nodes))))) (if (cdr triangle) (maplist #'(lambda (x y) (funcall fmake-node (car x) (subseq y 0 2))) (car triangle) (triangle2tree (cdr triangle))) (mapcar fmake-node (car triangle)))) (defun max-path (tree) (if (cdr tree) (+ (car tree) (apply #'max (mapcar #'max-path (cdr tree)))) (car tree)))|# (defun max-of-pairs (lst) (and (cdr lst) (cons (max (car lst) (cadr lst)) (max-of-pairs (cdr lst))))) (defun max-path (triangle) (if (cdr triangle) (mapcar #'+ (car triangle) (max-of-pairs (max-path (cdr triangle)))) (car triangle))) (defun problem18 () (with-open-file (stream "data/problem18.txt" :if-does-not-exist nil) (car (max-path (read-triangle stream)))))
1,055
Common Lisp
.lisp
24
40.375
117
0.66439
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
1cbeeb7967d74f01d257d4bedd7c64af88f3c86dcc94a3bfbea3b6c032657d8c
21,202
[ -1 ]
21,203
problem22.lisp
OlegTheCat_project-euler/problem22.lisp
(defun read-names (stream) (cl-utilities:split-sequence #\, (remove-if #'(lambda (x) (char= x #\")) (read-line stream nil nil)))) (defun problem22 () (with-open-file (stream "data/problem22.txt") (reduce #'+ (names-to-scores (read-names stream))))) (defun alphabet-pos-of (ch) (- (char-int (char-upcase ch)) 64)) (defun names-to-scores (names) (let ((i 0)) (mapcar #'(lambda (x) (incf i) (* i (reduce #'+ (mapcar #'alphabet-pos-of (explode x))))) (sort names #'string<))))
496
Common Lisp
.lisp
13
35.384615
103
0.629167
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
15f35733cd43f5f616e2eb4d9316e2d090b673b79debb77f2aeea112e90b63f5
21,203
[ -1 ]
21,204
problem34.lisp
OlegTheCat_project-euler/problem34.lisp
(defun problem34 () (let ((curious-nums (loop for i from 10 to 2903040 if (= i (reduce #'+ (mapcar #'factorial (explode i)))) collect i))) (reduce #'+ curious-nums)))
229
Common Lisp
.lisp
5
32.4
82
0.482143
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
662e40ebe13e1117063ed6a001fe00365f31a20ca15f7cd1833a4c11f8241432
21,204
[ -1 ]
21,205
problem23.lisp
OlegTheCat_project-euler/problem23.lisp
(defun abundants-below-eq (n) (loop for i from 1 to n if (> (sum-proper-divisors-of i) i) collect i)) #|(defun sum-of-abundant-below (n) (let ((abundants (abundant-numbers-below n))) (labels ((odd-abundants (even odd) (loop for i in even append (loop for j in odd for sum = (+ i j) if (not (> sum n)) collect sum))) (even-abundants () (let ((abundants-below-48 '(24 30 32 36 38 40 42 44))) (if (< n 48) (remove-if #'(lambda (x) (> x n)) abundants-below-48) (append abundants-below-48 (loop for i from 48 to n by 2 collect i)))))) (append (odd-abundants (remove-if #'oddp abundants) (remove-if #'evenp abundants)) (even-abundants))))) |# (defun sums-of-two-abundants-below-eq (n) (funcall (alambda (lst) (and lst (union (mapcan #'(lambda (x) (let ((sum (+ (car lst) x))) (and (not (> sum n)) (list sum)))) lst) (self (cdr lst))))) (abundants-below-eq n))) (defun problem23 () (- (reduce #'+ (make-num-lst 1 20161)) (reduce #'+ (sums-of-two-abundants-below-eq 20161))))
1,123
Common Lisp
.lisp
27
34.851852
93
0.572869
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
da212c7c4264b9e8b7f36702c5895f71964b7f5b971ceaf44c8b0eefdcddee3e
21,205
[ -1 ]
21,206
problem14.lisp
OlegTheCat_project-euler/problem14.lisp
(defun collatz-seq-next (n) (if (evenp n) (/ n 2) (1+ (* 3 n)))) (defun collatz-seq-length (n) (if (> n 1) (+ 1 (collatz-seq-length (collatz-seq-next n))) 1)) (setf (fdefinition 'collatz-seq-length) (memoize #'collatz-seq-length)) (defun problem14 () (let ((alst (loop for i from 1 to 1000000 collect (cons i (collatz-seq-length i))))) (car (rassoc (apply #'max (mapcar #'cdr alst)) alst))))
406
Common Lisp
.lisp
12
31.666667
86
0.644501
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e5eab10a218dc55726816b28d9b9d5d447efade72e68f92c0b099fa42ca43139
21,206
[ -1 ]
21,207
problem31.lisp
OlegTheCat_project-euler/problem31.lisp
(defun problem31 () (count-coins 200 '(1 2 5 10 20 50 100 200))) (defun count-coins (money coins) (cond ((= money 0) 1) ((or (< money 0) (null coins)) 0) (t (+ (count-coins (- money (car coins)) coins) (count-coins money (cdr coins))))))
255
Common Lisp
.lisp
7
33
87
0.59919
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a15b4e15a7327abd6d4551ae10182477af3d64b3455a7c09a532bf449983e75d
21,207
[ -1 ]
21,208
problem25.lisp
OlegTheCat_project-euler/problem25.lisp
(defun problem25 () (do ((i 1 (1+ i))) ((= 1000 (length (explode (fibo i :initial-values '(1 . 1))))) i)))
110
Common Lisp
.lisp
3
34.666667
68
0.542056
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
169fb36dc6a34a31c325e86bc5042e5dccfa3fc2a2eac8a6f51ff0923cdeff7c
21,208
[ -1 ]
21,209
problem21.lisp
OlegTheCat_project-euler/problem21.lisp
(defun dotted-pair-equal-p (x y) (or (and (= (car x) (car y)) (= (cdr x) (cdr y))) (and (= (cdr x) (car y)) (= (car x) (cdr y))))) (defun sum-proper-divisors-of (n) (reduce #'+ (proper-divisors-of n))) (defun amicable-pair-of (n) (let ((new (sum-proper-divisors-of n))) (and (not (= n new)) (= (sum-proper-divisors-of new) n) (cons n new)))) (defun amicable-pairs-below (below) (do ((i 1 (1+ i)) (result nil)) ((> i below) result) (awhen (amicable-pair-of i) (pushnew it result :test #'dotted-pair-equal-p)))) (defun problem21 () (reduce #'+ (mapcar #'(lambda (x) (+ (car x) (cdr x))) (amicable-pairs-below 10000))))
667
Common Lisp
.lisp
23
25.826087
88
0.58216
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e954b3d46d9464e7c515a3d92b904d0a55bbd39817994fc798860794916920ab
21,209
[ -1 ]
21,210
project-euler.asd
OlegTheCat_project-euler/project-euler.asd
(in-package :asdf) (defsystem "project-euler" :description "Project's Euler problems solutions in LISP" :version "0.0.1" :author "OlegTheCat" :licence "Public Domain" :components ((:file "utils") (:file "problem1" :depends-on ("utils")) (:file "problem2" :depends-on ("utils")) (:file "problem3" :depends-on ("utils")) (:file "problem4" :depends-on ("utils")) (:file "problem5" :depends-on ("utils")) (:file "problem6" :depends-on ("utils")) (:file "problem7" :depends-on ("utils")) (:file "problem8" :depends-on ("utils")) (:file "problem9" :depends-on ("utils")) (:file "problem10" :depends-on ("utils")) (:file "problem12" :depends-on ("utils")) (:file "problem13" :depends-on ("utils")) (:file "problem14" :depends-on ("utils")) (:file "problem15" :depends-on ("utils")) (:file "problem16" :depends-on ("utils")) (:file "problem17" :depends-on ("utils")) (:file "problem18" :depends-on ("utils")) (:file "problem19" :depends-on ("utils")) (:file "problem20" :depends-on ("utils")) (:file "problem21" :depends-on ("utils")) (:file "problem22" :depends-on ("utils")) (:file "problem23" :depends-on ("utils")) (:file "problem24" :depends-on ("utils")) (:file "problem25" :depends-on ("utils")) (:file "problem26" :depends-on ("utils")) (:file "problem27" :depends-on ("utils")) (:file "problem28" :depends-on ("utils")) (:file "problem29" :depends-on ("utils")) (:file "problem30" :depends-on ("utils")) (:file "problem31" :depends-on ("utils")) (:file "problem32" :depends-on ("utils")) (:file "problem33" :depends-on ("utils")) (:file "problem34" :depends-on ("utils")) (:file "problem35" :depends-on ("utils")) (:file "problem36" :depends-on ("utils")) (:file "problem37" :depends-on ("utils")) (:file "problem67" :depends-on ("utils"))) :depends-on ("cl-utilities"))
1,965
Common Lisp
.asd
45
38.377778
58
0.60219
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
4047038a6ce4eabf67fdb057693865556406c4941073da8dac85d1601528e433
21,210
[ -1 ]
21,246
problem67.txt
OlegTheCat_project-euler/data/problem67.txt
59 73 41 52 40 09 26 53 06 34 10 51 87 86 81 61 95 66 57 25 68 90 81 80 38 92 67 73 30 28 51 76 81 18 75 44 84 14 95 87 62 81 17 78 58 21 46 71 58 02 79 62 39 31 09 56 34 35 53 78 31 81 18 90 93 15 78 53 04 21 84 93 32 13 97 11 37 51 45 03 81 79 05 18 78 86 13 30 63 99 95 39 87 96 28 03 38 42 17 82 87 58 07 22 57 06 17 51 17 07 93 09 07 75 97 95 78 87 08 53 67 66 59 60 88 99 94 65 55 77 55 34 27 53 78 28 76 40 41 04 87 16 09 42 75 69 23 97 30 60 10 79 87 12 10 44 26 21 36 32 84 98 60 13 12 36 16 63 31 91 35 70 39 06 05 55 27 38 48 28 22 34 35 62 62 15 14 94 89 86 66 56 68 84 96 21 34 34 34 81 62 40 65 54 62 05 98 03 02 60 38 89 46 37 99 54 34 53 36 14 70 26 02 90 45 13 31 61 83 73 47 36 10 63 96 60 49 41 05 37 42 14 58 84 93 96 17 09 43 05 43 06 59 66 57 87 57 61 28 37 51 84 73 79 15 39 95 88 87 43 39 11 86 77 74 18 54 42 05 79 30 49 99 73 46 37 50 02 45 09 54 52 27 95 27 65 19 45 26 45 71 39 17 78 76 29 52 90 18 99 78 19 35 62 71 19 23 65 93 85 49 33 75 09 02 33 24 47 61 60 55 32 88 57 55 91 54 46 57 07 77 98 52 80 99 24 25 46 78 79 05 92 09 13 55 10 67 26 78 76 82 63 49 51 31 24 68 05 57 07 54 69 21 67 43 17 63 12 24 59 06 08 98 74 66 26 61 60 13 03 09 09 24 30 71 08 88 70 72 70 29 90 11 82 41 34 66 82 67 04 36 60 92 77 91 85 62 49 59 61 30 90 29 94 26 41 89 04 53 22 83 41 09 74 90 48 28 26 37 28 52 77 26 51 32 18 98 79 36 62 13 17 08 19 54 89 29 73 68 42 14 08 16 70 37 37 60 69 70 72 71 09 59 13 60 38 13 57 36 09 30 43 89 30 39 15 02 44 73 05 73 26 63 56 86 12 55 55 85 50 62 99 84 77 28 85 03 21 27 22 19 26 82 69 54 04 13 07 85 14 01 15 70 59 89 95 10 19 04 09 31 92 91 38 92 86 98 75 21 05 64 42 62 84 36 20 73 42 21 23 22 51 51 79 25 45 85 53 03 43 22 75 63 02 49 14 12 89 14 60 78 92 16 44 82 38 30 72 11 46 52 90 27 08 65 78 03 85 41 57 79 39 52 33 48 78 27 56 56 39 13 19 43 86 72 58 95 39 07 04 34 21 98 39 15 39 84 89 69 84 46 37 57 59 35 59 50 26 15 93 42 89 36 27 78 91 24 11 17 41 05 94 07 69 51 96 03 96 47 90 90 45 91 20 50 56 10 32 36 49 04 53 85 92 25 65 52 09 61 30 61 97 66 21 96 92 98 90 06 34 96 60 32 69 68 33 75 84 18 31 71 50 84 63 03 03 19 11 28 42 75 45 45 61 31 61 68 96 34 49 39 05 71 76 59 62 67 06 47 96 99 34 21 32 47 52 07 71 60 42 72 94 56 82 83 84 40 94 87 82 46 01 20 60 14 17 38 26 78 66 81 45 95 18 51 98 81 48 16 53 88 37 52 69 95 72 93 22 34 98 20 54 27 73 61 56 63 60 34 63 93 42 94 83 47 61 27 51 79 79 45 01 44 73 31 70 83 42 88 25 53 51 30 15 65 94 80 44 61 84 12 77 02 62 02 65 94 42 14 94 32 73 09 67 68 29 74 98 10 19 85 48 38 31 85 67 53 93 93 77 47 67 39 72 94 53 18 43 77 40 78 32 29 59 24 06 02 83 50 60 66 32 01 44 30 16 51 15 81 98 15 10 62 86 79 50 62 45 60 70 38 31 85 65 61 64 06 69 84 14 22 56 43 09 48 66 69 83 91 60 40 36 61 92 48 22 99 15 95 64 43 01 16 94 02 99 19 17 69 11 58 97 56 89 31 77 45 67 96 12 73 08 20 36 47 81 44 50 64 68 85 40 81 85 52 09 91 35 92 45 32 84 62 15 19 64 21 66 06 01 52 80 62 59 12 25 88 28 91 50 40 16 22 99 92 79 87 51 21 77 74 77 07 42 38 42 74 83 02 05 46 19 77 66 24 18 05 32 02 84 31 99 92 58 96 72 91 36 62 99 55 29 53 42 12 37 26 58 89 50 66 19 82 75 12 48 24 87 91 85 02 07 03 76 86 99 98 84 93 07 17 33 61 92 20 66 60 24 66 40 30 67 05 37 29 24 96 03 27 70 62 13 04 45 47 59 88 43 20 66 15 46 92 30 04 71 66 78 70 53 99 67 60 38 06 88 04 17 72 10 99 71 07 42 25 54 05 26 64 91 50 45 71 06 30 67 48 69 82 08 56 80 67 18 46 66 63 01 20 08 80 47 07 91 16 03 79 87 18 54 78 49 80 48 77 40 68 23 60 88 58 80 33 57 11 69 55 53 64 02 94 49 60 92 16 35 81 21 82 96 25 24 96 18 02 05 49 03 50 77 06 32 84 27 18 38 68 01 50 04 03 21 42 94 53 24 89 05 92 26 52 36 68 11 85 01 04 42 02 45 15 06 50 04 53 73 25 74 81 88 98 21 67 84 79 97 99 20 95 04 40 46 02 58 87 94 10 02 78 88 52 21 03 88 60 06 53 49 71 20 91 12 65 07 49 21 22 11 41 58 99 36 16 09 48 17 24 52 36 23 15 72 16 84 56 02 99 43 76 81 71 29 39 49 17 64 39 59 84 86 16 17 66 03 09 43 06 64 18 63 29 68 06 23 07 87 14 26 35 17 12 98 41 53 64 78 18 98 27 28 84 80 67 75 62 10 11 76 90 54 10 05 54 41 39 66 43 83 18 37 32 31 52 29 95 47 08 76 35 11 04 53 35 43 34 10 52 57 12 36 20 39 40 55 78 44 07 31 38 26 08 15 56 88 86 01 52 62 10 24 32 05 60 65 53 28 57 99 03 50 03 52 07 73 49 92 66 80 01 46 08 67 25 36 73 93 07 42 25 53 13 96 76 83 87 90 54 89 78 22 78 91 73 51 69 09 79 94 83 53 09 40 69 62 10 79 49 47 03 81 30 71 54 73 33 51 76 59 54 79 37 56 45 84 17 62 21 98 69 41 95 65 24 39 37 62 03 24 48 54 64 46 82 71 78 33 67 09 16 96 68 52 74 79 68 32 21 13 78 96 60 09 69 20 36 73 26 21 44 46 38 17 83 65 98 07 23 52 46 61 97 33 13 60 31 70 15 36 77 31 58 56 93 75 68 21 36 69 53 90 75 25 82 39 50 65 94 29 30 11 33 11 13 96 02 56 47 07 49 02 76 46 73 30 10 20 60 70 14 56 34 26 37 39 48 24 55 76 84 91 39 86 95 61 50 14 53 93 64 67 37 31 10 84 42 70 48 20 10 72 60 61 84 79 69 65 99 73 89 25 85 48 92 56 97 16 03 14 80 27 22 30 44 27 67 75 79 32 51 54 81 29 65 14 19 04 13 82 04 91 43 40 12 52 29 99 07 76 60 25 01 07 61 71 37 92 40 47 99 66 57 01 43 44 22 40 53 53 09 69 26 81 07 49 80 56 90 93 87 47 13 75 28 87 23 72 79 32 18 27 20 28 10 37 59 21 18 70 04 79 96 03 31 45 71 81 06 14 18 17 05 31 50 92 79 23 47 09 39 47 91 43 54 69 47 42 95 62 46 32 85 37 18 62 85 87 28 64 05 77 51 47 26 30 65 05 70 65 75 59 80 42 52 25 20 44 10 92 17 71 95 52 14 77 13 24 55 11 65 26 91 01 30 63 15 49 48 41 17 67 47 03 68 20 90 98 32 04 40 68 90 51 58 60 06 55 23 68 05 19 76 94 82 36 96 43 38 90 87 28 33 83 05 17 70 83 96 93 06 04 78 47 80 06 23 84 75 23 87 72 99 14 50 98 92 38 90 64 61 58 76 94 36 66 87 80 51 35 61 38 57 95 64 06 53 36 82 51 40 33 47 14 07 98 78 65 39 58 53 06 50 53 04 69 40 68 36 69 75 78 75 60 03 32 39 24 74 47 26 90 13 40 44 71 90 76 51 24 36 50 25 45 70 80 61 80 61 43 90 64 11 18 29 86 56 68 42 79 10 42 44 30 12 96 18 23 18 52 59 02 99 67 46 60 86 43 38 55 17 44 93 42 21 55 14 47 34 55 16 49 24 23 29 96 51 55 10 46 53 27 92 27 46 63 57 30 65 43 27 21 20 24 83 81 72 93 19 69 52 48 01 13 83 92 69 20 48 69 59 20 62 05 42 28 89 90 99 32 72 84 17 08 87 36 03 60 31 36 36 81 26 97 36 48 54 56 56 27 16 91 08 23 11 87 99 33 47 02 14 44 73 70 99 43 35 33 90 56 61 86 56 12 70 59 63 32 01 15 81 47 71 76 95 32 65 80 54 70 34 51 40 45 33 04 64 55 78 68 88 47 31 47 68 87 03 84 23 44 89 72 35 08 31 76 63 26 90 85 96 67 65 91 19 14 17 86 04 71 32 95 37 13 04 22 64 37 37 28 56 62 86 33 07 37 10 44 52 82 52 06 19 52 57 75 90 26 91 24 06 21 14 67 76 30 46 14 35 89 89 41 03 64 56 97 87 63 22 34 03 79 17 45 11 53 25 56 96 61 23 18 63 31 37 37 47 77 23 26 70 72 76 77 04 28 64 71 69 14 85 96 54 95 48 06 62 99 83 86 77 97 75 71 66 30 19 57 90 33 01 60 61 14 12 90 99 32 77 56 41 18 14 87 49 10 14 90 64 18 50 21 74 14 16 88 05 45 73 82 47 74 44 22 97 41 13 34 31 54 61 56 94 03 24 59 27 98 77 04 09 37 40 12 26 87 09 71 70 07 18 64 57 80 21 12 71 83 94 60 39 73 79 73 19 97 32 64 29 41 07 48 84 85 67 12 74 95 20 24 52 41 67 56 61 29 93 35 72 69 72 23 63 66 01 11 07 30 52 56 95 16 65 26 83 90 50 74 60 18 16 48 43 77 37 11 99 98 30 94 91 26 62 73 45 12 87 73 47 27 01 88 66 99 21 41 95 80 02 53 23 32 61 48 32 43 43 83 14 66 95 91 19 81 80 67 25 88 08 62 32 18 92 14 83 71 37 96 11 83 39 99 05 16 23 27 10 67 02 25 44 11 55 31 46 64 41 56 44 74 26 81 51 31 45 85 87 09 81 95 22 28 76 69 46 48 64 87 67 76 27 89 31 11 74 16 62 03 60 94 42 47 09 34 94 93 72 56 18 90 18 42 17 42 32 14 86 06 53 33 95 99 35 29 15 44 20 49 59 25 54 34 59 84 21 23 54 35 90 78 16 93 13 37 88 54 19 86 67 68 55 66 84 65 42 98 37 87 56 33 28 58 38 28 38 66 27 52 21 81 15 08 22 97 32 85 27 91 53 40 28 13 34 91 25 01 63 50 37 22 49 71 58 32 28 30 18 68 94 23 83 63 62 94 76 80 41 90 22 82 52 29 12 18 56 10 08 35 14 37 57 23 65 67 40 72 39 93 39 70 89 40 34 07 46 94 22 20 05 53 64 56 30 05 56 61 88 27 23 95 11 12 37 69 68 24 66 10 87 70 43 50 75 07 62 41 83 58 95 93 89 79 45 39 02 22 05 22 95 43 62 11 68 29 17 40 26 44 25 71 87 16 70 85 19 25 59 94 90 41 41 80 61 70 55 60 84 33 95 76 42 63 15 09 03 40 38 12 03 32 09 84 56 80 61 55 85 97 16 94 82 94 98 57 84 30 84 48 93 90 71 05 95 90 73 17 30 98 40 64 65 89 07 79 09 19 56 36 42 30 23 69 73 72 07 05 27 61 24 31 43 48 71 84 21 28 26 65 65 59 65 74 77 20 10 81 61 84 95 08 52 23 70 47 81 28 09 98 51 67 64 35 51 59 36 92 82 77 65 80 24 72 53 22 07 27 10 21 28 30 22 48 82 80 48 56 20 14 43 18 25 50 95 90 31 77 08 09 48 44 80 90 22 93 45 82 17 13 96 25 26 08 73 34 99 06 49 24 06 83 51 40 14 15 10 25 01 54 25 10 81 30 64 24 74 75 80 36 75 82 60 22 69 72 91 45 67 03 62 79 54 89 74 44 83 64 96 66 73 44 30 74 50 37 05 09 97 70 01 60 46 37 91 39 75 75 18 58 52 72 78 51 81 86 52 08 97 01 46 43 66 98 62 81 18 70 93 73 08 32 46 34 96 80 82 07 59 71 92 53 19 20 88 66 03 26 26 10 24 27 50 82 94 73 63 08 51 33 22 45 19 13 58 33 90 15 22 50 36 13 55 06 35 47 82 52 33 61 36 27 28 46 98 14 73 20 73 32 16 26 80 53 47 66 76 38 94 45 02 01 22 52 47 96 64 58 52 39 88 46 23 39 74 63 81 64 20 90 33 33 76 55 58 26 10 46 42 26 74 74 12 83 32 43 09 02 73 55 86 54 85 34 28 23 29 79 91 62 47 41 82 87 99 22 48 90 20 05 96 75 95 04 43 28 81 39 81 01 28 42 78 25 39 77 90 57 58 98 17 36 73 22 63 74 51 29 39 74 94 95 78 64 24 38 86 63 87 93 06 70 92 22 16 80 64 29 52 20 27 23 50 14 13 87 15 72 96 81 22 08 49 72 30 70 24 79 31 16 64 59 21 89 34 96 91 48 76 43 53 88 01 57 80 23 81 90 79 58 01 80 87 17 99 86 90 72 63 32 69 14 28 88 69 37 17 71 95 56 93 71 35 43 45 04 98 92 94 84 96 11 30 31 27 31 60 92 03 48 05 98 91 86 94 35 90 90 08 48 19 33 28 68 37 59 26 65 96 50 68 22 07 09 49 34 31 77 49 43 06 75 17 81 87 61 79 52 26 27 72 29 50 07 98 86 01 17 10 46 64 24 18 56 51 30 25 94 88 85 79 91 40 33 63 84 49 67 98 92 15 26 75 19 82 05 18 78 65 93 61 48 91 43 59 41 70 51 22 15 92 81 67 91 46 98 11 11 65 31 66 10 98 65 83 21 05 56 05 98 73 67 46 74 69 34 08 30 05 52 07 98 32 95 30 94 65 50 24 63 28 81 99 57 19 23 61 36 09 89 71 98 65 17 30 29 89 26 79 74 94 11 44 48 97 54 81 55 39 66 69 45 28 47 13 86 15 76 74 70 84 32 36 33 79 20 78 14 41 47 89 28 81 05 99 66 81 86 38 26 06 25 13 60 54 55 23 53 27 05 89 25 23 11 13 54 59 54 56 34 16 24 53 44 06 13 40 57 72 21 15 60 08 04 19 11 98 34 45 09 97 86 71 03 15 56 19 15 44 97 31 90 04 87 87 76 08 12 30 24 62 84 28 12 85 82 53 99 52 13 94 06 65 97 86 09 50 94 68 69 74 30 67 87 94 63 07 78 27 80 36 69 41 06 92 32 78 37 82 30 05 18 87 99 72 19 99 44 20 55 77 69 91 27 31 28 81 80 27 02 07 97 23 95 98 12 25 75 29 47 71 07 47 78 39 41 59 27 76 13 15 66 61 68 35 69 86 16 53 67 63 99 85 41 56 08 28 33 40 94 76 90 85 31 70 24 65 84 65 99 82 19 25 54 37 21 46 33 02 52 99 51 33 26 04 87 02 08 18 96 54 42 61 45 91 06 64 79 80 82 32 16 83 63 42 49 19 78 65 97 40 42 14 61 49 34 04 18 25 98 59 30 82 72 26 88 54 36 21 75 03 88 99 53 46 51 55 78 22 94 34 40 68 87 84 25 30 76 25 08 92 84 42 61 40 38 09 99 40 23 29 39 46 55 10 90 35 84 56 70 63 23 91 39 52 92 03 71 89 07 09 37 68 66 58 20 44 92 51 56 13 71 79 99 26 37 02 06 16 67 36 52 58 16 79 73 56 60 59 27 44 77 94 82 20 50 98 33 09 87 94 37 40 83 64 83 58 85 17 76 53 02 83 52 22 27 39 20 48 92 45 21 09 42 24 23 12 37 52 28 50 78 79 20 86 62 73 20 59 54 96 80 15 91 90 99 70 10 09 58 90 93 50 81 99 54 38 36 10 30 11 35 84 16 45 82 18 11 97 36 43 96 79 97 65 40 48 23 19 17 31 64 52 65 65 37 32 65 76 99 79 34 65 79 27 55 33 03 01 33 27 61 28 66 08 04 70 49 46 48 83 01 45 19 96 13 81 14 21 31 79 93 85 50 05 92 92 48 84 59 98 31 53 23 27 15 22 79 95 24 76 05 79 16 93 97 89 38 89 42 83 02 88 94 95 82 21 01 97 48 39 31 78 09 65 50 56 97 61 01 07 65 27 21 23 14 15 80 97 44 78 49 35 33 45 81 74 34 05 31 57 09 38 94 07 69 54 69 32 65 68 46 68 78 90 24 28 49 51 45 86 35 41 63 89 76 87 31 86 09 46 14 87 82 22 29 47 16 13 10 70 72 82 95 48 64 58 43 13 75 42 69 21 12 67 13 64 85 58 23 98 09 37 76 05 22 31 12 66 50 29 99 86 72 45 25 10 28 19 06 90 43 29 31 67 79 46 25 74 14 97 35 76 37 65 46 23 82 06 22 30 76 93 66 94 17 96 13 20 72 63 40 78 08 52 09 90 41 70 28 36 14 46 44 85 96 24 52 58 15 87 37 05 98 99 39 13 61 76 38 44 99 83 74 90 22 53 80 56 98 30 51 63 39 44 30 91 91 04 22 27 73 17 35 53 18 35 45 54 56 27 78 48 13 69 36 44 38 71 25 30 56 15 22 73 43 32 69 59 25 93 83 45 11 34 94 44 39 92 12 36 56 88 13 96 16 12 55 54 11 47 19 78 17 17 68 81 77 51 42 55 99 85 66 27 81 79 93 42 65 61 69 74 14 01 18 56 12 01 58 37 91 22 42 66 83 25 19 04 96 41 25 45 18 69 96 88 36 93 10 12 98 32 44 83 83 04 72 91 04 27 73 07 34 37 71 60 59 31 01 54 54 44 96 93 83 36 04 45 30 18 22 20 42 96 65 79 17 41 55 69 94 81 29 80 91 31 85 25 47 26 43 49 02 99 34 67 99 76 16 14 15 93 08 32 99 44 61 77 67 50 43 55 87 55 53 72 17 46 62 25 50 99 73 05 93 48 17 31 70 80 59 09 44 59 45 13 74 66 58 94 87 73 16 14 85 38 74 99 64 23 79 28 71 42 20 37 82 31 23 51 96 39 65 46 71 56 13 29 68 53 86 45 33 51 49 12 91 21 21 76 85 02 17 98 15 46 12 60 21 88 30 92 83 44 59 42 50 27 88 46 86 94 73 45 54 23 24 14 10 94 21 20 34 23 51 04 83 99 75 90 63 60 16 22 33 83 70 11 32 10 50 29 30 83 46 11 05 31 17 86 42 49 01 44 63 28 60 07 78 95 40 44 61 89 59 04 49 51 27 69 71 46 76 44 04 09 34 56 39 15 06 94 91 75 90 65 27 56 23 74 06 23 33 36 69 14 39 05 34 35 57 33 22 76 46 56 10 61 65 98 09 16 69 04 62 65 18 99 76 49 18 72 66 73 83 82 40 76 31 89 91 27 88 17 35 41 35 32 51 32 67 52 68 74 85 80 57 07 11 62 66 47 22 67 65 37 19 97 26 17 16 24 24 17 50 37 64 82 24 36 32 11 68 34 69 31 32 89 79 93 96 68 49 90 14 23 04 04 67 99 81 74 70 74 36 96 68 09 64 39 88 35 54 89 96 58 66 27 88 97 32 14 06 35 78 20 71 06 85 66 57 02 58 91 72 05 29 56 73 48 86 52 09 93 22 57 79 42 12 01 31 68 17 59 63 76 07 77 73 81 14 13 17 20 11 09 01 83 08 85 91 70 84 63 62 77 37 07 47 01 59 95 39 69 39 21 99 09 87 02 97 16 92 36 74 71 90 66 33 73 73 75 52 91 11 12 26 53 05 26 26 48 61 50 90 65 01 87 42 47 74 35 22 73 24 26 56 70 52 05 48 41 31 18 83 27 21 39 80 85 26 08 44 02 71 07 63 22 05 52 19 08 20 17 25 21 11 72 93 33 49 64 23 53 82 03 13 91 65 85 02 40 05 42 31 77 42 05 36 06 54 04 58 07 76 87 83 25 57 66 12 74 33 85 37 74 32 20 69 03 97 91 68 82 44 19 14 89 28 85 85 80 53 34 87 58 98 88 78 48 65 98 40 11 57 10 67 70 81 60 79 74 72 97 59 79 47 30 20 54 80 89 91 14 05 33 36 79 39 60 85 59 39 60 07 57 76 77 92 06 35 15 72 23 41 45 52 95 18 64 79 86 53 56 31 69 11 91 31 84 50 44 82 22 81 41 40 30 42 30 91 48 94 74 76 64 58 74 25 96 57 14 19 03 99 28 83 15 75 99 01 89 85 79 50 03 95 32 67 44 08 07 41 62 64 29 20 14 76 26 55 48 71 69 66 19 72 44 25 14 01 48 74 12 98 07 64 66 84 24 18 16 27 48 20 14 47 69 30 86 48 40 23 16 61 21 51 50 26 47 35 33 91 28 78 64 43 68 04 79 51 08 19 60 52 95 06 68 46 86 35 97 27 58 04 65 30 58 99 12 12 75 91 39 50 31 42 64 70 04 46 07 98 73 98 93 37 89 77 91 64 71 64 65 66 21 78 62 81 74 42 20 83 70 73 95 78 45 92 27 34 53 71 15 30 11 85 31 34 71 13 48 05 14 44 03 19 67 23 73 19 57 06 90 94 72 57 69 81 62 59 68 88 57 55 69 49 13 07 87 97 80 89 05 71 05 05 26 38 40 16 62 45 99 18 38 98 24 21 26 62 74 69 04 85 57 77 35 58 67 91 79 79 57 86 28 66 34 72 51 76 78 36 95 63 90 08 78 47 63 45 31 22 70 52 48 79 94 15 77 61 67 68 23 33 44 81 80 92 93 75 94 88 23 61 39 76 22 03 28 94 32 06 49 65 41 34 18 23 08 47 62 60 03 63 33 13 80 52 31 54 73 43 70 26 16 69 57 87 83 31 03 93 70 81 47 95 77 44 29 68 39 51 56 59 63 07 25 70 07 77 43 53 64 03 94 42 95 39 18 01 66 21 16 97 20 50 90 16 70 10 95 69 29 06 25 61 41 26 15 59 63 35
15,150
Common Lisp
.l
100
150.5
299
0.671096
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
3983f6cc2bda389ba1d0bf0cfcb619552a94b03c60d43156cab99453b08f9970
21,246
[ -1 ]
21,247
problem18.txt
OlegTheCat_project-euler/data/problem18.txt
75 95 64 17 47 82 18 35 87 10 20 04 82 47 65 19 01 23 75 03 34 88 02 77 73 07 63 67 99 65 04 28 06 16 70 92 41 41 26 56 83 40 80 70 33 41 48 72 33 47 32 37 16 94 29 53 71 44 65 25 43 91 52 97 51 14 70 11 33 28 77 73 17 78 39 68 17 57 91 71 52 38 17 14 91 43 58 50 27 29 48 63 66 04 68 89 53 67 30 73 16 69 87 40 31 04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
360
Common Lisp
.l
15
23
44
0.695652
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
48706624e54607b58c57b18176431a15ce2948a4b4012f222f5627425692cf3e
21,247
[ -1 ]
21,248
problem13.txt
OlegTheCat_project-euler/data/problem13.txt
37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072406154908250 23067588207539346171171980310421047513778063246676 89261670696623633820136378418383684178734361726757 28112879812849979408065481931592621691275889832738 44274228917432520321923589422876796487670272189318 47451445736001306439091167216856844588711603153276 70386486105843025439939619828917593665686757934951 62176457141856560629502157223196586755079324193331 64906352462741904929101432445813822663347944758178 92575867718337217661963751590579239728245598838407 58203565325359399008402633568948830189458628227828 80181199384826282014278194139940567587151170094390 35398664372827112653829987240784473053190104293586 86515506006295864861532075273371959191420517255829 71693888707715466499115593487603532921714970056938 54370070576826684624621495650076471787294438377604 53282654108756828443191190634694037855217779295145 36123272525000296071075082563815656710885258350721 45876576172410976447339110607218265236877223636045 17423706905851860660448207621209813287860733969412 81142660418086830619328460811191061556940512689692 51934325451728388641918047049293215058642563049483 62467221648435076201727918039944693004732956340691 15732444386908125794514089057706229429197107928209 55037687525678773091862540744969844508330393682126 18336384825330154686196124348767681297534375946515 80386287592878490201521685554828717201219257766954 78182833757993103614740356856449095527097864797581 16726320100436897842553539920931837441497806860984 48403098129077791799088218795327364475675590848030 87086987551392711854517078544161852424320693150332 59959406895756536782107074926966537676326235447210 69793950679652694742597709739166693763042633987085 41052684708299085211399427365734116182760315001271 65378607361501080857009149939512557028198746004375 35829035317434717326932123578154982629742552737307 94953759765105305946966067683156574377167401875275 88902802571733229619176668713819931811048770190271 25267680276078003013678680992525463401061632866526 36270218540497705585629946580636237993140746255962 24074486908231174977792365466257246923322810917141 91430288197103288597806669760892938638285025333403 34413065578016127815921815005561868836468420090470 23053081172816430487623791969842487255036638784583 11487696932154902810424020138335124462181441773470 63783299490636259666498587618221225225512486764533 67720186971698544312419572409913959008952310058822 95548255300263520781532296796249481641953868218774 76085327132285723110424803456124867697064507995236 37774242535411291684276865538926205024910326572967 23701913275725675285653248258265463092207058596522 29798860272258331913126375147341994889534765745501 18495701454879288984856827726077713721403798879715 38298203783031473527721580348144513491373226651381 34829543829199918180278916522431027392251122869539 40957953066405232632538044100059654939159879593635 29746152185502371307642255121183693803580388584903 41698116222072977186158236678424689157993532961922 62467957194401269043877107275048102390895523597457 23189706772547915061505504953922979530901129967519 86188088225875314529584099251203829009407770775672 11306739708304724483816533873502340845647058077308 82959174767140363198008187129011875491310547126581 97623331044818386269515456334926366572897563400500 42846280183517070527831839425882145521227251250327 55121603546981200581762165212827652751691296897789 32238195734329339946437501907836945765883352399886 75506164965184775180738168837861091527357929701337 62177842752192623401942399639168044983993173312731 32924185707147349566916674687634660915035914677504 99518671430235219628894890102423325116913619626622 73267460800591547471830798392868535206946944540724 76841822524674417161514036427982273348055556214818 97142617910342598647204516893989422179826088076852 87783646182799346313767754307809363333018982642090 10848802521674670883215120185883543223812876952786 71329612474782464538636993009049310363619763878039 62184073572399794223406235393808339651327408011116 66627891981488087797941876876144230030984490851411 60661826293682836764744779239180335110989069790714 85786944089552990653640447425576083659976645795096 66024396409905389607120198219976047599490197230297 64913982680032973156037120041377903785566085089252 16730939319872750275468906903707539413042652315011 94809377245048795150954100921645863754710598436791 78639167021187492431995700641917969777599028300699 15368713711936614952811305876380278410754449733078 40789923115535562561142322423255033685442488917353 44889911501440648020369068063960672322193204149535 41503128880339536053299340368006977710650566631954 81234880673210146739058568557934581403627822703280 82616570773948327592232845941706525094512325230608 22918802058777319719839450180888072429661980811197 77158542502016545090413245809786882778948721859617 72107838435069186155435662884062257473692284509516 20849603980134001723930671666823555245252804609722 53503534226472524250874054075591789781264330331690
5,100
Common Lisp
.l
100
50
50
1
OlegTheCat/project-euler
2
0
0
GPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
b48328239597fe5cec4b18151d4dc59da9481a15af13a0926e70a38868d0f670
21,248
[ -1 ]
21,263
assertion-error-test.lisp
noloop_assertion-error/test/assertion-error-test.lisp
(in-package #:cl-user) (defpackage #:noloop.assertion-error-test (:use #:common-lisp) (:nicknames #:assertion-error-test) (:import-from #:assertion-error #:assertion-error #:get-stack-trace #:assertion-error-message #:assertion-error-result #:assertion-error-actual #:assertion-error-expected #:assertion-error-stack)) (in-package #:noloop.assertion-error-test) ;; Simple assertion library (defun is-t? (actual) (assertion (equal t actual) actual t 'equal)) (defun is-nil? (actual) (assertion (equal nil actual) actual nil 'equal)) (defun assertion (result actual expected operator) (unless result (error 'assertion-error :assertion-error-message (concatenate 'string (string actual) " " (string operator) " " (string expected)) :assertion-error-result result :assertion-error-actual actual :assertion-error-expected expected :assertion-error-stack (get-stack-trace)))) ;; Simple Test Runner (defun run () (handler-case (is-t? nil) (assertion-error (c) (format t "Test result: ~a" (and (string= "NIL EQUAL T" (assertion-error-message c)) (equal nil (assertion-error-result c)) (equal nil (assertion-error-actual c)) (equal t (assertion-error-expected c)))))))
1,481
Common Lisp
.lisp
34
33.117647
117
0.598474
noloop/assertion-error
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
b7184297d2c81301ab016f738b39c73341217ceac4058a8521c0196b51fdd78a
21,263
[ -1 ]
21,264
package.lisp
noloop_assertion-error/src/package.lisp
(in-package #:cl-user) (defpackage #:noloop.assertion-error (:use #:common-lisp) (:nicknames #:assertion-error) (:import-from #:dissect #:stack) (:export #:assertion-error #:get-stack-trace #:assertion-error-message #:assertion-error-result #:assertion-error-actual #:assertion-error-expected #:assertion-error-stack)) (in-package #:noloop.assertion-error)
491
Common Lisp
.lisp
14
24.5
42
0.559748
noloop/assertion-error
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f2f111d21695c169dff43ac5d2c48d04a2f950b08742b41c6960ff73b1e58dcd
21,264
[ -1 ]
21,265
assertion-error.lisp
noloop_assertion-error/src/assertion-error.lisp
(in-package #:assertion-error) (define-condition assertion-error (error) ((assertion-error-message :initarg :assertion-error-message :reader assertion-error-message) (assertion-error-result :initarg :assertion-error-result :reader assertion-error-result) (assertion-error-actual :initarg :assertion-error-actual :reader assertion-error-actual) (assertion-error-expected :initarg :assertion-error-expected :reader assertion-error-expected) (assertion-error-stack :initarg :assertion-error-stack :reader assertion-error-stack))) (defun get-stack-trace () (stack))
580
Common Lisp
.lisp
9
61.444444
97
0.792619
noloop/assertion-error
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d7f926d9fa2fb6e1adaaa5b3454a51f1e66e7c3699be9eed44d64bdeb3dcf135
21,265
[ -1 ]
21,266
assertion-error.asd
noloop_assertion-error/assertion-error.asd
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- (defsystem :assertion-error :author "noloop <[email protected]>" :maintainer "noloop <[email protected]>" :license "GPLv3" :version "0.1.0" :homepage "https://github.com/noloop/assertion-error" :bug-tracker "https://github.com/noloop/assertion-error/issues" :source-control (:git "[email protected]:noloop/assertion-error.git") :description "Error pattern for assertion libraries in Common Lisp." :depends-on (:dissect) :components ((:module "src" :components ((:file "package") (:file "assertion-error" :depends-on ("package"))))) :in-order-to ((test-op (test-op "assertion-error/test")))) (defsystem :assertion-error/test :author "noloop <[email protected]>" :maintainer "noloop <[email protected]>" :license "GNU General Public License v3.0" :description "assertion-error Test." :depends-on (:assertion-error) :components ((:module "test" :components ((:file "assertion-error-test")))) :perform (test-op (op system) (funcall (read-from-string "assertion-error-test::run"))))
1,146
Common Lisp
.asd
26
38.5
90
0.663685
noloop/assertion-error
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9524151e417550b0fb737a485f9af039eaa3c000334a61142171c3050a333c0a
21,266
[ -1 ]
21,285
grantha.lisp
parjanya_grantha/grantha.lisp
#| This file is a part of Grantha project. Copyright (c) 2020 Edgard Bikelis ([email protected]) Author: Edgard Bikelis ([email protected]) Grantha 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. Grantha 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 Grantha. If not, see <https://www.gnu.org/licenses/>. |# (in-package :cl-user) (defpackage grantha (:use :cl) (:nicknames :gra) (:export alias list-exported-symbols-with-docstrings get-even-elements get-odd-elements make-plist last-member reverse-cons tree-remove nested-getf ;; truncate-memory ;; truncate-time ;; round-to pretty-number human-readable-number print-bin print-hex convert subtract-time-of-day time-to-execute-and-result parse-time current-date-string int-to-char char-to-int int-to-str str-to-int next previous str concat padding ;; from grantha-dependent.lisp garbage-full kill-all-threads-but-current url-encode url-decode)) (in-package :grantha) ;; ;; symbols ;; ;; (defmacro alias (new-name prev-name) ;; "Makes an alias named NEW-NAME for PREV-NAME." ;; `(defmacro ,new-name (&rest args) ;; `(,',prev-name ,@args))) (defun alias (quoted-new-name quoted-prev-name) "Makes an alias named QUOTED-NEW-NAME for QUOTED-PREV-NAME." (setf (symbol-function quoted-new-name) (symbol-function quoted-prev-name))) ;; ;; packages ;; ;; see https://stackoverflow.com/questions/9743056/common-lisp-exporting-symbols-from-packages (defun list-exported-symbols-with-docstrings (package) "I return a simple definition list in org-mode with the exported symbols of a package. I should do that in the order they are defined in the source code, but I do not." (let ((out "")) (do-external-symbols (p package) (if (ignore-errors (symbol-function p)) (setq out (concat out *newline* "- " (symbol-name p) " (function) :: " (coerce (subst #\space #\Newline (coerce (documentation p 'function) 'list)) 'string)))) (if (ignore-errors (symbol-value p)) (setq out (concat out *newline* "- " (symbol-name p) " (variable) :: " (coerce (subst #\space #\Newline (coerce (documentation p 'variable) 'list)) 'string))))) out)) ;; ;; lists ;; ;; https://stackoverflow.com/a/36353587 (defun get-even-elements (lst) "Give me a list and I shall return thee its even elements." (loop :for element :in (rest lst) :by #'cddr :collect element)) (defun get-odd-elements (lst) "Give me a list and I shall return thee its odd elements." (loop :for element :in lst :by #'cddr :collect element)) ;; inspired by /usr/share/sbcl-source/src/code/list.lisp, `pairlis' (defun make-plist (keys data &optional append-to-car-p) "Construct a property list from KEYS and DATA." (let (out) (do ((x keys (cdr x)) (y data (cdr y))) ((and (endp x) (endp y)) out) (if (or (endp x) (endp y)) (error "The lists of keys and data are of unequal length.")) (if append-to-car-p (setq out (append (list (car x) (car y)) out)) (setq out (append out (list (car x) (car y)))))))) (defun last-member (lst) "I return the actual last member of a list." (car (last lst))) (defun reverse-cons (cns) "I reverse a cons pair." (cons (cdr cns) (car cns))) ;; from https://github.com/briangu/OPS5/blob/master/src/ops-util.lisp ;; circa 1992 (defun tree-remove (element tree &key (test #'equal)) "TREE-REMOVE is a function which deletes every occurrence of ELEMENT from TREE. This function was defined because Common Lisp's REMOVE function only removes top level elements from a list." (when tree (if (funcall test element (car tree)) (tree-remove element (cdr tree) :test test) (cons (car tree) (tree-remove element (cdr tree) :test test))))) ;; ;; association lists, alists ;; (defun alist-remove-by-car (the-car alist) "I am not destructive. (alist-remove-by-car 1 '((1 . \"a\") (2 . \"b\"))) → ((2 . \"b\"))" (remove the-car alist :key #'car :test #'equal)) ;; ;; property lists, plists ;; (defun nested-getf (place &rest indicators) "(nested-getf a b c) → (getf (getf a b) c)." (let (out) (setq out place) (dolist (indicator indicators) (setq out (getf out indicator))) out)) ;; ;; numbers ;; ;; lossy : / ;; ;; Heavily inspired by Roy Anderson, on [email protected] (defun truncate-memory (bytes) "Give me some bytes, and them I shall return thee divided by the maximum possible unit, together with that unit." (let* ((kb (truncate bytes 1024)) (mb (truncate kb 1024)) (gb (truncate mb 1024)) (tb (truncate gb 1024)) (pb (truncate tb 1024))) (cond ((zerop kb) (list bytes "B")) ((zerop mb) (list kb "KB")) ((zerop gb) (list mb "MB")) ((zerop tb) (list gb "GB")) ((zerop pb) (list tb "TB")) (t (list pb "PB"))))) ;; Heavily inspired by Roy Anderson, on [email protected] (defun truncate-time (s) "Give me some seconds, and them I shall return thee divided by the maximum possible unit, together with that unit." (let* ((min (truncate s 60)) (hours (truncate min 60)) (days (truncate hours 24)) (years (truncate days 365)) (millenia (truncate years 1000))) (cond ((zerop min) (list s "sec")) ((zerop hours) (list min "min")) ((zerop days) (list hours "hours")) ((zerop years) (list days "days")) ((zerop millenia) (list days "years")) (t (list days "millenia"))))) (defun round-to (number precision &optional (what #'round)) "I round NUMBER to PRECISION." (let ((div (expt 10 precision))) (/ (funcall what (* number div)) div))) ;; TODO: check serapeum:file-size-human-readable (defun pretty-number (n) "I truncate the bytes you give me. I am more expensive than `truncate-memory'." (declare (integer n)) (let ((parsed (cond ((< n 1024) (cons n "B" )) ((< n 1048576) (cons (float (/ n 1024)) "K")) ((< n 1073741824) (cons (float (/ n 1048576)) "M")) ((< n 1099511627776) (cons (float (/ n 1073741824)) "G")) ((< n 1125899906842624) (cons (float (/ n 1099511627776)) "T")) ((< n 1152921504606846976) (cons (float (/ n 1125899906842624)) "P")) (t "out of bounds")))) (if (typep parsed 'simple-array) parsed (concatenate 'string (str (float (round-to (car parsed) 1))) (cdr parsed))))) (defparameter +number-suffixes+ (list (list 10 1024 "b") (list 20 1048576 "kb") (list 30 1073741824 "mb") (list 40 1099511627776 "gb") (list 50 1125899906842624 "tb") (list 60 1152921504606846976 "pb")) "A list of 2^ to what gives each unit, followed by the unit itself, and the short string for it.") ;; FIX (defun human-readable-number (number) (let (out) (dolist (each +number-suffixes+) (if (and (not out) (> number 1) (< number (expt 2 (car each)))) (progn (setq number (/ number (expt 2 (car each)))) (setq out (cons (float number) (cdr each)))))) out)) (defun print-bin (n) "I print the given number in a binary representation." (format nil "~b" n)) (defun print-hex (n) "I print the given number in a hexadecimal representation." (format nil "~x" n)) ;; ;; conversion of units ;; (defparameter *equivalences* '(((foot . metre) . 0.3048) ((centimetre . inch) . 0.39370078740157) ((quart . litre) . 0.94635295) ((cup . litre) . 0.2365882375)) "I hold equivalences, probably for `convert' to use.") (defun convert (quantity before after) "I try converting the given quantity from the before unit to the after unit. I am not smart. Check `*equivalences*' to see all I know." (let (conversion-pair equivalence invertedp) (setq conversion-pair (cons before after)) (setq equivalence (assoc conversion-pair *equivalences* :test 'equal)) (unless equivalence (setq equivalence (assoc (reverse-cons conversion-pair) *equivalences* :test 'equal)) (setq invertedp t)) (if equivalence (if invertedp (/ quantity (cdr equivalence)) (* quantity (cdr equivalence))) (error "I do not know how to convert this!")))) ;; ;; time ;; (defun subtract-time-of-day (x y) "I get two times in the format (seconds microseconds), returned by `get-time-of-day' for instance, and return their difference." (let (seconds microseconds) (setq seconds (- (nth 0 x) (nth 0 y))) (setq microseconds (- (nth 1 x) (nth 1 y))) (list seconds microseconds))) (defun time-to-execute-and-result (form &optional multiple-value-p) "Returns the time (always in miliseconds?) to execute FORM, and its result. In order to grab multiple values, the result might be returned as a list. If we got an error, return a plist: (:error 'the-error-object). NOTA BENE: If this is to be memoized, the object will be gone eventually, so `princ-to-string' it." (let ((before-time (get-internal-real-time)) result after-time) (setq result (handler-case (eval (if multiple-value-p `(multiple-value-list ,form) form)) (sb-c:compiler-error (the-error) (list :error (slot-value the-error 'condition))) (t (the-error) (list :error the-error)))) (setq after-time (get-internal-real-time)) (list :miliseconds (- after-time before-time) :result result))) (defun parse-time (&optional (given-time (multiple-value-list (get-decoded-time)))) "I either return thee the current `get-decoded-time' as a plist, or I parse the time given in the same format, that thou providest me." (let ((keywords (list :second :minute :hour :day :month :year :day-of-week :daylight-savings-times-p :timezone))) (make-plist keywords given-time))) (defun current-date-string (&key timep timezonep) "I return thee a string with the current date, and time if thou so wishest, and likewise the timezone. Cf. ISO 8601. Time should be separated with 'T' instead of '_', but Edgard thinks it less legible." (let ((time (parse-time)) (date "") (hour&c "") (timezone "")) (setq date (concatenate 'string ;; behold the bug of milleniumX10 (padding (str (getf time :year)) 4 "0") "-" (padding (str (getf time :month)) 2 "0") "-" (padding (str (getf time :day)) 2 "0"))) (when (or timep timezonep) (setq hour&c (concatenate 'string "_" (padding (str (getf time :hour)) 2 "0") ":" (padding (str (getf time :minute)) 2 "0") ":" (padding (str (getf time :second)) 2 "0")))) (when timezonep (setq timezone (concatenate 'string (if (> (getf time :timezone) 0) "+" "-") (padding (str (getf time :timezone)) 2 "0"))) (if (equal timezone "+00") (setq timezone "Z"))) (concatenate 'string date hour&c timezone))) ;; (eval `(encode-universal-time ,@(subseq (multiple-value-list (decode-universal-time (get-universal-time))) 0 6))) ;; → 3814968316 ;; CL-USER> (get-universal-time) ;; → 3814968322 ;; ;; characters ;; (defun int-to-char (chr) "Give me either an int or a list of them, and I shall return them converted to chars to thee. I am the contrary of `char-to-int'." (let ((lst '()) (out '())) ;; if it’s just a number, add it to a list, ;; so DOLIST won’t fail (if (numberp chr) (setq lst (list chr)) (setq lst chr)) (dolist (item lst) (setq out (push (code-char item) out))) ;; if we got just a number, return just it, ;; instead of a list (if (= (length out) 1) (car out) (reverse out)))) (defun char-to-int (chr) "Give me either a character or a list of them, and I shall return them converted to ints to thee. I am the contrary of `int-to-char'." (let ((lst '()) (out '())) (if (characterp chr) (setq lst (list chr)) (setq lst chr)) (dolist (item lst) (setq out (push (char-code item) out))) (if (= (length out) 1) (car out) (reverse out)))) (defun int-to-str (chr) "Give me either an int or a list of them, and I shall return them as a string, after converting them to characters. I am the contrary of `str-to-int'." (let ((out '())) (if (listp chr) (dolist (item chr) (setq out (concatenate 'string out (string (code-char item))))) (setq out (string (code-char chr)))) out)) (defun str-to-int (str) "Give me either a string or a list of them, and I shall return everything as a list, after converting them to integers. I am the contrary of `int-to-str'." (let ((lst (coerce str 'list)) (out '())) (dolist (item lst) (push (char-to-int (character item)) out)) (if (= (length out) 1) (car out) (reverse out)))) (defun next (thing) "Give me something, like an integer, a character, or a string, and I will return thee the next one of its kind. I am the contrary of `previous'." (typecase thing (number (+ thing 1)) (character (int-to-char (+ (char-to-int thing) 1))) (string (if (= (length thing) 1) (int-to-str (+ (str-to-int thing) 1)) (concatenate 'string (subseq thing 0 (- (length thing) 1)) (next (subseq thing (- (length thing) 1))))) ;; (error "I don’t know quite what to do with this.") ))) (defun previous (thing) "Give me something, like an integer, a character, or a string, and I will return thee the previous one of its kind. I am the contrary of `next'." (typecase thing (number (- thing 1)) (character (int-to-char (- (char-to-int thing) 1))) (string (int-to-str (- (str-to-int thing) 1))))) ;; ;; strings ;; (defvar *newline* (string #\newline)) (defun str (i) "I return i represented as a string." (princ-to-string i)) (defun concat (&rest items) "I try to be smart in concatenating items, silently converting them to strings." (let ((out "")) (dolist (item items) (if (or (numberp item) (consp item)) (setq out (concatenate 'string out (princ-to-string item))) (setq out (concatenate 'string out item)))) out)) (defun padding (str length pad &optional afterp) "Give me a string, the length it should have, and what to pad it with, and I shall return thee the selfsame string thus padded." (setq str (coerce str 'list)) (if (not (eq (length pad) 1)) (error "The pad given isn’t of length 1.")) (if (stringp pad) (setq pad (coerce pad 'character))) (loop while (< (length str) length) do (if afterp (setq str (append str (list pad))) (push pad str))) (coerce str 'string)) (defun string-to-octets (str) (flexi-streams:string-to-octets str)) (defun octets-to-string (str) (flexi-streams:octets-to-string str)) ;; ;; base64 foolery ;; (defun base64-encode-octets-to-string (str) "I am the contrary of `base64-encode-octets-to-string'. (base64-encode-octets-to-string #(1 2 3 224 164 178)) → \"AQID4KSy\"." (with-output-to-string (out) (s-base64:encode-base64-bytes str out nil))) (defun base64-decode-string-to-octets (str) "I am the contrary of `base64-encode-string-to-octets'. (base64-decode-string-to-octets \"AQID4KSy\") → #(1 2 3 224 164 178)." (with-input-from-string (s str) (s-base64:decode-base64-bytes s))) (defun base64-encode-string-to-string (str) "Weird, I know, but I am useful to hide control characters. (base64-encode-string-to-string (concat \"a\" *newline* \"b\")) → \"YQpi\"." (with-output-to-string (out) (s-base64:encode-base64-bytes (flexi-streams:string-to-octets str :external-format :utf-8) out nil))) (defun base64-decode-string-to-string (str) (flexi-streams:octets-to-string (with-input-from-string (s str) (s-base64:decode-base64-bytes s)))) ;; ;; files ;; (defun file-exists-p (file) "I check if `file' exists. I return NIL if not, the path if true." (directory file)) (defun write-file-as-sexp (thing file) "I write a THING into some FILE." (with-open-file (f file :direction :output :if-exists :supersede :if-does-not-exist :create) ;; we change *print-pretty* to avoid useless newlines in the file (let ((*print-pretty* nil)) (write thing :stream f :escape t))) nil) (defun read-file-as-sexp (file) "I READ something that was written into some FILE." (if (probe-file file) (with-open-file (f file :direction :input :if-does-not-exist nil) (read f)) (print "The file does not exist."))) (defun file-append (thing file &optional (end-with-newline-p nil)) (let (the-offset) (with-open-file (f file :direction :output :if-exists :append :if-does-not-exist :create) (setq the-offset (file-length f)) ;; we change *print-pretty* to avoid useless newlines in the file (write thing :stream f :escape t :pretty nil) (if end-with-newline-p (terpri f))) (list :offset the-offset))) (defun file-read-from-offset (file offset) (with-open-file (f file :direction :input :if-does-not-exist :error) (file-position f offset) (read-line f))) (defun file-read-binary-with-offset (pathname begin end) "Read PATHNAME into a freshly allocated (unsigned-byte 8) vector." (alexandria:with-input-from-file (stream pathname :element-type '(unsigned-byte 8)) (file-position stream begin) (coerce (loop for i from 0 to end collect (read-byte stream)) 'vector))) ;; while byte != 10 ;; *newline* (defun file-write-octets (octets file) (alexandria:write-byte-vector-into-file octets file :if-exists :supersede :if-does-not-exist :create)) (defun file-read-as-octets (file) (alexandria:read-file-into-byte-vector file)) ;; ;; serialization / serialisation ;; ;; (defun serialize-as-octet=store (thing) ;; "(store-as-octet-vector=store '(+ 1 1)) ;; #(67 76 67 76 43 10 35 1 1 43 35 1 11 67 79 77 77 79 78 45 76 73 83 80 0 24 0 1 ;; 1 0 24 0 1 1 1 41)" ;; (flex:with-output-to-sequence (s) (cl-store:store thing s))) (defun serialize-as-octet=encode (thing) (conspack:encode thing)) (defun serialize-as-octet=decode (thing) (conspack:decode thing)) (defun deserialize-file (file) (conspack:decode-file file)) ;; ;; compression ;; (defun compress-octets (octets) (salza2:compress-data octets 'salza2:gzip-compressor)) (defun decompress-octets (octets) (chipz:decompress nil 'chipz:gzip octets)) ;; ;; memoization / memoisation ;; (defun memoize=eval (sexp &optional multiple-value-p) "I eval SEXP and return a plist with :sexp, the time taken to execute as :miliseconds, and the results as :result. If you want multiple values to be grabbed, give me a true multiple-value-p." (let (result) (setq result (gra:time-to-execute-and-result sexp multiple-value-p)) ;; if we got an error, print it so the result is more enlightening. (when (ignore-errors (gra:nested-getf result :result :error)) (setf (getf (getf result :result) :error) (princ-to-string (gra:nested-getf result :result :error)))) (list :sexp sexp :multiple-value-p multiple-value-p :miliseconds (getf result :miliseconds) :universal-time (get-universal-time) :result (getf result :result)))) (defparameter *stash-path* "~/ksipra/stash/" "We save the results of sexps in ‘stashes’, which are files with related data, and for that we need a path to save them. Not everything is easily serialized, so beware.") (defparameter *stash-key-hash-tables-alist* '() "I am a list composed of (\"stash\" . 'hash-table).") (defun memoize=write (key value stash &optional (stash-path *stash-path*)) "I receive a KEY and a VALUE, saving VALUE on a file named STASH-values, which has one field per line. VALUE comes from `memoize=eval', which returns a plist; the only one that we have to take care of here is `:result', which is the information we want to save for easy retrieval. In order to do that, we serialize it into octets, then compress those octets, and finally encode them in a base64 string. This is the format in which `:result' will be written. Now we append the whole VALUE thus updated on the STASH-values file, which has one field per line. The VALUE is taken care of. For retrieval, I read the STASH-keys file, a serialized hash-table, and append the new key having the new offset as its value, and finally I rewrite that STASH-keys file. I do all that so we don’t need to have the entire STASH-values on memory, while still being able to retrieve the VALUE at a decent speed, hopefully. Also, appending the STASH-values file should be cheap, which wouldn’t be the case if we saved the whole thing as a hash-table, and superseding/rewriting it at every new addition. WARNING: `:result's bigger than the usual, ie. > 800kb, choke everything. TODO: make everything work with streams instead." (ensure-directories-exist stash-path) (let ((keys-file (concat stash-path stash "-keys")) (values-file (concat stash-path stash "-values")) (keys-hash-table) (result) (result-encoded) (keys-file-offset)) ;; now we find the correct hash-table. it should inhabit ;; *stash-key-hash-tables-alist*, so we try that first (setq keys-hash-table (cdr (assoc stash *stash-key-hash-tables-alist* :test #'equal))) ;; if we don’t get it, it might be in a file he haven’t read ;; yet. if the file exists, get it from there. (when (file-exists-p keys-file) (setq keys-hash-table (serialize-as-octet=decode (decompress-octets (file-read-as-octets keys-file))))) ;; otherwise we never saw that stash before, and so we create a ;; new hash-table. (when (not keys-hash-table) (setq keys-hash-table (make-hash-table :test #'equal))) ;; ;; encode the result ;; (setq result (getf value :result)) (setq result (serialize-as-octet=encode result)) (setq result-encoded (compress-octets result)) (setq result-encoded (base64-encode-octets-to-string result-encoded)) ;; update VALUE with the encoded result (setf (getf value :result) result-encoded) ;; write the value on the file (setq keys-file-offset (last-member (file-append value values-file t))) ;; add the key and offset on the appropriate hash-table. (setf (gethash key keys-hash-table) keys-file-offset) ;; remove the hash-table from the list of hash-tables, in case ;; it’s there, so we don’t have two entries about it. (setq *stash-key-hash-tables-alist* (alist-remove-by-car stash *stash-key-hash-tables-alist*)) ;; add it (back) (setq *stash-key-hash-tables-alist* (acons stash keys-hash-table *stash-key-hash-tables-alist*)) ;; write the hash-table back ;; first, serialize it (setq keys-hash-table (serialize-as-octet=encode keys-hash-table)) (setq keys-hash-table (compress-octets keys-hash-table)) ;; then actually write it (file-write-octets keys-hash-table keys-file) (list :size-bytes-before (length result) :size-bytes-after (length result-encoded)))) (defun memoize=read (key stash &optional (stash-path *stash-path*)) (let ((keys-file (concat stash-path stash "-keys")) (values-file (concat stash-path stash "-values")) (keys-hash-table) (keys-file-offset) (value) (result)) ;; now we find the correct hash-table. it should inhabit ;; *stash-key-hash-tables-alist*, so we try that first (setq keys-hash-table (cdr (assoc stash *stash-key-hash-tables-alist* :test #'equal))) ;; if we don’t get it, it might be in a file he haven’t read ;; yet. if the file exists, get it from there. (unless keys-hash-table (when (file-exists-p keys-file) (setq keys-hash-table (serialize-as-octet=decode (decompress-octets (file-read-as-octets keys-file)))))) ;; otherwise we never saw that stash before, so we give an error. (when (not keys-hash-table) (error "This stash doesn’t exist.")) (setq keys-file-offset (gethash key keys-hash-table)) ;; ;; decode the result ;;; (setq value (file-read-from-offset values-file keys-file-offset)) (setq value (read-from-string value)) (setq result (getf value :result)) (setq result (base64-decode-string-to-string result)) (setq result (string-to-octets result)) (setq result (decompress-octets result)) (setq result (serialize-as-octet=decode result)) (setf (getf value :result) result) value)) (defun memoizedp (key stash &optional (stash-path *stash-path*)) (let ((keys-file (concat stash-path stash "-keys")) (keys-hash-table)) ;; now we find the correct hash-table. it should inhabit ;; *stash-key-hash-tables-alist*, so we try that first (setq keys-hash-table (cdr (assoc stash *stash-key-hash-tables-alist* :test #'equal))) ;; if we don’t get it, it might be in a file he haven’t read ;; yet. if the file exists, get it from there. (unless keys-hash-table (when (file-exists-p keys-file) (setq keys-hash-table (serialize-as-octet=decode (decompress-octets (file-read-as-octets keys-file)))))) ;; otherwise we never saw that stash before. (if (not keys-hash-table) nil (gethash key keys-hash-table)))) (defun memoized (sexp &optional return-whole-entry-p (stash-path *stash-path*)) "TODO: the function name shouldn’t have /, otherwise the file can’t be written, at least on ext4 filesystems. What to do? Replace it by what?" ;; `princ-to-string' strips the package part of the name, as ;; `dex:get' → "GET", but `prin1-to-string does give "DEX:GET". (let ((stash (prin1-to-string (car sexp))) (key (str (cdr sexp))) value) (if (memoizedp key stash stash-path) (setq value (memoize=read key stash stash-path)) (progn (setq value (memoize=eval sexp)) (memoize=write key value stash))) (if return-whole-entry-p value (getf value :result)))) ;; ;; threads, threadmaster ;; (defun thread-info () (let* ((curr-thread (bt:current-thread)) (curr-thread-name (bt:thread-name curr-thread)) (all-threads (bt:all-threads))) (format t "Current thread: ~a~%~%" curr-thread) (format t "Current thread name: ~a~%~%" curr-thread-name) (format t "All threads:~% ~{~a~%~}~%" all-threads)) nil) (defparameter *time-units* '((:millenia . 31536000000) (:years . 31536000) (:days . 86400) (:hours . 3600) (:minutes . 60) (:seconds . 1))) (defun pretty-time (n) (let ((parsed (list :seconds n)) (tmp 0)) (dolist (unit *time-units*) (if (>= (getf parsed :seconds) (cdr unit)) (progn (loop while (>= (getf parsed :seconds) (cdr unit)) do (setf (getf parsed :seconds) (- (getf parsed :seconds) (cdr unit))) (setq tmp (1+ tmp))) (setq parsed (append parsed (list (car unit) tmp))) (setq tmp 0)))) (cddr parsed))) (defun pretty-time-to-seconds (time) (let ((out 0)) (dolist (unit *time-units*) (setq out (+ out (* (if (getf time (car unit)) (getf time (car unit)) 0) (cdr unit))))) out))
27,402
Common Lisp
.lisp
712
34.516854
116
0.674331
parjanya/grantha
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
48ff015a608333831d0ff11a8d2e252ef06530790a925b56fe01133087949259
21,285
[ -1 ]
21,286
grantha-dependent.lisp
parjanya_grantha/grantha-dependent.lisp
#| This file is a part of grantha project. Copyright (c) 2020 Edgard Bikelis ([email protected]) Author: Edgard Bikelis ([email protected]) Grantha 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. Grantha 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 Grantha. If not, see <https://www.gnu.org/licenses/>. |# ;; ;; Here I place everything that depends on other packages. ;; (in-package :grantha) ;; ;; garbage collection ;; (defun garbage-full (&optional raw-bytes-p) "I ask for full garbage collection and return thee the number of bytes freed. Sometimes I return negative numbers, what should I do with them?" (let ((old-dynamic-usage (sb-kernel:dynamic-usage)) difference) (sb-ext:gc :full t) (setq difference (- old-dynamic-usage (sb-kernel:dynamic-usage))) (if raw-bytes-p difference (grantha:pretty-number difference)))) ;; ;; threads ;; (defun kill-all-threads-but-current () (dolist (thread (sb-thread:list-all-threads)) (unless (equal sb-thread:*current-thread* thread) (sb-thread:terminate-thread thread)))) ;; ;; lisp images ;; ;; ;; internet related ;; (defun url-encode (str) "I transform \"lá\" into \"l%C3%A1\", so you can use it in an URL." (do-urlencode:urlencode str)) (defun url-decode (str) "I transform \"l%C3%A1\" into \"lá\", so you can get the string from an URL." (do-urlencode:urldecode str))
1,845
Common Lisp
.lisp
52
32.634615
79
0.737798
parjanya/grantha
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9915bb659d1da68e1d77cc859f72465ce6ec33d89c0752dc0fe491a76374242f
21,286
[ -1 ]
21,287
grantha-tests.lisp
parjanya_grantha/grantha-tests.lisp
(defpackage grantham/tests/main (:use :cl :grantham :rove)) (in-package :grantham/tests/main) ;; NOTE: To run this test file, execute `(asdf:test-system :grantha)' in your Lisp. (deftest test-target-1 (testing "should (= 1 1) to be true" (ok (= 1 1))))
279
Common Lisp
.lisp
9
27.111111
83
0.649254
parjanya/grantha
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
2429d9b3a7373061df5c653449c0d79fd9bd459e8f198ae04bca173fc8bcd5b9
21,287
[ -1 ]
21,288
grantha.asd
parjanya_grantha/grantha.asd
(defsystem "grantha" :version "0.1.0" :author "Edgard Bikelis" :license "GPLv3" :depends-on ("do-urlencode" "dexador" "cl-ppcre" "plump" ;; "cl-store" "cl-conspack" "flexi-streams" "salza2" "s-base64" "bordeaux-threads") :components ((:file "grantha") (:file "grantha-dependent")) :description "Personal library of recurrent sundries." :in-order-to ((test-op (test-op "grantha/tests")))) (defsystem "grantha/tests" :author "Edgard Bikelis" :license "GPLv3" :depends-on ("grantha" "rove") :components ((:file "grantha-tests")) :description "Test system for grantha." :perform (test-op (op c) (symbol-call :rove :run c)))
695
Common Lisp
.asd
26
22.846154
56
0.651198
parjanya/grantha
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
c9cbbc5db7c5d20a5017785c7388400ee48ed03bfb97d4c98b077e19f7f0a524
21,288
[ -1 ]
21,307
package.lisp
Izaakwltn_scale-your-violin/package.lisp
;;;;package.lisp ;;;; ;;;;Copyright (c) 2021 Izaak Walton (ql:quickload "hunchentoot") (defpackage #:scale-your-violin (:documentation "scaleyourviolin.com") (:use #:cl #:parenscript #:spinneret #:hunchentoot #:vibratsia))
229
Common Lisp
.lisp
7
30.857143
66
0.722727
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d1ca24bc364b71078c058c7b6581405293cbb8626363b86dea886b866db262f3
21,307
[ -1 ]
21,308
build-that-site.lisp
Izaakwltn_scale-your-violin/build-that-site.lisp
;;;;build-that-site.lisp (in-package :scale-your-violin) (defvar *server* (make-instance 'hunchentoot:easy-acceptor :port 4242 :document-root #p"/home/izaakwalton/programming/lisp-projects/scale-your-violin/www/")) (hunchentoot::start *server*) ;http://127.0.0.1:4242/ ;(push ; (hunchentoot:create-prefix-dispatcher "/index.html" #'matrix-page) ; hunchentoot:*dispatch-table*)
386
Common Lisp
.lisp
9
40.888889
88
0.751337
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
5d50572b9b96b99e9e03044e85f2cba51635cec0169acea9f4c9194df6b0ebf8
21,308
[ -1 ]
21,309
scale-your-page.lisp
Izaakwltn_scale-your-violin/scale-your-page.lisp
;;;;scale-your-page.lisp ;;;; (in-package :scale-your-violin) "Page template for website as a whole." (defmacro with-page ((&key title) &body body) `(spinneret::with-html-string (:doctype) (:html (:head (:meta :charset "utf-8") (:meta :name "viewport" :content "width=device-width, initial-scale=1") (:link :rel "stylesheet" :href "https://cdn.simplecss.org/simple.min.css") (:title ,title)) (:header (:nav (:a :style "color:black;" :href "index.html" "Scale Your Violin") (:a :href "about.html" "About") (:a :href "blog.html" "Blog") (:a :href "resonance.html" "Resonance Calculator") (:a :href "contact.html" "Contact"))) (:body ,@body) (:footer "Scale Your Violin " (:a :href "https://www.github.com/Izaakwltn/scale-your-violin" "code at github.com")))))
853
Common Lisp
.lisp
25
29.32
72
0.616687
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
30f66459f26338388687a8aba9189df43c1f7d6203d22d972e760ba5a0c60cc5
21,309
[ -1 ]
21,310
resonance-output.lisp
Izaakwltn_scale-your-violin/www/resonance-output.lisp
;;;;resonance-output.lisp (in-package :scale-your-violin) ;;;;------------------------------------------------------------------------ ;;;;Instrument Assessment ;;;;------------------------------------------------------------------------ (defvar instrument-parse-list '(("violin" (vibratsia::luthier 'violin '(196 293.66 440 659.25))) ("VIOLA" (vibratsia::luthier 'viola '(130.8 196 293.66 440))) ("CELLO" (vibratsia::luthier 'cello '(65.4 98 146.8 220))) ("BASS" (vibratsia::luthier 'bass '(65.4 98 146.8 220))))) (defvar instr-assessment) (hunchentoot::define-easy-handler (instrument-assess :uri "/instrument-assess") (instrument-option) (setf (hunchentoot:content-type*) "text/html") (setq instr-assessment (vibratsia::assess-instrument (eval (second (assoc instrument-option instrument-parse-list :test #'string-equal))))) (with-page (:title "Instrument Resonance Profile") (:header (:h1 "Resonance Calculator") (:h2 "Instrument Assessment") (:p "A comprehensive analysis of the resonant keys and frequencies on the violin. ")) (:section (:h5 (format nil "Instrument name: ~a" (vibratsia::name (vibratsia::instrument instr-assessment))))) (:section (:h5 (format nil "Open-strings:~%")) (:ul (loop for s in (vibratsia::strings (vibratsia::instrument instr-assessment)) do (:li (format nil "~a-~a Frequency: ~a" (vibratsia::note-name s) (vibratsia::octave s) (vibratsia::freq-float s)))))) (:section (:h5 (format nil "Most Resonant Keys:")) (:ul (loop for k in (vibratsia::key-ranks instr-assessment) do (:li (format nil "~a ~a, resonance rating: ~a" (second k) (third k) (first k)))))) (:section (:h5 (format nil "Most Resonant Notes:")) (:ul (loop for n in (vibratsia::note-ranks instr-assessment) do (:li (format nil "~a-~a Frequency: ~a" (vibratsia::note-name (second n)) (vibratsia::octave (second n)) (vibratsia::freq-float (second n))))))) (:button (progn (push (hunchentoot:create-prefix-dispatcher "/resonance.html" #'resonance-calculator) hunchentoot:*dispatch-table*) (:a :href "/resonance.html" "Try another calculation"))))) ;;;;------------------------------------------------------------------------ ;;;;Key Assessment ;;;;------------------------------------------------------------------------ ;(vibratsia::assess-scale (vibratsia::build-scale root-option quality-option ;3) instrument-option) ;(defvar quality-parse-list '(("major" (defun lowest-note-available (note-name instrument) "Finds the lowest octave of a particular note on an instrument" (second (assoc (second (assoc note-name root-parse-list :test #'string-equal)) (mapcar #'(lambda (freq) (list (first (vibratsia::freq-to-note freq)) freq)) (vibratsia::frequency-ladder (vibratsia::lower-bound instrument) (vibratsia::freq-adjust (vibratsia::lower-bound instrument) 11)))))) (defvar key-assessment) (defvar instrument-object) (hunchentoot::define-easy-handler (scale-assess :uri "/key-assess") (root-option quality-option instrument-option) (setf (hunchentoot:content-type*) "text/html") (setq instrument-object (eval (second (assoc instrument-option instrument-parse-list :test #'string-equal)))) (setq key-assessment (vibratsia::assess-scale (vibratsia::build-scale (lowest-note-available root-option instrument-object) (second (assoc quality-option quality-parse-list :test #'string-equal)) 3) instrument-object)) (with-page (:title "Key Resonance Profile") (:header (:h1 "Resonance Calculator") (:h2 "Key Resonance Profile") (:p (format nil "A comprehensive analysis of the key ~a ~a, as played on the ~a" (first (freq-to-note (vibratsia::root (vibratsia::scale key-assessment)))) (vibratsia::quality (vibratsia::scale key-assessment)) (vibratsia::name (vibratsia::instr key-assessment))))) (:section (:h5 (format nil "Average Sympathetic Vibration Rating: ~a" (vibratsia::avg-rating key-assessment)))) (:section (:h5 "The notes of the key ranked by resonance on the chosen instrument:") (:ul (loop for n in (vibratsia::rank-list key-assessment) do (:li (format nil "~a" n))))) (:button (progn (push (hunchentoot:create-prefix-dispatcher "/resonance.html" #'resonance-calculator) hunchentoot:*dispatch-table*) (:a :href "/resonance.html" "Try another calculation"))))) ;;;;find the lowest iteration of the key on the instrument, generate a 3 octave scale, return ;the scale assessment ;;;;------------------------------------------------------------------------ ;;;;Note Assessment ;;;;------------------------------------------------------------------------ (defvar note-assessment) (hunchentoot::define-easy-handler (note-assess :uri "/note-assess") (note-option instrument-option) (setf (hunchentoot:content-type*) "text/html") (setq note-assessment (vibratsia::assess-note (first (freq-to-note (parse-float:parse-float note-option))) (second (freq-to-note (parse-float:parse-float note-option))) (eval (second (assoc instrument-option instrument-parse-list :test #'string-equal))))) (with-page (:title "Instrument Resonance Profile") (:header (:h1 "Resonance Calculator") (:h2 "Note-instrument Assessment") (:p (format nil "A comprehensive analysis of the note, ~a-~a, as played on the ~a" (first (freq-to-note (parse-float:parse-float note-option))) (second (freq-to-note (parse-float:parse-float note-option))) instrument-option))) (:section (:h5 (format nil "Sympathetic Vibration Rating: ~a" (vibratsia::rating note-assessment)))) (:section (:h5 "List of Resonant Frequencies:") (:ul (loop for note in (vibratsia::res-list note-assessment) if (equal (second note) 'string) do (:li (:b (format nil "~a ~a" (first note) (second note)))) else do (:ul (loop for n in note do (:li (format nil "~a" n))))))) (:button (progn (push (hunchentoot:create-prefix-dispatcher "/resonance.html" #'resonance-calculator) hunchentoot:*dispatch-table*) (:a :href "/resonance.html" "Try another calculation")))))
6,369
Common Lisp
.lisp
142
39.788732
99
0.625725
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
87db79129f1a86dad8c2d7094c440c79b02d1fbd38d515a832915e027ba049ce
21,310
[ -1 ]
21,311
index.lisp
Izaakwltn_scale-your-violin/www/index.lisp
;;;;index.lisp (in-package :scale-your-violin) (defun index-page () (with-page (:title "Scale Your Violin") (:header (:h1 "Scale Your Violin")) (:section (:img :src "IMG_0036.JPG" :width "600" :height "auto") (:p "Hello, welcome to Scale Your Violin, a virtual violin studio dedicated to helping students find their best sound, fastest progress, and most effective technique possible!") (:p "Check out the " (:a :href "/blog.html" "blog,")) (:p "check your resonance with the " (:a :href "/resonance.html" "resonance calculator,")) (:p "Or get in touch:") (:p (:a :href "mailto: [email protected]" "[email protected]"))))) (push (hunchentoot:create-prefix-dispatcher "/index.html" #'index-page) hunchentoot:*dispatch-table*)
792
Common Lisp
.lisp
18
39.722222
182
0.668831
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
b2dc2e6f3bc88259df8cdd0c5535ff1c20e161255f77b83f4a151cc1a145703a
21,311
[ -1 ]
21,312
resonance.lisp
Izaakwltn_scale-your-violin/www/resonance.lisp
;;;;resonance.lisp ;;;;Resonance Calculator (in-package :scale-your-violin) ;;;;------------------------------------------------------------------------ (defvar note-option-list (mapcar #'vibratsia::freq-to-note (vibratsia::frequency-ladder 16.35 4185.6))) (defvar instrument-option-list '("violin" "viola" "cello" "bass" "hardingfele")) (defvar instrument-parse-list '(("violin" (vibratsia::luthier 'violin '(196 293.66 440 659.25))) ("VIOLA" (vibratsia::luthier 'viola '(130.8 196 293.66 440))) ("CELLO" (vibratsia::luthier 'cello '(65.4 98 146.8 220))) ("BASS" (vibratsia::luthier 'bass '(65.4 98 146.8 220))) ("hardingfele" (vibratsia::luthier 'hardanger-fiddle vibratsia::hardanger-fiddle-strings)))) (defvar root-option-list '(C C# D D# E F F# G G# A Bb B)) (defvar root-parse-list '(("c" vibratsia::c) ("c#" vibratsia::c#) ("d" vibratsia::d) ("d#" vibratsia::d#) ("e" vibratsia::e) ("f" vibratsia::f) ("f#" vibratsia::f#) ("g" vibratsia::g) ("g#" vibratsia::g#) ("a" vibratsia::a) ("bb" vibratsia::bb) ("b" vibratsia::b))) (defvar quality-parse-list '(("major" vibratsia::major) ("ionian" vibratsia::ionian) ( "dorian" vibratsia::dorian) ("phrygian" vibratsia::phrygian) ("lydian" vibratsia::lydian) ("mixolydian" vibratsia::mixolydian) ("aeolian" vibratsia::aeolian) ("nat-min" vibratsia::nat-min) ("mel-min" vibratsia::mel-min) ("har-min" vibratsia::har-min) ("locrian" vibratsia::locrian))) (defvar quality-option-list '(major ionian dorian phrygian lydian mixolydian aeolian nat-min mel-min har-min locrian)) ;;;;------------------------------------------------------------------------ (defun resonance-calculator () (with-page (:title "Resonance Calculator") (:header (:h1 "Resonance Calculator")) (:section (:p "Every note played on an instrument, or even sung, is actually a composite sound consisting of approximately 32 overtones. On stringed instruments, these overtones can be isolated using harmonics. Sympathetic vibration occurs when the overtones of an executed note overlap with the overtones of an open string. Harmonic nodes, as the overtones are called in string geography, respond to similar frequencies, and vibrate the open string audibly, and sometimes even visually.")) (:section (:h2 "Instrument Assessment") (:p "Select an instrument to calculate its most resonant keys and most resonant notes:") (:form :action "/instrument-assess" :id "instrument-assess" (:select :name "instrument-option" :form "instrument-assess" (loop for instrument in scale-your-violin::instrument-option-list do (:option :value instrument (format nil "~a" instrument)))) (:input :type "submit" :value "Assess Instrument" :class "button"))) (:section (:h3 (:i "Key Assessment")) (:p "Select the tonic, scale quality, and instrument to find the most resonant notes in the key.") (:form :action "/key-assess" :id "key-assess" (:select :name "root-option" :form "key-assess" (loop for r in scale-your-violin::root-option-list do (:option :value r (format nil "~A" r)))) (:select :name "quality-option" :form "key-assess" (loop for qual in scale-your-violin::quality-option-list do (:option :value qual (format nil "~a" qual)))) (:select :name "instrument-option" :form "key-assess" (loop for instrument in scale-your-violin::instrument-option-list do (:option :value instrument (format nil "~a" instrument)))) (:input :type "submit" :value "Assess Key" :class "button"))) (:section (:h2 "Note Assessment") (:p "Select a note and an instrument to calculate the sympathetic frequencies on each string.") (:form :action "/note-assess" :id "note-assess" :method "get" (:select :name "note-option" :form "note-assess" (loop for note in (vibratsia::frequency-ladder 16.35 4185.6) do (:option :value note (format nil "~a-~a" (first (freq-to-note note)) (second (freq-to-note note)))))) (:select :name "instrument-option" :form "note-assess" (loop for instrument in scale-your-violin::instrument-option-list do (:option :value instrument (format nil "~a" instrument)))) (:input :type "submit" :value "Assess Note" :class "button" ))) (:footer (:p "Made using " (:a :href "https://www.github.com/Izaakwltn/vibratsia" "Vibratsia"))))) (push (hunchentoot:create-prefix-dispatcher "/resonance.html" #'resonance-calculator) hunchentoot:*dispatch-table*) ;;;;------------------------------------------------------------------------
4,814
Common Lisp
.lisp
96
44.0625
279
0.626862
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e9d6cb0092a7f4e8ff2870069264fa5d12903528b6303ed1de2991f12723520d
21,312
[ -1 ]
21,313
contact.lisp
Izaakwltn_scale-your-violin/www/contact.lisp
;;;;contact.lisp (in-package :scale-your-violin) (defun contact-page () (with-page (:title "Contact") (:header (:h1 "Contact")) (:section (:h2 "Send me an email at:") (:h3 (:a :href "mailto: [email protected]" "[email protected]"))))) ;(:h2 "Or visit our affiliate website:") ;(:h3 (:a :href "https://www.conservethebow.com" "conservethebow.com"))))) (push (hunchentoot:create-prefix-dispatcher "/contact.html" #'contact-page) hunchentoot:*dispatch-table*)
505
Common Lisp
.lisp
14
32.214286
80
0.657787
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
615582da3cdeefd981f77fe270729fbae1d52b89103aeba431c54ad7da754ec8
21,313
[ -1 ]
21,314
blog.lisp
Izaakwltn_scale-your-violin/www/blog.lisp
;;;;blog.lisp (in-package :scale-your-violin) (defun blog-page () (with-page (:title "Not that Kind of String Theory") (:header (:h1 "Not that Kind of String Theory")) (:section (:h3 "Blog coming soon")))) (push (hunchentoot:create-prefix-dispatcher "/blog.html" #'blog-page) hunchentoot:*dispatch-table*)
331
Common Lisp
.lisp
11
26.818182
64
0.681388
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
3a23b04710f8cc4afe42b2297b7fe50cf8fa92d1c0e8b4cb3641f7f29f7f5762
21,314
[ -1 ]
21,315
about.lisp
Izaakwltn_scale-your-violin/www/about.lisp
;;;;about.lisp (in-package :scale-your-violin) (defun about-page () (with-page (:title "About") (:header (:h1 "About")) (:section (:h3 "Izaak Walton") (:p "Hello! I'm Izaak, a violinist and teacher of violin, viola, and mandolin based out of Denver, CO.") (:br) (:iframe :width "560" :height "315" :src "https://www.youtube.com/embed/heN-QRplYyo" :title "YouTube video player") (:p "As a teacher, I am particularly passionate about helping students find the best sound on their instrument, both through technical setup, ear training, and musical development. Finding a strong, focused sound as a foundation for their further studies can, and will, carry the student far into their musical explorations!") (:p " I received my Bachelors in Violin Performance from the University of Georgia, studying with Levon Ambartsumian, Shakhida Azimkodjaeva, and Dr. Michael Heald, in addition to Raymond Leung of the Atlanta Symphony. In 2017 I moved out here to Denver, receiving my Masters in Violin Performance with Dr. Linda Wang at the University of Denver." )))) (push (hunchentoot:create-prefix-dispatcher "/about.html" #'about-page) hunchentoot:*dispatch-table*)
1,234
Common Lisp
.lisp
18
63.388889
356
0.723001
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
6a373436fe76a20bc39d3de6f9d2bd9bbc4be3d9dfea816d3cff5881214302f2
21,315
[ -1 ]
21,316
teachers.lisp
Izaakwltn_scale-your-violin/www/teachers.lisp
;;;;teachers.lisp (in-package :scale-your-violin) (defun teacher-page () (with-page (:title "Meet the Teachers") (:h1 "Studio Teachers") ;(:br) (:section (:h2 "Izaak Walton") (:h3 "Violin, Viola, and Mandolin") (:img :src "FB_IMG_1573334579763.jpg" :width "300" :height "auto") (:p " Raised in Atlanta in a musical household, Izaak began playing at a young age under his parents’ instruction. He studied in the studios of Levon Ambartsumian, Shakhida Azimkodjaeva, and Dr. Michael Heald at the University of Georgia, and Raymond Leung of the Atlanta Symphony. Izaak graduated in 2015 from the University of Georgia with a degree in Violin Performance and a minor in English. He currently is studying towards his Masters in Violin Performance with Dr. Linda Wang at the University of Denver. On the stage, he has been the second violinist in the Walton String Quartet since 2011, an events quartet based in Atlanta that has performed at various events across the southeast. He has performed with a variety of ensembles, from the Macon Symphony to Origin Creative, a recording orchestra based in Atlanta, GA. While primarily a classical musician, Izaak also dabbles in improvisatory styles, and had the opportunity to perform behind Kishi Bashi at the Georgia Theatre in April of 2014. Izaak has taught around the Atlanta area since 2015, teaching a wide variety of ages, levels, and styles. As a teacher, he is especially passionate about helping students find the best sound on their instrument, both through technical setup and musical development. Finding a strong, focused sound as a foundation for their further studies can, and will, carry the student far into their musical explorations!")) (:br) (:section (:h2 "Alexandra Kagan") (:h3 "Violin and Piano") (:img :src "bestYesDSC02214.JPG" :width "300" :height "auto") (:p "American-born and Russian-raised violinist Alexandra Kagan is an active performer and teacher in the Denver Metropolitan Area, with over 8 years of violin and piano teaching experience. Through the pursuit of her Bachelor’s degree in Violin Performance at DePaul University and her Master’s degree at the University of Denver, Alexandra has studied with such renowned violinists and pedagogues as Olga Kaler, Linda Wang, and Igor Pikayzen, and participated in masterclasses led by Margaret Batjer, Kathleen Winkler, and Richard O’Neal among others. She enjoys performing new music and has premiered numerous works in Chicago and Denver in addition to participating in recording sessions in the Los Angeles and St Petersburg area. As a former member of the St Petersburg-based Violin Ensemble of the Anichkov Palace, Ms Kagan has performed in renowned music halls, such as the Mariinsky Theatre, Smolny Cathedral, St Petersburg Grand Philharmonic Hall, St Petersburg State Capella,Novgorod’s St Sophia Cathedral, Neumarkt’s Reitstadel, Makarska’s Main Square, the Swedish National History Museum in Stockholm, and Dubrovnik, among others.The ensemble won both local and international music competitions and toured France, Sweden, Croatia, and Germany extensively. Alexandra’s violin duet received an Honorable Mention at the Stockholm International Music Competition along with numerous state awards. This chamber music activity lead Alexandra for nomination and winning of the Star of the Palace, award given to the outstanding students of the Anichkov Palace of St Petersburg. Alexandra has experience teaching beginner, intermediate, and advanced students of all ages. In particular, Ms Kagan is passionate about helping students through every stage of the audition process for festivals, schools, and orchestras.") (:h4 (:a :href "https://conservethebow.com/about" "Read More about Alex"))))) (push (hunchentoot:create-prefix-dispatcher "/teachers.html" #'teacher-page) hunchentoot:*dispatch-table*)
3,949
Common Lisp
.lisp
29
131.137931
1,587
0.788011
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
fc2071f390f707cb93b98956242017d5828b97f977a06c73b74ab1ed331b539c
21,316
[ -1 ]
21,317
scale-your-violin.asd
Izaakwltn_scale-your-violin/scale-your-violin.asd
;;;;scale-your-violin.asd ;;;; ;;;;Copyright (c) 2021 Izaak Walton (asdf:defsystem #:scale-your-violin :version "0.0.1" :author "Izaak Walton <[email protected]>" :license "GNU General Purpose License" :description "scaleyourviolin.com" :depends-on (#:parenscript #:spinneret #:hunchentoot #:vibratsia #:parse-float) :serial t :components ((:file "package") (:file "build-that-site") (:file "scale-your-page") (:module "www" :serial t :components ((:file "index") (:file "about") (:file "blog") (:file "contact") (:file "teachers") (:file "resonance") (:file "resonance-output")))))
678
Common Lisp
.asd
22
25.681818
81
0.618321
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
b3dc384b19603434b92d3ed4b1f473af4ba8abb81cb6ac0c508b97495a511298
21,317
[ -1 ]
21,330
index.html
Izaakwltn_scale-your-violin/www/index.html
<html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <title>Scale Your Violin</title> </head> <body> <nav> <button><a href= "index.html">Scale Your Violin</a></button> <button><a href= "contact.html">Contact</a></button> <button><a href= "teachers.html">Teachers</a></button> <button><a href= "resonance.html">Resonance Tool</a></button> </nav> <h1>Scale Your Violin</h1> <p> Hello, welcome to Scale Your Violin, a virtual violin studio dedicated to helping students find their best sound, fastest progress, and most effective technique possible! Look around our site, or get in touch: [email protected]</p> </body> </html>
1,343
Common Lisp
.l
25
35.68
176
0.555465
Izaakwltn/scale-your-violin
2
0
0
MPL-2.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9e19926f7779b35c3077c83f5d779873a79b304998624973f0b75c8554de53fe
21,330
[ -1 ]
21,345
freeipa-master.asd
innaky_freeipa-master/freeipa-master.asd
#| This file is a part of utils project. Copyright (c) 2019 Innaky ([email protected]) |# #| Author: Innaky ([email protected]) |# (defsystem "freeipa-master" :version "0.1.1" :author "Innaky" :license "GPLv3" :depends-on (:cl-launch :cl-scripting :inferior-shell :ip-interfaces :alexandria :cl-ppcre) :components ((:module "src" :components ((:file "freeipa-master")))) :description "Install FreeIPA" :long-description #.(read-file-string (subpathname *load-pathname* "README.md")))
564
Common Lisp
.asd
24
19.5
51
0.66171
innaky/freeipa-master
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
6289f0bfcd7a99f796b9554c4966478e86e4702acb95637dce77c6d60d051073
21,345
[ -1 ]
21,361
math.lisp
alexpalade_such-is-life/src/math.lisp
(cl:in-package :sil-game) (defun rotate-vec (vec angle) (vec2 (- (* (x vec) (cos angle)) (* (y vec) (sin angle))) (+ (* (x vec) (sin angle)) (* (y vec) (cos angle))))) (defun len (vec) (sqrt (+ (expt (x vec) 2) (expt (y vec) 2))))
245
Common Lisp
.lisp
6
37.5
61
0.527426
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f92dcdaf6dd93a013402ba3ea8d309d42c4dfba0eb2470d109feb36f711a2e6d
21,361
[ -1 ]
21,362
person.lisp
alexpalade_such-is-life/src/person.lisp
(cl:in-package :sil-game) (defclass person () ((destination :initform nil :accessor destination) (path :initform nil :accessor path) (target :initform nil :accessor target) (state :initform 'wander :accessor state) (rest-time :initform (+ 0.5 (/ 1 (+ 0.1 (random 10)))) :accessor rest-time) (row :initform nil :accessor row) (col :initform nil :accessor col) (health :initform 100 :accessor health) (sick :initform nil :accessor sick) (gender :initform (nth (random 2) (list 'male 'female)) :accessor gender) (last-cough-time :initform nil :accessor last-cough-time) (last-move-time :initform (/ 1 (1+ (random 10))) :accessor last-move-time))) (defmethod state-p ((this person) state) (equal (state this) state)) (defmethod regular-person-p ((person person)) (not (or (typep person 'police) (typep person 'killer) (typep person 'medic)))) (defmethod become-sick ((this person)) (when (not (sick this)) (play :cough) (setf (last-cough-time this) (real-time-seconds)) (setf (sick this) T))) (defmethod become-healthy ((this person)) (setf (health this) 100) (setf (sick this) nil) (play :heal)) (defmethod cough ((this person)) (decf (health this) *sick-cough-damage*) (setf (last-cough-time this) (real-time-seconds))) (defmethod move-person ((game sil-game) person to-row to-col) (when (and (typep person 'killer) (locked person)) (return-from move-person)) (let ((from-row (row person)) (from-col (col person)) (cells (cells game))) (when (and (typep person 'killer) (in-quarantine-p game from-row from-col) (not (in-quarantine-p game to-row to-col))) (lose-disguise game person) (setf (last-kill-time person) (real-time-seconds))) (setf (aref cells from-row from-col) nil) (setf (aref cells to-row to-col) person) (setf (row person) to-row) (setf (col person) to-col) (setf (last-move-time person) (real-time-seconds)))) (defmethod tick ((game sil-game) (person person)) (when (sick person) (when (> (- (real-time-seconds) (last-cough-time person)) (/ 1 *sick-cough-frequency*)) (cough person) (when (<= (health person) 0) (remove-person game person) (play :death) (return-from tick))) (dolist (near-person (get-near-persons game person)) (when (= 0 (random 500)) (become-sick near-person)))) (with-slots (rest-time last-move-time) person (when (and (state-p person 'wander) (> (- (real-time-seconds) last-move-time) rest-time)) (let* ((to (get-random-move-cell game person)) (to-row (first to)) (to-col (second to))) (when to (setf (rest-time person) (/ (+ 1000 (random 2000)) 1000)) (move-person game person to-row to-col)))))) (defmethod render-avatar ((this person) asset) (with-pushed-canvas () (let* ((width (image-width asset)) (height (image-height asset)) (scale-for (max width height)) (scale (/ (- *cell-size* *cell-padding*) scale-for)) (scaled-cell-size (/ *cell-size* scale))) (when (sick this) (let ((alpha (+ 0.5 (- 0.5 (/ (health this) 100))))) (draw-rect (vec2 0 0) *cell-size* *cell-size* :fill-paint (vec4 0.9 0.1 0.1 alpha)))) (scale-canvas scale scale) (draw-image (vec2 (- (/ scaled-cell-size 2) (/ width 2)) (- (/ scaled-cell-size 2) (/ height 2))) asset)))) (defmethod render ((person person)) (if (equal (gender person) 'female) (render-avatar person :person-female) (render-avatar person :person-male)))
3,736
Common Lisp
.lisp
89
35.325843
91
0.615109
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
db3684d4e5ae53818f1258ec882544c6a03edb2613202e6e6df62ea6475a8875
21,362
[ -1 ]
21,363
util.lisp
alexpalade_such-is-life/src/util.lisp
(cl:in-package :sil-game) (defmacro random-nth (lst) `(when ,lst (nth (random (length ,lst)) ,lst))) (defun asset-path (pathname) (asdf:system-relative-pathname :sil-game (merge-pathnames pathname "assets/"))) (defun valid-cell (row col num-rows num-cols) (and (>= row 0) (>= col 0) (< row num-rows) (< col num-cols))) (defun invalid-cell (row col num-rows num-cols) (not (valid-cell row col num-rows num-cols))) (defun get-near-cells (row col num-rows num-cols) (remove-if (lambda (xy) (invalid-cell (first xy) (second xy) num-rows num-cols)) (map 'list (lambda (d) (list (+ row (first d)) (+ col (second d)))) (list '(0 1) '(1 1) '(1 0) '(1 -1) '(0 -1) '(-1 -1) '(-1 0) '(-1 1)))))
762
Common Lisp
.lisp
21
31.571429
81
0.586957
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
6969cd0f6f99041a4acf6e741df9bc792bd9877c65f79f0d61b0e496e74c510b
21,363
[ -1 ]