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
15,380
indigo.tests.lisp
olewhalehunter_indigo-lisp/indigo.tests.lisp
(in-package :indigo.tests) (defun run-tests () (if (prove:run #P"test/tree.lisp" :reporter :tap) t nil))
108
Common Lisp
.lisp
3
34
59
0.682692
olewhalehunter/indigo-lisp
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
153347e2aeffebef2fbf24e2e7f7af1ef49af95e6f493d6e4908f4b78e41b98c
15,380
[ -1 ]
15,381
tree.lisp
olewhalehunter_indigo-lisp/test/tree.lisp
(in-package :indigo.tests) (plan nil) (subtest "Testing Definitions" (ok (data Tree Empty (Leaf Integer) (Branch Tree Tree)) ) (ok (def depth Empty 0 (Leaf n) 1 (Branch l r) (+ 1 (max (depth l) (depth r)))) )) (subtest "Testing Type Predicates" (ok (typep Empty 'Tree)) (ok (typep (Leaf 4) 'Tree)) (ok (typep (Branch (Leaf 2) (Leaf 4)) 'Tree)) (ok (typep (Branch Empty Empty) 'Tree)) ) (subtest "Testing Type Checks" (is-error (Leaf "foo") 'type-error) (is-error (Branch 1 1) 'type-error) (is-error (Branch Empty (Leaf "bar")) 'type-error) ) (subtest "Testing Pattern Matched Function" (is (depth Empty) 0) (is (depth (Leaf 7)) 1) (is (depth (Branch Empty Empty)) 1) (is (depth (Branch (Leaf 4) (Leaf 5))) 2) (is (depth (Branch (Branch (Leaf 1) (Leaf 2)) (Leaf 3))) 3) (is (depth (Branch (Branch Empty Empty) (Leaf 1))) 2) ) (finalize)
930
Common Lisp
.lisp
36
22.222222
61
0.616516
olewhalehunter/indigo-lisp
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
8fa0e852afeef061de4b8f3003c324a37e8522641392098f9e1109b37b26058d
15,381
[ -1 ]
15,382
indigo.asd
olewhalehunter_indigo-lisp/indigo.asd
(asdf:defsystem :indigo :version "0.0.1" :description "Algebraic Data Types, Pattern Matching, and Strong Static Typing on Common Lisp." :author "Anders Puckett <[email protected]>" :license "GNU AGPLv3" :serial t :depends-on ("gambol") :components ((:file "indigo") (:file "typing")) ) (asdf:defsystem :indigo.tests :serial t :depends-on ("indigo" "prove") :components ((:file "indigo.tests")) )
463
Common Lisp
.asd
15
26
99
0.662132
olewhalehunter/indigo-lisp
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
502d03a5fcb04f0aa3389ce926377dc4ba27fd8162802b47dd92db735cc9e86b
15,382
[ -1 ]
15,403
operators.lisp
jollheef_cl-logic/operators.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) ;;; Определение элементарных булевых функций (defun ¬ (p) "Инверсия, uac" (not p)) (defun ∧ (p q) "Конъюнкция, u2227" (and p q)) (defun ∨ (p q) "Дизъюнкция, u2228" (or p q)) (defun → (p q) "Импликация, u2192" (or (not p) q)) (defun ⊕ (p q) "Сложение по модулю 2, u2295" (not (equal p q))) (defun ∼ (p q) "Эквивалентность, u223c" (equal p q)) (defun ↑ (p q) "Штрих Шеффера, u2191" (not (and p q))) (defun ↓ (p q) "Стрелка Пирса, u2193" (not (or p q))) (defun ∀ (p list) "Предикат всеобщности" (every p list)) (defun ∃ (p list) "Предикат существования" (some p list)) (defun help-operators () (format t "¬~%∧~%∨~%→~%⊕~%∼~%↑~%↓~%") (format t "¬ \\uac~%") (format t "∧ \\u2227~%") (format t "∨ \\u2228~%") (format t "→ \\u2192~%") (format t "⊕ \\u2295~%") (format t "∼ \\u223c~%") (format t "↑ \\u2191~%") (format t "↓ \\u2193~%"))
1,305
Common Lisp
.lisp
27
38.037037
63
0.604207
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
5404f3156e73fc24197d0531067e0a7cca1f7f7e7e3db4efc80ce61341d6a986
15,403
[ -1 ]
15,404
boolean-simplify.lisp
jollheef_cl-logic/boolean-simplify.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package :cl-logic) (defun boolean-terms (vector) (remove nil (loop for i in vector for n from 0 collect (if i n)))) (defun convert-raw-string-to-boolean (raw-string) (append '(∧) (loop for i across raw-string for n from 0 collect (let ((var (intern (string (char+ #\a n))))) (cond ((equalp i #\1) var) ((equalp i #\0) (list '¬ var))))))) (defun convert-raw-list-to-boolean (raw-list) (loop for disj in raw-list collect (remove nil (convert-raw-string-to-boolean disj)))) (defun boolean-simplify-raw (result-vector) (quine-mccluskey:quine-mccluskey (concatenate 'string (loop for i from 0 repeat (log (length result-vector) 2) collect (char+ #\a i))) (boolean-terms result-vector))) (defun boolean-simplify-vector (vector) (if (numberp (car vector)) (setf vector (map 'list (lambda (x) (if (equalp x 1) t nil)) vector))) (prefix->infix (append '(∨) (convert-raw-list-to-boolean (nth-value 1 (boolean-simplify-raw vector)))))) (defun boolean-simplify (function) (boolean-simplify-vector (result-vector function)))
1,312
Common Lisp
.lisp
33
35.909091
68
0.67719
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
0e74399f84c06fe171430b5414563e73f86af2fc3551853cc80603ceac1d3fe3
15,404
[ -1 ]
15,405
package.lisp
jollheef_cl-logic/package.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (defpackage #:cl-logic (:use #:cl) (:export #:infix->prefix)) (defpackage #:quine-mccluskey (:nicknames "qm") (:use #:cl) (:export #:quine-mccluskey))
365
Common Lisp
.lisp
12
28.416667
62
0.68661
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
fae996514144e5f471d70623fc71be1ee5dbc36bf4b77fe12b05c1380d36392c
15,405
[ -1 ]
15,406
cl-logic.lisp
jollheef_cl-logic/cl-logic.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) (defun boolean-table (nvars) "Генерирует таблицу значений для nvars переменных" (loop for i from 0 to (1- (expt 2 nvars)) collect (append-to-length (int->bool-list i) nvars nil))) (defun truth-table (function) "Генерирует таблицу истинности функции" (map 'list (lambda (args) (list args (apply function args))) (boolean-table (nvars function)))) (defun result-vector (function) "Возвращает вектор значений функции" (map 'list 'cadr (truth-table function))) (defun print-chars (n) "Выводит символы в виде x, y, z \dots" (loop for i from 0 to (1- n) do (format t "~c " (char+ #\a i)))) (defun truth-table-print (function) "Вывод таблицы истинности для функции" (print-chars (nvars function)) (format t " ~s~%" function) (loop for line in (truth-table function) do (map 'list (lambda (l) (format t "~d " (bool->int l))) (car line)) (format t "-> ~d~%" (bool->int (cadr line))))) (defun equivalent (functions) (apply 'equalp (map 'list (lambda (func) (result-vector func)) functions))) (defun general-validity-p (function) (let ((result-vector (result-vector function))) (equalp (length result-vector) (apply '+ (map 'list 'bool->int result-vector))))) (defun tautology (functions) (if (listp functions) (equivalent functions)) (general-validity-p functions))
1,729
Common Lisp
.lisp
38
38.078947
73
0.683901
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
749bba763c16ab0cbf6a05b202bff5b091547b49355865ade4607de34c55feb7
15,406
[ -1 ]
15,407
shortcuts.lisp
jollheef_cl-logic/shortcuts.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package :cl-logic) ;;; Вспомогательные функции (defun int->bool (char) "Переводит из двоичной формы в булеву" (if (equalp (parse-integer (string char)) 0) nil t)) (defun nvars (function) "Количество переменных для функции" (length (sb-introspect:function-lambda-list function))) (defun bool->int (bool) "Переводит из булевой формы в двоичную" (if bool 1 0)) (defun gen-list (obj n) "Генерирует список размера n из объект obj" (if (plusp n) (append (list obj) (gen-list obj (1- n))))) (defun int->bool-list (int) "Переводит число из десятичной системы в список булевых" (map 'list (lambda (char) (int->bool char)) (format nil "~b" int))) (defun append-to-length (list int obj) "Добавляет объект obj к списку list до длины int" (append (gen-list obj (- int (length list))) list)) (defun char+ (char &optional (n 1)) "Возвращает следующий либо char+n символ в таблице" (code-char (+ (char-code char) n))) (defun newline () "Переход на новую строку" (format t "~%")) (defun strcat (&rest strings) (apply 'concatenate 'string strings)) (defun boolean-list->binary-str (list) (apply 'strcat (loop for i in list collect (if i "1" "0")))) (defun int->bool-bin-list (n) (mapcar 'bool->int (int->bool-list n)))
1,745
Common Lisp
.lisp
38
36.026316
69
0.69894
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
77b32c812c9d070318e903fbc02dcf0365ac8ce6ad31532713dc48c72fd7ae7c
15,407
[ -1 ]
15,408
dual.lisp
jollheef_cl-logic/dual.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) ;;; Двойственная функция (defun map-recursive (func list) (loop for i in list collect (if (listp i) (map-recursive func i) (apply func (list i))))) (defun dual (listfunc) (map-recursive (lambda (x) (cond ((equal x '∧) '∨) ((equal x '∨) '∧) ((equal x '↑) '↓) ((equal x '↓) '↑) ((equal x '⊕) '∼) ((equal x '∼) '⊕) ((equal x 't) 'nil) ((equal (string x) "NIL") 't) (t x))) listfunc)) (defun dual-infix (listfunc) (dual (infix->prefix listfunc)))
760
Common Lisp
.lisp
26
24.730769
62
0.610787
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b14d6d9dde2cf13612c3bf80c8601290414ffa6a66edaba6de52522778f2d614
15,408
[ -1 ]
15,409
infix.lisp
jollheef_cl-logic/infix.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) (defvar *separators* '(↓ ↑ ∼ ⊕ → ∨ ∧ ¬) "Операторы по убыванию приоритета.") (defun remove-brackets (lst) "Reduses lists with just one item to the item itself" (do ((result lst (car result))) ((or (not (consp result)) (not (null (cdr result)))) result))) (defun separate-list (lst separator test) "Returns list of sub-sequences defined by separator" (if (not (consp lst)) lst (let ((result (cons separator nil)) (end 0) (sub) (lst (if (funcall test (car lst) separator) (cdr lst) lst))) (do () ((null lst) result) (setf end (position separator lst :test test)) (setf sub (cons (subseq lst 0 end) nil)) (setf result (append result sub)) (setf lst (if end (nthcdr (+ 1 end) lst) nil))) (setf (cdr result) (mapcar #'remove-brackets (cdr result))) result))) (defun separate-tree (lst separator test) "Apply separate-list on all sublists" (if (or (not (consp lst)) (eql (first lst) 'quote)) lst (progn (setf lst (mapcar #'(lambda (x) (if (not (consp x)) x (separate-tree x separator test))) lst)) (if (not (find separator (rest lst))) lst (separate-list lst separator test))))) (defun infix->prefix-optimized (infix-expr &optional (separators *separators*) (test #'eql)) "Переходит от инфиксной записи к префиксной" (let ((result infix-expr)) (dolist (sep separators) (setf result (separate-tree result sep test))) (remove-brackets result))) (defun only-two-arg (prefix-expression) (defun op2 (lst func) "Преобразует список вида '(+ 1 2 3 4) в '(+ 1 (+ 2 (+ 3 4)))" (setf lst (map 'list (lambda (l) (if (and l (listp l)) (op2 (cdr l) (car l)) l)) lst)) (if (> (length lst) 2) (list func (op2 (cdr lst) func) (car lst)) (append (list func) lst))) (op2 (cdr prefix-expression) (car prefix-expression))) (defun append-func (func list) (only-two-arg (append (list func) list))) (defun infix->prefix (infix-expr &optional (separators *separators*) (test #'eql)) (only-two-arg (infix->prefix-optimized infix-expr separators test))) ;;; PREFIX->INFIX (defun insert-between (lst sep) (if (or (not (consp lst)) (not (rest lst))) lst (cons (first lst) (mapcan #'(lambda (x) (list sep x)) (rest lst))))) (defun prefix->infix (prefix-expr &optional (separators *separators*) (test #'eql)) "Converts a prefix expression to infix" (let ((in-expr (mapcar #'(lambda (x) (remove-brackets (if (and (listp x) (not (equalp (car x) '¬))) (prefix->infix x separators) x))) prefix-expr))) (if (or (not (listp in-expr)) (not (member (first in-expr) separators :test test))) in-expr (insert-between (rest in-expr) (first in-expr)))))
3,186
Common Lisp
.lisp
97
27.154639
74
0.624242
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
ea074807ffc74101d66e018049509e8651c6665aeb5406420d6328da0ea93748
15,409
[ -1 ]
15,410
def.lisp
jollheef_cl-logic/def.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) ;; Определение булевых функций (defun symbol-lessp (symbol1 symbol2) (string-lessp (string symbol1) (string symbol2))) (defun get-symbols (list) (loop for seq in (cdr list) collect (if (listp seq) (get-symbols seq) seq))) (defun get-args (list) (let ((args-list '())) (defun args (lst) (loop for i in lst do (if (listp i) (args i) (if (not (or (equal i 't) (equal i 'nil))) (push i args-list))))) (args (get-symbols list)) (sort (remove-duplicates args-list) 'symbol-lessp))) (defmacro def-infix (name body) (let ((lfunc (infix->prefix body))) `(defun ,name ,(get-args lfunc) ,lfunc))) (defmacro def (name body) `(defun ,name ,(get-args body) ,body)) (defmacro def-dual-infix (name body) (let ((lfunc (dual-infix body))) `(defun ,name ,(get-args lfunc) ,lfunc)))
1,100
Common Lisp
.lisp
32
29.90625
62
0.649275
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
5de37a256b0a9bd0166aaa532a71397ffd444bc75250fa2ad503e8b3de58e608
15,410
[ -1 ]
15,411
bool-structs.lisp
jollheef_cl-logic/bool-structs.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) ;; Булевы структуры (defun describe-boolean-cube (n) (let ((boolean-table (boolean-table n))) (loop for i to n do (loop for j in boolean-table do (if (equalp (count 't j) i) (format t "~A " (boolean-list->binary-str j)))) (newline))))
500
Common Lisp
.lisp
14
31.928571
62
0.673077
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
d9d2f535e9a863b34ed729fd7e572c627942818bf0668fdf48bfa5c8f7f4178d
15,411
[ -1 ]
15,412
form.lisp
jollheef_cl-logic/form.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) ;;; Полином жегалкина (алгебраическая нормальная форма) (defun anf-conversion (list) (loop for i to (1- (length list)) collect (let ((var (intern (string (char+ #\a i))))) (if (nth i list) var (list '⊕ var t))))) (defun anf-disjuncts (vector) (let ((table (boolean-table (log (length vector) 2 )))) (loop for i to (length vector) collect (if (equalp (nth i vector) 1) (append-func '∧ (anf-conversion (nth i table))))))) (defun result-vector->anf (vector) (append-func '⊕ (remove 'nil (anf-disjuncts vector)))) (defun ->anf (func) (result-vector->anf (map 'list 'bool->int (result-vector func)))) ;;; Дизъюнктивная нормальная форма (defun pdnf-conversion (list) (loop for i to (1- (length list)) collect (let ((var (intern (string (char+ #\a i))))) (if (nth i list) var (list '¬ var))))) (defun pdnf-disjuncts (vector) (let ((table (boolean-table (log (length vector) 2 )))) (loop for i to (length vector) collect (if (equalp (nth i vector) 1) (append-func '∧ (pdnf-conversion (nth i table))))))) (defun result-vector->perfect-dnf (vector) (append-func '∨ (remove 'nil (pdnf-disjuncts vector)))) (defun ->dnf (func) (result-vector->perfect-dnf (map 'list 'bool->int (result-vector func)))) ;;; Конъюктивная нормальная форма (defun pcnf-conversion (list) (loop for i to (1- (length list)) collect (let ((var (intern (string (char+ #\a i))))) (if (nth i list) (list '¬ var) var)))) (defun pcnf-conjuncts (vector) (let ((table (boolean-table (log (length vector) 2 )))) (loop for i to (length vector) collect (if (equalp (nth i vector) 0) (append-func '∨ (pcnf-conversion (nth i table))))))) (defun result-vector->perfect-cnf (vector) (append-func '∧ (remove 'nil (pcnf-conjuncts vector)))) (defun ->cnf (func) (result-vector->perfect-cnf (map 'list 'bool->int (result-vector func))))
2,232
Common Lisp
.lisp
50
39.14
67
0.660488
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
436f8accded2d06e78cb022c4ba41251d932ca683c937827867f0f2db30c3e08
15,412
[ -1 ]
15,413
combinator.lisp
jollheef_cl-logic/combinator.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package #:cl-logic) (defun all-permutations (lst &optional (remain lst)) (cond ((null remain) nil) ((null (rest lst)) (list lst)) (t (append (mapcar (lambda (l) (cons (first lst) l)) (all-permutations (rest lst))) (all-permutations (append (rest lst) (list (first lst))) (rest remain)))))) (defun permute (n) (all-permutations (loop for i from 1 to n collect i))) (defun rand-permute (n) (alexandria:shuffle (loop for i from 1 to n collect i))) (defun mul-perms-assoc (zlist var) (if (not (null zlist)) (let ((associated (assoc var zlist))) (append (list (car associated)) (if (null associated) (mul-perms-assoc zlist (caar zlist)) (mul-perms-assoc (remove associated zlist) (cadr associated))))))) (defun mul-perms (flist slist) (let ((zlist (mapcar 'list flist slist))) (remove nil (mul-perms-assoc zlist (caar zlist))))) (defun perms-commutativityp (f s) (equalp (mul-perms f s) (mul-perms s f))) (defun perms-groupp (list) (let ((sorted-list (map 'list (lambda (x) (sort x '>)) list))) (equalp (count (car sorted-list) sorted-list :test 'equalp) (length list))))
1,401
Common Lisp
.lisp
35
35.371429
87
0.645803
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
80aee3abd300aac328566f76e1310d9fb10a162d36aa01bc63875f6123bd3cd0
15,413
[ -1 ]
15,414
random-bool.lisp
jollheef_cl-logic/random-bool.lisp
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (in-package :cl-logic) (defun random-bool-func (nvars &optional (form 'dnf)) (if (< nvars 2) (error "nvars cannot less than 2")) (let ((vector (loop for i from 1 to (expt 2 nvars) collect (random 2)))) (cond ((equalp form 'dnf) (result-vector->perfect-dnf vector)) ((equalp form 'cnf) (result-vector->perfect-cnf vector)) ((equalp form 'anf) (result-vector->anf vector)) (t (error "Sorry, form ~s not implemented." form)))))
646
Common Lisp
.lisp
13
47.230769
74
0.684628
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
fb4dfb6c54d14cabb50c4fe9bd51eb979595611f9680b1211428d1cc8f30750e
15,414
[ -1 ]
15,415
cl-logic.asd
jollheef_cl-logic/cl-logic.asd
;;;; This file is part of the cl-logic library, released under ;;;; GNU General Public License, Version 3.0 ;;;; See file COPYING for details. ;;;; ;;;; Author: Klementyev Mikhail <[email protected]> (asdf:defsystem #:cl-logic :serial t :description "Boolean algebra package" :author "Mikhail Klementyev <[email protected]>" :license "GNU GPLv3" :depends-on (:quine-mccluskey :alexandria #+sbcl :sb-introspect) :components ((:static-file "COPYING") (:file "package") (:file "cl-logic" :depends-on ("package")) (:file "def" :depends-on ("package")) (:file "dual" :depends-on ("package")) (:file "infix" :depends-on ("package")) (:file "operators" :depends-on ("package")) (:file "shortcuts" :depends-on ("package")) (:file "form" :depends-on ("package")) (:file "bool-structs" :depends-on ("package")) (:file "boolean-simplify" :depends-on ("package")) (:file "random-bool" :depends-on ("package")) (:file "combinator" :depends-on ("package")))) (asdf:defsystem :quine-mccluskey :author ("Ritchie Cai") :maintainer "Ritchie Cai" :description "Quine-McCluskey method implementation" :components ((:file "package") (:file "quine-mccluskey" :depends-on ("package"))))
1,327
Common Lisp
.asd
32
35.5
68
0.62877
jollheef/cl-logic
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
c262f955381eb01d04b71902d70d656fb2a08cd93a386be41309c7456863eb9a
15,415
[ -1 ]
15,444
cl-autologger.lisp
ashok-khanna_autologger/cl-autologger.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;; ************************************************************************* ;;;; AUTHORS ;;;; <AK> Ashok Khanna <[email protected]> ;;;; MODIFICATIONS ;;;; 2021-09-24 <AK> Initial Version ;;;; BUGS ;;;; Logging functions when not in IBCL causes errors ;;;; Logged functions cannot have &key, &optional and &rest parameters as ;;;; we use a funcall/lambda in LOG-DEFUN and such arguments cannot be easily ;;;; spliced into the funcall [We will try and modify in the future to allow this] ;;;; Only logs functions, not macros (no type check currently applied to ;;;; prevent this) ;;;; Does not have full code walker, so when trying to collect all functions ;;;; within a function, any variables that appear in the CAR of a list, ;;;; e.g. (let ((A ...) will spuriously be collected if they are also ;;;; bound to a function at the top-level) ;;;; LEGAL ;;;; AGPL3 ;;;; ;;;; This program is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU Affero General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU Affero General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Affero General Public License ;;;; along with this program. If not, see <http://www.gnu.org/licenses/> ;;;; ************************************************************************* (defpackage :autologger (:use :ibcl) (:shadow :log) (:export :log :unlog :unlog-all :launch :select-logs :all-logs :log-all-within :autolaunch) (:nicknames :log) (:documentation " [To Add].")) (in-package :autologger) ;;; 0.0 Special Variables ;;; ************************************************************************* (defparameter *logged-functions* (make-hash-table) "Hash table of functions being logged (key) and their source definitions prior to tranformation by autologger (value).") (defparameter *flat-list* nil "A flat list of logging results, together with their nesting level within the function call. Emacs front-end manipulates this to present nested logging results.") (defparameter *counter* 0 "Counter reflecting position of logged function call within its parent function.") ;; Note that we use vector not lists simply because I wanted to learn ;; how to use vectors in my code (defparameter *levels* (make-array 1 :fill-pointer 0 :adjustable t) "Vector reflecting nested position of logged function call. For example, #(1 2 3) is the third function logged within the second function logged within the first function logged within the top-level function call.") ;; Technically DEFUN is a macro and also not a higher order function ;; However, for our purposes we include it in the below because we want ;; to pick up name in (DEFUN name ...) (defvar *higher-order-cl-functions* (list 'funcall 'apply 'mapcar 'mapc 'defun 'maplist 'mapcan 'mapcon 'mapl) "Partial list of functions that accept a function as their first argument.") ;; Thanks to PJB (defparameter *cl-functions* (let ((macros nil) (funs nil) (specops nil)) (declare (ignore macros)) (declare (ignore specops)) (do-external-symbols (s "CL") (cond ((special-operator-p s) (push s funs)) ((macro-function s) (push s funs)) ((fboundp s) (push s funs)))) funs) "List of standard CL functions (refer DEFPARAMETER form below).") ;;; 1.0 Primary Logging Function ;;; ************************************************************************* (defmacro log-defun (name parameters &body body) "Transforms supplied source code into an equivalent function that logs its arguments and results into global variable *flat-list*." `(defun ,name ,parameters (incf *counter*) (let ((*levels* (generate-logging-level *levels* *counter*)) (*counter* 0)) (let ((result (funcall (lambda (*counter* *levels* ,@parameters) ,@body) *counter* *levels* ,@parameters))) (push-to-log *levels* ',name ',parameters ',body (list ,@parameters) result) result)))) (defun generate-logging-level (levels counter) "Generate a new logging level by appending counter to the existing level." (let ((x (copy-adjustable-vector levels))) (vector-push-extend counter x) x)) (defun push-to-log (logging-level function-name function-parameters function-body function-arguments function-result) "Pushes logging data to *flat-list* as strings (except logging-level, which is a list). We use lists here vs. a structure as we transfer this data to Emacs via Swank." (push (cons (vector-to-list logging-level) (list function-name function-parameters function-body (mapcar (lambda (a) (write-to-string a)) function-arguments) (write-to-string function-result))) *flat-list*)) ;;; 2.0 Exported Functions ;;; ************************************************************************* ;; Autologger is typically called from top-level ;; (defun autolaunch (expr) ;; "A crude autolauncher that clears all logging, then logs all loggable functions within EXPR, launches and then unlogs all again." ;; (unlog-all) ;; (log-all-within (car 'expr)) ;; (launch expr) ;; (unlog-all)) (defmacro launch (expr) "Evalautes an expression and then displays logging results within an Autologger Buffer." `(progn (reset-log-data) (let ((result ,expr)) (swank::eval-in-emacs `(autologger-create-buffer ',*flat-list*)) result))) (defun log (&rest symbols) "Add a function to the *logged-functions* table unless it already is there. Store its unlogged source code within the hash table." (loop for symbol in symbols do (unless (gethash symbol *logged-functions*) (let ((source-def (ibcl:source symbol :function))) (unless (or (contains-lambda-list-keywords source-def) (check-null source-def)) (setf (gethash symbol *logged-functions*) source-def) (eval `(log-defun ,(second source-def) ,(third source-def) ,@(nthcdr 3 source-def)))))))) (defun unlog (&rest symbols) "Remove a function from the *logged-functions* table and reset it to its old definition (prior to transformation to include logging)." (loop for symbol in symbols do (progn (let ((orig-source (gethash symbol *logged-functions*))) (eval `(ibcl:defun ,(second orig-source) ,(third orig-source) ,@(nthcdr 3 orig-source)))) (remhash symbol *logged-functions*)))) (defun log-all-within (&rest symbols) "Turn logging on for all user-defined top-level functions within FUNCTION-NAME." (loop for function-name in symbols do (let ((function-symbols (get-functions-in-definition function-name))) (apply #'log function-symbols)))) (defun unlog-all () "Unlog all functions in *logged-functions*." (loop for key being the hash-keys of *logged-functions* do (unlog key)) (print "All logged functions cleared.")) (defun select-logs (function-name) "Extract all user-defined top-level functions within FUNCTION-NAME and render Autologger's Emacs Menu Buffer." (let ((function-symbols (get-functions-in-definition function-name))) (let ((log-symbols-list (log-symbols-list function-name function-symbols))) (print log-symbols-list) (swank::eval-in-emacs `(autologger-create-menu-buffer ',log-symbols-list))))) (defun all-logs () "Extract all logged functions found in *logged-functions* and render Autologger's Emacs Menu Buffer." (let ((log-symbols-list (log-symbols-list "all-logs" (hash-keys *logged-functions*)))) (swank::eval-in-emacs `(autologger-create-menu-buffer ',log-symbols-list)))) ;;; 3.0 Internal Functions ;;; ************************************************************************* (defun contains-lambda-list-keywords (source-def) "Returns T if function's lambda list contains lambda list keywords and prints this to screen." (when (loop for item in (third source-def) thereis (find item '(&key &rest &optional) :test #'symbol-name-equal-p)) (format t "Cannot log ~s due to presence of lambda-list keywords (&key, &rest and/or &optional)~%" (second source-def)) t)) (defun check-null (source-def) "Returns T if function source definition cannot be found in IBCL." (when (null source-def) (format t "Cannot log ~s as unable to find source definition in IBCL~%" (second source-def)) t)) (defun reset-log-data () "Reset global variables used for logging to their starting values." (setf *flat-list* nil) (setf *counter* 0) (setf *levels* (make-array 1 :fill-pointer 0 :adjustable t))) (defun get-functions-in-definition (function-symbol) (let ((function-definition (or (gethash function-symbol *logged-functions*) (source function-symbol :function)))) (let ((collected-functions nil)) (declare (special collected-functions)) (recursive-collect-functions function-definition) (keep-only-user-functions collected-functions)))) (defun keep-only-user-functions (collected-functions) "Remove all symbols that are not user-defined top-level functions and also any duplicates." (remove-duplicates (remove-if-not #'(lambda (a) (and (fboundp a) (not (macro-function a)))) collected-functions))) (defun recursive-collect-functions (fn-list) (declare (special collected-functions)) (cond ((null fn-list) nil) ((atom fn-list) nil) ((listp (car fn-list))(recurse-collect-functions fn-list)) ((higher-order-cl-function-p (car fn-list)) (cond ((listp (second fn-list)) (recurse-collect-functions-cdr fn-list)) ((cl-function-p (second fn-list)) (recurse-collect-functions-cddr fn-list)) (t (push (cadr fn-list) collected-functions) (recurse-collect-functions-cddr fn-list)))) ((cl-function-p (car fn-list)) (recurse-collect-functions-cdr fn-list)) (t (push (car fn-list) collected-functions) (recurse-collect-functions-cdr fn-list)))) (defun recurse-collect-functions (fn-list) "Recurse RECURSIVE-COLLECT-FUNCTION across all items in FN-LIST. When the CAR of FN-LIST is a list itself, then we treat all items of FN-LIST as forms that potentially contain functions and hence we recurse across all items of FN-LIST." (declare (special collected-functions)) (loop for item in fn-list do (recursive-collect-functions item))) (defun recurse-collect-functions-cdr (fn-list) "Recurse RECURSIVE-COLLECT-FUNCTION across all items in FN-LIST except first. When the CAR of FN-LIST is an atom, we analyse it for whether it is a user-defined top-level funciton, and (regardless of the outcome of that analysis) recurse down the remaining items of FN-LIST which are the arguments to the CAR of the FN-LIST and themselves may be forms containing functions." (declare (special collected-functions)) (loop for item in (cdr fn-list) do (recursive-collect-functions item))) (defun recurse-collect-functions-cddr (fn-list) "Recurse RECURSIVE-COLLECT-FUNCTION across all items in FN-LIST except first two. When the CAR of FN-LIST is a higher order function, we analyse the second item of FN-LIST. If that is an atom, we need to recurse down all the items of FN-LIST after the second." (declare (special collected-functions)) (loop for item in (cddr fn-list) do (recursive-collect-functions item))) (defun higher-order-cl-function-p (symbol) "Returns true/false on whether SYMBOL represents a standard CL function." (find symbol *higher-order-cl-functions* :test #'symbol-name-equal-p)) (defun cl-function-p (symbol) "Returns true/false on whether SYMBOL represents a standard CL function." (find symbol *cl-functions* :test #'symbol-name-equal-p)) (defun log-symbols-list (function-name function-symbols) "Destructures a list of function symbols associated with a function (see GET-FUNCTIONS-IN-DEFINITION) into strings that can be parsed by Emacs Autologger Buffer." (cons (write-to-string function-name) (loop for symbol in function-symbols collect (cons (destructure-symbol symbol) (hash-exists symbol *logged-functions*))))) (defun destructure-symbol (symbol) "Destructure SYMBOL into a list of SYMBOL-NAME, PACKAGE-NAME and STATUS." (list (symbol-name symbol) (package-name (symbol-package symbol)) (multiple-value-bind (name status) (find-symbol (symbol-name symbol) (symbol-package symbol)) (declare (ignore name)) (write-to-string status)))) (defun hash-exists (key table) "Returns true/false on whether a hash entry exists for KEY in TABLE." (when (gethash key table) t)) ;; We keep this internal as we only call it from Emacs and users ;; shouldn't have a reason to call it directly (defun set-function-logs (emacs-symbol-data-list) "Modify logging state for functions supplied by Emacs Autologger Menu Buffer." (print emacs-symbol-data-list) (loop for item in emacs-symbol-data-list do (destructuring-bind ((name package) . log-status) item (let ((function-symbol (find-symbol name package))) (if (equal log-status ":yes-log") (unless (gethash function-symbol *logged-functions*) (when (fboundp function-symbol) (log function-symbol))) (when (gethash function-symbol *logged-functions*) (unlog function-symbol))))))) ;;; 4.0 Helper Functions ;;; ************************************************************************* (defun symbol-name-equal-p (a b) "Test if A and B have the same symbol name." (when (and (symbolp a) (symbolp b)) (equal (symbol-name a) (symbol-name b)))) (defun copy-adjustable-vector (vector) "Make a copy of VECTOR." (map-into (make-array (array-dimensions vector) :adjustable (adjustable-array-p vector) :fill-pointer (fill-pointer vector)) #'copy-tree vector)) (defun vector-to-list (vector) "Convert VECTOR to a list." (coerce vector 'list)) (defun hash-keys (hash-table) "Return the keys of HASH-TABLE." (loop for key being the hash-keys of hash-table collect key))
14,257
Common Lisp
.lisp
284
46.957746
134
0.697419
ashok-khanna/autologger
5
0
4
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
25cbb3bee25180024980222ea31a6f339f3b5b37092fff1e4fd547547917835d
15,444
[ -1 ]
15,445
autologger.asd
ashok-khanna_autologger/autologger.asd
(defsystem "autologger" :description "Autologger: A Simple Logging Tool" :version "0.0.1" :author "Ashok Khanna <[email protected]>" :license "AGPL" :depends-on ("com.informatimago.common-lisp.lisp.ibcl") :serial t :components ((:file "cl-autologger")) :in-order-to ((test-op (test-op :autologger-test))))
329
Common Lisp
.asd
9
33.777778
57
0.7125
ashok-khanna/autologger
5
0
4
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
4b26d46223f9186067132b444e024b5fb21d954644090c1054a963de7add2e4d
15,445
[ -1 ]
15,447
el-autologger.el
ashok-khanna_autologger/el-autologger.el
;;; el-autologger.el --- Convenient look-through of Function Results in Common Lisp -*- lexical-binding: t -*- ;;; Need to clean up the below code (defun autologger-next-hashkey (hashkey) (let ((new-hashkey (copy-list hashkey))) (setf (car (last new-hashkey)) (+ (car (last new-hashkey)) 1)) new-hashkey)) (defun autologger-prev-hashkey (hashkey) (let ((new-hashkey (copy-list hashkey))) (setf (car (last new-hashkey)) (- (car (last new-hashkey)) 1)) new-hashkey)) (defun autologger-up-hashkey (hashkey) (butlast hashkey)) (defun autologger-down-hashkey (hashkey) (append hashkey '(1))) ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html (defun autologger-kill-all-buffers () (interactive) (kill-matching-buffers "^autologger" nil t) (pop-to-buffer "*slime-repl sbcl*")) (defun autologger-bury-buffer () (interactive) (bury-buffer)) (defun autologger-create-buffer (data-from-cl) (let* ((new-buffer (generate-new-buffer "autologger")) (buffer-name (buffer-name new-buffer))) (with-current-buffer new-buffer (autologger-mode) (make-local-variable 'autologger-hash) (make-local-variable 'autologger-hashkey) (make-local-variable 'autologger-menu-data) (setq autologger-menu-mode nil) (setq autologger-hash (autologger-hash data-from-cl)) (setq autologger-hashkey '(1)) (autologger-draw-screen autologger-hashkey) (read-only-mode)) (pop-to-buffer new-buffer) (message buffer-name))) (defun autologger-jump-to-buffer (arg) (interactive "sEnter autologger buffer number to jump to (RET to go to newest): ") (cond ((equal arg "") (let* ((buffer-names (loop for buffer in (buffer-list) collect (buffer-name buffer))) (new-buffer-list (remove-if-not #'autologger-buffer-p buffer-names))) (switch-to-buffer (car (sort new-buffer-list #'string-greaterp))))) (t (if (or (equal arg "0") (equal arg "1")) (switch-to-buffer "autologger") (switch-to-buffer (concat "autologger<" arg ">")))))) (defun autologger-goto (arg) (interactive "nEnter number to jump to: ") (if autologger-menu-mode (progn (let ((line-pos (+ arg 11))) (when (> line-pos 11) (goto-char (point-min)) (beginning-of-line line-pos)))) (unless (null (gethash (append autologger-hashkey (list arg)) autologger-hash)) (read-only-mode 'toggle) (setq autologger-hashkey (append autologger-hashkey (list arg))) (autologger-draw-screen autologger-hashkey) (read-only-mode)))) (defun autologger-goto-hashkey (hashkey num) (let ((new-hashkey (copy-list hashkey))) (setf (car (last new-hashkey)) num) new-hashkey)) (defun autologger-buffer-p (buffer-name) (when (string-match "^autologger" buffer-name) (unless (string-match-p (regex-quote ".") buffer-name) t))) (defun autologger-down () (interactive) (unless (null (gethash (autologger-down-hashkey autologger-hashkey) autologger-hash)) (read-only-mode 'toggle) (setq autologger-hashkey (autologger-down-hashkey autologger-hashkey)) (autologger-draw-screen autologger-hashkey) (read-only-mode))) (defun autologger-up () (interactive) (when (> (length autologger-hashkey) 1) (read-only-mode 'toggle) (setq autologger-hashkey (autologger-up-hashkey autologger-hashkey)) (autologger-draw-screen autologger-hashkey) (read-only-mode))) (defun autologger-next () (interactive) (unless (null (gethash (autologger-next-hashkey autologger-hashkey) autologger-hash)) (read-only-mode 'toggle) (setq autologger-hashkey (autologger-next-hashkey autologger-hashkey)) (autologger-draw-screen autologger-hashkey) (read-only-mode))) (defun autologger-prev () (interactive) (when (> (car (last autologger-hashkey)) 1) (read-only-mode 'toggle) (setq autologger-hashkey (autologger-prev-hashkey autologger-hashkey)) (autologger-draw-screen autologger-hashkey) (read-only-mode))) (defun autologger-toggle () (interactive) (let ((line-pos (line-number-at-pos))) (let ((new-menu-data (cons (car autologger-menu-data) (loop for item in (cdr autologger-menu-data) collect (if (cdr item) (cons (car item) nil) (cons (car item) t)))))) (setq autologger-menu-data new-menu-data) (read-only-mode 'toggle) (autologger-draw-menu autologger-menu-data) (read-only-mode 'toggle) (goto-char (point-min)) (beginning-of-line line-pos)))) (defun autologger-item-toggle () (interactive) (let ((line-pos (line-number-at-pos))) (when (> line-pos 11) (setf (cdr (nth (- line-pos 12) (cdr autologger-menu-data))) (not (cdr (nth (- line-pos 12) (cdr autologger-menu-data))))) (read-only-mode 'toggle) (autologger-draw-menu autologger-menu-data) (read-only-mode 'toggle) (goto-char (point-min)) (beginning-of-line lineq-pos)))) (defun autologger-menu-reset () (interactive) (let ((line-pos (line-number-at-pos))) (let ((new-menu-data (cons (car autologger-menu-data) (loop for item in (cdr autologger-menu-data) collect (cons (car item) nil))))) (setq autologger-menu-data new-menu-data) (read-only-mode 'toggle) (autologger-draw-menu autologger-menu-data) (read-only-mode 'toggle) (goto-char (point-min)) (beginning-of-line line-pos)))) (defun autologger-menu-save () (interactive) (let ((symbol-data (loop for item in (cdr autologger-menu-data) collect (cons (list (format "%s" (first (car item))) (format "%s" (second (car item)))) (cdr item))))) (slime-eval `(autologger::set-function-logs ',symbol-data)))) (define-derived-mode autologger-mode lisp-mode "autologger" :syntax-table nil "major mode for viewing common lisp function results." (use-local-map (copy-keymap text-mode-map)) (local-set-key (kbd "u") #'autologger-up) (local-set-key (kbd "d") #'autologger-down) (local-set-key (kbd "n") #'autologger-next) (local-set-key (kbd "p") #'autologger-prev) (local-set-key (kbd "g") #'autologger-goto) (local-set-key (kbd "w") #'autologger-kill-all-buffers) (local-set-key (kbd "t") #'autologger-toggle) (local-set-key (kbd "i") #'autologger-item-toggle) (local-set-key (kbd "r") #'autologger-menu-reset) (local-set-key (kbd "s") #'autologger-menu-save) (local-set-key (kbd "k") #'(lambda () (interactive) (forward-line -1))) (local-set-key (kbd "j") #'(lambda () (interactive) (forward-line))) (local-set-key (kbd "1") #'(lambda () (interactive) (autologger-goto 1))) (local-set-key (kbd "2") #'(lambda () (interactive) (autologger-goto 2))) (local-set-key (kbd "3") #'(lambda () (interactive) (autologger-goto 3))) (local-set-key (kbd "4") #'(lambda () (interactive) (autologger-goto 4))) (local-set-key (kbd "5") #'(lambda () (interactive) (autologger-goto 5))) (local-set-key (kbd "6") #'(lambda () (interactive) (autologger-goto 6))) (local-set-key (kbd "7") #'(lambda () (interactive) (autologger-goto 7))) (local-set-key (kbd "8") #'(lambda () (interactive) (autologger-goto 8))) (local-set-key (kbd "9") #'(lambda () (interactive) (autologger-goto 9))) (local-set-key (kbd "q") #'(lambda () (interactive) (kill-all-local-variables) (kill-current-buffer) (pop-to-buffer "*slime-repl sbcl*"))) (make-local-variable 'autologger-menu-data) (make-local-variable 'autologger-menu-mode) ;; (use-local-map autologger-mode-map) -> will override all keymaps ) (defun autologger-endcons (a b) (reverse (cons b (reverse a)))) (defun autologger-draw-levels (list) (insert (propertize (format "%s" (car list)) 'font-lock-face 'bold)) (loop for item in (cdr list) do (unless (null item) (insert (propertize (format ".%s" item) 'font-lock-face 'bold) )))) (defun autologger-recursive-draw-paths (hash-key counter) (let* ((new-key (autologger-endcons hash-key counter)) (hash-value (car (gethash new-key autologger-hash)))) (when hash-value (insert (format "%s" counter) ": " (propertize (upcase (format "%s" (first hash-value))) 'font-lock-face '(:foreground "blue"))) (newline) (autologger-recursive-draw-paths hash-key (+ counter 1))))) (defun autologger-draw-inputs (hash-data) (loop for param-name in (second hash-data) for param-value in (fourth hash-data) do (insert (format "%s" param-name) " -> " (format "%s" param-value) "\n"))) ;; Creating hash tables (defun autologger-hash (data-from-cl) (let ((my-hash (make-hash-table :test #'equal))) (loop for item in data-from-cl do (puthash (car item) (cons (cdr item) 0) my-hash)) my-hash)) (defun autologger-draw-screen (hash-key) "Removes existing contents of buffer and inserts new screen based on hash-key supplied." (let ((hash-data (car (gethash hash-key autologger-hash)))) (erase-buffer) (insert (propertize "~ Autologger v0.1 ~\n" 'font-lock-face 'bold)) (insert (propertize "~ Utilising IBCL http://www.informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/ibcl/index.html ~\n")) (insert "~ Significant help & code refactoring by PJB & Beach (+ others) on #CLSCHOOL (IRC.LIBERA.CHAT) ~\n\n") (insert (propertize "u" 'font-lock-face '(bold (:foreground "blue"))) ": up " (propertize "d" 'font-lock-face '(bold (:foreground "blue"))) ": down " (propertize "g" 'font-lock-face '(bold (:foreground "blue"))) ": goto " (propertize "m" 'font-lock-face '(bold (:foreground "blue"))) ": minimise-this-buffer\n") (insert (propertize "n" 'font-lock-face '(bold (:foreground "blue"))) ": next " (propertize "p" 'font-lock-face '(bold (:foreground "blue"))) ": prev " (propertize "q" 'font-lock-face '(bold (:foreground "blue"))) ": quit " (propertize "w" 'font-lock-face '(bold (:foreground "blue"))) ": kill-all-autologger-buffers\n") (newline 2) (insert "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n") (insert (propertize "Autologger for " 'font-lock-face 'bold) (propertize (upcase (format "%s" (first hash-data))) 'font-lock-face '('bold (:foreground "blue"))) (propertize " on level " 'font-lock-face 'bold)) (autologger-draw-levels hash-key) (newline) (insert "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n") (newline) (insert "Outputs\n") (insert "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n") (insert (format "%s\n" (fifth hash-data))) (newline 1) (insert "Inputs\n") (insert "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n") (autologger-draw-inputs hash-data) (newline 2) (insert "Step Into (for numbers > 9, use goto via " (propertize "g" 'font-lock-face 'bold) ")\n") (insert "- - - - - - - - - - - - - - - - - - - - - - - - - - -\n") (autologger-recursive-draw-paths hash-key 1) (newline 2) (insert "Function Definition\n") (insert "- - - - - - - - - - - - - - - - - - - - - - - - - - -") (cl-prettyprint (append (list 'defun (first hash-data) (second hash-data)) (third hash-data))) (goto-char (point-min))) ;; Ensure autologger loads in Emacs state for Evil: ;; Test if this is required (add-hook 'autologger-mode-hook 'turn-on-font-lock)) (defun autologger-create-menu-buffer (data-from-cl) (let* ((new-buffer (generate-new-buffer "autologger")) (buffer-name (buffer-name new-buffer))) (with-current-buffer new-buffer (autologger-mode) (setq autologger-menu-mode t) (setq autologger-menu-data data-from-cl) (autologger-draw-menu autologger-menu-data) (read-only-mode)) (pop-to-buffer new-buffer) (message buffer-name))) (defun autologger-draw-menu (menu-data) (erase-buffer) (insert (propertize "~ Autologger v0.1 ~\n" 'font-lock-face 'bold)) (insert (propertize "~ Utilising IBCL http://www.informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/ibcl/index.html ~\n")) (insert "~ Significant help & code refactoring by PJB & Beach (+ others) on #CLSCHOOL (IRC.LIBERA.CHAT) ~\n\n") (insert (propertize "j" 'font-lock-face '(bold (:foreground "blue"))) ": down " (propertize "t" 'font-lock-face '(bold (:foreground "blue"))) ": toggle-all " (propertize "r" 'font-lock-face '(bold (:foreground "blue"))) ": unlog-all " (propertize "g" 'font-lock-face '(bold (:foreground "blue"))) ": goto " (propertize "m" 'font-lock-face '(bold (:foreground "blue"))) ": minimise-this-buffer\n") (insert (propertize "k" 'font-lock-face '(bold (:foreground "blue"))) ": up " (propertize "i" 'font-lock-face '(bold (:foreground "blue"))) ": toggle-item " (propertize "s" 'font-lock-face '(bold (:foreground "blue"))) ": save " (propertize "q" 'font-lock-face '(bold (:foreground "blue"))) ": quit " (propertize "w" 'font-lock-face '(bold (:foreground "blue"))) ": kill-all-autologger-buffers\n") (newline 2) (insert "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n") (insert "Logging Menu for " (propertize (upcase (format "%s" (car menu-data))) 'font-lock-face '('bold (:foreground "blue")))) (insert " (" (propertize "purple" 'font-lock-face '(:foreground "purple")) " for logged functions and " (propertize "blue" 'font-lock-face '(:foreground "blue")) " for unlogged functions)") (newline 1) (loop for item in (cdr menu-data) for index from 1 to (length (cdr menu-data)) do (progn (newline) (if (cdr item) (progn (insert (format "%s:" index) (propertize (upcase (concat (second (car item)) ":" (when (equal (third (car item)) ":INTERNAL") ":") (first (car item)))) 'font-lock-face '(:foreground "purple")))) (insert (format "%s:" index) (propertize (upcase (concat (second (car item)) ":" (when (equal (third (car item)) ":INTERNAL") ":") (first (car item)))) 'font-lock-face '(:foreground "blue")))))) (goto-char (point-min)) (beginning-of-line 12)) (add-to-list 'evil-emacs-state-modes 'autologger-mode) (provide 'autologger-mode) ;;; autologger.el ends here
14,515
Common Lisp
.l
322
40.034161
138
0.629894
ashok-khanna/autologger
5
0
4
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
a5d0a676e35ea89aad5fb511513cb61c454c163190958ca7ba91fcb5e8962439
15,447
[ -1 ]
15,464
bookmark-ui.lisp
jstoddard_observatory/bookmark-ui.lisp
;;;; bookmark-ui.lisp ;;;; User interface for managing bookmarks ;;;; Part of Observatory, by Jeremiah Stoddard (in-package :observatory) (defclass bookmark-holder () ((bookmark :initform (error "bookmark can't be nil!") :initarg :bookmark :accessor bookmark-holder-bookmark))) (defun make-bookmark-holder (bookmark) (make-instance 'bookmark-holder :bookmark bookmark)) (defun bookmark-ui (app-pane) "Display bookmarks with option to load page or delete." (window-clear app-pane) (with-text-style (t *h1-style*) (format t "Bookmarks~%")) (format t "Click on a bookmark link to follow. Right click for options.~%~%") (dolist (bm *bookmarks*) (let ((bmh (make-bookmark-holder bm))) (with-drawing-options (t :ink *link-color*) (with-output-as-presentation (t bmh 'bookmark-holder) (format t "~a" (getf (bookmark-holder-bookmark bmh) :uri)))) (format t " -- ~a~%" (getf (bookmark-holder-bookmark bmh) :title)))))
963
Common Lisp
.lisp
22
40.318182
79
0.697972
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
03dc4fb25103efde64f1892372bf3ea5d424830352a5944bd7dedf3a732fee2f
15,464
[ -1 ]
15,465
package.lisp
jstoddard_observatory/package.lisp
;;;; package.lisp ;;;; Package definition for Observatory (defpackage :observatory (:use :clim :clim-lisp :clim-extensions) (:export :observatory-main))
158
Common Lisp
.lisp
5
29.6
42
0.743421
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
433cd5697436ed5fcf137b7144952741772b5f79a7cc38e85c283bbd979f653a
15,465
[ -1 ]
15,466
bookmarks.lisp
jstoddard_observatory/bookmarks.lisp
;;;; bookmarks.lisp ;;;; Functions for handling bookmarks ;;;; Part of Observatory, by Jeremiah Stoddard (in-package :observatory) (defvar *bookmarks* nil) (defun make-bookmark (uri title) (push (list :uri uri :title title) *bookmarks*)) (defun delete-bookmark (bookmark) "Delete a bookmark." (setf *bookmarks* (remove-if #'(lambda (b) (equalp b bookmark)) *bookmarks*))) (defun load-bookmarks (filename) "Load bookmarks from file given in filename." (handler-case (with-open-file (stream filename :direction :input) (setf *bookmarks* (read stream))) (error (err) (setf *bookmarks* nil)))) (defun save-bookmarks (filename) "Save bookmarks to filename." (with-open-file (stream filename :direction :output :if-exists :supersede) (pprint *bookmarks* stream)))
794
Common Lisp
.lisp
21
35.095238
76
0.723598
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
230a3259ab47fc202cca766367e50ab4f374f58219d605e88c15cec5e00d1c33
15,466
[ -1 ]
15,467
document.lisp
jstoddard_observatory/document.lisp
;;;; document.lisp ;;;; Document structure and functions for parsing text/gemini documents ;;;; Part of Observatory, by Jeremiah Stoddard (in-package :observatory) (defparameter +whitespace+ (format nil "~c~c~c~c~c" #\Newline #\Space #\Tab #\Return #\Linefeed)) (defvar *parser-state* :normal) (defun toggle-parser-state () (if (eql *parser-state* :normal) (setf *parser-state* :pre) (setf *parser-state* :normal))) (defclass document () ((resource :initform (error "Resource required.") :initarg :resource :accessor document-resource) (response-code :initform 0 :initarg :response-code :accessor document-response-code) (meta :initform "" :initarg :meta :accessor document-meta) (type :initform :other :initarg :type :accessor document-type) (source :initform "" :initarg :source :accessor document-source) (parts :initform () :initarg :parts :accessor document-parts))) (defun make-document (&key (resource (parse-uri "gemini://gemini.circumlunar.space/")) (response-code 0) (meta "") (type :other) (source "") (parts nil)) (make-instance 'document :resource resource :response-code response-code :meta meta :type type :source source :parts parts)) (defgeneric save-document (document filename) (:documentation "Save document (source) to pathname given in filename.")) (defmethod save-document ((document document) filename) (with-open-file (stream filename :direction :output :if-exists :supersede) (write-sequence (document-source document) stream))) (defclass doc-part () ((text :initarg :text :initform "" :accessor doc-part-text)) (:documentation "Base class for parts of a document.")) (defgeneric write-doc-part (line) (:documentation "Set appropriate style and write line to standard output.")) (defclass text-line (doc-part) () (:documentation "A line of plain text.")) (defun make-text-line (text) (make-instance 'text-line :text text)) (defclass link-line (doc-part) ((uri :initarg :uri :initform nil :accessor link-line-uri) (description :initarg :description :initform "" :accessor link-line-description)) (:documentation "A link.")) (defun ensure-complete-uri (uri res) "If uri is relative, add server, etc. from res and return absolute uri." ;; Some gemini sites like to use // as a shorthand for gemini:// (when (and (> (length uri) 2) (string= (subseq uri 0 2) "//")) (setf uri (concatenate 'string "gemini:" uri))) (unless (position #\: uri) (if (eql (char uri 0) #\/) (setf uri (concatenate 'string (resource-protocol res) "://" (resource-server res) uri)) (let* ((path (resource-get-uri res)) (last/ (position #\/ path :from-end t))) (setf uri (concatenate 'string (subseq path 0 last/) "/" uri))))) uri) (defun make-link-line (text res) (let* ((trimmed-line (string-trim +whitespace+ (subseq text 2))) (pos (min (or (position #\Space trimmed-line) (length trimmed-line)) (or (position #\Tab trimmed-line) (length trimmed-line))))) (make-instance 'link-line :text text :uri (parse-uri (ensure-complete-uri (subseq trimmed-line 0 pos) res)) :description (if (and pos (< pos (length trimmed-line))) (string-trim +whitespace+ (subseq trimmed-line (+ pos 1))) "")))) (defclass toggle-line (doc-part) () (:documentation "Following lines should be mono-line until next toggle-line.")) (defun make-toggle-line (text) (toggle-parser-state) (make-instance 'toggle-line :text (string-trim +whitespace+ (subseq text 3)))) (defclass mono-line (doc-part) () (:documentation "Preformatted text for output in monospace font.")) (defun make-mono-line (text) (make-instance 'mono-line :text text)) (defclass heading1-line (doc-part) () (:documentation "A heading.")) (defun make-heading1-line (text) (make-instance 'heading1-line :text (string-trim +whitespace+ (string-left-trim "#" text)))) (defclass heading2-line (doc-part) () (:documentation "A subheading.")) (defun make-heading2-line (text) (make-instance 'heading2-line :text (string-trim +whitespace+ (string-left-trim "#" text)))) (defclass heading3-line (doc-part) () (:documentation "A sub-subheading.")) (defun make-heading3-line (text) (make-instance 'heading3-line :text (string-trim +whitespace+ (string-left-trim "#" text)))) (defclass ul-line (doc-part) () (:documentation "An unordered list item.")) (defun make-ul-line (text) (make-instance 'ul-line :text text)) (defclass quote-line (doc-part) () (:documentation "Quoted text.")) (defun make-quote-line (text) (make-instance 'quote-line :text text)) ;;; Parsing functions ;;; TODO: support for image files, at least png and jpeg, for inline ;;; display. (defun parse-gemini-line (line resource) (cond ((and (>= (length line) 3) (string= "```" (subseq line 0 3))) (make-toggle-line line)) ((eql *parser-state* :pre) (make-mono-line line)) ((= (length line) 0) (make-text-line line)) ((and (>= (length line) 2) (string= "=>" (subseq line 0 2))) (make-link-line line resource)) ((and (>= (length line) 3) (string= "###" (subseq line 0 3))) (make-heading3-line line)) ((and (>= (length line) 2) (string= "##" (subseq line 0 2))) (make-heading2-line line)) ((string= "#" (subseq line 0 1)) (make-heading1-line line)) ((string= "*" (subseq line 0 1)) (make-ul-line line)) ((string= ">" (subseq line 0 1)) (make-quote-line line)) (t (make-text-line line)))) (defun parse-line (line document resource) "Parse a line received from Gemini server." (setf (document-source document) (concatenate 'string (document-source document) line (string #\Newline))) (case (document-type document) (:text (setf (document-parts document) (append (document-parts document) (list (make-text-line line))))) (:gemini (setf (document-parts document) (append (document-parts document) (list (parse-gemini-line line resource)))))) nil) ;;; Helper functions for parse-response-header (defun make-unrecognized-response-document (res) (make-document :resource res :response-code 0 :type :error :parts (list (make-heading1-line "Error") (make-text-line "Unrecognized response from server.")))) (defun make-unsupported-document (line res) (make-document :resource res :response-code (parse-integer line :end 2 :junk-allowed t) :type :error :meta (string-trim +whitespace+ (subseq line 3)) :parts (list (make-heading1-line "Error") (make-text-line (format nil "Unsupported file type: ~a." (string-trim +whitespace+ (subseq line 3))))))) (defun make-error-document (line res) (make-document :resource res :response-code (parse-integer line :end 2 :junk-allowed t) :type :error :meta (string-trim +whitespace+ (subseq line 3)) :parts (list (make-heading1-line "Error") (make-text-line (format nil "Server returned error code ~a: ~a" (subseq line 0 2) (string-trim +whitespace+ (subseq line 3))))))) (defun make-observatory-error-document (line res) (make-document :resource res :response-code 0 :type :error :parts (list (make-heading1-line "Error") (make-text-line line)))) (defun make-bad-protocol-document (line res) (make-document :resource res :response-code 0 :type :error :parts (list (make-heading1-line "Error") (make-text-line (format nil "Protocol not supported: ~a." line))))) (defun make-redirect-document (line res) (make-document :resource res :response-code (parse-integer line :end 2 :junk-allowed t) :type :redirect :meta (string-trim +whitespace+ (subseq line 3)) :parts (list (make-heading1-line "Redirect") (make-text-line (format nil "The server returned status code ~a: ~a." (subseq line 0 2) (string-trim +whitespace+ (subseq line 3))))))) (defun make-input-document (line res) (make-document :resource res :response-code (parse-integer line :end 2 :junk-allowed t) :type :input :meta (string-trim +whitespace+ (subseq line 3)) :parts (list (make-heading1-line "Input Requested") (make-text-line (string-trim +whitespace+ (subseq line 3)))))) (defun make-gemini-document (line res) (make-document :resource res :response-code (parse-integer line :end 2 :junk-allowed t) :type :gemini)) (defun make-text-document (line res) (make-document :resource res :response-code (parse-integer line :end 2 :junk-allowed t) :type :text)) (defun is-utf-8? (header-line) (if (search "charset" header-line :test #'char-equal) (if (search "utf-8" header-line :test #'char-equal) t nil) t)) ; if no charset indicated, default is utf8 (defun parse-response-header (line res) "Return document class based on provided header." (setf *parser-state* :normal) (let ((status-digit (parse-integer (subseq line 0 1) :junk-allowed t))) (cond ((not status-digit) (make-unrecognized-response-document res)) ((= status-digit 1) (make-input-document line res)) ((= status-digit 3) (make-redirect-document line res)) ((/= status-digit 2) (make-error-document line res)) ((< (length line) 4) (make-gemini-document line res)) ((and (search "text/gemini" line) (is-utf-8? line)) (make-gemini-document line res)) ((and (search "text/" line) (is-utf-8? line)) (make-text-document line res)) (t (make-unsupported-document line res)))))
9,605
Common Lisp
.lisp
227
37.806167
99
0.674202
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
0e35591adf7c512f8c02cd2c512b682d0e2f7e22b7ddccc2c0547f0180a5995e
15,467
[ -1 ]
15,468
request.lisp
jstoddard_observatory/request.lisp
;;;; request.lisp ;;;; Functions for requesting a Gemini page ;;;; Part of Observatory, A Gemini client by Jeremiah Stoddard (in-package :observatory) (defstruct resource (raw-uri nil) (protocol "gemini") (server "gemini.circumlunar.space") (port nil) (page "/")) (defun resource-get-uri (res) "Rebuild uri from components of resource res and return as string." (with-output-to-string (uri) (if (resource-port res) (format uri "~a://~a:~a~a" (resource-protocol res) (resource-server res) (resource-port res) (resource-page res)) (format uri "~a://~a~a" (resource-protocol res) (resource-server res) (resource-page res))))) ;; This still needs to be made more robust. What if a uri with no protocol ;; but with a port is given (e.g. site.org:1956/home.gmi)? (defun parse-protocol (uri) "Return the part of uri prior to the first colon." (let ((colon-pos (position #\: uri))) (if colon-pos (string-downcase (string-trim " " (subseq uri 0 colon-pos))) nil))) (defun parse-server (uri) "Return the server part of uri." (let ((colon-pos (position #\: uri))) (unless colon-pos (setf colon-pos 0)) (let* ((uri-without-protocol (string-trim "/" (subseq uri (+ colon-pos 1)))) (l (length uri-without-protocol)) (slash-or-colon-pos (min (or (position #\/ uri-without-protocol) l) (or (position #\: uri-without-protocol) l)))) (if slash-or-colon-pos (string-downcase (string-trim " " (subseq uri-without-protocol 0 slash-or-colon-pos))) (string-downcase (string-trim " " uri-without-protocol)))))) (defun parse-port (uri) "Return the port in uri, or nil if none." (let ((colon-pos (position #\: uri))) (unless colon-pos (setf colon-pos 0)) (let* ((uri-without-protocol (string-trim "/" (subseq uri (+ colon-pos 1)))) (colon-pos (position #\: uri-without-protocol)) (after-colon (+ (or colon-pos -1) 1)) (slash-pos (position #\/ uri-without-protocol :start after-colon)) (port-str (string-trim " " (subseq uri-without-protocol after-colon (or slash-pos (length uri-without-protocol)))))) (if (and colon-pos (> (length port-str) 0)) (handler-case (parse-integer port-str) (error (c) (values nil c))) nil)))) (defun parse-page (uri) "Return the page from the uri, or a simple forward slash if none." (let ((colon-pos (position #\: uri))) (unless colon-pos (setf colon-pos 0)) (let* ((uri-without-protocol (string-left-trim "/" (subseq uri (+ colon-pos 1)))) (colon-pos (position #\: uri-without-protocol)) (after-colon (+ (or colon-pos -1) 1)) (slash-pos (position #\/ uri-without-protocol :start after-colon))) (if slash-pos (subseq uri-without-protocol slash-pos) "/")))) ;;; This is not very efficient, since the whole uri string is repeatedly ;;; analyzed to pull out the protocol, server, port, and page. It could ;;; be broken up as the protocol is pulled out, then the server, etc., ;;; but passing the whole uri to separate little functions which return ;;; a specific component seemed a little more readable to me. I don't ;;; think this is going to be a performance bottleneck in any significant ;;; manner, so I'm not too worried about it. (defun parse-uri (uri) "Parse uri into a resource struct and return the struct. Return nil if not a uri." (let ((protocol (parse-protocol uri)) (server (parse-server uri)) (port (parse-port uri)) (page (parse-page uri)) (res nil)) (when (not protocol) (setf protocol "gemini")) (when server (setf res (make-resource :raw-uri uri :protocol protocol :server server :page page)) (when port (setf (resource-port res) port))) res)) ;;; TODO: gemini-page class, which will include page contents when ;;; request is successful, and have additional response and error ;;; information whether request is successful or not. (defun get-gemini-page (res) "Request page at uri identified by resource res and output to stream out." (when (not (string= (resource-protocol res) "gemini")) (return-from get-gemini-page (make-bad-protocol-document (resource-protocol res) res))) (handler-case (progn (usocket:with-client-socket (socket stream (resource-server res) (or (resource-port res) 1965)) (let ((gem-stream (cl+ssl:make-ssl-client-stream stream :external-format '(:utf-8 :eol-style :lf) :unwrap-stream-p t :verify nil :hostname (resource-server res))) doc) (unwind-protect (progn (format gem-stream "~a~c~c" (resource-get-uri res) #\Return #\Linefeed) (force-output gem-stream) (setf doc (parse-response-header (read-line gem-stream nil) res)) (loop :for line = (read-line gem-stream nil) :while line :do (parse-line line doc res))) (close gem-stream)) doc))) (error (err) (make-observatory-error-document (format nil "An error occurred while requesting the document: ~a." err) res))))
4,993
Common Lisp
.lisp
116
38.784483
91
0.673172
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
1ebba65c70123a3001405dce65b6864b63d4b99bf2d905b1c349feaf246b7f6a
15,468
[ -1 ]
15,469
observatory.lisp
jstoddard_observatory/observatory.lisp
;;;; Observatory - A Gemini Client in Common Lisp ;;;; Written by Jeremiah Stoddard (in-package :observatory) ;; Recently visited documents (defvar *back-button-history* nil) (defparameter *max-history-pages* 10) (defun push-to-history (doc) "Add doc to *back-button-history*, removing old entries if needed. Returns doc." (push doc *back-button-history*) (when (> (length *back-button-history*) *max-history-pages*) (setf (cdr (nthcdr (- *max-history-pages* 1) *back-button-history*)) nil)) doc) (defun pop-from-history () "Pop first entry from *back-button-history*, or return nil if none." (when *back-button-history* (pop *back-button-history*))) ;;; Utility function for URL encoding ;;; Based on a function from rosettacode.org (defun uri-encode (str) "URI encode string str." (apply #'concatenate 'string (map 'list #'(lambda (c) (if (not (alphanumericp c)) (format nil "%~2,'0x" (char-code c)) (string c))) str))) ;;; Application GUI (define-application-frame observatory-app () ((current-doc :initform nil :accessor current-doc)) (:pretty-name "Observatory") (:menu-bar observatory-menu-bar) (:panes (app :application :display-time nil :width 800 :height 400 :end-of-line-action :wrap*) (uri-input :text-field :value *homepage* :activate-callback 'uri-input-callback :background +white+) (back-button :push-button :label (format nil "~a" (code-char 8592)) ; #\LEFTWARDS_ARROW :max-width 80 :activate-callback 'back-button-callback)) (:layouts (default (vertically () (horizontally () (spacing (:thickness 10) back-button) (labelling (:label "URI:") uri-input)) app)))) (make-command-table 'observatory-menu-bar :errorp nil :menu '(("File" :menu file-menu) ("Bookmarks" :menu bookmarks-menu))) (make-command-table 'file-menu :errorp nil :menu '(("Home" :command com-homepage) ("Save" :command com-save) ("Quit" :command com-quit))) (make-command-table 'bookmarks-menu :errorp nil :menu '(("Add Bookmark" :command com-add-bookmark) ("Manage Bookmarks" :command com-manage-bookmarks))) ;;; Make uri-input field active when application frame is run (defmethod run-frame-top-level :before ((frame observatory-app) &key &allow-other-keys) (stream-set-input-focus (find-pane-named frame 'uri-input))) ;;; TODO: Implement this (define-observatory-app-command (com-save :name t) () (let ((doc (current-doc *application-frame*))) (when doc (let* ((uri (resource-get-uri (document-resource (current-doc *application-frame*)))) (filename (subseq uri (+ (position #\/ uri :from-end t) 1)))) (when (= (length filename) 0) (setf filename "untitled.gmi")) (let ((selected-fn (sf:select-file :title "Save" :prompt "Save As:" :dialog-type :save :default-fn filename))) (when selected-fn (save-document doc selected-fn))))))) (define-observatory-app-command (com-quit :name t) () (frame-exit *application-frame*)) ;;; Document display functions (defmethod write-doc-part ((line doc-part)) (format t "~a~%" (doc-part-text line))) (defmethod write-doc-part ((line link-line)) (let ((res (link-line-uri line))) (if res (if (string= (resource-protocol res) "gemini") (with-drawing-options (t :ink *link-color*) (with-output-as-presentation (t line 'link-line) (format t "~a" (resource-get-uri res)))) (format t "~a" (resource-get-uri res))))) (format t " -- ~a~%" (link-line-description line))) (defmethod write-doc-part ((line mono-line)) (with-text-style (t *mono-style*) (format t "~a~%" (doc-part-text line)))) (defmethod write-doc-part ((line heading1-line)) (with-text-style (t *h1-style*) (format t "~a~%" (doc-part-text line)))) (defmethod write-doc-part ((line heading2-line)) (with-text-style (t *h2-style*) (format t "~a~%" (doc-part-text line)))) (defmethod write-doc-part ((line heading3-line)) (with-text-style (t *h3-style*) (format t "~a~%" (doc-part-text line)))) (defmethod write-doc-part ((line ul-line)) ; (code-char 8226) = #\Bullet (format t "~c~a~%" (code-char 8226) (subseq (doc-part-text line) 1))) (defun write-gemini-page (doc) (let ((app-pane (get-frame-pane *application-frame* 'app))) (window-clear app-pane) (dolist (line (document-parts doc)) (write-doc-part line)) (setf (gadget-value (find-pane-named *application-frame* 'uri-input)) (resource-get-uri (document-resource doc))) (scroll-extent app-pane 0 0))) (defun show-prompt (doc) ;; (format t "Input: ") (let (response-field) (surrounding-output-with-border (t) (with-output-as-gadget (t) (setf response-field (make-pane 'text-field :min-width 100 :width 700 :activate-callback #'(lambda (gadget) (load-page (concatenate 'string (resource-get-uri (document-resource doc)) "?" (uri-encode (gadget-value gadget))))))))) (stream-set-input-focus response-field))) (defun load-page (uri) (let ((res (parse-uri uri))) (when res (let ((doc (get-gemini-page res))) (when (eql (document-type doc) :redirect) ;; Allow one redirect; a second will display a message to the user. (setf doc (get-gemini-page (parse-uri (document-meta doc))))) (write-gemini-page doc) (when (eql (document-type doc) :input) (show-prompt doc)) (when (current-doc *application-frame*) (push-to-history (current-doc *application-frame*))) (setf (current-doc *application-frame*) doc))))) (defun go-back () (let ((doc (pop-from-history))) (when doc (write-gemini-page doc) (setf (current-doc *application-frame*) doc)))) (define-observatory-app-command (com-homepage :name t) () (load-page *homepage*)) (define-observatory-app-command (com-follow-link :name t) ((link 'link-line)) (load-page (resource-get-uri (link-line-uri link)))) (define-presentation-to-command-translator follow-link (link-line com-follow-link observatory-app :gesture :select :menu t) (object) (list object)) (defun uri-input-callback (gadget) "Load and display user-input page." (load-page (gadget-value gadget))) (defun back-button-callback (gadget) (declare (ignore gadget)) (go-back)) ;;; Bookmark commands (define-observatory-app-command (com-manage-bookmarks :name t) () (push-to-history (current-doc *application-frame*)) (bookmark-ui (get-frame-pane *application-frame* 'app))) (define-observatory-app-command (com-add-bookmark :name t) () (restart-case (when (current-doc *application-frame*) (let (name (uri (resource-get-uri (document-resource (current-doc *application-frame*))))) (accepting-values (t :own-window t) (setf name (accept 'string :prompt "Bookmark Name:"))) (if name (make-bookmark uri name) (make-bookmark uri uri)) (save-bookmarks *bookmarks-file*))) (abort () nil))) (define-observatory-app-command (com-load-bookmark :name t) ((bmh 'bookmark-holder)) (load-page (getf (bookmark-holder-bookmark bmh) :uri))) (define-presentation-to-command-translator load-bookmarked-page (bookmark-holder com-load-bookmark observatory-app :gesture :select :menu t) (object) (list object)) (define-observatory-app-command (com-delete-bookmark :name t) ((bmh 'bookmark-holder)) (delete-bookmark (bookmark-holder-bookmark bmh)) (save-bookmarks *bookmarks-file*) (bookmark-ui (get-frame-pane *application-frame* 'app))) (define-presentation-to-command-translator delete-bookmark (bookmark-holder com-delete-bookmark observatory-app :gesture :delete :menu t) (object) (list object)) ;; Run Application (defun observatory-main () "Display and run Gemini Client." (load-bookmarks *bookmarks-file*) (run-frame-top-level (make-application-frame 'observatory-app)))
7,961
Common Lisp
.lisp
210
33.671429
91
0.675875
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
91d662aae077f8c504e626a375a01a67bb4e64271ebe3b0b42a1a1c186596a37
15,469
[ -1 ]
15,470
select-file.lisp
jstoddard_observatory/select-file.lisp
;;;; select-file.lisp ;;;; ;;;; A file selection dialog adapted by Jeremiah Stoddard for use with Observatory ;;;; Although Observatory as a whole is licensed under the terms of version 3 of the ;;;; GNU General Public License, the software in this file, which is a slightly ;;;; modified version of select-file originally written by the authors mentioned ;;;; in the copyright notice below, is distributed under the following license: ;;;; ;;;; Copyright (c) 2017-2020 John Carroll, Ann Copestake, Robert Malouf, Stephan Oepen, Angelo Rossi ;;; ;;; Permission is hereby granted, free of charge, to any person obtaining a copy ;;; of this software and associated documentation files (the "Software"), to deal ;;; in the Software without restriction, including without limitation the rights ;;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ;;; copies of the Software, and to permit persons to whom the Software is ;;; furnished to do so, subject to the following conditions: ;;; ;;; The above copyright notice and this permission notice shall be included in all ;;; copies or substantial portions of the Software. ;;; ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;;; SOFTWARE. (defpackage #:select-file (:nicknames #:sf) (:use #:cl) (:export #:select-file #:file-selector #:list-directory #:list-places #:list-devices)) (in-package #:select-file) ;;; Parameters in use by the application. (defparameter +outline-gray+ #+:mcclim climi::*3d-dark-color* #-:mcclim (clim:make-gray-color 0.59)) (defparameter +text-gray+ (clim:make-gray-color 0.66)) (defparameter *cancel-button-string* " Cancel ") ;;; Files, folders and devices icon patterns (defparameter +folder-icon+ (clim:make-pattern #2A((0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0) (0 1 2 2 2 2 1 0 0 0 0 0 0 0 0 0) (1 2 2 2 2 2 2 1 1 1 1 1 1 1 1 0) (1 3 3 3 3 3 3 3 3 3 3 3 3 3 1 4) (1 3 3 3 3 3 3 3 3 3 3 3 3 3 1 4) (1 5 5 5 5 5 5 5 5 5 5 5 5 5 1 4) (1 5 5 5 5 5 5 5 5 5 5 5 5 5 1 4) (6 5 5 5 5 5 5 5 5 5 5 5 5 5 6 4) (6 7 7 7 7 7 7 7 7 7 7 7 7 7 6 4) (6 7 7 7 7 7 7 7 7 7 7 7 7 7 6 4) (8 7 7 7 7 7 7 7 7 7 7 7 7 7 8 4) (8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 4) (0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) (list #+:mcclim clim:+transparent-ink+ #-:mcclim clim:+white+ ; Allegro CLIM pattern limitation (clim:make-rgb-color 160/255 153/255 123/255) (clim:make-rgb-color 239/255 229/255 186/255) (clim:make-rgb-color 239/255 227/255 174/255) (clim:make-rgb-color 173/255 173/255 173/255) (clim:make-rgb-color 237/255 224/255 158/255) (clim:make-rgb-color 145/255 138/255 103/255) (clim:make-rgb-color 234/255 223/255 147/255) (clim:make-rgb-color 119/255 113/255 85/255)))) (defparameter +document-icon+ (clim:make-pattern #2A((0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0) (0 0 1 2 2 2 2 2 2 2 1 1 0 0 0 0) (0 0 1 2 2 2 2 2 2 2 1 3 1 0 0 0) (0 0 1 2 2 2 2 2 2 2 1 3 3 1 0 0) (0 0 1 2 2 2 2 2 2 2 1 1 1 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 4 4 5 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 2 2 2 2 2 2 2 2 2 2 1 4 0) (0 0 1 1 1 1 1 1 1 1 1 1 1 1 4 0) (0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 0)) (list #+:mcclim clim:+transparent-ink+ #-:mcclim clim:+white+ ; Allegro CLIM pattern limitation (clim:make-rgb-color 112/255 112/255 112/255) (clim:make-rgb-color 232/255 232/255 232/255) (clim:make-rgb-color 255/255 255/255 255/255) (clim:make-rgb-color 137/255 137/255 137/255) (clim:make-rgb-color 99/255 99/255 99/255)))) (defparameter +up-folder-icon+ (clim:make-pattern #2A((0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0) (0 1 2 2 2 2 1 0 0 0 0 0 0 0 0 0) (1 2 2 2 2 2 2 1 1 1 1 1 1 1 1 0) (1 3 3 3 4 3 3 3 3 3 3 3 3 3 1 5) (1 3 3 4 4 4 3 3 3 3 3 3 3 3 1 5) (1 6 4 6 4 6 4 6 6 6 6 6 6 6 1 5) (1 6 6 6 4 6 6 6 6 6 6 6 6 6 1 5) (7 6 6 6 4 6 6 6 6 6 6 6 6 6 7 5) (7 8 8 8 8 4 8 8 8 8 8 8 8 8 7 5) (7 8 8 8 8 8 4 4 4 4 4 8 8 8 7 5) (9 8 8 8 8 8 8 8 8 8 8 8 8 8 9 5) (9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 5) (0 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) (list #+:mcclim clim:+transparent-ink+ #-:mcclim clim:+white+ ; Allegro CLIM pattern limitation (clim:make-rgb-color 109/255 158/255 176/255) (clim:make-rgb-color 189/255 232/255 252/255) (clim:make-rgb-color 176/255 229/255 253/255) (clim:make-rgb-color 0/255 0/255 0/255) (clim:make-rgb-color 188/255 188/255 188/255) (clim:make-rgb-color 154/255 219/255 253/255) (clim:make-rgb-color 81/255 133/255 152/255) (clim:make-rgb-color 140/255 211/255 251/255) (clim:make-rgb-color 58/255 96/255 109/255)))) (defparameter +device-icon+ (clim:make-pattern #2A((0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0) (0 0 1 4 4 4 4 4 4 4 4 4 1 6 0 0) (0 1 3 3 3 3 3 3 3 3 3 3 3 1 6 0) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6) (1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 6) (1 2 2 2 2 2 2 2 2 2 2 5 5 2 1 6) (1 2 2 2 2 2 2 2 2 2 2 5 5 2 1 6) (1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 6) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6) (0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) (list #+:mcclim clim:+transparent-ink+ #-:mcclim clim:+white+ ; Allegro CLIM pattern limitation (clim:make-rgb-color 112/255 112/255 112/255) (clim:make-rgb-color 190/255 190/255 190/255) (clim:make-rgb-color 220/255 220/255 220/255) (clim:make-rgb-color 240/255 240/255 240/255) (clim:make-rgb-color 48/255 240/255 48/255) (clim:make-rgb-color 173/255 173/255 173/255)))) ;;; Main function. ;;; See the README file for documentation. (defun select-file (&rest args &key (frame-name 'file-selector) (title nil) (prompt "Name:") ; "Save As:" is appropriate for dialog-type :save (directory (user-homedir-pathname)) (default-fn "untitled") (dialog-type :save) (show-hidden-p nil) (ok-label "OK") ; "Open", "Load" or "Save" may also be appropriate &allow-other-keys) (check-type frame-name symbol) (check-type title (or string null)) (check-type prompt (or string null)) (check-type directory (or string pathname)) (check-type dialog-type (member :open :save :directory)) (check-type ok-label (or string null)) (when (eql dialog-type :directory) (setq default-fn nil)) (unless title (setq title (ecase dialog-type (:open "Select File") (:save "Specify File Name") (:directory "Select Directory")))) (unless prompt (setq prompt "Name:")) (setq directory (ensure-valid-directory directory)) (unless ok-label (setq ok-label "OK")) (setq args (loop for (k v) on args by #'cddr unless (or (eq k :frame-name) (eq k :title)) nconc (list k v))) (let ((frame (apply #'clim:make-application-frame frame-name :pretty-name title :prompt prompt :directory directory :default-fn default-fn :dialog-type dialog-type :show-hidden-p show-hidden-p :ok-label ok-label args))) (setf (file-selector-files-dirs frame) (list-directory frame directory show-hidden-p)) (clim:run-frame-top-level frame) (file-selector-result frame))) (defun ensure-valid-directory (x) (if x (cl-fad:pathname-as-directory (pathname x)) (user-homedir-pathname))) ;;; Classes. (cl:defclass files-dirs-application-pane (clim:application-pane) ;; inheriting instead from clim-stream-pane might be more appropriate, but in that case in ;; McCLIM we don't get scroll wheel support (we don't for either in Allegro CLIM) ()) ;;; The file-selector application frame, including gadget definitions and layout (clim:define-application-frame file-selector () ((prompt :initform nil :initarg :prompt :reader file-selector-prompt) (directory :initform "" :initarg :directory :reader file-selector-directory) (default-fn :initform nil :initarg :default-fn :reader file-selector-default-fn) (dialog-type :initform nil :initarg :dialog-type :reader file-selector-dialog-type) (show-hidden-p :initform nil :initarg :show-hidden-p :accessor file-selector-show-hidden-p) (ok-label :initform nil :initarg :ok-label :reader file-selector-ok-label) (files-dirs :initform nil :accessor file-selector-files-dirs) (last-margin :initform nil :accessor file-selector-last-margin) (last-ncolumns :initform 0 :accessor file-selector-last-ncolumns) (result :initform nil :accessor file-selector-result)) (:menu-bar nil) (:panes ;; In McCLIM, putting the file selection text-field here ensures it gets keyboard focus, ;; since frame-standard-output returns the first defined application-pane that's visible. ;; In Allegro CL this does not work - nor does specialising frame-standard-output to ;; return this pane since a text-field is not a stream; see 'bugs' (selection-pane (clim:make-pane 'clim:text-field :foreground clim:+black+ :background clim:+white+ :editable-p (if (member (file-selector-dialog-type clim:*application-frame*) '(:open :directory)) nil t) :value (if (file-selector-default-fn clim:*application-frame*) (namestring (fad:merge-pathnames-as-file (file-selector-directory clim:*application-frame*) (file-selector-default-fn clim:*application-frame*))) (namestring (file-selector-directory clim:*application-frame*))) :value-changed-callback #'(lambda (gadget new-value) (declare (ignore gadget)) (clim:with-application-frame (frame) (update-ok-button frame new-value))) :max-width clim:+fill+)) (places-devices-pane (clim:make-pane 'clim:application-pane :foreground clim:+black+ :background clim:+white+ :text-cursor nil :max-width 150 ; in Allegro CLIM, this is completely ; overridden by the hbox-pane spec :display-time nil :display-function #'display-places-devices)) (files-dirs-pane (clim:make-pane 'files-dirs-application-pane :foreground clim:+black+ :background clim:+white+ :text-cursor nil :display-time t ; nil in upstream, but doesn't seem to display files :display-function #'display-files-dirs)) (prompt-pane (clim:make-pane 'clim:label-pane :label (file-selector-prompt clim:*application-frame*) ;; prevent the label stretching ;; 2022-01-03 added (not :ccl) to conditional because this does not ;; appear to work in Clozure CL -Jeremiah #+(and :mcclim (not :ccl)) :max-width #+(and :mcclim (not :ccl)) '(:relative 0))) (show-hidden-files-check-box (clim:make-pane 'clim:toggle-button :label "Show hidden files" :indicator-type :some-of :value (file-selector-show-hidden-p clim:*application-frame*) :value-changed-callback 'show-hidden-files-callback)) (ok-button (clim:make-pane 'clim:push-button :label (concatenate 'string " " (file-selector-ok-label clim:*application-frame*) " ") :align-x :center :y-spacing 4 #-:mcclim :show-as-default #+:mcclim :show-as-default-p t ; incorrect keyword in McCLIM :activate-callback #'ok-callback)) (cancel-button (clim:make-pane 'clim:push-button :label *cancel-button-string* :align-x :center :y-spacing 4 :activate-callback #'close-callback))) (:geometry :left 100 :top 100 :width 600 :height 400) ; default placement and size (:layouts (default (clim:spacing (:thickness 15) (clim:vertically (:y-spacing 15) (clim:horizontally (:x-spacing 10 :equalize-height t) (1/4 (clim:outlining (:thickness 1 ;; in Allegro CLIM, outlining is grey by default - and indeed if ;; we were to specify the colour then the scroll bar would also ;; pick it up, which we definitely don't want #+:mcclim :background #+:mcclim +outline-gray+) (clim:scrolling (:scroll-bar :vertical :scroll-bars :vertical) ; CLIM spec ambiguous places-devices-pane))) (3/4 (clim:outlining (:thickness 1 #+:mcclim :background #+:mcclim +outline-gray+) (clim:scrolling (:scroll-bar :vertical :scroll-bars :vertical) files-dirs-pane)))) (clim:horizontally () show-hidden-files-check-box :fill) (clim:horizontally (:x-spacing 10 :align-y :center :equalize-height nil) prompt-pane ;; in McCLIM only, wrap whitespace and outline around text-field gadget, otherwise ;; it looks too tight and flat #-:mcclim selection-pane #+:mcclim (clim:outlining (:thickness 1 :background +outline-gray+) (clim:outlining (:thickness 3 :background clim:+white+) selection-pane))) ;; For two equal width push-buttons on the left side of the frame, an approach ;; that works in Allegro CLIM is an hbox-pane split 50-50 inside another hbox ;; with a right fill. Unfortunately, this doesn't work in McCLIM since the button ;; with the narrower label fails to expand to its allotted half. Instead, we use ;; a grid-pane (which is not implemented in Allegro CLIM), adding spacing manually ;; since the McCLIM grid-pane ignores :x-spacing. However there's still a bug ;; (probably in grid-pane allocate-space): if the left button label is wider than ;; the right, the right button won't move over to the right or grow to match it. (clim:horizontally () #+:mcclim (clim:make-pane 'clim:grid-pane :contents (list (list (clim:horizontally () ok-button 5) (clim:horizontally () 5 cancel-button)))) #-:mcclim (clim:horizontally (:x-spacing 10) (1/2 ok-button) (1/2 cancel-button)) :fill)))))) ;;; Methods related to file-selector class. #+:mcclim (defmethod clim-extensions:find-frame-type ((frame file-selector)) ;; make file selector have more dialog-like window controls (e.g. no maximize button) :dialog) (defmethod clim:run-frame-top-level :before ((frame file-selector) &key &allow-other-keys) ;; !!! The order in which threads run in McCLIM/CLX/X11 may prevent a new frame from opening ;; at the top of the stack, requiring the user to click on it to activate it. I can't pin ;; down the circumstances in which this happens, but calling sleep here seems to be an ;; effective workaround. #+:mcclim (sleep 0.05) (update-ok-button frame (clim:gadget-value (clim:find-pane-named frame 'selection-pane)))) ;;; Callback functions related to the action gadgets. (defun update-ok-button (frame new-value) (let ((ok-button (clim:find-pane-named frame 'ok-button)) (require-directory-p (eq (file-selector-dialog-type frame) :directory))) (when ok-button ; the gadget might not be associated with this frame yet (if (eq (and (cl-fad:directory-pathname-p new-value) t) require-directory-p) (clim:activate-gadget ok-button) (clim:deactivate-gadget ok-button))))) (defun ok-callback (button) (declare (ignore button)) (clim:with-application-frame (frame) (setf (file-selector-result frame) (pathname (clim:gadget-value (clim:find-pane-named frame 'selection-pane)))) (clim:frame-exit frame))) (defun close-callback (button) (declare (ignore button)) (clim:with-application-frame (frame) (clim:frame-exit frame))) (defun show-hidden-files-callback (checkbox value) (declare (ignore checkbox)) (clim:with-application-frame (frame) (with-slots (files-dirs show-hidden-p) frame (setf show-hidden-p value) (setf files-dirs (list-directory frame (pathname-directory-pathname (clim:gadget-value (clim:find-pane-named frame 'selection-pane))) value)) (display-files-dirs frame (clim:find-pane-named frame 'files-dirs-pane))))) ;;; Detect resizing of the dialog, by an :after method on allocate-space. A more direct ;;; solution might be be a handle-event method on window-configuration-event; however ;;; handle-event is called on the frame's top level sheet and it doesn't seem possible to ;;; specialise that sheet portably. (define-file-selector-command com-resize-panes ((frame 'file-selector)) (display-files-dirs frame (clim:find-pane-named frame 'files-dirs-pane) t)) (defmethod clim:allocate-space :after ((pane files-dirs-application-pane) width height) (declare (ignore width height)) ;; in McCLIM, a horizontal resize of an application / scroll pane combo updates the ;; application pane's text-margin if the scroll pane has a horizontal scroll bar, ;; but not otherwise - I think it should always #+:mcclim (setf (clim:stream-text-margin pane) (clim:bounding-rectangle-width (clim:pane-viewport-region pane))) (let ((margin (clim:stream-text-margin pane))) (clim:with-application-frame (frame) (with-slots (last-margin) frame (cond ((null last-margin) ; a brand new frame, not a resize? (setf last-margin margin)) ((> (abs (- margin last-margin)) 10) ; significant change since last redisplay attempt? (setf last-margin margin) (clim:execute-frame-command frame `(com-resize-panes ,frame)))))))) ;;; Panes class definitions. ;;; Files and directories list pane. This is the pane on the right. (eval-when (:compile-toplevel :load-toplevel :execute) (clim:define-presentation-type file-dir-namestring ())) (define-file-selector-command com-select-file-dir ((data 'file-dir-namestring :gesture :select)) (select-file-dir data)) (defun select-file-dir (data &optional relist-if-file-p) (let* ((p (cadr data)) (parent clim:*application-frame*) (selection-pane (clim:find-pane-named parent 'selection-pane))) (setf (clim:gadget-value selection-pane) (namestring p)) (update-ok-button parent p) (when (and relist-if-file-p (not (cl-fad:directory-pathname-p p))) (setq p (cl-fad:pathname-as-directory p))) (when (cl-fad:directory-pathname-p p) (with-slots (files-dirs show-hidden-p) parent (setf files-dirs (list-directory parent p show-hidden-p))) (display-files-dirs parent (clim:find-pane-named parent 'files-dirs-pane))))) (defun display-files-dirs (frame stream &optional lazyp) (let* ((files-dirs (file-selector-files-dirs frame)) (items (nconc (if (car files-dirs) (list (list* "Parent directory" (car files-dirs) 'parent)) nil) (mapcar #'(lambda (p) (list* (file-dir-namestring p) p (if (cl-fad:directory-pathname-p p) 'folder 'document))) (cdr files-dirs)))) (max-width (+ 12 ; x-spacing - see display-fs-items / draw-namestring for these spacing values (max (+ 16 4 (reduce #'max items :key #'(lambda (x) (clim:text-size stream (if (atom x) x (car x))))) 2) 120))) ; min cell width (margin ;; we don't need all of the last column to be visible so extend right margin a bit (+ (clim:stream-text-margin stream) (floor max-width 4) 3 12)) (ncolumns (min (max (floor margin max-width) 1) (length items)))) ;; the lazyp flag indicates that if there are the same number of columns as were displayed ;; last time around then no redisplay is necessary (when (or (not lazyp) (not (eql ncolumns (file-selector-last-ncolumns frame)))) (setf (file-selector-last-ncolumns frame) ncolumns) (display-fs-items items stream 'file-dir-namestring ncolumns max-width)))) ;;; Each item is of the form (namestring pathname . type) where type is one of the symbols ;;; {device, parent, folder, document}. This function doesn't use the formatting-table ;;; :multiple-columns facility because it's not guaranteed to use all the columns - but we ;;; want that since it might bring into view items near the bottom of the table that otherwise ;;; would have to be scrolled down to. (defun display-fs-items (items stream presentation-type ncolumns &optional (col-width 0)) (let* ((x-margin 3) (y-margin (clim:stream-vertical-spacing stream)) (row-height (+ (max 16 (clim:stream-line-height stream)) (clim:stream-vertical-spacing stream))) (record (clim:with-output-recording-options (stream :draw nil :record t) (clim:with-new-output-record (stream) (clim:window-clear stream) (loop with last-row-index = (1- (ceiling (length items) ncolumns)) for item in items for ri = 0 then (if (= ri last-row-index) 0 (1+ ri)) for ci = 0 then (if (zerop ri) (1+ ci) ci) ; display in column-wise order do (clim:stream-set-cursor-position stream (+ (* ci col-width) x-margin) (+ (* ri row-height) y-margin)) (if (atom item) (draw-heading stream item) (clim:with-output-as-presentation (stream item presentation-type :single-box t) (let ((icon (ecase (cddr item) (device +device-icon+) (parent +up-folder-icon+) (folder +folder-icon+) (document +document-icon+)))) (draw-namestring stream icon (car item)))))) (clim:scroll-extent stream 0 0))))) (clim:replay record stream) ;; in McCLIM only, need to indicate that the content of this pane may have a new height ;; so the scroller should update - and a new width to prevent the pane being scrollable ;; horizontally (e.g. with touchpad) if it has got narrower #+:mcclim (multiple-value-bind (w h) (clim:bounding-rectangle-size (clim:stream-output-history stream)) (clim:change-space-requirements stream :width w :height (+ h 4))))) (defun draw-namestring (stream pattern text) (flet ((backup/lock-namestring (s) ;; starts with ~$ or ends with ~ / # / .bak (let ((len (length s))) (and (> len 1) (or (string= s "~$" :end1 2) (member (char s (1- len)) '(#\~ #\#)) (and (> len 4) (string-equal s ".bak" :start1 (- len 4)))))))) ;; !!! in McCLIM only, draw invisible points immediately to the left and right, otherwise ;; presentation highlighting does not give enough room (multiple-value-bind (x y) (clim:stream-cursor-position stream) #+:mcclim (progn (clim:draw-point* stream x (1- y) :line-thickness 1 :ink clim:+white+) (incf x)) (clim:draw-pattern* stream pattern x y) (incf x (+ (clim:pattern-width pattern) 4)) (clim:draw-text* stream text x (+ y 7) :align-y :center :ink (if (backup/lock-namestring text) +text-gray+ clim:+black+)) #+:mcclim (progn (incf x (1+ (clim:text-size stream text))) (clim:draw-point* stream x (1- y) :line-thickness 1 :ink clim:+white+))))) (defun draw-heading (stream text) (multiple-value-bind (x y) (clim:stream-cursor-position stream) (clim:draw-text* stream text x y :align-y :top :ink +text-gray+ :text-style (clim:merge-text-styles (clim:make-text-style nil :bold :smaller) (clim:medium-text-style stream))))) ;;; Create a list of pathnames in current directory, headed by the pathname of the ;;; parent of this directory (or nil if we're at the root of this file system). (defgeneric list-directory (frame dir &optional show-hidden-p) (:documentation "Returns a list of pathnames, the first being the parent directory of dir (or NIL if dir is the root of a file system) and the rest being the contents of dir. The show-hidden-p argument is passed through from the top-level call, intended to control whether file names starting with a period should be filtered out or not.")) (defmethod list-directory ((frame file-selector) dir &optional (show-hidden-p nil)) (flet ((sorted-filtered-ls (d) ;; macOS always encodes file names as Unicode NFD no matter what the locale setting ;; is, so avoid a possible error here (in sbcl it's sb-int:c-string-decoding-error) ;; by ignoring a possibly misleading setting (let* (#+(and :sbcl :darwin) (sb-alien::*default-c-string-external-format* :utf-8) ;; this call to list-directory resolves symlinks otherwise it's not possible ;; to follow a symbolic link to a directory (e.g. tmp -> private/tmp, since ;; in this case tmp looks like a normal file) (items (cl-fad:list-directory d))) (sort (if show-hidden-p items (remove-if #'(lambda (p) (eql (char (file-dir-namestring p) 0) #\.)) items)) #'string< :key #'file-dir-namestring)))) (cons (if (pathname-root-p dir) nil (pathname-parent-directory dir)) (handler-case (sorted-filtered-ls dir) (error (e) (warn "Unable to list directory ~A: ~A" dir e) nil))))) (defun file-dir-namestring (x &optional homedir-tilde-p) (cond ((not (cl-fad:directory-pathname-p x)) (file-namestring x)) ((pathname-root-p x) ; NB could encounter root here via a symbolic link (directory-namestring x)) ((and homedir-tilde-p (equal x (user-homedir-pathname))) (let ((dir (car (last (pathname-directory x))))) (concatenate 'string #+:unix "~" (if (and dir (stringp dir)) dir "home")))) (t (car (last (pathname-directory x)))))) ;;; Avoid problems if we're in an environment with an old version of cl-fad (before 0.7.0?) (defun pathname-root-p (p) (if (fboundp (intern "PATHNAME-ROOT-P" :fad)) (funcall (intern "PATHNAME-ROOT-P" :fad) p) (equal (pathname-directory p) '(:absolute)))) (defun pathname-parent-directory (p) ;; argument p known not to be root (if (fboundp (intern "PATHNAME-PARENT-DIRECTORY" :fad)) (funcall (intern "PATHNAME-PARENT-DIRECTORY" :fad) p) (make-pathname :directory (butlast (pathname-directory p)) :defaults p))) (defun pathname-directory-pathname (p) (if (fboundp (intern "PATHNAME-DIRECTORY-PATHNAME" :fad)) (funcall (intern "PATHNAME-DIRECTORY-PATHNAME" :fad) p) (make-pathname :defaults p :name nil :type nil))) ;;; 'Places' and 'devices' pane containing user home directory, any useful files or directories ;;; (achieved by specialising list-places), and roots of file systems on mounted devices. This ;;; is the pane on the left. (eval-when (:compile-toplevel :load-toplevel :execute) (clim:define-presentation-type place-device-namestring ())) (define-file-selector-command com-select-place-device-namestring ((data 'place-device-namestring :gesture :select)) (display-places-devices clim:*application-frame* (clim:find-pane-named clim:*application-frame* 'places-devices-pane)) (select-file-dir data t)) (defun display-places-devices (frame stream) (display-fs-items (nconc (list "PLACES") (mapcar #'(lambda (p) (list* (file-dir-namestring p t) p (if (cl-fad:directory-pathname-p p) 'folder 'document))) (list-places frame)) (list " " "DEVICES") (mapcar #'(lambda (p) (list* (place-device-namestring p) p 'device)) (list-devices frame))) stream 'place-device-namestring 1)) (defun place-device-namestring (x) ;; return name containing pathname device and last component of directory (if any) - to ;; look like a "device" as might be shown to the user on the desktop (let ((dev (pathname-device x)) (dir (car (last (pathname-directory x))))) (when dir (unless (stringp dir) (setq dir nil))) (cond ((and dev (or (stringp dev) (symbolp dev) (characterp dev)) (not (member dev '(:unspecific :unc)))) (concatenate 'string (string dev) ":" dir)) (dir) (t (directory-namestring x))))) ;;; Create a list of pathnames representing common places (= directories) in which the user ;;; might want to select files. (defgeneric list-places (frame) (:documentation "Returns a list of pathnames, each of which is a regularly-used directory in which the user might want to select files.")) (defmethod list-places ((frame file-selector)) (list (user-homedir-pathname))) ;;; Return a sorted list of pathnames representing roots of all mounted file systems. In ;;; Allegro CL on Windows there is a built-in function that does most of the work. On macOS, ;;; file systems are available under /Volumes/ (defgeneric list-devices (frame) (:documentation "Returns a list of pathnames, each of which is the root of a currently mounted file system - either local or via a network.")) (defmethod list-devices ((frame file-selector)) (sort #+(and :mswindows :allegro) (mapcar #'(lambda (dev) (make-pathname :device (string dev) :directory '(:absolute))) (windows:file-systems)) ; Allegro CL only, defined in the :winapi module #+(and :mswindows (not :allegro)) (list (make-pathname :device "C" :directory '(:absolute))) #+:darwin ; = macOS (cl-fad:list-directory "/Volumes/") #+(or :freebsd :linux) (append (list (make-pathname :directory '(:absolute))) (cl-fad:list-directory "/media/") (cl-fad:list-directory "/mnt/")) #+:openbsd (cons (make-pathname :directory '(:absolute)) (cl-fad:list-directory "/mnt/")) #-(or :mswindows :darwin :linux :bsd) (list (make-pathname :directory '(:absolute))) #'(lambda (p1 p2) (let ((p1-dev (pathname-device p1)) (p1-dir (car (last (pathname-directory p1)))) (p2-dev (pathname-device p2)) (p2-dir (car (last (pathname-directory p2))))) (cond ((and p1-dev (null p2-dev)) t) ((and p2-dev (null p1-dev)) nil) ((or p1-dev p2-dev) (string< (string p1-dev) (string p2-dev))) ((and p1-dir (symbolp p1-dir)) t) ((and p2-dir (symbolp p2-dir)) nil) (t (string< (string p1-dir) (string p2-dir)))))))) ;;; Having successfully loaded, add :select-file as a feature. (eval-when (:compile-toplevel :load-toplevel :execute) (pushnew :select-file *features*))
38,477
Common Lisp
.lisp
695
39.296403
342
0.529602
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
7124341fe973243c98747790f9cf62aaaa7deb16c4d702b103ea7d141b741b57
15,470
[ -1 ]
15,471
defaults.lisp
jstoddard_observatory/defaults.lisp
;;;; defaults.lisp ;;;; Default options/parameters for various items. ;;;; Part of Observatory, by Jeremiah Stoddard (in-package :observatory) ;; Homepage (defparameter *homepage* "gemini://gemini.circumlunar.space/") ;; Styles (defparameter *h1-style* (make-text-style :sans-serif :bold :huge)) (defparameter *h2-style* (make-text-style :sans-serif :bold :very-large)) (defparameter *h3-style* (make-text-style :sans-serif :bold :large)) (defparameter *mono-style* (make-text-style :fix :roman :normal)) (defparameter *link-color* +blue+) ;; Where to save/load bookmarks (defparameter *bookmarks-file* (merge-pathnames (user-homedir-pathname) (make-pathname :name ".observatory-bookmarks")))
704
Common Lisp
.lisp
15
45.2
73
0.748538
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
cf8b0fc1433038338cf19bae0f7b20323c3f703ad1f5545ed4214f35c3eb0551
15,471
[ -1 ]
15,472
observatory.asd
jstoddard_observatory/observatory.asd
;;;; observatory.asd ;;;; System definition for Observatory (asdf:defsystem :observatory :description "A Gemini client" :author "Jeremiah Stoddard" :license "GPLv3" :depends-on (:cl-fad :mcclim :usocket :cl+ssl) :components ((:file "package") (:file "defaults" :depends-on ("package")) (:file "request" :depends-on ("package")) (:file "document" :depends-on ("package")) (:file "bookmarks" :depends-on ("package")) (:file "bookmark-ui" :depends-on ("package" "bookmarks" "defaults")) (:file "select-file") (:file "observatory" :depends-on ("package" "defaults" "request" "document" "select-file" "bookmarks" "bookmark-ui"))))
749
Common Lisp
.asd
23
26.217391
51
0.6
jstoddard/observatory
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
ff1a8694b4e55efa0af942e4838b192d751f18aaf0e35c01169f7f0cae498220
15,472
[ -1 ]
15,496
package.lisp
vcerovski_binfix/package.lisp
; BINFIX by V.Cerovski 2015,9 (defpackage #:binfix #-gcl(:use #:cl) #+gcl(:use #:lisp) (:export #:binfix #:def-Bop #:set-Bop #:rem-Bops #:list-Bops #:keep-Bops))
169
Common Lisp
.lisp
5
31.4
76
0.631902
vcerovski/binfix
5
1
1
GPL-2.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
bc2e269fbaeeef76fe6186601fb078805c4e718659582176f21c25d696f1bcdf
15,496
[ -1 ]
15,497
binfix-5am.lisp
vcerovski_binfix/binfix-5am.lisp
(defpackage #:binfix/5am (:use #:cl #:fiveam) (:export #:run-tests)) (in-package :binfix/5am) (def-suite binfix-tests) (in-suite binfix-tests) (defmacro B1 (test B-expr &rest rest) (declare (symbol test) (string B-expr)) "Reading and evaluating string B-EXPR in a one-argument TEST" `(,test (eval (read-from-string ,B-expr)) ,@rest)) (defmacro B2 (test (pred B-expr S-expr &rest rest1) &rest rest2) (declare (symbol test pred) (string B-expr)) "Reading and evaluating string B-EXPR in a two-argument TEST PRED. Note that B-EXPR is the 1st and S-EXPR the 2nd argument." `(,test (,pred ,S-expr (eval (read-from-string ,B-expr)) ,@rest1) ,@rest2)) (defmacro Berror (B-expr &rest rest) (declare (string B-expr)) "Check that reading (w/o evaluation) of string B-EXPR signals error" `(signals error (read-from-string ,B-expr) ,@rest)) (test S-expressions (B2 is (equal "'{a $ b}" '(a b) )) (B2 is (equal "'{f $ g x}" '(f (g x)) )) (B2 is (equal "'{f .$ g x}" '(f (g x)) )) (B2 is (equal "'{f x $ g x}" '((f x) (g x)) )) (B2 is (equal "'{f x .$ g x}" '(f x (g x)) )) (B2 is (equal "'{f $ g $ h x y z}" '(f (g (h x y z))) )) (B2 is (equal "'{f .$ g .$ h x y z}" '(f (g (h x y z))) )) (B2 is (equal "'{a b $ c d $ e f}" '((a b) ((c d) (e f))) )) (B2 is (equal "'{a b .$ c d .$ e f}" '(a b (c d (e f))) )) (B2 is (equal "'{a b .$ c d $ e f}" '(a b ((c d) (e f))) )) (B2 is (equal "'{a b $ c d .$ e f}" '((a b) (c d (e f))) )) (B2 is (equal "'{a $ b;}" '(a b) )) (B2 is (equal "'{a $ b; c}" '(a b c) )) (B2 is (equal "'{f a $ g b; h c}" '((f a) (g b) (h c)) )) (B2 is (equal "'{f a .$ g b; h c}" '(f a (g b) (h c)) )) (B2 is (equal "'{when {a > x}.$ print x; g x a}" '(when (> a x) (print x) (g x a)) )) (B1 is-true "{1 :. 2 equal '(1 . 2)}" ) (B1 is-true "{'{f $ x * y} equal '{f {x * y}}}" ) (B2 is (equal "'{-2 :. loop for i upto 9 collect i}" '(cons -2 (loop for i upto 9 collect i)) )) (B2 is (equal " '{loop for i = 1 to 3 collect loop for j = 2 to 4 collect {i :. j}} "'(loop for i = 1 to 3 collect (loop for j = 2 to 4 collect (cons i j))) )) (B2 is (equal " '{loop for i to n nconc loop for j to m collect .$ i :. j} "'(loop for i to n nconc (loop for j to m collect (cons i j))) )) (B2 is (equal " '(cond {x > 1 $ x} {x < 1 $ sin x} {b $ x + y} {t $ a}) "'(cond ((> x 1) x) ((< x 1) (sin x)) (b (+ x y)) (t a)) )) ) (test arithmetic (B2 is (equal "'{1 + 2} " '(+ 1 2) )) (B2 is ( = " {1 / 2} " 1/2 )) (B2 is (equal "'{a - b - c - d} " '(- a b c d) )) (B2 is (equal "'{- a - b - c - d} " '(- (- a) b c d) )) (B2 is (equal "'{a + b - c + d} " '(+ a (- b c) d) )) (B2 is (equal "'{- a * b} " '(- (* a b)) )) (B2 is (equal "'{a + b * c} " '(+ a (* b c)) )) (B2 is (equal "'{a + 1- b * c} " '(+ a (* (1- b) c)) )) (B2 is (equal "'{a * b / c * d + 1}" '(+ (/ (* a b) (* c d)) 1) )) (B2 is (equal "'{a - g b - c - f d}" '(- a (g b) c (f d)) )) ) (test functional (B2 is (equal "'{x -> x + a}" '(lambda (x) (+ x a)) ) "Lambda sanity check.") (B2 is (equal "'{x y = 1 -> x + y}" '(lambda (x &optional (y 1)) (+ x y)) )) (B2 is (equal "'{x y :number = 1 -> x + y}" '(lambda (x &optional (y 1)) (declare (type number y)) (+ x y)) )) (B2 is (equal "'{x :number = 1 y :number = 1 -> x + y}" '(lambda (&optional (x 1) (y 1)) (declare (type number x) (type number y)) (+ x y)) )) (B2 is (equal "'{x = 1 y = 1 -> declare x y :number x + y}" '(lambda (&optional (x 1) (y 1)) (declare (type number x y)) (+ x y)) )) (B1 is-true " {'{ x -> y -> z -> x * y + z @ 2 @ 3 @ 4} equal '(funcall (funcall (funcall (lambda (x) (lambda (y) (lambda (z) (+ (* x y) z)))) 2) 3) 4)}" ) (B2 is (equal "'{'min @/ a b -> abs {a - b} @. a b}" '(reduce 'min (mapcar (lambda (a b) (abs (- a b))) a b)) )) (B2 is (= "{-> 1 @}" 1 )) (B2 is (equal "'{-> 1 @}" '(funcall (lambda () 1)) )) (B2 is (= "{x -> y -> z -> x * y + z @ 2 @ 3 @ 4}" 10 )) ) (test let-forms (B2 is (equal "'{let x = 1 x}" '(let ((x 1)) x) ) "LET-form sanity check.") (B1 is-true "{1 = let x = 1 x}" ) (B1 is-true "{1 = flet {f := 1} (f)}" ) (B2 is (equal" '{flet {f x :integer y :number := {x / y}; g x :number y := {x ** y}} f 1 2 / g 2 3} " '(flet ((f (x y) (declare (type integer x) (type number y)) (/ x y)) (g (x y) (declare (type number x)) (expt x y))) (/ (f 1 2) (g 2 3))) )) (B2 is (equal " '{flet {f x := x + x; g x := y * y} f $ g x} " '(flet ((f (x) (+ x x)) (g (x) (* y y))) (f (g x))) )) (B2 is (equal " '{g x := x * x; declaim (inline f) & f x := x * x} "'(progn (defun g (x) (* x x)) (declaim (inline f)) (defun f (x) (* x x))) )) (B2 is (equal " '{g x := x * x; declaim (inline f); f x := x * x} "'(progn (defun g (x) (* x x)) (declaim (inline f)) (defun f (x) (* x x))) )) (B2 is (equal " '{g x := x * x declaim (inline f); f x := x * x} "'(progn (defun g (x) (* x x)) (declaim (inline f)) (defun f (x) (* x x))) )) (B2 is (equal " '{declaim (inline g); g x := x * x declaim (inline f); f x := x * x} "'(progn (declaim (inline g)) (defun g (x) (* x x)) (declaim (inline f)) (defun f (x) (* x x))) )) (B2 is (equal " '{g x := x * x; h y := g (g y) declaim (inline f) & f x := x * x; h x := f x} "'(progn (defun g (x) (* x x)) (defun h (y) (g (g y))) (declaim (inline f)) (progn (defun f (x) (* x x)) (defun h (x) (f x)))) )) (B2 is (equal " '{g x := x * x; h y := g (g y) declaim (inline f); f x := x * x; h x := f x} "'(progn (defun g (x) (* x x)) (defun h (y) (g (g y))) (declaim (inline f)) (defun f (x) (* x x)) (defun h (x) (f x))) )) ) (test multiple-let (B2 is (equal "'{let a b = floor a b; a + b}" '(multiple-value-bind (a b) (floor a b) (+ a b)) )) (B2 is (equal "'{let a :int b = floor a b; a + b}" '(multiple-value-bind (a b) (floor a b) (declare (type int a)) (+ a b)) )) (B2 is (equal "'{let a :int b :int = floor a b; a + b}" '(multiple-value-bind (a b) (floor a b) (declare (type int a) (type int b)) (+ a b)) )) (B2 is (equal "'{let (a b) = '(1 2); list a b}" '(destructuring-bind (a b) '(1 2) (list a b)) )) (B2 is (equal "'{let (a b) = '(1 2) list a b}" '(destructuring-bind (a b) '(1 2) (list a b)) )) (B2 is (equal "'{let (a = 2 b = 2) = f x; list a b}" '(destructuring-bind (&optional (a 2) (b 2)) (f x) (list a b)) )) (Berror "'{let a b = floor a b a + b}") (Berror "'{let a b floor a b a + b}") (Berror "'{let a b floor a b; a + b}") ) (test prefix (B2 is (equal "'{progn a}" '(progn a) )) (B2 is (equal "'{progn a;}" '(progn a) )) (B2 is (equal "'{progn (a)}" '(progn (a)) )) (B2 is (equal "'{progn (a);}" '(progn (a)) )) (B2 is (equal "'{values a b}" '(values a b) )) (B2 is (equal "'{values a; b}" '(values a b) )) (B2 is (equal "'{progn a; b;}" '(progn a b) )) (B2 is (equal "'{progn (a); b}" '(progn (a) b) )) (B2 is (equal "'{progn (a); (b)}" '(progn (a) (b)) )) (B2 is (equal "'{progn f a; f b}" '(progn (f a) (f b)) )) (B2 is (equal "'{f progn a b}" '(f (progn a b)) )) (B2 is (equal "'{f progn f a; b}" '(f (progn (f a) b)) )) (B2 is (equal "'{x / progn f a; b}" '(/ x (progn (f a) b)) )) (B1 is-true " {t == block b; return-from b t} " ) ) (test also-prefix (B2 is (equal "'{min f x y; g y x; h x}" '(min (f x y) (g y x) (h x)) )) (B2 is (equal "'{or a and b; p; c and d; pred q}" '(or (and a b) p (and c d) (pred q)) )) ) (test also-unary (B2 is (= " { - 1 } " -1 )) (B2 is (= " {- $ 1} " -1 )) (B2 is (= " {- $ / $ 2} " -1/2 )) (B2 is (equal "'{- $ a + b - c}" '(- {a + b - c}) )) (B2 is (equal "'{- $ a * b - c}" '(- {a * b - c}) )) (B2 is (equal "'{x > 0 $ - $ sqrt x}" '((> x 0) (- (sqrt x))) )) (B2 is (equal "'{.not. $ a .xor. b}" '(bit-not (bit-xor a b)) )) ) (test sets/binds (B2 is (equal "'{*print-case* =. :downcase}" '(setq *print-case* :downcase) )) (B2 is (equal "'{x -> a =. x}" '(lambda (x) (setq a x)) )) (B2 is (equal "'{x -> a _'x .= x}" '(lambda (x) (setf (slot-value a 'x) x)) )) (B2 is (equal "'{x -> s-x a .= x}" '(lambda (x) (setf (s-x a) x)) )) (B2 is (equal "'{i -> a[i] += d; b[i] += d .@ ind}" '(mapc (lambda (i) (incf (aref a i) d) (incf (aref b i) d)) ind) )) (B2 is (equal" '{let x :bit = 1 x}" '(let ((x 1)) (declare (type bit x)) x) )) (B2 is (equal "'{A ! I J += B ! I K * C ! K J}" '(INCF (AREF A I J) (* (AREF B I K) (AREF C K J))) )) (B2 is (equal" '{1 + setf a ! 1 = f 1 + 2; a ! 2 = 3 + f 4; + f 5} " '(+ 1 (setf (aref a 1) (+ (f 1) 2) (aref a 2) (+ 3 (f 4))) (f 5)) )) (B2 is (equal" '{x -> a :int b =.. (f x) c d :int =.. (g x) a * c / b * d @. h a;} " '(mapcar (lambda (x) (multiple-value-bind (a b) (f x) (declare (type int a)) (multiple-value-bind (c d) (g x) (declare (type int d)) (/ (* a c) (* b d))))) (h a)) )) (B2 is (equal " '{let a = b c; let* x = y z; l r =.. (f g) p q ..= (f l) declare q :int h a x l r p q} " '(let ((a (b c))) (let* ((x (y z))) (multiple-value-bind (l r) (f g) (destructuring-bind (p q) (f l) (declare (type int q)) (h a x l r p q))))) )) (B2 is (equal " '{let a = b c; let* x = y z; l r ..= (f g) p q =.. (f l) declare q :int h a x l r p q} " '(let ((a (b c))) (let* ((x (y z))) (destructuring-bind (l r) (f g) (multiple-value-bind (p q) (f l) (declare (type int q)) (h a x l r p q))))) )) (B2 is (equal "'{with-slots a b :_ s f a b}" '(with-slots (a b) s (f a b)) )) (B2 is (equal "'{with-slots a :t1 b :t2 :_ s f a b}" '(with-slots (a b) s (declare (type t2 b) (type t1 a)) (f a b)) )) (B2 is (equal " '{with-slots a1 = a b1 = b :_ s1 with-slots a2 = a b2 = b :_ s2 f a1 b2; g b1 a2} "'(with-slots ((a1 a) (b1 b)) s1 (with-slots ((a2 a) (b2 b)) s2 (f a1 b2) (g b1 a2))) )) (B2 is (equal " '{with-slots a1 :t1 = a b1 :t2 = b :_ s1 with-slots a2 :t1 = a b2 :t2 = b :_ s2 f a1 b2; g b1 a2} "'(with-slots ((a1 a) (b1 b)) s1 (declare (type t2 b1) (type t1 a1)) (with-slots ((a2 a) (b2 b)) s2 (declare (type t2 b2) (type t1 a2)) (f a1 b2) (g b1 a2))) )) ) (test Bop-symbol (B2 is (equal "'{a =c= b =c= c}" '(char= a b c) )) (B2 is (equal "'{cond a = b => c; a :=> b}" '(cond ((= a b) c (a :=> b))) )) (is-true (defpackage :test-bops (:use :cl))) (is-true (in-package :test-bops)) (is-true (defvar => 1)) (is-true (defvar =s= 2)) (B1 is-true "{t == cond package-name *package* =s= \"TEST-BOPS\" => t}") ) (test implicit-progn (B2 is (equal" '{x -> print x; setf car x = f x; cdr x = y -> g y @. x; .@ xs} " '(mapc (lambda (x) (print x) (setf (car x) (f x) (cdr x) (mapcar (lambda (y) (g y)) x))) xs) )) (B2 is (equal "'{cond (a) => (f); 1; g => 22; (f) => nil}" '(cond ((a) (f) 1) (g 22) ((f) nil)) )) (B2 is (equal " '{cond x > 1 => x; x < 1 => print 1; sin x; b => let y = g y; x + y ** 3; t => a} " '(cond ((> x 1) x) ((< x 1) (print 1) (sin x)) (b (let ((y (g y))) (+ x (expt y 3)))) (t a)) )) (B2 is (equal "'{ecase f x; 0 1 2 => print 'a; g a; 3 4 => print 'b; g b; 6 => print 'c; h c} "'(ecase (f x) ((0 1 2) (print 'a) (g a)) ((3 4) (print 'b) (g b)) (6 (print 'c) (h c))) )) (B2 is (equal "'{case f a; 1 a; 2 b; 3 c}" '(case (f a) (1 a) (2 b) (3 c)) )) ) (test definitions (B2 is (equal "'{def var *x* :fixnum = 1}" '(progn (declaim (type fixnum *x*)) (defvar *x* 1)) )) (B2 is (equal "'{def var *x* :fixnum = 1;}" '(progn (declaim (type fixnum *x*)) (defvar *x* 1)) )) (B2 is (equal "'{def parameter a = x; g y := y}" '(progn (defparameter a x) (defun g (y) y)) )) (B2 is (equal "'{declaim (inline f); f x := x}" '(progn (declaim (inline f)) (defun f (x) x)) )) (B2 is (equal "'{def struct s a b c; var *v* = 1}" '(progn (defstruct s a b c) (defvar *v* 1)) )) (B2 is (equal " '{def parameter *x* = 1 *y* = 2 def struct point x y z; f x := sqrt x * sin x} ;; from v0.50, it is an error to use def here. "'(progn (defparameter *x* 1) (defparameter *y* 2) (defstruct point x y z) (defun f (x) (* (sqrt x) (sin x)))) )) (B2 is (equal " '{def struct point x y z; f x := sqrt x * sin x} "'(progn (defstruct point x y z) (defun f (x) (* (sqrt x) (sin x)))) )) (B2 is (equalp " '{def generic join a b; \"Generic join.\" a :list b :list :- append a b; a :t b :list :- a :. b; a :list b :t :- `(,@a ,b); a :t b :t :- list a b} "'(progn (defgeneric join (a b) (:documentation "Generic join.") (:method ((a list) (b list)) (append a b)) (:method ((a t) (b list)) (cons a b)) (:method ((a list) (b t)) `(,@a ,b)) (:method ((a t) (b t)) (list a b)))) )) (B2 is (equal "'{f x := 1- x; g x := 1+ x}" '(progn (defun f (x) (1- x)) (defun g (x) (1+ x))) )) (B2 is (equalp "'{f x :== `(1- ,x); g x :== `(1+ ,x)}" '(progn (defmacro f (x) `(1- ,x)) (defmacro g (x) `(1+ ,x))) )) (B2 is (equal "'{f x :t1 :- 1- x; f x :t2 :- 1+ x}" '(progn (defmethod f ((x t1)) (1- x)) (defmethod f ((x t2)) (1+ x))) )) (B2 is (equal "'{f x := print x; 1- x; g x := print x; 1+ x}" '(progn (defun f (x) (print x) (1- x)) (defun g (x) (print x) (1+ x))) )) (B2 is (equal "'{f x := let y = g x; x + y; g x := x * x}" '(progn (defun f (x) (let ((y (g x))) (+ x y))) (defun g (x) (* x x))) )) (B2 is (equalp "'{m x == 'a b :n :- a + b}" '(defmethod m ((x (eql 'a)) (b n)) (+ a b)) )) (B2 is (equal " '{f x := x ** 2; m a :== binfix $ list a '** 2; g x := cond x > 0 => 1; t => -1; h x := - x} "'(progn (defun f (x) (expt x 2)) (defmacro m (a) (binfix (list a '** 2))) (defun g (x) (cond ((> x 0) 1) (t -1))) (defun h (x) (- x))) )) (B2 is (equalp "'{type int := '(signed-byte 32)}" '(defun type (int) '(signed-byte 32)) )) (B2 is (equalp "'{type int :== '(signed-byte 32)}" '(deftype int () '(signed-byte 32)) )) (B2 is (equalp "'{compiler-macro f x := x}" '(defun compiler-macro (f x) x) )) (B2 is (equalp "'{compiler-macro f x :== x}" '(define-compiler-macro f (x) x) )) (B2 is (equalp " '{f x := x; g x :- x; m x :== x; type I x :== x; compiler-macro c x :== x} "'(progn (defun f (x) x) (defmethod g (x) x) (defmacro m (x) x) (deftype i (x) x) (define-compiler-macro c (x) x)) )) ) (test obsolete (Berror " '{def f x := x; g y := y} " ) ;; use of def here is (Berror " '{f x := x; def g y := y} " ) ;; obsolete from v0.50 (Berror " '{f x := x def g y := y} " ) ;;<-- ; instead of def needed ) (test macro (B1 is-true " {defmacro m1 (x) `(expt ,x 2) & m2 x :== `{,x ** 2} & macroexpand '(m1 3) equal macroexpand '(m2 3) and m1 3 = m2 3 = 9}" ) (B2 is (equal "'{macrolet {m x y :== `x :. y} m 1 2}" '(macrolet ((m (x y) (cons `x y))) (m 1 2)) )) ) (test B-terms (B2 is (equal " '{A[i]} " '(aref a i) ) "B-terms sanity check" ) (B2 is (equal "'{(a)[i]}" '(aref (a) i) )) (B2 is (equal "'{a[i] + b[i;j] / c[i;j] - a[f k]}" '(+ (aref a i) (- (/ (aref b i j) (aref c i j)) (aref a (f k)))) )) (B2 is (equal "'{a[1;2][2;3]}" '(aref (aref a 1 2) 2 3) )) (B2 is (equal "'{incf table[[key;0]]}" '(incf (gethash key table 0)) )) (B2 is (equal "'{a index b}" '(a index b) )) (B2 is (equal "'{a (index b)}" '(a (index b)) )) (B2 is (equal "'{a {index b}}" '(a (index b)) )) ) (test parsing-errors (Berror " '{a; b} ") (Berror " '{a &} ") (Berror " '{a $} ") (Berror " '{$ a} ") (Berror " '{progn $ a} ") (Berror " '{min $ a} ") (Berror " '{a ->} ") (Berror " '{f :=} ") (Berror " '{f :-} ") (Berror " '{f :==} ") (Berror " '{f :type=} ") (Berror " '{:= f} ") (Berror " '{:- f} ") (Berror " '{:== f} ") (Berror " '{:type= f} ") (Berror " '{1 min 3 max 2} ") (Berror " '{1 <= 2 < 3} ") (Berror " '{a 1 =.. f x} ") (Berror " '{def atruct x y} ") (Berror " '{def :var x = 1} ") (Berror " '{def f x := x} ") ;; These are obsolete. (Berror " '{def f x :- x} ") ;; Starting with v0.50, (Berror " '{def f x :== x} ") ;; binfix reports now (Berror " '{def type ty :== 'fixnum} ") ;; "def trailing error" ) (test interface ;; These must be evaluated in order ;; and non-concurrently with other tests (is-false binfix::*init-binfix*) (B1 is-true "(binfix:def-Bop % mod :after +)") (is-true binfix::*init-binfix*) (B2 is (equal "'{a % b}" '(mod a b))) (B2 is (equal "'{a % b + c}" '(+ (mod a b) c))) (B1 is-false "(binfix:set-Bop % my-mod)") (B2 is (equal "'{a % b + c}" '(+ (my-mod a b) c))) (B1 is-false "(binfix:set-Bop binfix::index my-ref)") (B2 is (equal "'{a[i % j]}" '(my-ref a (my-mod i j)))) (B1 is-false "(binfix:set-Bop binfix::index aref)") (B1 is-false "(binfix:set-Bop binfix::index funcall)") (B2 is (equal "'{f[x;y;z]}" '(funcall f x y z) )) (B2 is (equal "'{f[x;y;]}" '(funcall f x y) )) (B2 is (equal "'{f[]}" '(funcall f) )) (B2 is (= "{'+[1;2]}" 3 )) (B2 is (= "{{x y -> y - x}[2;3]}" 1 )) (B1 is-false "(binfix:set-Bop binfix::index2 svref)") (B2 is (equal "'{f[x;a[[i]]]}" '(funcall f x (svref a i)) )) (B1 is-false "(binfix:set-Bop binfix::index2 svref :term)") (B2 is (equal "'{f[x;a[[i]]]}" '(funcall f x (svref a i)) )) (B1 is-false "(binfix:rem-Bops %)") (B2 is (equal "'{a % b + c}" '(+ (a % b) c))) (B1 is-false "(binfix:rem-Bops + ++ := let def - flet |;| = && :.)") (B2 is (equal "'{f := x + y}" '(f := x + y))) (B1 is-false "(some 'identity {b -> get (binfix::find-Bop b) 'binfix::properties @. '(+ ++ := let def - flet |;| = && :.)})") (B1 is-false "(binfix:keep-Bops)") (B1 is-true "(every 'identity {b -> get (binfix::find-Bop b) 'binfix::properties @. '(+ := let def - flet |;| = && :.)})") (B1 is-false "(binfix:keep-Bops +)") (B2 is (equal "'{a + b - c}" '(+ a (b - c)) )) (B1 is-false "(binfix:keep-Bops let := + - |;|)") (B2 is (equal "'{f x := let a = b + c; f x - f b / a * x}" '(defun f (x) (let ((a (+ b c))) (- (f x) (f b / a * x)))) )) (B1 is-false "(binfix:keep-Bops)")) (defun run-tests () "Returns t if all tests pass, otherwise nil" (setq *on-error* nil *on-failure* nil) (run! 'binfix-tests))
24,557
Common Lisp
.lisp
585
31.307692
94
0.351328
vcerovski/binfix
5
1
1
GPL-2.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
7336785e7bcc8136fc7cbcb978e705e94fff38dea41376095dc24cbef8500840
15,497
[ -1 ]
15,498
proto.lisp
vcerovski_binfix/proto.lisp
; BINFIX by V.Cerovski 2015,7 (in-package :binfix) (defparameter *binfix* '((|;| infix (progn)) (:== def defmacro) (:= def defun) (:- def defmethod) ( =. infix (setq)) (.= infix (setf)) (-> def-lambda) ($ infix ()) (symbol-macrolet let= symbol-macrolet) (let let= let) (let* let= let*) (labels flet= labels) (=.. var-bind multiple-value-bind) (..= var-bind destructuring-bind) (.x. unreduc .x. values) (:. infix (cons)) (|| infix (or)) (&& infix (and)) (== infix (eql)) (=c= infix (char=)) (=s= infix (string=)) ( < infix (<)) (in infix (member)) ( ! infix (aref)))) (defun binfix (e &optional (ops *binfix*)) (cond ((atom e) e) ((null ops) (if (cdr e) e (car e))) (t (let* ((op (car ops)) (op.rhs (member (pop op) e))) (if (null op.rhs) (binfix e (cdr ops)) (let ((lhs (ldiff e op.rhs))) (macroexpand-1 `(,@op ,lhs ,(cdr op.rhs))))))))) (defmacro infix (op lhs rhs) `(,@op ,(binfix lhs) ,(binfix rhs))) (defun semicolon (s ch) (declare (ignore ch)) (if (char= #\; (peek-char nil s)) (loop until (char= #\Newline (read-char s nil #\Newline t)) finally (return (values))) (values (intern ";")))) (defvar *timing* 0) (defun indexing (s ch) (declare (ignore ch)) (let* ((indices (read-delimited-list #\] s t))) (if (and (consp (car indices)) (eql (caar indices) 'index) (null (cdr indices))) `(index2 ,@(cdar indices)) `(index ,@indices)))) (defmacro binfix-reader () '(lambda (s ch) (declare (ignore ch)) (let ((time (get-internal-real-time)) (\; (get-macro-character #\;)) (\[ (get-macro-character #\[)) (\] (get-macro-character #\]))) (unwind-protect (progn (set-macro-character #\; #'semicolon) (set-macro-character #\[ #'indexing) (set-macro-character #\] (get-macro-character #\) )) (values (binfix (read-delimited-list #\} s t)))) (set-macro-character #\; \;) (set-macro-character #\[ \[) (set-macro-character #\] \]) (incf *timing* (- (get-internal-real-time) time)))))) (set-macro-character #\{ (binfix-reader)) (set-macro-character #\} (get-macro-character #\) )) #+ecl (defmacro use-binfix () "Helper macro for defining binfix interface in ECL." `(eval-when (:load-toplevel :compile-toplevel :execute) (set-macro-character #\{ (binfix-reader)) (set-macro-character #\} (get-macro-character #\) nil))))
2,811
Common Lisp
.lisp
77
29.87013
67
0.505874
vcerovski/binfix
5
1
1
GPL-2.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
fc3afbfc871b2781c9da3125c506acfa3ab1eb79c07393639a3426ad5669262b
15,498
[ -1 ]
15,499
proto1.lisp
vcerovski_binfix/proto1.lisp
; BINFIX by V.Cerovski 2015,7 (in-package :binfix) {defmacro def (what args body) `(,what ,@(if (atom args) `(,args ()) `(,(car args),(cdr args))) ,(binfix body)); def-lambda args body :== `(lambda ,(if (consp args) args `(,args)) ,(binfix body)); let= let lhs body &aux vars :== loop while {cadr body == '=} do {push `(,(car body),(caddr body)) vars; body =. cdddr body} finally (return (let ((let `(,let ,(nreverse vars) ,(binfix body)))) (if lhs (binfix `(,@lhs ,let)) let))); flet= flet lhs body &aux funs :== loop for r = {'= in body} while r for (name . lambda) = (ldiff body r) do {push `(,name ,lambda ,(cadr r)) funs; body =. cddr r} finally {return let flet = `(,flet ,(reverse funs) ,(binfix body)) if lhs (binfix `(,@lhs ,flet)) flet}; unreduc op op-lisp lhs rhs :== labels unreduce e &optional args arg = (cond {null e $ nreverse {binfix (nreverse arg) :. args}} {car e == op $ unreduce (cdr e) {binfix (nreverse arg) :. args}} {t $ unreduce (cdr e) args {car e :. arg}}) `(,op-lisp ,@(unreduce rhs `(,(binfix lhs)))); var-bind op lhs rhs :== `(,op ,lhs ,(car rhs) ,(binfix (cdr rhs)))} ;BOOTSTRAP PHASE 2 DONE. (DEFs and LETs in proto BINFIX defined) ;PROTO BINFIX DEFINED.
1,413
Common Lisp
.lisp
33
35.454545
77
0.54267
vcerovski/binfix
5
1
1
GPL-2.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
d8768e905fbfc663e545eeaf32532dbe5e7e3b9e28071850c503b5976d644076
15,499
[ -1 ]
15,500
binfix.asd
vcerovski_binfix/binfix.asd
; BINFIX by V.Cerovski 2015,9 (defsystem #:binfix :description "BINFIX -- A powerful binary infix syntax for Common LISP." :author "Viktor Cerovski" :licence "GNU GPLv2" :version "0.50" :serial t :components ((:file "package") (:file "proto") (:file "proto1") (:file "binfix") (:file "interface") (:static-file "README.md") (:static-file "doc/index.html") (:static-file "doc/markdown.css") (:static-file "doc/syntax-term.png") (:static-file "doc/syntax-gui.png")) :in-order-to ((test-op (test-op "binfix/5am")))) (defsystem #:binfix/5am :description "5am test suite for BINFIX" :author "Viktor Cerovski" :licence "GNU GPLv2" :depends-on (:binfix :fiveam) :components ((:file "binfix-5am")) :perform (test-op (o s) (symbol-call :binfix/5am :run-tests)))
864
Common Lisp
.asd
26
27.961538
75
0.627545
vcerovski/binfix
5
1
1
GPL-2.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
89ca920a72d50f23fab9837ae0590a876a4212f87886d786429943132af0ced5
15,500
[ -1 ]
15,504
.travis.yml
vcerovski_binfix/.travis.yml
language: lisp sudo: required env: matrix: - LISP=sbcl - LISP=ccl - LISP=abcl matrix: allow_failures: - LISP=ecl install: - curl https://raw.githubusercontent.com/luismbo/cl-travis/master/install.sh | bash - git clone https://github.com/vcerovski/binfix ~/lisp/binfix script: - cl -l fiveam -l binfix -e '(uiop:quit (if (asdf:test-system :binfix) 0 1))'
408
Common Lisp
.l
17
19.823529
87
0.664083
vcerovski/binfix
5
1
1
GPL-2.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
edf318dfdeade4941ffb221b486fec00c89e653069dbc932a6243a0de81ece0e
15,504
[ -1 ]
15,507
index.html
vcerovski_binfix/doc/index.html
<p><link href="markdown.css" rel="stylesheet" type="text/css"></link></p> <h1>BINFIX</h1> <p>Viktor Cerovski, August 2019.</p> <p><a href="https://travis-ci.org/vcerovski/binfix"><img src="https://travis-ci.org/vcerovski/binfix.png" alt="Build Status" title="" /></a> <a href="http://quickdocs.org/binfix/"><img src="http://quickdocs.org/badge/binfix.svg" alt="Quicklisp dist" title="" /></a></p> <p><a name="Introduction"></a></p> <h2>Introduction</h2> <p>BINFIX (blend from "Binary Infix") is a powerful infix syntax notation for S-expressions of Common LISP ranging from simple arithmetic and logical forms to whole programs.</p> <p><strong>NEW FEATURES in v0.50</strong> (July/August 2019): <a href="#Multi-defs"><code>;</code>-separated definitions</a> of functions which makes use of <code>def</code> for this purpose <a href="#Multi-defs">obsolete</a>; <a href="#Local-functions">Simpler</a> local definitions of longer/multiple functions; <a href="#packaging">No need to import any symbols to use BINFIX</a>.</p> <p><strong>NEW FEATURE</strong> (July 2019): <a href="#Destructuring-multiple-values"><code>let</code> supports multiple-value- and destructuring-bind</a>. <br> <strong>NEW FEATURES</strong> (July 2019): Introduced <code>=&gt;</code> for writing <a href="#Multiple-choice-forms"><code>cond</code> forms</a>, use of <code>?</code> is <em>depreciated</em>. Introduced BINFIX <a href="#with-slots"><code>with-slots</code></a>. <br> <strong>NEW FEATURE</strong> (Jun 2019): <em>B-terms</em>, allowing <a href="#Indexing">indexing</a>-like operations.</p> <p>Currently developed v0.50, once it's finished, should mark transition from experimental to a stable version of BINFIX. Although there are still a few important new features to come, BINFIX begins to look about right.</p> <!-- One of them, available from v0.16, is use of a single `;` symbol as a form-separating symbol in [implicit-progn](#LET-impl-progn-example), [expression terminator](#SETF-expr-termination) for SETFs, or as end of [LET binds symbol](#LET-impl-progn-examples) or [local functions definition](#Local-functions). There is also `def`, for [defining things](#def), and the latest is writing standard LISP definitions [without outer parens](#progn-m). Once the rest of them have been implemented, BINFIX will go to RC and then to reference 1.0 version. --> <hr /> <h2>Content</h2> <ul> <li><a href="#Installation">Installation</a></li> <li><a href="#B-expression">B-expression</a></li> <li><a href="#Examples">Examples</a> <ul> <li><a href="#Arithmetic-and-logical-expressions">Arithmetic and logical expressions</a></li> <li><a href="#Consing">Consing</a></li> <li><a href="#Lambdas-definitions-and-type-annotations">Lambdas, definitions and type annotations</a> <ul> <li><a href="#lambda">lambda</a></li> <li><a href="#Maps">Mappings</a></li> <li><a href="#defun">defun</a></li> <li><a href="#&amp;optional">&amp;optional</a></li> <li><a href="#Multi-defs">Multiple definitions (<strong>new feature in v0.50</strong>)</a></li> <li><a href="#Local-functions">Local functions (<strong>new feture in v0.50</strong>)</a></li> <li><a href="#defmethod">defmethod</a></li> <li><a href="#defmacro">defmacro</a></li> <li><a href="#def">def</a></li> <li><a href="#types">Type annotations, declarations and definitions</a></li> <li><a href="#funtypes">Funtion types</a></li> <li><a href="#progn-m">Definitions and declarations without parens</a></li> </ul></li> <li><a href="#LETs">LETs (<strong>new feature</strong>)</a></li> <li><a href="#SETs">SETs</a></li> <li><a href="#Implicit-progn">Implicit <code>progn</code></a></li> <li><a href="#<code>$</code>plitters"><code>$</code>plitters</a></li> <li><a href="#Multiple-choice-forms">Multiple-choice forms (<strong>new feature</strong>)</a></li> <li><a href="#Destructuring-multiple-values">Destructuring, multiple values (<strong>new feature</strong>)</a></li> <li><a href="#Loops">Loops</a></li> <li><a href="#Hash-tables-and-association-lists">Hash tables and association lists</a></li> </ul></li> <li><a href="#Indexing">Indexing (<strong>new feature</strong>)</a></li> <li><a href="#Mappings">Mappings</a></li> <li><a href="#Bits">Working with bits</a></li> <li><a href="#Support-for-macros">Support for macros</a></li> <li><a href="#More-involved-examples">More involved examples</a> <ul> <li><a href="#ordinal">ordinal</a></li> <li><a href="#join">join</a></li> <li><a href="#values-bind">values-bind</a></li> <li><a href="#for">for</a></li> <li><a href="#Cartesian-to-polar-coordinates">Cartesian to polar coordinates</a></li> <li><a href="#packaging">Using BINFIX in packages (<strong>new feature</strong>)</a></li> </ul></li> <li><a href="#Interface">Controlling Bops (<strong>new feature</strong>)</a></li> <li><a href="#Implementation">Implementation</a> <ul> <li><a href="#proto-BINFIX">proto-BINFIX</a></li> <li><a href="#CLISP-problems">Problems with CLISP</a></li> </ul></li> <li><a href="#Appendix">Appendix</a> <ul> <li><a href="#Syntax-highlighting">Syntax highlighting</a></li> <li><a href="#Operation-properties">Operation properties</a></li> <li><a href="#Unused-symbols">Unused symbols</a></li> <li><a href="#List-of-all-operations">List of all operations</a></li> </ul></li> </ul> <hr /> <p><a name="Installation"></a></p> <h2>Installation</h2> <p><a href="https://www.quicklisp.org/">Quicklisp</a> makes the downloading/installation/loading trivial:</p> <pre><code>(ql:quickload :binfix) </code></pre> <p>System can be tested via</p> <pre><code>(asdf:test-system :binfix) </code></pre> <p>Supported LISP implementations are <a href="http://sbcl.org">SBCL</a> (also used for development,) <a href="https://ccl.clozure.com/">Clozure CL</a>, <a href="https://en.wikipedia.org/wiki/Embeddable_Common_Lisp">ECL</a> (tested with v15.3.7 and v16.1.3) and <a href="https://abcl.org/">ABCL</a>, while <a href="https://github.com/rurban/clisp">CLISP</a> as of this release <a href="#CLISP-problems">is not supported</a>.</p> <p>BINFIX shadows <code>@</code> in Clozure CL and ECL, as well as <code>var</code> (<code>sb-debug:var</code>) and <code>struct</code> (<code>sb-alien:struct</code>) in SBCL.</p> <p>The latest version is available at <a href="https://github.com/vcerovski/binfix">github</a>, and can be obtained by</p> <pre><code>git clone https://github.com/vcerovski/binfix </code></pre> <p>There is also a syntax-highlighting file for <code>vim</code> editor, <code>binfix.vim</code>. Its installation consists of copying it into vimrc/syntax folder, which is on Linux located at <code>~/.vim/syntax</code> (should be created if it doesn't exist.)</p> <p>Once installed, after loading a LISP file, LISP+BINFIX syntax highlighting can be activated by <code>:set syntax=binfix</code>. Loading can be done automatically by adding</p> <pre><code>filetype on au BufNewFile,BufRead *.lisp,*.cl set syntax=binfix </code></pre> <p>to <code>.vimrc</code>.</p> <p><a name="B-expression"></a></p> <h2>B-expression</h2> <p>BINFIX rewrites a <em>B-expression</em> (B-expr) into an S-expression, written using curly brackets <code>{</code>...<code>}</code>, and may contain, in addition to symbols, constants, S-exprs and B-exprs, also <em>B-operations</em> (B-ops) and <em>B-terms</em>. Bops are just symbols that BINFIX recognizes and prioritizes according to each Bop's precedence (priority). In addition to priority, each Bop may have properties, which further specify how to handle Bop's left- and right-hand side. B-term is a B-op that works from within B-expr to allow indexing-like operations.</p> <p>BINFIX is a free-form notation (just like S-expr), i.e any number of empty spaces (including tabs and newlines) between tokens is treated the same as a single white space.</p> <p>Generally, quoting a BINFIX expression in REPL will produce the corresponding S-expression.</p> <p><a name="Examples"></a></p> <h2>Examples</h2> <p>For easier comparison of input and output forms in following examples, LISP printer is first <code>setq</code> (Bop <code>=.</code>) to lowercase output with</p> <pre><code>{*print-case* =. :downcase} </code></pre> <p>=> <code>:downcase</code></p> <p><a name="Arithmetic-and-logical-expressions"></a></p> <h3>Arithmetic and logical expressions</h3> <p>Classic math stuff:</p> <pre><code>{2 * 3 + 4} </code></pre> <p>=> <code>10</code></p> <pre><code>'{a * {b + c}} </code></pre> <p>=> <code>(* a (+ b c))</code></p> <pre><code>'{- {x + y} / x * y} </code></pre> <p>=> <code>(- (/ (+ x y) (* x y)))</code></p> <pre><code>'{0 &lt; x &lt; 1 &amp;&amp; y &gt;= 1 || y &gt;= 2} </code></pre> <p>=> <code>(or (and (&lt; 0 x 1) (&gt;= y 1)) (&gt;= y 2))</code></p> <pre><code>'{- f x - g x - h x} </code></pre> <p>=> <code>(- (- (f x)) (g x) (h x))</code></p> <p>Expressions like <code>{(f x y) * (g a b)}</code> and <code>{{f x y} * {g a b}}</code> generally produce the same result. The inner brackets, however, can be removed:</p> <pre><code>'{sqrt x * sin x} </code></pre> <p>=> <code>(* (sqrt x) (sin x))</code></p> <pre><code>'{A ! i .= B ! j + C ! k} </code></pre> <p>=> <code>(setf (aref a i) (+ (aref b j) (aref c k)))</code></p> <pre><code>'{a ! i j += b ! i k * c ! k j} </code></pre> <p>=> <code>(incf (aref a i j) (* (aref b i k) (aref c k j)))</code></p> <pre><code>'{listp A &amp;&amp; car A == 'x &amp;&amp; cdr A || A} </code></pre> <p>=> <code>(or (and (listp a) (eql (car a) 'x) (cdr x)) a)</code></p> <p><a name="Consing"></a></p> <h3>Consing</h3> <p>Operation <code>:.</code> stands for <code>cons</code>. For instance,</p> <pre><code>{-2 :. loop for i to 9 collect i} </code></pre> <p>=> <code>(-2 0 1 2 3 4 5 6 7 8 9)</code></p> <p>with the familiar behavior:</p> <pre><code>{1 :. 2 :. 3 equal '(1 2 . 3)} </code></pre> <p>=> <code>t</code></p> <pre><code>{1 :. 2 :. 3 :. {} equal '(1 2 3)} </code></pre> <p>=> <code>t</code></p> <p><a name="Lambdas-definitions-and-type-annotations"></a></p> <h3>Lambdas, definitions and type annotations</h3> <p><a name="lambda"></a></p> <h4><code>lambda</code></h4> <pre><code>'{x -&gt; sqrt x * sin x} </code></pre> <p>=> <code>(lambda (x) (* (sqrt x) (sin x)))</code></p> <pre><code>'{x :single-float -&gt; sqrt x * sin x} </code></pre> <p>=> <code>(lambda (x) (declare (type single-float x)) (* (sqrt x) (sin x)))</code></p> <pre><code>'{x y -&gt; {x - y}/{x + y}} </code></pre> <p>=> <code>(lambda (x y) (/ (- x y) (+ x y)))</code></p> <p>Mixing of notations works as well, so each of the following</p> <pre><code>{x y -&gt; / (- x y) (+ x y)} {x y -&gt; (- x y)/(+ x y)} {x y -&gt; (/ (- x y) (+ x y))} </code></pre> <p>produces the same form.</p> <p>Fancy way of writing <code>{2 * 3 + 4}</code></p> <pre><code>{x -&gt; y -&gt; z -&gt; x * y + z @ 2 @ 3 @ 4} </code></pre> <p>=> <code>10</code></p> <p>Quoting reveals the expanded S-expr</p> <pre><code>'{x -&gt; y -&gt; z -&gt; x * y + z @ 2 @ 3 @ 4} </code></pre> <p>=></p> <pre><code>(funcall (funcall (funcall (lambda (x) (lambda (y) (lambda (z) (+ (* x y) z)))) 2) 3) 4) </code></pre> <p>Indeed, <code>@</code> is left-associative, standing for <code>funcall</code>.</p> <p>More complicated types can be also explicitly given after an argument, </p> <pre><code>'{x :|or symbol number| -&gt; x :. x} </code></pre> <p>=></p> <pre><code>(lambda (x) (declare (type (or symbol number) x)) (cons x x)) </code></pre> <p><a name="Maps"></a></p> <h4><code>Mappings</code></h4> <p><code>mapcar</code> is also supported:</p> <pre><code>'{x -&gt; sin x * sqrt x @. (f x)} </code></pre> <p>=></p> <pre><code>(mapcar (lambda (x) (* (sin x) (sqrt x))) (f x)) </code></pre> <p>Alternatively, it is possible to use the expression-termination symbol <code>;</code>,</p> <pre><code>{x -&gt; sin x * sqrt x @. f x;} </code></pre> <p>to the same effect.</p> <p><code>reduce</code> is represented by <code>@/</code>,</p> <pre><code>'{#'max @/ x y -&gt; abs{x - y} @. a b} </code></pre> <p>=></p> <pre><code>(reduce #'max (mapcar (lambda (x y) (abs (- x y))) a b)) </code></pre> <p>and other maps have their <code>@</code>'s as well.</p> <p><a name="defun"></a></p> <h4><code>defun</code></h4> <p>Factorial fun:</p> <pre><code>'{f n :integer := if {n &lt;= 0} 1 {n * f {1- n}}} </code></pre> <p>=></p> <pre><code>(defun f (n) (declare (type integer n)) (if (&lt;= n 0) 1 (* n (f (1- n))))) </code></pre> <p>Function documentation, local declarations, local bindings and comments have a straightforward syntax:</p> <pre><code>'{g x := "Auxilary fn." declare (inline) let x*x = x * x; ;; Note binds termination via ; x*x / 1+ x*x} </code></pre> <p>=></p> <pre><code>(defun g (x) "Auxilary fn." (declare (inline)) (let ((x*x (* x x))) (/ x*x (1+ x*x)))) </code></pre> <p><a name="&amp;optional"></a></p> <h4><code>&amp;optional</code> is optional</h4> <p>Explicitly tail-recursive version of <code>f</code></p> <pre><code>'{fac n m = 1 := declare (integer m n) if {n &lt;= 0} m {fac {n - 1} {n * m}}} </code></pre> <p>=></p> <pre><code>(defun fac (n &amp;optional (m 1)) (declare (integer m n)) (if (&lt;= n 0) m (fac (- n 1) (* n m)))) </code></pre> <p>As you may by now expect, the following is also permitted</p> <pre><code>{fac n :integer m :integer = 1 := if {n &lt;= 0} m {fac {n - 1} {n * m}}} </code></pre> <p><em>supplied-p</em> variable <code>var</code> for an optional/keyword argument is given by <code>?var</code> after the assignment.</p> <p><code>{f x y = 0 ?supplied-y &amp;key z = 0 ?supplied-z :=</code><em><code>&lt;body expr&gt;</code></em><code>}</code>,</p> <p>where, within <em><code>&lt;body expr&gt;</code></em>, boolean variables <code>supplied-y</code> and <code>supplied-z</code> are available (for the standard check whether respective values were provided in the call of <code>f</code>.)</p> <p><a name="Multi-defs"></a></p> <h4>Multiple definitions (<strong>new feature in v0.50</strong>)</h4> <p>Definitions of several functions are simply written as <code>;</code>-separated individual definitions,</p> <pre><code>'{f x y := print "Addition"; x + y; g x :num y :num :- x + y; m x y :== `{,x + ,y}} </code></pre> <p>=></p> <pre><code>(progn (defun f (x y) (print "Addition") (+ x y)) (defmethod g ((x num) (y num)) (+ x y)) (defmacro m (x y) `(+ ,x ,y))) </code></pre> <p>Another way to obtain the same Sexpr until v0.50 was to use <code>def</code>,</p> <pre><code>'{def f x y := print "Addition"; x + y def g x :num y :num :- x + y def m x y :== `{,x + ,y}} </code></pre> <p>but this way of defining functions is <strong>obsolete</strong>.</p> <p>Furthermore, to define types or compiler macros in v0.50, it is sufficient to prefix a macro definition with <code>type</code> or <code>compiler-macro</code>, respectively. Here is the simplest example that puts together defining various kinds of Common LISP functions using BINFIX,</p> <pre><code>'{f x := x; g x :- x; m x :== x; type I x :== x; compiler-macro c x :== x} </code></pre> <p>=></p> <pre><code>(progn (defun f (x) x) (defmethod g (x) x) (defmacro m (x) x) (deftype i (x) x) (define-compiler-macro c (x) x)) </code></pre> <p><a name="Local-functions"></a></p> <h4>Local functions (<strong>new feature in v0.50</strong>)</h4> <p>Version of <code>fac</code> with a local recursive function <code>f</code> prior to v0.50 could be written as:</p> <pre><code>{fac n :integer := labels f n m := {if {n = 0} m {f (1- n) {n * m}}} f n 1} </code></pre> <p>or, by using a single <code>;</code> to terminate definition, as in</p> <pre><code>{fac n :integer := labels f n m := if {n = 0} m {f (1- n) {n * m}}; f n 1} </code></pre> <p>where both forms are translated into the following S-expr,</p> <pre><code>(defun fac (n) (declare (type integer n)) (labels ((f (n m) (if (= n 0) m (f (1- n) (* n m))))) (f n 1))) </code></pre> <p>which can be demonstrated by simply evaluating the quoted expressions.</p> <p>These two ways of defining local functions are <strong>not supported anymore starting with v0.50</strong>. Instead, the local function definition(s) must be enclosed in <code>{</code>...<code>}</code>,</p> <pre><code>{fac n :integer := labels {f n m := if {n = 0} m {f (1- n) {n * m}}} f n 1} </code></pre> <p>The new way of writing local definitions has advantages over old when multiple and/or more complicated local functions are defined.</p> <p>The same syntax is used also in the case of <code>flet</code> and <code>macrolet</code>, except that in the latter case <a href="#defmacro"><code>:==</code> is written</a> instead of <code>:=</code>.</p> <p><a name="defmethod"></a></p> <h4><code>defmethod</code></h4> <p>The following two generic versions of <code>f</code></p> <pre><code>'{f n :integer :- if {n &lt;= 0} 1 {n * f {1- n}}} '{f (n integer):- if {n &lt;= 0} 1 {n * f {1- n}}} </code></pre> <!-- '{f n :integer :- {if n <= 0; 1; n * f(1- n)}} --> <p>both produce</p> <pre><code>(defmethod f ((n integer)) (if (&lt;= n 0) 1 (* n (f (1- n))))) </code></pre> <p><code>:-</code> supports also eql-specialization via <code>==</code> op, analogous to the way <code>=</code> is used for optional arguments initialization, as well as an optional method qualifier, given as the first argument after the method name, that can be either a keyword or an atom surrounded by parens (i.e <code>:around</code>, <code>(reduce)</code> etc.)</p> <p><a name="defmacro"></a></p> <h4><code>defmacro</code></h4> <p>Macros are defined via <code>:==</code> operation, similar to the previous examples. See Sec. <a href="#Support-for-macros">Support for macros</a>.</p> <p><a name="types"></a></p> <h4>Type annotations, declarations and definitions</h4> <p>The examples shown so far demonstrate the possibility to type-annotate symbols in binds and lambda-lists by an (optional) keyword representing the type (for instance <code>:fixnum</code>, <code>:my-class</code>, <code>:|simple-array single-float|</code>, <code>:|or symbol number|</code>, <code>:|{symbol or number}|</code>, etc.)</p> <p>Bops that represent LISP forms which allow declaration(s), in BINFIX can have in addition to the standard <code>(declare ...)</code> form also unparenthesized variant:</p> <pre><code>'{f x :fixnum y = 2 := declare (inline) declare (fixnum y) x + y ** 2} </code></pre> <p>=></p> <pre><code>(defun f (x &amp;optional (y 2)) (declare (type fixnum x)) (declare (inline)) (declare (fixnum y)) (+ x (expt y 2))) </code></pre> <p>Another way to declare <code>x</code> and <code>y</code> is</p> <pre><code>'{f x y = 2 := declare x y :fixnum declare (inline) x + y ** 2} </code></pre> <p>=></p> <pre><code>(defun f (x &amp;optional (y 2)) (declare (inline)) (declare (fixnum x y)) (+ x (expt y 2))) </code></pre> <p><a name="funtypes"></a></p> <h4>Function types</h4> <p>Operation <code>:-&gt;</code> can be used to specify function type. For example, in SBCL 1.1.17 function <code>sin</code> has declared type that can be written as</p> <pre><code>'{number :-&gt; single-float -1.0 1.0 || double-float -1.0 1.0 || complex single-float || complex double-float .x. &amp;optional} </code></pre> <p>=></p> <pre><code>(function (number) (values (or (single-float -1.0 1.0) (double-float -1.0 1.0) (complex single-float) (complex double-float)) &amp;optional)) </code></pre> <p>Function <code>fac</code> with a local function from <a href="#Local-functions">this example</a> can have its type declared as</p> <pre><code>'{fac n :integer := labels {f n m := if {n = 0} m {f (1- n) {n * m}}} declare f {integer integer :-&gt; integer} f n 1} </code></pre> <p>=></p> <pre><code>(defun fac (n) (declare (type integer n)) (labels ((f (n m) (if (= n 0) m (f (1- n) (* n m))))) (declare (ftype (function (integer integer) integer) f)) (f n 1))) </code></pre> <p>Declaration which annotates that symbol value of a symbol is a function can be achieved by using <code>-&gt;</code> instead of <code>:-&gt;</code> in declaration of the symbol. For instance:</p> <pre><code>'{f x :integer := let f = x -&gt; 1+ x; declare f {integer -&gt; integer} flet {f x := 1- x} declare f {integer :-&gt; integer} cons (f x) {f @ x}} </code></pre> <p>=></p> <pre><code>(defun f (x) (declare (type integer x)) (let ((f (lambda (x) (1+ x)))) (declare (type (function (integer) integer) f)) (flet ((f (x) (1- x))) (declare (ftype (function (integer) integer) f)) (cons (f x) (funcall f x))))) </code></pre> <p>which has the expected behavior: <code>(f 0)</code> => <code>(-1 . 1)</code></p> <p>Type definitions are given using <code>:type=</code> OP, as in</p> <pre><code>`{mod n :type= `(integer 0 (,n))} </code></pre> <p>=></p> <pre><code>(deftype mod (n) `(integer 0 (,n))) </code></pre> <p><a name="def"></a></p> <h4><code>def</code></h4> <p>Program typically consists of a number of definitions. Bop <code>def</code> can be used to define variables, parameters, constants, structures, classes and generic functions. For instance,</p> <pre><code>'{def parameter *x* = 1 *y* = 2 def struct point x y z def f x := sqrt x * sin x} </code></pre> <p>=></p> <pre><code>(progn nil (defparameter *x* 1) (defparameter *y* 2) (defstruct point x y z) (defun f (x) (* (sqrt x) (sin x)))) </code></pre> <p>As it is clear from the example, the definitions are wrapped up in <code>progn</code>.</p> <p><a name="with-slots"></a> More detailed definitions are also straightforward to specify:</p> <pre><code>'{def parameter *y* :single-float = 1f0 *z* :single-float = 1f0 def struct point "Point" :print-function {p s d -&gt; declare (ignore d) with-slots x y z :_ p format s "#&lt;~$ ~$ ~$&gt;" x y z} :constructor create-point (x y = *y* z = *z*) x :single-float = 0f0 y :single-float = 0f0 z :single-float = 0f0; point+= p :point q :point := p _'x += q _'x; p _'y += q _'y; p _'z += q _'z; p; point-= p :point q :point := with-slots x y z :_ p with-slots dx = x dy = y dz = z :_ q x -= dx; y -= dy; z -= dz; p} </code></pre> <p>=></p> <pre><code>(progn (declaim (type single-float *y*) (type single-float *z*)) (defparameter *y* 1.0) (defparameter *z* 1.0) (defstruct (point (:print-function (lambda (p s d) (declare (ignore d)) (with-slots (x y z) p (format s "#&lt;~$ ~$ ~$&gt;" x y z)))) (:constructor create-point (x &amp;optional (y *y*) (z *z*)))) "Point" (x 0.0 :type single-float) (y 0.0 :type single-float) (z 0.0 :type single-float)) (progn (defun point+= (p q) (declare (type point p) (type point q)) (incf (slot-value p 'x) (slot-value q 'x)) (incf (slot-value p 'y) (slot-value q 'y)) (incf (slot-value p 'z) (slot-value q 'z)) p) (defun point-= (p q) (declare (type point p) (type point q)) (with-slots (x y z) p (with-slots ((dx x) (dy y) (dz z)) q (decf x dx) (decf y dy) (decf z dz) p))))) </code></pre> <p><code>def class</code> syntax is like <code>defclass</code> without parens. For this to work, class options (<code>:documentation</code> and <code>:metaclass</code>) have to be given <em>before</em> description of slots, while <code>:default-initargs</code> comes last as usual, just unparenthesized (see <a href="#Cartesian-to-polar-coordinates">example</a>.)</p> <p><code>def</code>ining of symbols follows the same syntax as <code>let</code> binding, which is covered next.</p> <p><a name="progn-m"></a></p> <h4>Definitions and declarations without parens</h4> <p>BINFIX allows writing of standard LISP definition forms without outer parens, as in</p> <pre><code>'{declaim (fixnum a b c) defvar a 0 defvar b 1 "variable b" defvar c 2} </code></pre> <p>=> </p> <pre><code>(progn (declaim (fixnum a b c)) (defvar a 0) (defvar b 1 "variable b") (defvar c 2)) </code></pre> <p>This extends to all Common LISP def-forms, <code>declaim</code> and <code>proclaim</code>.</p> <p>The result is wrapped up in a <code>progn</code>.</p> <p><a name="LETs"></a></p> <h3>LETs (<strong>new feature</strong>)</h3> <p>LET symbol-binding forms (<code>let</code>, <code>let*</code>, <code>symbol-macrolet</code>, etc) in BINFIX use <code>=</code> with an optional type-annotation:</p> <pre><code>'{let x :bit = 1 y = {2 ** 3} z = 4 x + y * z} </code></pre> <p>=></p> <pre><code>(let ((x 1) (y (expt 2 3)) (z 4)) (declare (type bit x)) (+ x (* y z))) </code></pre> <p><strong>New feature</strong>: BINFIX <code>let</code> <a href="#Destructuring-multiple-values">supports <code>multiple-value-bind</code> and <code>destructuring-bind</code></a> </p> <p><a name="LET-impl-progn-examples"></a> A single <code>;</code> can be used as a terminator of bindings:</p> <pre><code>'{let x :bit = 1 y = 2 ** 3 z = f a; x + y * z} </code></pre> <p>=></p> <pre><code>(let ((x 1) (y (expt 2 3)) (z (f a))) (declare (type bit x)) (+ x (* y z))) </code></pre> <p><a name="LET-impl-progn-example"></a> Finally, a single <code>;</code> can also be used to separate forms in implicit-progn, as in</p> <pre><code>'{let x :bit = 1 y = 2 ** 3 z = f a; ;; end of binds print "Let binds"; ;; 1st form x + y * z} ;; 2nd form of implicit-progn </code></pre> <p>=></p> <pre><code>(let ((x 1) (y (expt 2 3)) (z (f a))) (declare (type bit x)) (print "Let binds") (+ x (* y z))) </code></pre> <p><a name="LET-associativity"></a> Nesting of <code>let</code>s without parens follows the right-associativity</p> <pre><code>'{let a = f x; if a (g x) let b = h x; f b} </code></pre> <p>=></p> <pre><code>(let ((a (f x))) (if a (g x) (let ((b (h x))) (f b)))) </code></pre> <p>Note the three levels of parens gone.</p> <p><a name="SETs"></a></p> <h3>SETs</h3> <p>In addition to <code>=.</code>, <code>=...</code> and <code>.=</code>, Bops representing, respectively, a single <code>setq</code>, <code>multiple-value-setq</code> and <code>setf</code> assignment, multiple assignments via SETs can be done using <code>=</code>,</p> <pre><code>'{psetq x = cos a * x + sin a * y y = - sin a * x + cos a * y} </code></pre> <p>=></p> <pre><code>(psetq x (+ (* (cos a) x) (* (sin a) y)) y (+ (- (* (sin a) x)) (* (cos a) y))) </code></pre> <p>If it is necessary to remove repeating <code>sin a</code> and <code>cos a</code>, it is easy to use <code>let</code>,</p> <pre><code>{let sin = sin a cos = cos a; psetq x = cos * x + sin * y y = - sin * x + cos * y} </code></pre> <p>and in the case of SETF assignments, RHS are represented with a single expression,</p> <pre><code>'{psetf a ! 0 = {a ! 1} a ! 1 = {a ! 0}} </code></pre> <p>=></p> <pre><code>(psetf (aref a 0) (aref a 1) (aref a 1) (aref a 0)) </code></pre> <p><a name="SETF-expr-termination"></a> Alternatively, it is possible to use a single <code>;</code> as an expression-termination symbol,</p> <pre><code>'{psetf a ! 0 = a ! 1; ;; expr. termination via single ; a ! 1 = a ! 0} </code></pre> <p>=></p> <pre><code>(psetf (aref a 0) (aref a 1) (aref a 1) (aref a 0)) </code></pre> <p>It is also possible to mix infix SETFs with other expressions:</p> <pre><code>'{f x + setf a = b c = d; * h a c} </code></pre> <p>=></p> <pre><code>(+ (f x) (* (setf a b c d) (h a c))) </code></pre> <p><code>setf</code> and <code>setq</code> can be also represented via <code>.=</code> and <code>=.</code> Bops, and the main difference is in priority---the latter can be embedded within lambdas without parens. For instance, both</p> <pre><code>'{a -&gt; {setf car a = 0} .@ list} </code></pre> <p>and</p> <pre><code>'{a -&gt; car a .= 0 .@ list} </code></pre> <p>=></p> <pre><code>(mapc (lambda (a) (setf (car a) 0)) list) </code></pre> <p>In the case of implicit-progn within lambda,</p> <pre><code>'{a b -&gt; {setf car a = car b; car b = 0} .@ l1 l2} </code></pre> <p>=></p> <pre><code>(mapc (lambda (a b) (setf (car a) (car b) (car b) 0)) l1 l2) </code></pre> <p>while</p> <pre><code>'{a b -&gt; car a .= car b; car b .= 0 .@ l1 l2} </code></pre> <p>=></p> <pre><code>(mapc (lambda (a b) (setf (car a) (car b)) (setf (car b) 0)) l1 l2) </code></pre> <p><a name="Implicit-progn"></a></p> <h3>Implicit <code>progn</code></h3> <p>An implicit <code>progn</code> in BINFIX is achieved with a single <code>;</code> separating the forms forming the progn. In all cases (<code>-&gt;</code>, <code>:=</code>, <code>:-</code> and LETs) the syntax is following that of the <a href="#LET-impl-progn-example">LET example above</a>.</p> <p>As expected, other <code>prog</code>s have to be explicitly given,</p> <pre><code>'{x -&gt; prog2 (format t "Calculating... ") {f $ x * x} (format t "done.~%")} </code></pre> <p>or</p> <pre><code>'{x -&gt; prog2 format t "Calculating... "; f {x * x}; format t "done.~%"} </code></pre> <p>both producing the following form</p> <pre><code>(lambda (x) (prog2 (format t "Calculating... ") (f (* x x)) (format t "done.~%"))) </code></pre> <p>Since BINFIX is a free-form notation, the following one-liner also works:</p> <pre><code>'{x -&gt; prog2 format t "Calculating... "; f{x * x}; format t "done.~%"} </code></pre> <p>Bop <code>&lt;&amp;</code> stands for <code>prog1</code>,</p> <pre><code>'{x -&gt; {f {x * x} &lt;&amp; format t "Calculation done.~%"}} </code></pre> <p>=></p> <pre><code>(lambda (x) (prog1 (f (* x x)) (format t "Calculation done.~%"))) </code></pre> <p>while <code>multiple-value-prog1</code> is given by <code>&lt;&amp;..</code>.</p> <p><a name="<code>$</code>plitters"></a></p> <h3><code>$</code>plitters</h3> <p>Infix <code>$</code> is a vanishing OP, leaving only its arguments, effectively splitting the list in two parts.</p> <pre><code>'{f $ g $ h x y z} </code></pre> <p>=> <code>(f (g (h x y z)))</code></p> <p>Effect of <code>$</code> is similar to <code>$</code> in Haskell, except that here it works with Sexpr, so it is also possible to write</p> <pre><code>'{declare $ optimize (speed 1) (safety 1)} </code></pre> <p>or</p> <pre><code>'{declare {optimize $ speed 3; safety 1}} </code></pre> <p>both of which evaluate to</p> <pre><code>(declare (optimize (speed 1) (safety 1))) </code></pre> <p><code>$</code> also allows writing a shorter <code>cond</code>, as in</p> <pre><code>(cond {p x $ f x} {q x $ g x} {r x $ h x} {t $ x}) </code></pre> <p>compared to the equivalent</p> <pre><code>(cond ((p x) (f x)) ((q x) (g x)) ((r x) (h x)) (t x)) </code></pre> <p><code>$</code> parenthesizes its l.h.s, leaving r.h.s. unchanged. Another splitter is <code>.$</code>, which does the opposite, namely parenthesizes its r.h.s leaving l.h.s unchanged, providing yet another way to omit parens:</p> <pre><code>'{loop for i to n append loop for j to m collect .$ i :. j} </code></pre> <p>=></p> <pre><code>(loop for i to n append (loop for j to m collect (cons i j))) </code></pre> <p><a name="Multiple-choice-forms"></a></p> <h3>Multiple-choice forms (<code>cond</code>, <code>case</code>, ...) (<strong>new feature</strong>)</h3> <p>An alternative, <strong>depreciated</strong>, syntax to describe multiple-choice forms is to use <code>?</code> and <code>;</code></p> <pre><code>{cond p x ? f x; q x ? g x; r x ? h x; t ? x} </code></pre> <p>Preferred way to write such a form is to use <code>=&gt;</code> instead:</p> <pre><code>{cond p x =&gt; f x; q x =&gt; g x; r x =&gt; h x; t =&gt; x} </code></pre> <p>Similarly, <code>case</code>-like forms accept a B-expr before <code>=&gt;</code>-clauses,</p> <pre><code>{ecase f x; 0 1 2 =&gt; #\a; 3 4 =&gt; #\b; 6 =&gt; #\c} </code></pre> <p>where in simple cases <code>=&gt;</code> can be omitted</p> <pre><code>'{case f a; 1 a; 2 b; 3 c} </code></pre> <p>=></p> <pre><code>(case (f a) (1 a) (2 b) (3 c)) </code></pre> <p>Writing of implicit-progn in each clause is also supported in a straightforward way</p> <pre><code>{ecase f x; 0 1 2 =&gt; print "a"; g #\a; 3 4 =&gt; print "b"; g #\b; 6 =&gt; print "c"; h #\c} </code></pre> <p>=></p> <pre><code>(ecase (f x) ((0 1 2) (print "a") (g #\a)) ((3 4) (print "b") (g #\b)) (6 (print "c") (h #\c))) </code></pre> <p>See also <a href="#ordinal"><code>ordinal</code> example below</a>.</p> <p><a name="Destructuring-multiple-values"></a></p> <h3>Destructuring, multiple values (<strong>new feature</strong>)</h3> <p>BINFIX <code>let</code> supports binding of multiple values as well as destructuring,</p> <pre><code>`{let a = 1 b = 2 c = 3 let x y z = values 1 2 3; let (p (q = 2) r = 3) = '(1 nil); a = x = p = 1 &amp;&amp; b = y = q = 2 &amp;&amp; c = z = r = 3} </code></pre> <p>=></p> <pre><code>(let ((a 1) (b 2) (c 3)) (multiple-value-bind (x y z) (values 1 2 3) (destructuring-bind (p (&amp;optional (q 2)) &amp;optional (r 3)) '(1 nil) (and (= a x p 1) (= b y q 2) (= c z r 3))))) </code></pre> <p>which evaluates to <code>t</code>.</p> <p>Multiple values (<code>values</code>) are represented by <code>.x.</code> as well as <code>values</code>, <code>multiple-value-bind</code> by <code>=..</code> , and <code>destructuring-bind</code> by <code>..=</code></p> <pre><code>'{a (b) c ..= (f x) a + 1 .x. b + 2 .x. c + 3} </code></pre> <p>=></p> <pre><code>(destructuring-bind (a (b) c) (f x) (values (+ a 1) (+ b 2) (+ c 3))) </code></pre> <p>Another way to write the same expr:</p> <pre><code>'{a (b) c ..= (f x) values a + 1; b + 2; c + 3} </code></pre> <p><code>multiple-value-call</code> is represented by <code>.@.</code></p> <pre><code>'{#'list .@. 1 '(b 2) 3} </code></pre> <p>=></p> <pre><code>(multiple-value-call #'list 1 '(b 2) 3) </code></pre> <p>=></p> <pre><code>(1 (b 2) 3) </code></pre> <p>Both <code>..=</code> and <code>=..</code> can be nested,</p> <pre><code>'{a b c =.. (f x) x y z =.. (g z) a * x + b * y + c * z} </code></pre> <p>=></p> <pre><code>(multiple-value-bind (a b c) (f x) (multiple-value-bind (x y z) (g z) (+ (* a x) (* b y) (* c z)))) </code></pre> <p><code>multiple-value-setq</code> is given by <code>=...</code></p> <p><a name="Loops"></a></p> <h4>Loops</h4> <p>Loops can be also nested without writing parens:</p> <pre><code>'{loop for i = 1 to 3 collect loop for j = 2 to 4 collect {i :. j}} </code></pre> <p>=></p> <pre><code>(loop for i = 1 to 3 collect (loop for j = 2 to 4 collect (cons i j))) </code></pre> <p><a name="Hash-tables-and-association-lists"></a></p> <h4>Hash tables and association lists</h4> <p>Hash tables are supported via <code>~!</code> (<code>gethash</code>), <code>~~</code> (<code>remhash</code>) and <code>@~</code> (<code>maphash</code>) Bops. See also <a href="#Indexing">indexing</a>.</p> <p>Association lists are accessible via <code>!~~</code> (<code>assoc</code>) and <code>~~!</code> (<code>rassoc</code>).</p> <p><a name="Mappings"></a></p> <h3>Mappings</h3> <p>Mappings and function applications are what <code>@</code>-ops are all about, as summarized in the following table,</p> <table> <tr><td> <code>@</code></td> <td><code>funcall</code></td></tr> <tr><td> <code>@.</code></td> <td><code>mapcar</code></td></tr> <tr><td> <code>@..</code></td><td><code>maplist</code></td></tr> <tr><td> <code>@n</code></td> <td><code>mapcan</code></td></tr> <tr><td> <code>@.n</code></td><td><code>mapcon</code></td></tr> <tr><td> <code>.@</code></td> <td><code>mapc</code></td></tr> <tr><td><code>..@</code></td> <td><code>mapl</code></td></tr> <tr><td> <code>@/</code></td> <td><code>reduce</code></td></tr> <tr><td> <code>@~</code></td> <td><code>maphash</code></td></tr> <tr><td> <code>@@</code></td> <td><code>apply</code></td></tr> <tr><td> <code>.@.</code></td> <td><code>multiple-value-call</code></td></tr> </table> <p>They all have the same priority and are right-associative. Since they bind weaker than <code>-&gt;</code>, they are easy to string together with lambdas, as in a map-reduce expr.</p> <p><code>{'max @/ x y -&gt; abs{x - y} @. a b}</code></p> <p><a name="Indexing"></a></p> <h3>Indexing (<strong>new feature</strong>)</h3> <p>Indexing can be done using square brackets, <code>[</code>...<code>]</code>, by default set to <code>aref</code>,</p> <pre><code>'{a[i;j] += b[i;k] * c[k;j]} </code></pre> <p>=></p> <pre><code>(incf (aref a i j) (* (aref b i k) (aref c k j))) </code></pre> <p>or using double-square brackets, <code>[[</code>...<code>]]</code>, with one or two arguments, by default set to indexing of hash table,</p> <pre><code>'{ table[[key; default]] } </code></pre> <p>=></p> <pre><code>(gethash key table default) </code></pre> <p>What square-brackets represent can be changed <a href="#setbinfix">using <code>setbinfix</code></a>.</p> <p>The following table summarizes indexing Bops, from the weakest to the strongest binding:</p> <table> <tr><td><code>th-cdr</code></td> <td><code>nthcdr</code></td> </tr> <tr><td><code>th-bit</code></td> <td><code>logbitp</code></td> </tr> <tr><td><code>!..</code> &nbsp; <code>th-value</code></td><td><code>nth-value</code></td></tr> <tr><td><code>!.</code></td> <td><code>svref</code></td> </tr> <tr><td><code>.!</code></td> <td><code>elt</code></td> </tr> <tr><td><code>th</code></td> <td><code>nth</code></td> </tr> <tr><td><code>!!.</code></td> <td><code>row-major-aref</code></td></tr> <tr><td><code>.!!.</code></td> <td><code>bit</code></td> </tr> <tr><td><code>!!</code></td> <td><code>aref</code></td> </tr> <tr><td><code>~!</code> <code>!~~</code> <code>~~!</code></td> <td><code>gethash</code> <code>assoc</code> <code>rassoc</code></td> </tr> <tr><td><code>.!.</code></td> <td><code>bit</code></td> </tr> <tr><td><code>!</code></td> <td><code>aref</code></td> </tr> </table> <p><code>!..</code> and <code>th-value</code> are mere synonyms and thus of the same priority, as are <code>.!</code> <code>!.</code> and <code>!!.</code>, while <code>!!</code> is a weaker binding <code>!</code>, allowing easier writing of expr. with arithmetic operations with indices, like</p> <p><code>{a !! i + j}</code></p> <p><code>{a !! i + j; 1- k;}</code></p> <p>etc. In the same relation stand <code>.!.</code> and <code>.!!.</code></p> <p>Indexing of arrays is by default supported by the new square-brackets BINFIX reader, so the above two examples can be written as <code>{a[i + j]}</code> and <code>{a[i + j; 1- k]}</code>, respectively.</p> <p><a name="Bits"></a></p> <h3>Working with bits</h3> <p>Integer bit-logical BINFIX ops are given with a <code>.</code> after the name of OP, while bit-array version of the same OP with <code>.</code> before and after the name. For instance, <code>{a or. b}</code> transforms to <code>(logior a b)</code>, while <code>{a .or. b}</code> transforms to <code>(bit-ior a b)</code>.</p> <p><a name="Support-for-macros"></a></p> <h3>Support for macros</h3> <p>If BINFIX terms <em>only</em> are inserted under backquote, everything should work fine, </p> <pre><code>'{let t1 = 'x t2 = '{x + x} `{x -&gt; ,t1 / ,t2}} </code></pre> <p>=></p> <pre><code>(let ((t1 'x) (t2 '(+ x x))) `(lambda (x) (/ ,t1 ,t2))) </code></pre> <p>Replacing, however, BINFIX operations inside a backquoted BINFIX will <em>not</em> work. This is currently not considered as a problem because direct call of <code>binfix</code> will cover some important cases of macro transformations in a straightforward manner:</p> <pre><code>{m x y op = '/ type = :double-float :== let a = (gensym) b = (gensym) binfix:binfix `(let ,a ,type = ,x ,b ,type = ,y {,a - ,b} ,op {,a + ,b})} </code></pre> <p>Now macro <code>m</code> works as expected:</p> <pre><code>(macroexpand-1 '(m (f x y) {a + b})) </code></pre> <p>=></p> <pre><code>(let ((#:g805 (f x y)) (#:g806 (+ a b))) (declare (type double-float #:g806) (type double-float #:g805)) (/ (- #:g805 #:g806) (+ #:g805 #:g806))) t </code></pre> <p>or,</p> <pre><code>(macroexpand-1 '(m (f x y) {a + b}) * :double-float) </code></pre> <p>=></p> <pre><code>(let ((#:g817 (f x y)) (#:g818 (+ a b))) (declare (type double-float #:g817) (type double-float #:g818)) (* (- #:g817 #:g818) (+ #:g817 #:g818))) t </code></pre> <p>See more in <a href="#binfix-macros">implementation details</a></p> <p><a name="More-involved-examples"></a></p> <h3>More involved examples</h3> <p><a name="ordinal"></a></p> <h4><code>ordinal</code></h4> <p>Converting an integer into ordinal string in English can be defined as</p> <pre><code>{ordinal i :integer := let* a = i mod 10 b = i mod 100 suf = {cond a = b = 1 || a = 1 &amp;&amp; 21 &lt;= b &lt;= 91 =&gt; "st"; a = b = 2 || a = 2 &amp;&amp; 22 &lt;= b &lt;= 92 =&gt; "nd"; a = b = 3 || a = 3 &amp;&amp; 23 &lt;= b &lt;= 93 =&gt; "rd"; t =&gt; "th"} format () "~D~a" i suf} </code></pre> <p>It can be also written in a more "lispy" way without parens as</p> <pre><code>{ordinal1 i :integer := let* a = i mod 10 b = i mod 100 suf = {cond = a b 1 or = a 1 and &lt;= b 21 91 =&gt; "st"; = a b 2 or = a 2 and &lt;= b 22 92 =&gt; "nd"; = a b 3 or = a 3 and &lt;= b 23 93 =&gt; "rd"; t =&gt; "th"} format () "~D~a" i suf} </code></pre> <p>which can be tried using <code>@.</code> (<code>mapcar</code>)</p> <pre><code>{#'ordinal @. '(0 1 12 22 43 57 1901)} </code></pre> <p>=> <code>("0th" "1st" "12th" "22nd" "43rd" "57th" "1901st")</code></p> <p>(This example is picked up from <a href="http://blog.rust-lang.org/2015/04/17/Enums-match-mutation-and-moves.html">Rust blog</a>)</p> <p><a name="join"></a></p> <h4><code>join</code></h4> <p>APL-ish joining of things into list:</p> <pre><code>{ defgeneric join (a b) &amp; join a :list b :list :- append a b &amp; join a :t b :list :- cons a b &amp; join a :list b :t :- append a (list b) &amp; join a :t b :t :- list a b &amp; defbinfix ++ join } ; Must close here in order to use ++ {let e = '{2 in 'x ++ '(1 2 3) ++ '((a)) ++ -1 * 2} format t "~S~%=&gt; ~S" e (eval e)} </code></pre> <p>Evaluation of the above returns <code>t</code> and prints the following</p> <pre><code>(member 2 (join 'x (join '(1 2 3) (join '((a)) (* -1 2))))) =&gt; (2 3 (a) -2) </code></pre> <p>Another way to write <code>join</code> is as a single <code>defgeneric</code> definition, using <code>def generic</code>,</p> <pre><code>{def generic join a b; "Generic join." a :list b :list :- append a b; a :t b :list :- a :. b; a :list b :t :- `(,@a ,b); a :t b :t :- list a b} </code></pre> <p>which expands into</p> <pre><code>(progn (defgeneric join (a b) (:documentation "Generic join.") (:method ((a list) (b list)) (append a b)) (:method ((a t) (b list)) (cons a b)) (:method ((a list) (b t)) `(,@a ,b)) (:method ((a t) (b t)) (list a b)))) </code></pre> <p>(<strong>new feature in v0.50</strong>) This way of writing <code>;</code>-separated instances is possible also in the first example, by replacing the four <code>join</code> lines with</p> <pre><code> join a :list b :list :- append a b; join a :t b :list :- cons a b; join a :list b :t :- append a (list b); join a :t b :t :- list a b; </code></pre> <p><a name="values-bind"></a></p> <h4><code>values-bind</code></h4> <p>Macro <code>multiple-value-bind</code> with symbol <code>_</code> in variable list standing for an ignored value can be defined as</p> <pre><code>{values-bind v e &amp;rest r :== let* _ = () vars = a -&gt; if {a == '_} {car $ push (gensym) _} a @. v; `(multiple-value-bind ,vars ,e ,@{_ &amp;&amp; `({declare $ ignore ,@_})} ,@r)} </code></pre> <p>So, for instance,</p> <pre><code>(macroexpand-1 '(values-bind (a _) (truncate 10 3) a)) </code></pre> <p>=></p> <pre><code>(multiple-value-bind (a #:g823) (truncate 10 3) (declare (ignore #:g823)) a) t </code></pre> <p><a name="for"></a></p> <h4><code>for</code></h4> <p>Nested BINFIX lambda lists can be used in definitions of macros, as in the following example of a procedural for-loop macro</p> <pre><code>{for (v :symbol from below by = 1) &amp;rest r :== `(loop for,v fixnum from,from below,below ,@{by /= 1 &amp;&amp; `(by,by)} do ,@r)} </code></pre> <p>Now</p> <pre><code>(macroexpand-1 '(for (i 0 n) {a ! i .= 1+ i})) </code></pre> <p>=></p> <pre><code>(loop for i fixnum from 0 below n do (setf (aref a i) (1+ i))) t </code></pre> <p><a name="Cartesian-to-polar-coordinates"></a></p> <h4>Cartesian to polar coordinates</h4> <p>An example from <em>Common LISP the Language 2nd ed.</em> where Cartesian coordinates are converted into polar coordinates via change of class can be straightforwardly written in BINFIX (prior to v0.50) as</p> <pre><code>{def class position () (); class x-y-position (position) x :initform 0 :initarg :x y :initform 0 :initarg :y; class rho-theta-position (position) rho :initform 0 theta :initform 0 def update-instance-for-different-class :before old :x-y-position new :rho-theta-position &amp;key :- ;; Copy the position information from old to new to make new ;; be a rho-theta-position at the same position as old. let x = old _'x y = old _'y; new _'rho .= sqrt {x * x + y * y}; new _'theta .= atan y x ;;; At this point an instance of the class x-y-position can be ;;; changed to be an instance of the class rho-theta-position ;;; using change-class: &amp; p1 =. make-instance 'x-y-position :x 2 :y 0 &amp; change-class p1 'rho-theta-position ;;; The result is that the instance bound to p1 is now ;;; an instance of the class rho-theta-position. ;;; The update-instance-for-different-class method ;;; performed the initialization of the rho and theta ;;; slots based on the values of the x and y slots, ;;; which were maintained by the old instance. } </code></pre> <p>while in v0.50 <code>def class</code> section of the code has to be finished by <code>;</code> and <code>def</code> before <code>update-instance-for-different-class</code> is superfluous,</p> <pre><code>{def class position () (); class x-y-position (position) x :initform 0 :initarg :x y :initform 0 :initarg :y; class rho-theta-position (position) rho :initform 0 theta :initform 0; update-instance-for-different-class :before old :x-y-position new :rho-theta-position &amp;key :- ;; Copy the position information from old to new to make new ;; be a rho-theta-position at the same position as old. let x = old _'x y = old _'y; new _'rho .= sqrt {x * x + y * y}; new _'theta .= atan y x ;;; At this point an instance of the class x-y-position can be ;;; changed to be an instance of the class rho-theta-position ;;; using change-class: &amp; p1 =. make-instance 'x-y-position :x 2 :y 0 &amp; change-class p1 'rho-theta-position ;;; The result is that the instance bound to p1 is now ;;; an instance of the class rho-theta-position. ;;; The update-instance-for-different-class method ;;; performed the initialization of the rho and theta ;;; slots based on the values of the x and y slots, ;;; which were maintained by the old instance. } </code></pre> <p>where Steele's comments are left verbatim.</p> <p><a name="packaging"></a></p> <h4>Using BINFIX in packages (<strong>new feature</strong>)</h4> <p>v0.50 of BINFIX greatly simplifies use of BINFIX in packages by recognizing symbols representing Bops as having no package membership. Thus there is no need to export Bops by BINFIX and consequently no importing of Bops by a package is needed. The only symbols exported by BINFIX are names of macros needed for controlling Bops, described next.</p> <p><a name="Interface"></a></p> <h2>Controlling Bops (<strong>new feature</strong>)</h2> <p>The following set of forms modify BINFIX behavior by adding/removing/redefining Bops. They must be evaluated before and outside B-exprs in which the modified behavior takes place.</p> <ul> <li><p><code>(binfix:def-Bop Bop lisp-op priority &amp;rest properties)</code></p> <p>Macro function that defines new or redefines existing <code>Bop</code> to represent lisp operation <code>lisp-op</code> (both of these arguments are symbols,) where <code>priority</code> defines how weakly/strongly <code>Bop</code> binds its arguments (precedence,) with <a href="#Operation-properties">given <code>properties</code></a>.</p> <p><a name="setbinfix"></a></p></li> <li><p><code>(binfix:set-Bop Bop lisp-op)</code></p> <p>Macro function that associated with an existing <code>Bop</code> LISP symbol <code>lisp-op</code>. In effect it redefines what <code>Bop</code> does without changing any of its properties.</p> <p>Perhaps its most important role is to set what square-brackets in Bexpr represent. For instance, </p> <p><code>(binfix:set-Bop binfix::index binfix::hashget)</code></p> <p>sets B-terms <code>a[k]</code> to represent indexing of hashtable <code>a</code> by key <code>k</code>, while</p> <p><code>(binfix:set-Bop binfix::index2 svref)</code></p> <p>defines that <code>a[[i]]</code> represents <code>(svref a i)</code>.</p></li> <li><p><code>(binfix:rem-Bops Bop1 ... Bopn)</code></p> <p>Macro function that removes specified Bops <code>Bop1</code> ... <code>Bopn</code>. After this macro form is executed, symbols <code>Bop1</code> ... <code>Bopn</code> will not be interpreted as Bops within B-expressions.</p></li> <li><p><code>(binfix:keep-Bops Bop1 ... Bopn)</code></p> <p>Keep only given Bops <code>Bop1</code> ... <code>Bopn</code> . After this macro form is executed, only symbols <code>Bop1</code> ...<code>Bopn</code> will be interpreted as Bops within B-expressions, except in the case of <code>:=</code>, <code>:==</code> and <code>:-</code> which also require <code>progn</code> Bop if implicit-progn is to be used.</p></li> <li><p><code>(binfix:keep-Bops)</code></p> <p>After evaluation of this macro form, BINFIX is restored to its initial state.</p></li> </ul> <p><a name="Implementation"></a></p> <h2>Implementation</h2> <p>BINFIX expression is written as a list enclosed in curly brackets <code>{</code> ... <code>}</code> handled through LISP reader, so the usual syntax rules of LISP apply, e.g <code>a+b</code> is a single symbol, while <code>a + b</code> is three symbols. Lisp reader after tokenization calls the function <code>binfix</code> which does shallow transformation of BINFIX into S-expr representation of the expression.</p> <p>BINFIX uses a simple rewrite algorithm that divides a list in two, LHS and RHS of the lowest priority infix operator found within the list, then recursively processes each one.</p> <p><a name="proto-BINFIX"></a></p> <h3>proto-BINFIX</h3> <p>Bootstrapping is done beginning with proto-BINFIX,</p> <pre><code>(defparameter *binfix* '((|;| infix (progn)) (:== def defmacro) (:= def defun) (:- def defmethod) ( =. infix (setq)) (.= infix (setf)) (-&gt; def-lambda) ($ infix ()) (symbol-macrolet let= symbol-macrolet) (let let= let) (let* let= let*) (labels flet= labels) (=.. var-bind multiple-value-bind) (.x. unreduc .x. values) (:. infix (cons)) (|| infix (or)) (&amp;&amp; infix (and)) (== infix (eql)) (=c= infix (char=)) (in infix (member)) ( ! infix (aref)))) (defun binfix (e &amp;optional (ops *binfix*)) (cond ((atom e) e) ((null ops) (if (cdr e) e (car e))) (t (let* ((op (car ops)) (op.rhs (member (pop op) e))) (if (null op.rhs) (binfix e (cdr ops)) (let ((lhs (ldiff e op.rhs))) (macroexpand-1 `(,@op ,lhs ,(cdr op.rhs))))))))) (defmacro infix (op lhs rhs) `(,@op ,(binfix lhs) ,(binfix rhs))) (set-macro-character #\{ (lambda (s ch) (declare (ignore ch)) (binfix (read-delimited-list #\} s t)))) (set-macro-character #\} (get-macro-character #\) )) </code></pre> <p>which captures the basics of BINFIX.</p> <p>Since v0.15, BINFIX interns a symbol consisting of a single <code>;</code> char not followed by <code>;</code> char, while two or more consecutive <code>;</code> are interpreted as a usual LISP comment. This behavior is limited to BINFIX expressions only, while outside of them the standard LISP rules apply.</p> <p>The next bootstrap phase defines macros <code>def</code>, <code>def-lambda</code>, <code>let=</code>, <code>flet=</code>, <code>unreduc</code> and <code>var-bind</code>, done in <code>proto1.lisp</code>,</p> <pre><code>{defmacro def (what args body) `(,what ,@(if (atom args) `(,args ()) `(,(car args),(cdr args))) ,(binfix body)); def-lambda args body :== `(lambda ,(if (consp args) args `(,args)) ,(binfix body)); let= let lhs body &amp;aux vars :== loop while {cadr body == '=} do {push `(,(car body),(caddr body)) vars; body =. cdddr body} finally (return (let ((let `(,let ,(nreverse vars) ,(binfix body)))) (if lhs (binfix `(,@lhs ,let)) let))); flet= flet lhs body &amp;aux funs :== loop for r = {'= in body} while r for (name . lambda) = (ldiff body r) do {push `(,name ,lambda ,(cadr r)) funs; body =. cddr r} finally {return let flet = `(,flet ,(reverse funs) ,(binfix body)) if lhs (binfix `(,@lhs ,flet)) flet}; unreduc op op-lisp lhs rhs :== labels unreduce e &amp;optional args arg = (cond {null e $ nreverse {binfix (nreverse arg) :. args}} {car e == op $ unreduce (cdr e) {binfix (nreverse arg) :. args}} {t $ unreduce (cdr e) args {car e :. arg}}) `(,op-lisp ,@(unreduce rhs `(,(binfix lhs)))); var-bind op lhs rhs :== `(,op ,lhs ,(car rhs) ,(binfix (cdr rhs)))} </code></pre> <p>which wraps up proto-BINFIX.</p> <p>Since v0.15, BINFIX interns a symbol consisting of a single <code>;</code> char not followed by <code>;</code> char, while two or more consecutive <code>;</code> are interpreted as starting a comment. This behavior is limited to BINFIX expressions only, while outside of them the standard LISP rules apply.</p> <p>The rest is written using proto-BINFIX syntax, and consists of handling of lambda lists and <code>let</code>s, a longer list of OPs with properties, redefined <code>binfix</code> to its full capability, and, finally, several interface functions for dealing with OPs (<code>lsbinfix</code>, <code>defbinfix</code> and <code>rmbinfix</code>).</p> <p>Priorities of operations in proto-BINFIX are given only relatively, with no numerical values and thus with no two operations of the same priority.</p> <p>LHS and RHS of proto-BINFIX expressions refer to other proto-BINFIX expressions (since v0.22.3), which in particular means that there is no implicit-progn in proto-BINFIX let's and def's.</p> <p>Since v0.20, symbol of a BINFIX operation has a list of properties stored into the symbol property <code>binfix::properties</code>, which includes a numerically given priority of the OP (which also considerably speeds up parsing.) The actual value of number representing priority is supposed to be immaterial since only relation to other Bops priority values is relevant. Defining a new same-priority Bop should be done via <code>defbinfix</code> with <code>:as</code> option. <a href="#Interface">Using <code>defbinfix</code></a> typically changes priority values of other Bops.</p> <p><a name="binfix-macros"></a> Since shallow transformation into standard syntax is done by function <code>binfix</code> invoked recursively by the reader, <code>binfix</code> cannot be directly called for arbitrary macro transformation of BINFIX into BINFIX when standard macro helpers BACKTICK, COMA and COMA-AT are used. The reason is that <code>{</code>...<code>}</code> is invoked before them while the correct order would be after them. Examples of successful combinations of backquoting and BINFIX are given <a href="#Support-for-macros">above</a>.</p> <p><a name="CLISP-problems"></a></p> <h3>Problems with CLISP</h3> <p>The latest version of <code>clisp</code> I have tried is <code>2.49.93+ (2018-02-18)</code>, which has two problems with BINFIX:</p> <ol> <li><p>There seems to be a bug in <code>set-macro-character</code> (see <a href="https://github.com/rurban/clisp/issues/10">here</a>.) Workaround is possible, but BINFIX still doesn't work (while other implementations tried do.)</p></li> <li><p>Test subsystem of the current version of BINFIX uses <a href="https://github.com/sionescu/fiveam"><code>fiveam</code></a>, which requires ASDF>=3.1, which <code>clisp</code> does not seem to support. Workaround is of course possible pending solving problem 1.</p></li> </ol> <p><a name="Appendix"></a></p> <h2>Appendix</h2> <p><a name="Syntax-highlighting"></a></p> <h3>Syntax highlighting</h3> <p>Provided <code>binfix.vim</code> file covers <code>vim</code> editor with a syntax-highlighting extension, which is based and depends on <code>lisp.vim</code> that comes bundled with <code>vim</code>.</p> <p>Here are GUI and terminal looks:</p> <p><img src="syntax-gui.png" alt="gui" title="" /> (theme: <code>solarized</code>, font: <code>Inconsolata Medium</code>)</p> <p><img src="syntax-term.png" alt="gui" title="" /> (theme: <code>herald</code>, font: <code>Terminus</code>)</p> <p><a name="Operation-properties"></a></p> <h3>Operation properties</h3> <table> <col style="width:8em"> <tr><th>Property</th><th>Description</th></tr> <tr><td><code>:def </code></td> <td> Operation (OP) is a definition requiring LHS to has a name and lambda list. </td></tr> <tr><td><code>:defm </code></td><td> OP is a definition requiring LHS to have a name followed by unparenthesized method lambda list. <td></tr> <tr><td><code>:lhs-lambda </code></td><td> OP has lambda list as its LHS. </td></tr> <tr><td><code>:rhs-lbinds </code></td><td> OP has let-binds at the beginning of its RHS,<br> [<em>symbol</em> [<em>keyword</em>]* <code>=</code> <em>expr</em>]* <em>declaration</em>* </td></tr> <tr><td><code>:rhs-fbinds </code></td><td> OP has flet-binds at the beginning of its LHS, including optional declarations. </td></tr> <tr><td><code>:rhs-sbinds </code></td><td> OP has symbol-binds as its RHS. They are let-binds without annotations or declarations. </td></tr> <tr><td><code>:rhs-ebinds </code></td><td> OP has expr-binds at the beginning of its RHS. </td></tr> <tr><td><code>:unreduce </code></td><td> All appearances of OP at the current level should be unreduced, i.e replaced with a single call with multiple arguments. </td></tr> <tr><td><code>:left-assoc </code></td><td> OP is left--associative (OPs are right-associative by default.) </td></tr> <tr><td><code>:prefix </code></td><td> OP is prefix with RHS being its arguments, given as one or more atoms/exprs which can be also <code>;</code>-separated. </td></tr> <tr><td><code>:prefix-left </code></td><td> OP is prefix with RHS being its arguments, given as one or more atoms/exprs which can be also <code>;</code>-separated. Resulting forms will be appended to the forms on the LHS. </td></tr> <tr><td><code>:also-prefix </code></td><td> OP can be used as prefix when LHS is missing. </td></tr> <tr><td><code>:also-unary </code></td><td> OP can be used as unary when LHS is missing. </td></tr> <tr><td><code>:also-postfix </code></td><td> OP can be used as postfix when RHS is missing. </td></tr> <tr><td><code>:lambda/expr </code></td><td> OP takes lambda-list at LHS and an expression at RHS, followed by body. </td></tr> <tr><td><code>:syms/expr </code></td><td> OP takes a list of symbols as LHS (each with an optional [keyword-type](#types) annotation,) an expression as RHS followed by optional declarations and a BINFIX-expression. </td></tr> <tr><td><code>:split </code></td><td> OP splits the expr at this point. </td></tr> <tr><td><code>:rhs-args </code></td><td> OP takes LHS as 1st and RHS as remaining arguments, which can be <code>;</code>-separated Bexpr. </td></tr> <tr><td><code>:quote-lhs </code></td><td> OP quotes LHS. </td></tr> <tr><td><code>:quote-rhs </code></td><td> OP quotes RHS. </td></tr> <tr><td><code>:macro </code></td><td> OP is a macro. </td></tr> <tr><td><code>:progn </code></td><td> OP is in a <a href=#progn-m>progn-monad</a>. Currently implemented in combination with <code>:prefix</code>, <code>:quote-rhs</code>/<code>:macro</code> properties (**DEPRECIATED**,) and with <code>:terms</code>. </td></tr> <tr><td><code>:single </code></td><td> OP requires to be the only OP in the current expr with its priority. For example, reading <code>{values a b .x. c}</code> reports an ambiguity error. </td></tr> <tr><td><code>:term </code></td><td> OP is a B-term. For example, Bop <code>binfix::index</code> makes<br> <code>{a (binfix::index i (1+ j))}</code> become <code>(aref a i (1+ j))</code> (<strong>new feature</strong>) </td></tr> <tr><td><code>:rhs-implicit-progn <i>symbol</i> </code></td><td> OP splits the RHS into blocks of Bexprs separated by <code><i>symbol</i></code> and <code>;</code> (<strong>new feature</strong>) </td></tr> </table> <p><a name="Unused-symbols"></a></p> <h3>Unused symbols</h3> <p>BINFIX does not use symbols <code>~</code>, <code>%</code> and <code>^</code>. The use of splitter <code>?</code> as a Bop is <strong>depreciated</strong> and will be removed. The current plan is that these four will be left for user-defined Bops.</p> <p><a name="List-of-all-operations"></a></p> <h3>List of all operations</h3> <p>Command <code>(binfix:list-Bops)</code> prints the table of all Bops and their properties from the weakest- to the strongest-binding Bop, with parens enclosing Bop(s) of the same priority:</p> <pre><code> BINFIX LISP Properties ============================================================================== ( &lt;&amp; prog1 &lt;&amp;.. multiple-value-prog1 ) ( &amp; progn :progn ) ( def nil :binfix-defs defclass defclass :progn :prefix :quote-rhs defstruct defstruct :progn :prefix :quote-rhs deftype deftype :progn :prefix :quote-rhs defparameter defparameter :progn :prefix :quote-rhs defvar defvar :progn :prefix :quote-rhs defconstant defconstant :progn :prefix :quote-rhs define-condition define-condition :progn :prefix :quote-rhs define-setf-expander define-setf-expander :progn :prefix :quote-rhs define-setf-method binfix::define-setf-method :progn :prefix :quote-rhs defsetf defsetf :progn :prefix :quote-rhs defgeneric defgeneric :progn :prefix :quote-rhs defmethod defmethod :progn :prefix :quote-rhs define-method-combination define-method-combination :progn :prefix :quote-rhs defun defun :progn :prefix :quote-rhs defmacro defmacro :progn :prefix :quote-rhs define-compiler-macro define-compiler-macro :progn :prefix :quote-rhs define-symbol-macro define-symbol-macro :progn :prefix :quote-rhs define-modify-macro define-modify-macro :progn :prefix :quote-rhs declaim declaim :progn :prefix :quote-rhs proclaim proclaim :progn :prefix :quote-rhs ) ( :== defmacro :def ((type . deftype) (compiler-macro . define-compiler-macro)) := defun :def :- defmethod :defm :type= deftype :def ) ( cond cond :rhs-implicit-progn binfix::=&gt; :prefix case case :rhs-implicit-progn binfix::=&gt; :prefix ccase ccase :rhs-implicit-progn binfix::=&gt; :prefix ecase ecase :rhs-implicit-progn binfix::=&gt; :prefix typecase typecase :rhs-implicit-progn binfix::=&gt; :prefix ctypecase ctypecase :rhs-implicit-progn binfix::=&gt; :prefix etypecase etypecase :rhs-implicit-progn binfix::=&gt; :prefix ) ( let let :rhs-lbinds let* let* :rhs-lbinds symbol-macrolet symbol-macrolet :rhs-lbinds prog* prog* :rhs-lbinds prog prog :rhs-lbinds with-slots with-slots :rhs-slots macrolet macrolet :rhs-mbinds flet flet :rhs-fbinds labels labels :rhs-fbinds ) ( block block :prefix tagbody tagbody :prefix catch catch :prefix prog1 prog1 :prefix prog2 prog2 :prefix progn progn :prefix ) ( ? nil :split ) ( setq setq :rhs-sbinds set set :rhs-sbinds psetq psetq :rhs-sbinds ) ( setf setf :rhs-ebinds psetf psetf :rhs-ebinds ) ( $ nil :split :rhs-args .$ nil :split-left :rhs-args ) ( .@ mapc :rhs-args ..@ mapl :rhs-args @/ reduce :rhs-args @. mapcar :rhs-args @.. maplist :rhs-args @n mapcan :rhs-args @.n mapcon :rhs-args @~ maphash @@ apply :rhs-args .@. multiple-value-call :rhs-args @ funcall :rhs-args :left-assoc :also-postfix ) ( :-&gt; function :lhs-lambda ) ( -&gt; lambda :lhs-lambda ) ( =.. multiple-value-bind :syms/expr ..= destructuring-bind :lambda/expr ) ( values values :prefix :single .x. values :unreduce :single ) ( loop loop :prefix :quote-rhs ) ( =... multiple-value-setq :quote-lhs .= setf += incf -= decf =. setq .=. set ) ( || or :unreduce or or :unreduce :also-prefix ) ( &amp;&amp; and :unreduce and and :unreduce :also-prefix ) ( === equalp :single equal equal :single == eql :single eql eql :single eq eq :single ~~ remhash :single subtype-of subtypep :single ) ( :. cons ) ( in member ) ( th-cdr nthcdr ) ( =s= string= :single =c= char= :single :unreduce = = :single :unreduce :also-prefix /= /= :single :unreduce :also-prefix &lt; &lt; :single :unreduce :also-prefix &gt; &gt; :single :unreduce :also-prefix &lt;= &lt;= :single :unreduce :also-prefix &gt;= &gt;= :single :unreduce :also-prefix ) ( th-bit logbitp ) ( coerce coerce ) ( !.. nth-value th-value nth-value ) ( th nth ) ( .! elt !. svref !!. row-major-aref ) ( .!!. bit :rhs-args ) ( !! aref :rhs-args ) ( ~! gethash :single :rhs-args !~~ assoc :single ~~! rassoc :single ) ( .eqv. bit-eqv :rhs-args .or. bit-ior :rhs-args .xor. bit-xor :rhs-args .and. bit-and :rhs-args .nand. bit-and :rhs-args .nor. bit-nor :rhs-args .not. bit-not :also-unary .orc1. bit-orc1 :rhs-args .orc2. bit-orc2 :rhs-args .andc1. bit-andc1 :rhs-args .andc2. bit-andc2 :rhs-args ) ( dpb dpb :rhs-args ) ( ldb ldb ) ( ldb-test ldb-test ) ( deposit-field deposit-field :rhs-args ) ( mask-field mask-field ) ( byte byte ) ( eqv. logeqv :also-unary :unreduce ) ( or. logior :also-unary :unreduce ) ( xor. logxor :also-unary :unreduce ) ( and. logand :also-unary :unreduce ) ( nand. lognand ) ( nor. lognor ) ( test. logtest ) ( orc1. logorc1 ) ( orc2. logorc2 ) ( andc1. logandc1 ) ( andc2. logandc2 ) ( &lt;&lt; ash ) ( lcm lcm :also-unary :unreduce ) ( gcd gcd :also-unary :unreduce ) ( mod mod ) ( rem rem ) ( min min :also-prefix :unreduce :single max max :also-prefix :unreduce :single ) ( + + :also-unary :unreduce ) ( - - :also-unary :unreduce ) ( / / :also-unary ) ( * * :also-prefix :unreduce ) ( ** expt ) ( .!. bit :rhs-args ) ( ! aref :rhs-args :single _ slot-value :single ) ( ; binfix::|;| ) ( index aref :term index2 binfix::hashget :term :macro ) ------------------------------------------------------------------------------ </code></pre> <p>=> <code>nil</code></p>
72,927
Common Lisp
.l
1,701
39.463845
146
0.590966
vcerovski/binfix
5
1
1
GPL-2.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
73d2cd3aa1588110fd6d7423c71ba3f099417fa0db6bf71eeb2f1807df7e6f2a
15,507
[ -1 ]
15,522
schemish.lisp
j3pic_cl-htmlprag/schemish.lisp
;; Note: Since this was written specifically to port GPL'd HTMLPrag to Common Lisp, it ;; most likely counts as a derivative work of HTMLPrag, and therefore is itself ;; subject to the GPL. ;; 90% of the work of porting HTMLPrag to Common Lisp is done here. (cl:defpackage :schemish (:documentation "A Scheme-like environment for porting HTMLPrag to Common Lisp. It implements only those features of Scheme that were actually used by HTMLPrag.") (:export :let :LAMBDA :Λ :IF :COND :EQ? :PAIR? :CAR :CDR :DEFINE :APPLY :MAP :LENGTH :STRING-LENGTH :REVERSE :LIST->STRING :STRING->LIST :NOT :AND :OR :EQUAL? :NULL? :LIST? :EOF-OBJECT? :CLOSE-OUTPUT-PORT :CLOSE-INPUT-PORT :STRING->SYMBOL :SYMBOL? :STRING? :INTEGER? :EQV? :LIST-REF :STRING->NUMBER :VECTOR-REF :VECTOR-SET! :STRING-REF :STRING-SET! :SET! :FILTER :LETREC :OPEN-INPUT-STRING :DISPLAY :NEWLINE :DISPLAYLN :BEGIN :ELSE :ZERO? :+scheme-true+ :+scheme-false+ :string->number :exact->inexact :inexact->exact :number? :exact? :inexact? :integer->char :char->integer :set-car! :set-cdr! :string-append :read-char :member :memq :memv :cadr :cddr :open-output-string :get-output-string :case :current-output-port :write-char :symbol->string :for-each :let* :input-port? :assoc :assq :assv := :< :> :<= :>= :write-string :char? :char-alphabetic? :char-numeric? :string=? :string :string-append :call-with-values)) (cl:in-package :schemish) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (cl:defparameter *common-lisp-symbols* '(cl:&body cl:&rest cl:&optional cl:&key cl:cons cl:list cl:+ cl:- cl:/ cl:* cl:char-downcase cl:char-upcase cl:string-downcase cl:string-upcase cl:vector cl:write cl:values cl:append cl:list*)) (cl:import *common-lisp-symbols*) (cl:export *common-lisp-symbols*)) (cl:defconstant +scheme-false+ 'scheme-false) (cl:defconstant +scheme-true+ 'scheme-true) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (schemish-read-macros:enable-scheme-read-syntax)) (cl:defconstant else #t) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (cl:defmacro named-let (name defs &body body) (cl:let ((variables (cl:mapcar #'cl:car defs)) (values (cl:mapcar #'cl:cadr defs))) `(cl:labels ((,name ,variables ,@body)) (let () ;; to make inner (define ...) forms work. (,name ,@values))))) (cl:defmacro let (&body body) `(cl:progn ,@body))) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (cl:defun scheme-lambda-list->cl-lambda-list (lambda-list) (named-let loop ((scheme-lambda-list lambda-list) (cl-lambda-list '())) (cl:cond ((cl:null scheme-lambda-list) (cl:reverse cl-lambda-list)) ((cl:not (cl:consp scheme-lambda-list)) (loop '() (cl:list* scheme-lambda-list 'cl:&rest cl-lambda-list))) (cl:t (loop (cl:cdr scheme-lambda-list) (cl:cons (cl:car scheme-lambda-list) cl-lambda-list)))))) (cl:defmacro lambda (lambda-list &body body) `(cl:lambda ,(scheme-lambda-list->cl-lambda-list lambda-list) ,@body)) (cl:defmacro λ (lambda-list &body body) `(lambda ,lambda-list ,@body)) (cl:defmacro let (defs &body body) ;; We expand LET into (FUNCALL (LAMBDA (vars) ...)) instead ;; of using CL:LET. The reason for this is because our LAMBDA ;; allows the use of nested DEFINE forms, which is the same ;; semantics required by Scheme's LET. (cl:cond ((cl:null defs) `(cl:funcall (lambda () ,@body))) ((cl:symbolp defs) `(named-let ,defs ,@body)) (cl:t `(cl:funcall (lambda ,(cl:mapcar #'cl:first defs) ,@body) ,@(cl:mapcar #'cl:second defs))))) (cl:defmacro if (condition true-expr &optional false-expr) `(cl:if (cl:eq ,condition #f) ,false-expr ,true-expr)) (cl:defmacro cond (&rest cases) (let ((result '())) (cl:loop for (condition . body) in (cl:reverse cases) do (cl:setf result `(if ,condition (cl:progn ,@body) ,result))) result)) (cl:defun eq? (a b) (cl:if (cl:eq a b) #t #f)) (cl:defun pair? (obj) (cl:if (cl:consp obj) #t #f)) (cl:defun car (obj) (cl:declare (cl:type cl:cons obj)) (cl:car obj)) (cl:defun cdr (obj) (cl:declare (cl:type cl:cons obj)) (cl:cdr obj)) (cl:defmacro define-function ((function &rest arguments) &rest body) "A Scheme-like define form. Supports inner define forms, which expand to LABELS or LET." (let ((args cl:nil) (inner-functions cl:nil)) (cl:flet ((scheme-args->lisp-args (arguments) (let ((args cl:nil)) (cl:loop for (arg . rest) on arguments do (cl:push arg args) (cl:unless (cl:listp rest) (cl:push '&rest args) (cl:push rest args) (cl:return))) args))) (cl:setf args (scheme-lambda-list->cl-lambda-list arguments)) (cl:loop for form in body do (optima:match form ((cons 'define (cons (cons function-name args) local-body)) (cl:push `(,function-name ,(scheme-lambda-list->cl-lambda-list args) ,@local-body) inner-functions) (cl:pop body)) ((list 'define variable value) (cl:push `(local-var ,variable ,value) inner-functions) (cl:pop body)))) (cl:push cl:nil body) (cl:push 'cl:let body) (cl:if inner-functions (cl:loop for (prefix . func) in inner-functions do (cl:if (cl:eq prefix 'local-var) (cl:setf body `(let (,func) ,body)) (cl:setf body `(cl:labels ((,prefix ,@func)) ,body))))) `(cl:defun ,function ,args ,body)))) (cl:defmacro define-values (variables value-form) (let ((gensyms (cl:loop for v in variables collect (cl:gensym)))) `(cl:progn ,@(cl:loop for v in variables collect `(cl:defparameter ,v cl:nil)) (cl:multiple-value-bind ,gensyms ,value-form ,@(cl:loop for v in variables for g in gensyms collect `(cl:setf ,v ,g))) (cl:values)))) (cl:defmacro define (name &rest other-args) (cl:if (cl:listp name) `(define-function ,name ,@other-args) `(define-values (,name) ,@other-args))) (define (cadr obj) (car (cdr obj))) (define (caar obj) (car (car obj))) (define (cddr obj) (cdr (cdr obj))) (define (apply func . args) (cl:apply #'cl:apply (cons func args))) (define (map func . lists) (apply #'cl:mapcar (cons func lists))) (define (length list) (cl:declare (cl:type cl:list list)) (cl:length list)) (define (string-length list) (cl:declare (cl:type cl:string list)) (cl:length list)) (define (reverse list) (cl:declare (cl:type cl:list list)) (cl:reverse list)) (define (list->string list) (cl:declare (cl:type cl:list list)) (cl:coerce list 'cl:string)) (define (string->list string) (cl:declare (cl:type cl:string string)) (cl:coerce string 'cl:list)) (define (symbol->string symbol) (cl:symbol-name symbol)) (define (not obj) (if obj #f #t)) (cl:defmacro and (&rest conditions) (let ((it (cl:gensym))) (cl:if (cl:null conditions) '#t (cl:if (cl:cdr conditions) `(if ,(car conditions) (and ,@(cdr conditions)) #f) `(let ((,it ,(car conditions))) (if ,it ,it #f)))))) (cl:defmacro or (&rest conditions) (let ((it (cl:gensym))) (cl:if (cl:null conditions) '#f `(let ((,it ,(car conditions))) (if ,it ,it (or ,@(cdr conditions))))))) (define (equal? a b) (cl:typecase a (cl:null (null? b)) (cl:symbol (equal? (symbol->string a) (symbol->string b))) (cl:string (and (string? b) (not (eq? (cl:equalp a b) cl:nil)))) (cl:list (and (pair? b) (equal? (car a) (car b)) (equal? (cdr a) (cdr b)))) (cl:otherwise (cl:if (cl:eq (cl:equalp a b) cl:nil) #f #t)))) (define (null? obj) (eq? obj cl:nil)) (define (list? obj) (or (null? obj) (and (pair? obj) (list? (cdr obj))))) (cl:defstruct eof-object) (define (eof-object? obj) (not (null? (eof-object-p obj)))) (define (close-output-port port) (cl:close port)) (define (close-input-port port) (cl:close port)) (define (string->symbol string) (cl:intern string :keyword)) (define (symbol? obj) (not (null? (cl:symbolp obj)))) (define (string? obj) (not (null? (cl:stringp obj)))) (define (char? obj) (not (null? (cl:characterp obj)))) (define (char-alphabetic? obj) (not (null? (cl:alpha-char-p obj)))) (define (char-numeric? obj) (not (null? (cl:digit-char-p obj)))) (define (integer? obj) (not (null? (cl:integerp obj)))) (define (string=? a b) (not (null? (cl:string= a b)))) (define (eqv? a b) (not (null? (cl:eql a b)))) (define (list-ref list n) (cl:declare (cl:type list list)) (cl:elt list n)) (cl:defun string->number (string &optional (radix 10)) (parse-number:parse-number string :radix radix)) (define (exact->inexact number) (cl:coerce number 'cl:float)) (define (inexact->exact number) (cl:rationalize number)) (define (number? number) (not (null? (cl:numberp number)))) (define (exact? number) (not (null? (cl:rationalp number)))) (define (inexact? number) (and (number? number) (not (exact? number)))) (define (vector-ref vec n) (cl:aref vec n)) (define (string . args) (list->string args)) (define (vector-set! vec n new-value) (cl:setf (cl:aref vec n) new-value)) (define (string-ref str n) (cl:aref str n)) (define (string-set! str n new-value) (cl:setf (cl:aref str n) new-value)) (cl:defmacro set! (var value) `(begin (cl:setq ,var ,value) (values))) (define (filter pred list) (cl:declare (cl:type cl:list list)) (cl:remove-if-not (lambda (item) (cl:not (cl:eq (cl:funcall pred item) #f))) list)) (define (%member v list test) (cond ((null? list) #f) ((cl:funcall test v (car list)) #t) (else (%member v (cdr list) test)))) (define (member v list) (%member v list #'equal?)) (define (memv v list) (%member v list #'eqv?)) (define (memq v list) (%member v list #'eq?)) (cl:defmacro letrec (bindings &body body) "Like LET, but with a fucked-up hack that causes bindings to lambda forms to end up in the function cell, providing a half-assed emulation of Lisp-1. It doesn't work too well because there are a number of functions that Neil van Dyke wraps in conditional expressions, which defeat my analyzer." (let ((lambda-bindings (filter (λ (binding) (and (list? (cl:cadr binding)) (member (cl:caadr binding) '(lambda λ)))) bindings))) `(let ,(cl:loop for (var value) in bindings collect `(,var cl:nil)) (cl:labels ,(cl:loop for (function (lambda lambda-list . body)) in lambda-bindings collect `(,function ,lambda-list ,@body)) ,@(cl:loop for (var value) in bindings collect `(cl:setf ,var ,value)) ,@body)))) (define (open-input-string string) (cl:make-string-input-stream string)) (cl:defun write-string (string &optional (output-port cl:*standard-output*)) (cl:loop for ch across string do (write-char ch output-port))) (cl:defun display (value cl:&optional (out cl:*standard-output*)) (write-string (cond ((or (char? value) (string? value) (symbol? value)) (cl:format cl:nil "~a" value)) (else (cl:format cl:nil "~S" value))) out) (cl:values)) (cl:defun newline (cl:&optional (out cl:*standard-output*)) (cl:terpri out) (cl:values)) (cl:defun displayln (value cl:&optional (out cl:*standard-output*)) (display value out) (cl:terpri out) (cl:values)) (cl:defmacro begin (&body body) `(cl:progn ,@body)) (define (zero? num) (eq? num 0)) (define (call-with-values value-generating-function value-consuming-function) (cl:multiple-value-call value-consuming-function (cl:funcall value-generating-function))) (define (integer->char int) (cl:code-char int)) (define (char->integer ch) (cl:char-code ch)) (define (set-car! pair new-car) (cl:rplaca pair new-car)) (define (set-cdr! pair new-cdr) (cl:rplacd pair new-cdr)) (define (string-append . strings) (apply #'cl:concatenate (cons 'cl:string strings))) (cl:defstruct output-string-port contents) (define (write-char-to-string char output-string-port) (cl:declare (cl:type output-string-port output-string-port)) (cl:vector-push-extend char (cl:slot-value output-string-port 'contents))) (define (open-output-string) (make-output-string-port :contents (cl:make-array '(0) :element-type 'cl:character :adjustable cl:t :fill-pointer cl:t))) (define (get-output-string stream &optional (reset? #f)) (cl:prog1 (cl:slot-value stream 'contents) (if reset? (cl:setf (cl:slot-value stream 'contents) (cl:make-array '(0) :element-type 'cl:character :adjustable cl:t :fill-pointer cl:t))))) (cl:defun write-char (char &optional (port cl:*standard-output*)) (cl:if (output-string-port-p port) (write-char-to-string char port) (cl:write-char char port))) (cl:defun read-char (&optional (port cl:*standard-input*)) (cl:read-char port cl:nil (make-eof-object))) (cl:defmacro case (key &rest cases) `(cl:case ,key ,@(cl:loop for (matches . body) in cases collect `(,(if (eq? matches 'else) 'cl:otherwise matches) ,@body)))) (cl:defun current-output-port (&optional new-port) (cl:prog1 cl:*standard-output* (cl:when new-port (set! cl:*standard-output* new-port)))) (cl:defmacro when (condition &body body) `(if ,condition (begin ,@body))) (cl:defmacro unless (condition &body body) `(when (not ,condition) ,@body)) (define (for-each function . lists) (let loop ((lists lists)) (unless (memq '() lists) (apply function (map #'car lists)) (loop (map #'cdr lists))))) (cl:defmacro let* (defs &body body) (if (null? defs) `(let () ,@body) `(let (,(car defs)) (let* ,(cdr defs) ,@body)))) (define (%assoc object alist matches?) (cond ((null? alist) #f) ((cl:funcall matches? (caar alist) object) (car alist)) (else (%assoc object (cdr alist) matches?)))) (define (assoc object alist) (%assoc object alist #'equal?)) (define (assq object alist) (%assoc object alist #'eq?)) (define (assv object alist) (%assoc object alist #'eqv?)) (cl:defun = (&rest numbers) (not (null? (apply #'cl:= numbers)))) (cl:defun < (&rest numbers) (not (null? (apply #'cl:< numbers)))) (cl:defun > (&rest numbers) (not (null? (apply #'cl:> numbers)))) (cl:defun >= (&rest numbers) (not (null? (apply #'cl:>= numbers)))) (cl:defun <= (&rest numbers) (not (null? (apply #'cl:<= numbers)))) (define (input-port? port) (not (null? (cl:streamp port)))))
15,218
Common Lisp
.lisp
410
31.621951
127
0.626287
j3pic/cl-htmlprag
5
0
1
LGPL-2.1
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
894b6c09744a36449a15a290d35c230f66d5bcce683b2fb39230dd536212e9e0
15,522
[ -1 ]
15,523
htmlprag.lisp
j3pic_cl-htmlprag/htmlprag.lisp
;;; @Package HtmlPrag ;;; @Subtitle Pragmatic Parsing and Emitting of HTML using SXML and SHTML ;;; @HomePage http://www.neilvandyke.org/htmlprag/ ;;; @Author Neil W. Van Dyke ;;; @AuthorEmail neil@@neilvandyke.org ;;; @Version 0.16 ;;; @Date 2005-12-18 ;; $Id: htmlprag.scm,v 1.385 2005/12/19 03:28:28 neil Exp $ ;;; @legal ;;; Copyright @copyright{} 2003 - 2005 Neil W. Van Dyke. This program 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 2.1 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 ;;; @indicateurl{http://www.gnu.org/copyleft/lesser.html} for details. For ;;; other license options and consulting, contact the author. ;;; @end legal ;;; Ported to Common Lisp by Jeremy L. Phelps, May 15, 2016, ;;; from the original, Scheme version of HTMLPrag. ;; 90% of porting this to CL was just recreating the Scheme constructs ;; used by HTMLPrag in Common Lisp. This was easy, since HTMLPrag doesn't ;; use continuations and doesn't use macros very heavily. The macros it ;; does use had to be rewritten from scratch. ;; Other than that, the code didn't have to be modified except for ;; correcting Lisp-1 vs Lisp-2 issues, and adjusting for the fact that ;; Common Lisp symbols have packages, and therefore if you type ;; '(a (@ (href "bar")) "Click me!"), your @ would not be EQ to HTMLPRAG::@. ;; Rather than export every symbol that;; HTMLPrag treats specially, I ;; implemented a SYMBOL=? function that ignores the package and made ;; HTMLPrag use that for all comparisons. ;; SXML generated by HTMLPrag will contain symbols interned in the ;; KEYWORD package. ;; Also, a small amount of code was changed so that HTMLPrag generates ;; and expects capital-letter symbols instead of lower-case. ;; You can still generate lower-case letters in tag and entity names by ;; explicitly generating lower-case symbols such as '|foo|, and HTMLPrag ;; will emit case-preserved tag names just as it does in Scheme. (cl:defpackage :cl-htmlprag (:use :schemish :%testeez) (:nicknames :htmlprag) (:export :html->shtml :shtml->html)) (cl:in-package :cl-htmlprag) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (schemish-read-macros:enable-scheme-read-syntax)) (define *parent-constraints* '((area . (map)) (body . (html)) (caption . (table)) (colgroup . (table)) (dd . (dl)) (dt . (dl)) (frame . (frameset)) (head . (html)) (isindex . (head)) (li . (dir menu ol ul)) (meta . (head)) (noframes . (frameset)) (option . (select)) (p . (body td th)) (param . (applet)) (tbody . (table)) (td . (tr)) (th . (tr)) (thead . (table)) (title . (head)) (tr . (table tbody thead)))) ;;; @section Introduction ;;; HtmlPrag provides permissive HTML parsing and emitting capability to Scheme ;;; programs. The parser is useful for software agent extraction of ;;; information from Web pages, for programmatically transforming HTML files, ;;; and for implementing interactive Web browsers. HtmlPrag emits ``SHTML,'' ;;; which is an encoding of HTML in ;;; @uref{http://pobox.com/~oleg/ftp/Scheme/SXML.html, SXML}, so that ;;; conventional HTML may be processed with XML tools such as ;;; @uref{http://pair.com/lisovsky/query/sxpath/, SXPath}. Like Oleg ;;; Kiselyov's @uref{http://pobox.com/~oleg/ftp/Scheme/xml.html#HTML-parser, ;;; SSAX-based HTML parser}, HtmlPrag provides a permissive tokenizer, but also ;;; attempts to recover structure. HtmlPrag also includes procedures for ;;; encoding SHTML in HTML syntax. ;;; ;;; The HtmlPrag parsing behavior is permissive in that it accepts erroneous ;;; HTML, handling several classes of HTML syntax errors gracefully, without ;;; yielding a parse error. This is crucial for parsing arbitrary real-world ;;; Web pages, since many pages actually contain syntax errors that would ;;; defeat a strict or validating parser. HtmlPrag's handling of errors is ;;; intended to generally emulate popular Web browsers' interpretation of the ;;; structure of erroneous HTML. We euphemistically term this kind of parse ;;; ``pragmatic.'' ;;; ;;; HtmlPrag also has some support for XHTML, although XML namespace qualifiers ;;; are currently accepted but stripped from the resulting SHTML. Note that ;;; valid XHTML input is of course better handled by a validating XML parser ;;; like Kiselyov's ;;; @uref{http://pobox.com/~oleg/ftp/Scheme/xml.html#XML-parser, SSAX}. ;;; ;;; HtmlPrag requires R5RS, SRFI-6, and SRFI-23. ;; The following bindings are used internally by HtmlPrag for portability, with ;; the intention that packagings of HtmlPrag use more efficient procedures for ;; the particular Scheme implementation. This is waiting on universal support ;; of SRFI-0. ;; @defproc %a2c num ;; ;; Returns the character with ASCII value @var{num}. In most Scheme ;; implementations, this is the same as @code{integer->char}. Two exceptions ;; are Scheme 48 0.57 and Scsh 0.6.3, for which the user must manually edit ;; file @code{htmlprag.scm} to bind this variable to @code{ascii->char}. A ;; future version of HtmlPrag will automatically use @code{ascii->char} where ;; available. (define (symbol=? a b) (and (symbol? a) (symbol? b) (equal? (symbol->string a) (symbol->string b)))) (define (memsymb item list) (cond ((null? list) #f) ((symbol=? item (car list)) #t) (else (memsymb item (cdr list))))) (define (is-at? obj) (and (symbol? obj) (equal? (symbol->string obj) "@"))) (define (%a2c int) (integer->char int)) ;; @defproc %append! a b ;; ;; Returns a concatenation of lists @var{a} and @var{b}, modifying the tail of ;; @var{a} to point to the head of @var{b} if both lists are non-null. A ;; future version should use the more general @code{append!} where available. (define (%append! a b) (cond ((null? a) b) ((null? b) a) (else (let loop ((sub a)) (if (null? (cdr sub)) (begin (set-cdr! sub b) a) (loop (cdr sub))))))) ;; @defproc %reverse!ok lst ;; ;; Returns a reversed list @var{lst}, possibly destructive. A future version ;; will use @code{reverse!} where available, and @code{reverse} elsewhere. (define (%reverse!ok list) (cl:nreverse list)) ;; @defproc %down str ;; ;; Returns a string that is equivalent to @var{str} with all characters mapped ;; to lowercase, as if by @code{char-downcase}, without mutating @var{str}. A ;; future version should use the Scheme implementation's native nondestructive ;; procedure where available. ;; @defproc %error proc-str msg obj ;; ;; For Bigloo, this is changed to: ;; ;; @lisp ;; (define %error error) ;; @end lisp ;; TODO: Maybe go back to requiring a SRFI-23 "error". (cl:defmacro %error (p m o) `(cl:error "~a ~S" (string-append ,p " : " ,m) ,o)) (define (%down s) (list->string (map #'char-upcase (string->list s)))) ;; @defproc %down!ok str ;; ;; Returns a string that is equivalent to @var{str} with all characters mapped ;; to lowercase, as if by @code{char-downcase}, possibly mutating @var{str}. ;; A future version should use the Scheme implementation's native destructive ;; or nondestructive procedure where available. (define (%down!ok s) (%down s)) ;; @defproc %gosc os ;; ;; One-shot version of the conventional @code{get-output-string}. The result ;; of any subsequent attempt to write to the port or get the output string is ;; undefined. This may or may not free up resources. ; (define (get-output-string os) ; (let loop ((result '()) ; (ch (read-char os))) ; (if (eof-object? ch) ; (list->string (reverse result)) ; (loop (cons ch result) ; (read-char os))))) (define (%gosc os) (let ((str (get-output-string os #t))) ;; Note: By default, we don't call close-output-port, since at least one ;; tested Scheme implementation barfs on that. ;; ;; (close-output-port os) str)) ;;; @section SHTML and SXML ;;; SHTML is a variant of SXML, with two minor but useful extensions: ;;; ;;; @enumerate ;;; ;;; @item ;;; The SXML keyword symbols, such as @code{*TOP*}, are defined to be in all ;;; uppercase, regardless of the case-sensitivity of the reader of the hosting ;;; Scheme implementation in any context. This avoids several pitfalls. ;;; ;;; @item ;;; Since not all character entity references used in HTML can be converted to ;;; Scheme characters in all R5RS Scheme implementations, nor represented in ;;; conventional text files or other common external text formats to which one ;;; might wish to write SHTML, SHTML adds a special @code{&} syntax for ;;; non-ASCII (or non-Extended-ASCII) characters. The syntax is @code{(& ;;; @var{val})}, where @var{val} is a symbol or string naming with the symbolic ;;; name of the character, or an integer with the numeric value of the ;;; character. ;;; ;;; @end enumerate ;;; @defvar shtml-comment-symbol ;;; @defvarx shtml-decl-symbol ;;; @defvarx shtml-empty-symbol ;;; @defvarx shtml-end-symbol ;;; @defvarx shtml-entity-symbol ;;; @defvarx shtml-pi-symbol ;;; @defvarx shtml-start-symbol ;;; @defvarx shtml-text-symbol ;;; @defvarx shtml-top-symbol ;;; ;;; These variables are bound to the following case-sensitive symbols used in ;;; SHTML, respectively: @code{*COMMENT*}, @code{*DECL*}, @code{*EMPTY*}, ;;; @code{*END*}, @code{*ENTITY*}, @code{*PI*}, @code{*START*}, @code{*TEXT*}, ;;; and @code{*TOP*}. These can be used in lieu of the literal symbols in ;;; programs read by a case-insensitive Scheme reader.@footnote{Scheme ;;; implementators who have not yet made @code{read} case-sensitive by default ;;; are encouraged to do so.} (define shtml-comment-symbol (string->symbol "*COMMENT*")) (define shtml-decl-symbol (string->symbol "*DECL*")) (define shtml-empty-symbol (string->symbol "*EMPTY*")) (define shtml-end-symbol (string->symbol "*END*")) (define shtml-entity-symbol (string->symbol "*ENTITY*")) (define shtml-pi-symbol (string->symbol "*PI*")) (define shtml-start-symbol (string->symbol "*START*")) (define shtml-text-symbol (string->symbol "*TEXT*")) (define shtml-top-symbol (string->symbol "*TOP*")) ;;; @defvar shtml-named-char-id ;;; @defvarx shtml-numeric-char-id ;;; ;;; These variables are bound to the SHTML entity public identifier strings ;;; used in SHTML @code{*ENTITY*} named and numeric character entity ;;; references. (define shtml-named-char-id "shtml-named-char") (define shtml-numeric-char-id "shtml-numeric-char") ;;; @defproc make-shtml-entity val ;;; ;;; Yields an SHTML character entity reference for @var{val}. For example: ;;; ;;; @lisp ;;; (make-shtml-entity "rArr") @result{} (& rArr) ;;; (make-shtml-entity (string->symbol "rArr")) @result{} (& rArr) ;;; (make-shtml-entity 151) @result{} (& 151) ;;; @end lisp (define (make-shtml-entity val) (list :& (cond ((symbol? val) val) ((integer? val) val) ((string? val) (string->symbol (string-upcase val))) (else (%error "make-shtml-entity" "invalid SHTML entity value:" val))))) ;; TODO: ;; ;; (define (shtml-entity? x) ;; (and (shtml-entity-value entity) #t)) ;;; @defproc shtml-entity-value obj ;;; ;;; Yields the value for the SHTML entity @var{obj}, or @code{#f} if @var{obj} ;;; is not a recognized entity. Values of named entities are symbols, and ;;; values of numeric entities are numbers. An error may raised if @var{obj} ;;; is an entity with system ID inconsistent with its public ID. For example: ;;; ;;; @lisp ;;; (define (f s) (shtml-entity-value (cadr (html->shtml s)))) ;;; (f "&nbsp;") @result{} nbsp ;;; (f "&#2000;") @result{} 2000 ;;; @end lisp (define (shtml-entity-value entity) (cond ((not (pair? entity)) #f) ((null? (cdr entity)) #f) ((symbol=? (car entity) '&) ;; TODO: Error-check for extraneous list members? (let ((val (cadr entity))) (cond ((symbol? val) val) ((integer? val) val) ((string? val) (string->symbol val)) (else #f)))) ((eqv? (car entity) shtml-entity-symbol) (if (null? (cddr entity)) #f (let ((public-id (list-ref entity 1)) (system-id (list-ref entity 2))) ;; TODO: Error-check for extraneous list members? (cond ((equal? public-id shtml-named-char-id) (string->symbol system-id)) ((equal? public-id shtml-numeric-char-id) (string->number system-id)) (else #f))))) (else #f))) ;;; @section Tokenizing ;;; The tokenizer is used by the higher-level structural parser, but can also ;;; be called directly for debugging purposes or unusual applications. Some of ;;; the list structure of tokens, such as for start tag tokens, is mutated and ;;; incorporated into the SHTML list structure emitted by the parser. ;; TODO: Document the token format. ;;; @defproc make-html-tokenizer in normalized? ;;; ;;; Constructs an HTML tokenizer procedure on input port @var{in}. If boolean ;;; @var{normalized?} is true, then tokens will be in a format conducive to use ;;; with a parser emitting normalized SXML. Each call to the resulting ;;; procedure yields a successive token from the input. When the tokens have ;;; been exhausted, the procedure returns the null list. For example: ;;; ;;; @lisp ;;; (define input (open-input-string "<a href=\"foo\">bar</a>")) ;;; (define next (make-html-tokenizer input #f)) ;;; (next) @result{} (a (@@ (href "foo"))) ;;; (next) @result{} "bar" ;;; (next) @result{} (*END* a) ;;; (next) @result{} () ;;; (next) @result{} () ;;; @end lisp ;; TODO: Have the tokenizer replace contiguous whitespace within individual ;; text tokens with single space characters (except for when in `pre' and ;; verbatim elements). The parser will introduce new contiguous whitespace ;; (e.g., when text tokens are concatenated, invalid end tags are removed, ;; whitespace is irrelevant between certain elements), but then the parser ;; only has to worry about the first and last character of each string. ;; Perhaps the text tokens should have both leading and trailing whitespace ;; stripped, and contain flags for whether or not leading and trailing ;; whitespace occurred. (define make-html-tokenizer (letrec ((no-token '()) ;; TODO: Maybe make these three variables options. (verbatim-to-eof-elems '(plaintext)) (verbatim-pair-elems '(script server style xmp)) (ws-chars (list #\space (%a2c 9) (%a2c 10) (%a2c 11) (%a2c 12) (%a2c 13))) (gosc/string-or-false (lambda (os) (let ((s (%gosc os))) (if (string=? s "") #f s)))) (gosc/symbol-or-false (lambda (os) (let ((s (gosc/string-or-false os))) (if s (string->symbol s) #f)))) ) (lambda (in normalized?) ;; TODO: Make a tokenizer option that causes XML namespace qualifiers to ;; be ignored. (cl:declare (cl:type cl:stream in)) (letrec ( ;; Port buffer with inexpensive unread of one character and slightly ;; more expensive pushback of second character to unread. The ;; procedures themselves do no consing. The tokenizer currently ;; needs two-symbol lookahead, due to ambiguous "/" while parsing ;; element and attribute names, which could be either empty-tag ;; syntax or XML qualified names. (c #f) (next-c #f) (c-consumed? #t) (read-c (lambda () (if c-consumed? (if next-c (begin (set! c next-c) (set! next-c #f)) (set! c (read-char in))) (set! c-consumed? #t)))) (unread-c (lambda () (if c-consumed? (set! c-consumed? #f) ;; TODO: Procedure name in error message really ;; isn't "make-html-tokenizer"... (%error "make-html-tokenizer" "already unread:" c)))) (push-c (lambda (new-c) (if c-consumed? (begin (set! c new-c) (set! c-consumed? #f)) (if next-c (%error "make-html-tokenizer" "pushback full:" c) (begin (set! next-c c) (set! c new-c) (set! c-consumed? #f)))))) ;; TODO: These procedures are a temporary convenience for ;; enumerating the pertinent character classes, with an eye towards ;; removing redundant tests of character class. These procedures ;; should be eliminated in a future version. (c-eof? (lambda () (eof-object? c))) (c-amp? (lambda () (eqv? c #\&))) (c-apos? (lambda () (eqv? c #\'))) (c-bang? (lambda () (eqv? c #\!))) (c-colon? (lambda () (eqv? c #\:))) (c-quot? (lambda () (eqv? c #\"))) (c-equals? (lambda () (eqv? c #\=))) (c-gt? (lambda () (eqv? c #\>))) (c-lsquare? (lambda () (eqv? c #\[))) (c-lt? (lambda () (eqv? c #\<))) (c-minus? (lambda () (eqv? c #\-))) (c-pound? (lambda () (eqv? c #\#))) (c-ques? (lambda () (eqv? c #\?))) (c-semi? (lambda () (eqv? c #\;))) (c-slash? (lambda () (eqv? c #\/))) (c-splat? (lambda () (eqv? c #\*))) (c-lf? (lambda () (eqv? c #\newline))) (c-angle? (lambda () (memv c '(#\< #\>)))) (c-ws? (lambda () (memv c ws-chars))) (c-alpha? (lambda () (char-alphabetic? c))) (c-digit? (lambda () (char-numeric? c))) (c-alphanum? (lambda () (or (c-alpha?) (c-digit?)))) (c-hexlet? (lambda () (memv c '(#\a #\b #\c #\d #\e #\f #\A #\B #\C #\D #\E #\F)))) (skip-ws (lambda () (read-c) (if (c-ws?) (skip-ws) (unread-c)))) (if-read-chars (lambda (match-chars yes-thunk no-proc) (let loop ((chars match-chars) (match-count 0)) (if (null? chars) (cl:funcall yes-thunk) (begin (read-c) (if (eqv? c (car chars)) (begin (loop (cdr chars) (+ 1 match-count))) (begin (unread-c) (cl:funcall no-proc match-chars match-count)))))))) (write-chars-count (lambda (chars count port) (let loop ((chars chars) (count count)) (or (zero? count) (begin (write-char (car chars) port) (loop (cdr chars) (- count 1))))))) (make-start-token (if normalized? (lambda (name ns attrs) (list name (cons :@ attrs))) (lambda (name ns attrs) (if (null? attrs) (list name) (list name (cons :@ attrs)))))) (make-empty-token (lambda (name ns attrs) (cons shtml-empty-symbol (cl:funcall make-start-token name ns attrs)))) (make-end-token (if normalized? (lambda (name ns attrs) (list shtml-end-symbol name (cons :@ attrs))) (lambda (name ns attrs) (if (null? attrs) (list shtml-end-symbol name) (list shtml-end-symbol name (cons :@ attrs)))))) (make-comment-token (lambda (str) (list shtml-comment-symbol str))) (make-decl-token (lambda (parts) (cons shtml-decl-symbol parts))) (scan-qname ;; TODO: Make sure we don't accept local names that have "*", since ;; this can break SXML tools. Have to validate this afterwards if ;; "verbatim-safe?". Also check for "@" and maybe "@@". Check ;; qname parsing code, especially for verbatim mode. This is ;; important! (lambda (verbatim-safe?) ;; Note: If we accept some invalid local names, we only need two ;; symbols of lookahead to determine the end of a qname. (letrec ((os #f) (ns '()) (vcolons 0) (good-os (lambda () (or os (begin (set! os (open-output-string)) os))))) (let loop () (read-c) (cond ((c-eof?) #f) ((or (c-ws?) (c-splat?)) (if verbatim-safe? (unread-c))) ((or (c-angle?) (c-equals?) (c-quot?) (c-apos?)) (unread-c)) ((c-colon?) (or (null? ns) (set! ns (cons ":" ns))) (if os (begin (set! ns (cons (%gosc os) ns)) (set! os #f))) (loop)) ((c-slash?) (read-c) (cond ((or (c-eof?) (c-ws?) (c-equals?) (c-apos?) (c-quot?) (c-angle?) (c-splat?)) (unread-c) (push-c #\/)) (else (write-char #\/ (good-os)) (write-char c os) (loop)))) (else (write-char c (good-os)) (loop)))) (let ((ns (if (null? ns) #f (apply #'string-append (%reverse!ok ns)))) (local (if os (%gosc os) #f))) (if verbatim-safe? ;; TODO: Make sure we don't have ambiguous ":" or drop ;; any characters! (cons ns local) ;; Note: We represent "xml:" and "xmlns:" syntax as ;; normal qnames, for lack of something better to do with ;; them when we don't support XML namespaces. ;; ;; TODO: Local names are currently forced to lowercase, ;; since HTML is usually case-insensitive. If XML ;; namespaces are used, we might wish to keep local names ;; case-sensitive. (if local (if ns (if (or (string=? ns "xml") (string=? ns "xmlns")) (string->symbol (string-append ns ":" local)) (cons ns (string->symbol (%down!ok local)))) (string->symbol (%down!ok local))) (if ns (string->symbol (%down!ok ns)) ;; TODO: Ensure in rest of code that returning #f ;; as a name here is OK. #f))))))) (scan-tag (lambda (start?) (skip-ws) (let ((tag-name (scan-qname #f)) (tag-ns #f) (tag-attrs #f) (tag-empty? #f)) ;; Scan element name. (if (pair? tag-name) (begin (set! tag-ns (car tag-name)) (set! tag-name (cdr tag-name)))) ;; TODO: Ensure there's no case in which a #f tag-name isn't ;; compensated for later. ;; ;; Scan element attributes. (set! tag-attrs (let scan-attr-list () (read-c) (cond ((c-eof?) '()) ((c-angle?) (unread-c) '()) ((c-slash?) (set! tag-empty? #t) (scan-attr-list)) ((c-alpha?) (unread-c) (let ((attr (scan-attr))) (cons attr (scan-attr-list)))) (else (scan-attr-list))))) ;; Find ">" or unnatural end. (let loop () (read-c) (cond ((c-eof?) no-token) ((c-slash?) (set! tag-empty? #t) (loop)) ((c-gt?) #f) ((c-ws?) (loop)) (else (unread-c)))) ;; Change the tokenizer mode if necessary. (cond ((not start?) #f) (tag-empty? #f) ;; TODO: Maybe make one alist lookup here, instead of ;; two. ((memsymb tag-name verbatim-to-eof-elems) (set! nexttok verbeof-nexttok)) ((memsymb tag-name verbatim-pair-elems) (set! nexttok (make-verbpair-nexttok tag-name)))) ;; Return a token object. (if start? (if tag-empty? (make-empty-token tag-name tag-ns tag-attrs) (cl:funcall make-start-token tag-name tag-ns tag-attrs)) (cl:funcall make-end-token tag-name tag-ns tag-attrs))))) (scan-attr (lambda () (let ((name (scan-qname #f)) (val #f)) (if (pair? name) (set! name (cdr name))) (let loop-equals-or-end () (read-c) (cond ((c-eof?) no-token) ((c-ws?) (loop-equals-or-end)) ((c-equals?) (let loop-quote-or-unquoted () (read-c) (cond ((c-eof?) no-token) ((c-ws?) (loop-quote-or-unquoted)) ((or (c-apos?) (c-quot?)) (let ((term c)) (set! val (open-output-string)) (let loop-quoted-val () (read-c) (cond ((c-eof?) #f) ((eqv? c term) #f) (else (write-char c val) (loop-quoted-val)))))) ((c-angle?) (unread-c)) (else (set! val (open-output-string)) (write-char c val) (let loop-unquoted-val () (read-c) (cond ((c-eof?) no-token) ((c-apos?) #f) ((c-quot?) #f) ((or (c-ws?) (c-angle?) ;;(c-slash?) ) (unread-c)) ;; Note: We can treat a slash in an ;; unquoted attribute value as a ;; value constituent because the ;; slash is specially-handled only ;; for XHTML, and XHTML attribute ;; values must always be quoted. We ;; could do lookahead for "/>", but ;; that wouldn't let us parse HTML ;; "<a href=/>" correctly, so this is ;; an easier and more correct way to ;; do things. (else (write-char c val) (loop-unquoted-val)))))))) (else (unread-c)))) (if normalized? (list name (if val (%gosc val) (symbol->string name))) (if val (list name (%gosc val)) (list name)))))) (scan-comment ;; TODO: Rewrite this to use tail recursion rather than a state ;; variable. (lambda () (let ((os (open-output-string)) (state 'start-minus)) (let loop () (read-c) (cond ((c-eof?) #f) ((c-minus?) (set! state (case state ((start-minus) 'start-minus-minus) ((start-minus-minus body) 'end-minus) ((end-minus) 'end-minus-minus) ((end-minus-minus) (write-char #\- os) state) (else (%error "make-html-tokenizer" "invalid state:" state)))) (loop)) ((and (c-gt?) (eq? state 'end-minus-minus)) #f) (else (case state ((end-minus) (write-char #\- os)) ((end-minus-minus) (display "--" os))) (set! state 'body) (write-char c os) (loop)))) (make-comment-token (%gosc os))))) (scan-possible-cdata (lambda () ;; Read "<!" and current character is "[", so try to read the ;; rest of the CDATA start delimeter. (if-read-chars '(#\C #\D #\A #\T #\A #\[) (lambda () ;; Successfully read CDATA section start delimiter, so read ;; the section. (scan-cdata)) (lambda (chars count) ;; Did not read rest of CDATA section start delimiter, so ;; return a string for what we did read. (let ((os (open-output-string))) (display "<![" os) (write-chars-count chars count os) (%gosc os)))))) (scan-cdata (lambda () (let ((os (open-output-string))) (let loop () (if-read-chars '(#\] #\] #\>) (lambda () (%gosc os)) (lambda (chars count) (if (zero? count) (if (eof-object? c) (%gosc os) (begin (write-char c os) (read-c) (loop))) (begin (write-char #\] os) (if (= count 2) (push-c #\])) (loop))))))))) (scan-pi (lambda () (skip-ws) (let ((name (open-output-string)) (val (open-output-string))) (let scan-name () (read-c) (cond ((c-eof?) #f) ((c-ws?) #f) ((c-alpha?) (write-char c name) (scan-name)) (else (unread-c)))) ;; TODO: Do we really want to emit #f for PI name? (set! name (gosc/symbol-or-false name)) (let scan-val () (read-c) (cond ((c-eof?) #f) ;; ((c-amp?) (display (scan-entity) val) ;; (scan-val)) ((c-ques?) (read-c) (cond ((c-eof?) (write-char #\? val)) ((c-gt?) #f) (else (write-char #\? val) (unread-c) (scan-val)))) (else (write-char c val) (scan-val)))) (list shtml-pi-symbol name (%gosc val))))) (scan-decl ;; TODO: Find if SXML includes declaration forms, and if so, use ;; whatever format SXML wants. ;; ;; TODO: Rewrite to eliminate state variables. (letrec ((scan-parts (lambda () (let ((part (open-output-string)) (nonsymbol? #f) (state 'before) (last? #f)) (let loop () (read-c) (cond ((c-eof?) #f) ((c-ws?) (case state ((before) (loop)) ((quoted) (write-char c part) (loop)))) ((and (c-gt?) (not (eq? state 'quoted))) (set! last? #t)) ((and (c-lt?) (not (eq? state 'quoted))) (unread-c)) ((c-quot?) (case state ((before) (set! state 'quoted) (loop)) ((unquoted) (unread-c)) ((quoted) #f))) (else (if (eq? state 'before) (set! state 'unquoted)) (set! nonsymbol? (or nonsymbol? (not (c-alphanum?)))) (write-char c part) (loop)))) (set! part (%gosc part)) (if (string=? part "") '() (cons (if (or (eq? state 'quoted) nonsymbol?) part ;; TODO: Normalize case of things we make ;; into symbols here. (string->symbol part)) (if last? '() (scan-parts)))))))) (lambda () (make-decl-token (scan-parts))))) (scan-entity (lambda () (read-c) (cond ((c-eof?) "&") ((c-alpha?) ;; TODO: Do entity names have a maximum length? (let ((name (open-output-string))) (write-char c name) (let loop () (read-c) (cond ((c-eof?) #f) ((c-alpha?) (write-char c name) (loop)) ((c-semi?) #f) (else (unread-c)))) (set! name (%gosc name)) ;; TODO: Make the entity map an option. (let ((pair (assoc name '(("amp" . "&") ("apos" . "'") ("gt" . ">") ("lt" . "<") ("quot" . "\""))))) (if pair (cdr pair) (make-shtml-entity name))))) ((c-pound?) (let ((num (open-output-string)) (hex? #f)) (read-c) (cond ((c-eof?) #f) ((memv c '(#\x #\X)) (set! hex? #t) (read-c))) (let loop () (cond ((c-eof?) #f) ((c-semi?) #f) ((or (c-digit?) (and hex? (c-hexlet?))) (write-char c num) (read-c) (loop)) (else (unread-c)))) (set! num (%gosc num)) (if (string=? num "") "&#;" (let ((n (string->number num (if hex? 16 10)))) (if (<= 32 n 126) ;; (and (<= 32 n 255) (not (= n 127))) (string (%a2c n)) (make-shtml-entity n)))))) (else (unread-c) "&")))) (normal-nexttok (lambda () (read-c) (cond ((c-eof?) no-token) ((c-lt?) (let loop () (read-c) (cond ((c-eof?) "<") ((c-ws?) (loop)) ((c-slash?) (scan-tag #f)) ((c-ques?) (scan-pi)) ((c-alpha?) (unread-c) (scan-tag #t)) ((c-bang?) (read-c) (if (c-lsquare?) (scan-possible-cdata) (let loop () (cond ((c-eof?) no-token) ((c-ws?) (read-c) (loop)) ((c-minus?) (scan-comment)) (else (unread-c) (cl:funcall scan-decl)))))) (else (unread-c) "<")))) ((c-gt?) ">") (else (let ((os (open-output-string))) (let loop () (cond ((c-eof?) #f) ((c-angle?) (unread-c)) ((c-amp?) (let ((entity (scan-entity))) (if (string? entity) (begin (display entity os) (read-c) (loop)) (let ((saved-nexttok nexttok)) (set! nexttok (lambda () (set! nexttok saved-nexttok) entity)))))) (else (write-char c os) (or (c-lf?) (begin (read-c) (loop)))))) (let ((text (%gosc os))) (if (equal? text "") (cl:funcall nexttok) text))))))) (verbeof-nexttok (lambda () (read-c) (if (c-eof?) no-token (let ((os (open-output-string))) (let loop () (or (c-eof?) (begin (write-char c os) (or (c-lf?) (begin (read-c) (loop)))))) (%gosc os))))) (make-verbpair-nexttok (lambda (elem-name) (lambda () (let ((os (open-output-string))) ;; Accumulate up to a newline-terminated line. (let loop () (read-c) (cond ((c-eof?) ;; Got EOF in verbatim context, so set the normal ;; nextok procedure, then fall out of loop. (set! nexttok normal-nexttok)) ((c-lt?) ;; Got "<" in verbatim context, so get next ;; character. (read-c) (cond ((c-eof?) ;; Got "<" then EOF, so set to the normal ;; nexttok procedure, add the "<" to the ;; verbatim string, and fall out of loop. (set! nexttok normal-nexttok) (write-char #\< os)) ((c-slash?) ;; Got "</", so... (read-c) (cond ((c-eof?) (display "</" os)) ((c-alpha?) ;; Got "</" followed by alpha, so unread ;; the alpha, scan qname, compare... (unread-c) (let* ((vqname (scan-qname #t)) (ns (car vqname)) (local (cdr vqname))) ;; Note: We ignore XML namespace ;; qualifier for purposes of comparison. ;; ;; Note: We're interning strings here for ;; comparison when in theory there could ;; be many such unique interned strings ;; in a valid HTML document, although in ;; practice this should not be a problem. (if (and local (eqv? (string->symbol (%down local)) elem-name)) ;; This is the terminator tag, so ;; scan to the end of it, set the ;; nexttok, and fall out of the loop. (begin (let scan-to-end () (read-c) (cond ((c-eof?) #f) ((c-gt?) #f) ((c-lt?) (unread-c)) ((c-alpha?) (unread-c) ;; Note: This is an ;; expensive way to skip ;; over an attribute, but ;; in practice more ;; verbatim end tags will ;; not have attributes. (scan-attr) (scan-to-end)) (else (scan-to-end)))) (set! nexttok (lambda () (set! nexttok normal-nexttok) (cl:funcall make-end-token elem-name #f '())))) ;; This isn't the terminator tag, so ;; add to the verbatim string the ;; "</" and the characters of what we ;; were scanning as a qname, and ;; recurse in the loop. (begin (display "</" os) (if ns (begin (display ns os) (display ":" os))) (if local (display local os)) (loop))))) (else ;; Got "</" and non-alpha, so unread new ;; character, add the "</" to verbatim ;; string, then loop. (unread-c) (display "</" os) (loop)))) (else ;; Got "<" and non-slash, so unread the new ;; character, write the "<" to the verbatim ;; string, then loop. (unread-c) (write-char #\< os) (loop)))) (else ;; Got non-"<" in verbatim context, so just add it ;; to the buffer, then, if it's not a linefeed, fall ;; out of the loop so that the token can be ;; returned. (write-char c os) (or (c-lf?) (loop))))) ;; Return the accumulated line string, if non-null, or call ;; nexttok. (or (gosc/string-or-false os) (cl:funcall nexttok)))))) (nexttok #f)) (set! nexttok normal-nexttok) (lambda () (cl:funcall nexttok)))))) ;;; @defproc tokenize-html in normalized? ;;; ;;; Returns a list of tokens from input port @var{in}, normalizing according to ;;; boolean @var{normalized?}. This is probably most useful as a debugging ;;; convenience. For example: ;;; ;;; @lisp ;;; (tokenize-html (open-input-string "<a href=\"foo\">bar</a>") #f) ;;; @result{} ((a (@@ (href "foo"))) "bar" (*END* a)) ;;; @end lisp (define (tokenize-html in normalized?) (let ((next-tok (cl:funcall make-html-tokenizer in normalized?))) (let loop ((tok (cl:funcall next-tok))) (if (null? tok) '() (cons tok (loop (cl:funcall next-tok))))))) ;;; @defproc shtml-token-kind token ;;; ;;; Returns a symbol indicating the kind of tokenizer @var{token}: ;;; @code{*COMMENT*}, @code{*DECL*}, @code{*EMPTY*}, @code{*END*}, ;;; @code{*ENTITY*}, @code{*PI*}, @code{*START*}, @code{*TEXT*}. ;;; This is used by higher-level parsing code. For example: ;;; ;;; @lisp ;;; (map shtml-token-kind ;;; (tokenize-html (open-input-string "<a<b>><c</</c") #f)) ;;; @result{} (*START* *START* *TEXT* *START* *END* *END*) ;;; @end lisp (define (shtml-token-kind token) (cond ((string? token) shtml-text-symbol) ((list? token) (let ((s (list-ref token 0))) (if (memq s `(,shtml-comment-symbol ,shtml-decl-symbol ,shtml-empty-symbol ,shtml-end-symbol ,shtml-entity-symbol ,shtml-pi-symbol)) s shtml-start-symbol))) (else (%error "shtml-token-kind" "unrecognized token kind:" token)))) ;;; @section Parsing ;;; Most applications will call a parser procedure such as ;;; @code{html->shtml} rather than calling the tokenizer directly. ;; @defvar %empty-elements ;; ;; List of names of HTML element types that have no content, represented as a ;; list of symbols. This is used internally by the parser and encoder. The ;; effect of mutating this list is undefined. ;; TODO: Document exactly which elements these are, after we make the new ;; parameterized parser constructor. (define %empty-elements '(:& :area :base :br :frame :hr :img :input :isindex :keygen :link :meta :object :param :spacer :wbr)) ;;; @defproc parse-html/tokenizer tokenizer normalized? ;;; ;;; Emits a parse tree like @code{html->shtml} and related procedures, except ;;; using @var{tokenizer} as a source of tokens, rather than tokenizing from an ;;; input port. This procedure is used internally, and generally should not be ;;; called directly. (define parse-html/tokenizer ;; TODO: Document the algorithm, then see if rewriting as idiomatic Scheme ;; can make it more clear. (letrec ((empty-elements ;; TODO: Maybe make this an option. This might also be an ;; acceptable way to parse old HTML that uses the `p' element as a ;; paragraph terminator. %empty-elements) (start-tag-name (lambda (tag-token) (car tag-token))) (end-tag-name (lambda (tag-token) (list-ref tag-token 1)))) (lambda (tokenizer normalized?) ;; Example `begs' value: ;; ;; ( ((head ...) . ( (title ...) )) ;; ((html ...) . ( (head ...) (*COMMENT* ...) )) ;; (#f . ( (html ...) (*DECL* doctype ...) )) ) (let ((begs (list (cons #f '())))) (letrec ((add-to-current-beg (lambda (tok) (set-cdr! (car begs) (cons tok (cdr (car begs)))))) (finish-all-begs (lambda () (let ((toplist #f)) (map (lambda (beg) (set! toplist (finish-beg beg))) begs) toplist))) (finish-beg (lambda (beg) (let ((start-tok (car beg))) (if start-tok (%append! (car beg) (%reverse!ok (cdr beg))) (%reverse!ok (cdr beg)))))) (finish-begs-to (lambda (name lst) (let* ((top (car lst)) (starttag (car top))) (cond ((not starttag) #f) ((eqv? name (start-tag-name starttag)) (set! begs (cdr lst)) (finish-beg top) #t) (else (if (finish-begs-to name (cdr lst)) (begin (finish-beg top) #t) #f)))))) (finish-begs-upto (lambda (parents lst) (let* ((top (car lst)) (starttag (car top))) (cond ((not starttag) #f) ((memq (start-tag-name starttag) parents) (set! begs lst) #t) (else (if (finish-begs-upto parents (cdr lst)) (begin (finish-beg top) #t) #f))))))) (let loop () (let ((tok (cl:funcall tokenizer))) (if (null? tok) (finish-all-begs) (let ((kind (shtml-token-kind tok))) (cond ((memv kind `(,shtml-comment-symbol ,shtml-decl-symbol ,shtml-entity-symbol ,shtml-pi-symbol ,shtml-text-symbol)) (add-to-current-beg tok)) ((eqv? kind shtml-start-symbol) (let* ((name (start-tag-name tok)) (cell (assq name *parent-constraints*))) (and cell (finish-begs-upto (cons 'div (cdr cell)) begs)) (add-to-current-beg tok) (or (memsymb name empty-elements) (set! begs (cons (cons tok '()) begs))))) ((eqv? kind shtml-empty-symbol) ;; Empty tag token, so just add it to current ;; beginning while stripping off leading `*EMPTY*' ;; symbol so that the token becomes normal SXML ;; element syntax. (add-to-current-beg (cdr tok))) ((eqv? kind shtml-end-symbol) (let ((name (end-tag-name tok))) (if name ;; Try to finish to a start tag matching this ;; end tag. If none, just drop the token, ;; though we used to add it to the current ;; beginning. (finish-begs-to name begs) ;; We have an anonymous end tag, so match it ;; with the most recent beginning. If no ;; beginning to match, then just drop the ;; token, though we used to add it to the ;; current beginning. (and (car (car begs)) (begin (finish-beg (car begs)) (set! begs (cdr begs))))))) (else (%error "parse-html/tokenizer" "unknown tag kind:" kind))) (loop)))))))))) ;; @defproc %parse-html input normalized? top? ;; ;; This procedure is now used internally by @code{html->shtml} and its ;; variants, and should not be used directly by programs. The interface is ;; likely to change in future versions of HtmlPrag. (define (%parse-html input normalized? top?) (let ((parse (lambda () (cl:funcall parse-html/tokenizer (cl:funcall make-html-tokenizer (cond ((input-port? input) input) ((string? input) (open-input-string input)) (else (%error "%parse-html" "invalid input type:" input))) normalized?) normalized?)))) (if top? (cons shtml-top-symbol (cl:funcall parse)) (cl:funcall parse)))) ;;; @defproc html->sxml-0nf input ;;; @defprocx html->sxml-1nf input ;;; @defprocx html->sxml-2nf input ;;; @defprocx html->sxml input ;;; @defprocx html->shtml input ;;; ;;; Permissively parse HTML from @var{input}, which is either an input port or ;;; a string, and emit an SHTML equivalent or approximation. To borrow and ;;; slightly modify an example from Kiselyov's discussion of his HTML parser: ;;; ;;; @lisp ;;; (html->shtml ;;; "<html><head><title></title><title>whatever</title></head><body> ;;; <a href=\"url\">link</a><p align=center><ul compact style=\"aa\"> ;;; <p>BLah<!-- comment <comment> --> <i> italic <b> bold <tt> ened</i> ;;; still &lt; bold </b></body><P> But not done yet...") ;;; @result{} ;;; (*TOP* (html (head (title) (title "whatever")) ;;; (body "\n" ;;; (a (@@ (href "url")) "link") ;;; (p (@@ (align "center")) ;;; (ul (@@ (compact) (style "aa")) "\n")) ;;; (p "BLah" ;;; (*COMMENT* " comment <comment> ") ;;; " " ;;; (i " italic " (b " bold " (tt " ened"))) ;;; "\n" ;;; "still < bold ")) ;;; (p " But not done yet..."))) ;;; @end lisp ;;; ;;; Note that in the emitted SHTML the text token @code{"still < bold"} is ;;; @emph{not} inside the @code{b} element, which represents an unfortunate ;;; failure to emulate all the quirks-handling behavior of some popular Web ;;; browsers. ;;; ;;; The procedures @code{html->sxml-@var{n}nf} for @var{n} 0 through 2 ;;; correspond to 0th through 2nd normal forms of SXML as specified in SXML, ;;; and indicate the minimal requirements of the emitted SXML. ;;; ;;; @code{html->sxml} and @code{html->shtml} are currently aliases for ;;; @code{html->sxml-0nf}, and can be used in scripts and interactively, when ;;; terseness is important and any normal form of SXML would suffice. (define (html->sxml-0nf input) (%parse-html input #f #t)) (define (html->sxml-1nf input) (%parse-html input #f #t)) (define (html->sxml-2nf input) (%parse-html input #t #t)) (define (html->sxml input) (html->sxml-0nf input)) (define (html->shtml input) (html->sxml input)) ;;; @section Emitting HTML ;;; Two procedures encoding the SHTML representation as conventional HTML, ;;; @code{write-shtml-as-html} and @code{shtml->html}. These are perhaps most ;;; useful for emitting the result of parsed and transformed input HTML. They ;;; can also be used for emitting HTML from generated or handwritten SHTML. ;;; @defproc write-shtml-as-html shtml [out [foreign-filter]] ;;; ;;; Writes a conventional HTML transliteration of the SHTML @var{shtml} to ;;; output port @var{out}. If @var{out} is not specified, the default is the ;;; current output port. HTML elements of types that are always empty are ;;; written using HTML4-compatible XHTML tag syntax. ;;; ;;; If @var{foreign-filter} is specified, it is a procedure of two argument ;;; that is applied to any non-SHTML (``foreign'') object encountered in ;;; @var{shtml}, and should yield SHTML. The first argument is the object, and ;;; the second argument is a boolean for whether or not the object is part of ;;; an attribute value. ;;; ;;; No inter-tag whitespace or line breaks not explicit in @var{shtml} is ;;; emitted. The @var{shtml} should normally include a newline at the end of ;;; the document. For example: ;;; ;;; @lisp ;;; (write-shtml-as-html ;;; '((html (head (title "My Title")) ;;; (body (@@ (bgcolor "white")) ;;; (h1 "My Heading") ;;; (p "This is a paragraph.") ;;; (p "This is another paragraph."))))) ;;; @print{} <html><head><title>My Title</title></head><body bgcolor="whi ;;; @print{} te"><h1>My Heading</h1><p>This is a paragraph.</p><p>This is ;;; @print{} another paragraph.</p></body></html> ;;; @end lisp (define (%write-shtml-as-html/fixed shtml out foreign-filter) (letrec ((write-shtml-text (lambda (str out) (let ((len (string-length str))) (let loop ((i 0)) (if (< i len) (begin (display (let ((c (string-ref str i))) (case c ;; ((#\") "&quot;") ((#\&) "&amp;") ((#\<) "&lt;") ((#\>) "&gt;") (else c))) out) (loop (+ 1 i)))))))) (write-dquote-ampified (lambda (str out) ;; TODO: If we emit "&quot;", we really should parse it, and HTML ;; 4.01 says we should, but anachronisms in HTML create the potential ;; for nasty mutilation of URI in attribute values. (let ((len (string-length str))) (let loop ((i 0)) (if (< i len) (begin (display (let ((c (string-ref str i))) (if (eqv? c #\") "&quot;" c)) out) (loop (+ 1 i)))))))) (do-thing (lambda (thing) (cond ((string? thing) (write-shtml-text thing out)) ((list? thing) (if (not (null? thing)) (do-list-thing thing))) (else (do-thing (cl:funcall foreign-filter thing #f)))))) (do-list-thing (lambda (thing) (let ((head (car thing))) (cond ((symbol? head) ;; Head is a symbol, so... (cond ((eq? head shtml-comment-symbol) ;; TODO: Make sure the comment text doesn't contain a ;; comment end sequence. (display "<!-- " out) (let ((text (car (cdr thing)))) (if (string? text) ;; TODO: Enforce whitespace safety without ;; padding unnecessarily. ;; ;; (let ((len (string-length text))) ;; (if (= len 0) ;; (display #\space out) ;; (begin (if (not (eqv? ;; (string-ref text 0) ;; #\space)) (display text out) (%error "write-shtml-as-html" "invalid SHTML comment text:" thing))) (or (null? (cdr (cdr thing))) (%error "write-shtml-as-html" "invalid SHTML comment body:" thing)) (display " -->" out)) ((eq? head shtml-decl-symbol) (let ((head (car (cdr thing)))) (display "<!" out) (display (symbol->string head) out) (for-each (lambda (n) (cond ((symbol? n) (display #\space out) (display (symbol->string n) out)) ((string? n) (display " \"" out) (write-dquote-ampified n out) (display #\" out)) (else (%error "write-shtml-as-html" "invalid SHTML decl:" thing)))) (cdr (cdr thing))) (display #\> out))) ((eq? head shtml-pi-symbol) (display "<?" out) (display (symbol->string (car (cdr thing))) out) (display #\space out) (display (car (cdr (cdr thing))) out) ;; TODO: Error-check that no more rest of PI. (display "?>" out)) ((eq? head shtml-top-symbol) (for-each #'do-thing (cdr thing))) ((eq? head shtml-empty-symbol) #f) ((is-at? head) (%error "write-shtml-as-html" "illegal position of SHTML attributes:" thing)) ((or (symbol=? head '&) (eq? head shtml-entity-symbol)) (let ((val (shtml-entity-value thing))) (if val (begin (write-char #\& out) (if (integer? val) (write-char #\# out)) (display val out) (write-char #\; out)) (%error "write-shtml-as-html" "invalid SHTML entity reference:" thing)))) ((memq head `(,shtml-end-symbol ,shtml-start-symbol ,shtml-text-symbol)) (%error "write-shtml-as-html" "invalid SHTML symbol:" head)) (else (display #\< out) (display head out) (let* ((rest (cdr thing))) (if (not (null? rest)) (let ((second (car rest))) (and (list? second) (not (null? second)) (is-at? (car second)) (begin (for-each #'do-attr (cdr second)) (set! rest (cdr rest)))))) (if (memsymb head %empty-elements) ;; TODO: Error-check to make sure the element ;; has no content other than attributes. We ;; have to test for cases like: (br (@) () ;; (())) (display " />" out) (begin (display #\> out) (for-each #'do-thing rest) (display "</" out) (display (symbol->string head) out) (display #\> out))))))) ;; ((or (list? head) (string? head)) ;; ;; Head is a list or string, which might occur as the result ;; of an SXML transform, so we'll cope. (else ;; Head is not a symbol, which might occur as the result of ;; an SXML transform, so we'll cope. (for-each #'do-thing thing)) ;;(else ;; ;; Head is NOT a symbol, list, or string, so error. ;; (%error "write-shtml-as-html" ;; "invalid SHTML list:" ;; thing)) )))) (write-attr-val-dquoted (lambda (str out) (display #\" out) (display str out) (display #\" out))) (write-attr-val-squoted (lambda (str out) (display #\' out) (display str out) (display #\' out))) (write-attr-val-dquoted-and-amped (lambda (str out) (display #\" out) (write-dquote-ampified str out) (display #\" out))) (write-attr-val (lambda (str out) (let ((len (string-length str))) (let find-dquote-and-squote ((i 0)) (if (= i len) (write-attr-val-dquoted str out) (let ((c (string-ref str i))) (cond ((eqv? c #\") (let find-squote ((i (+ 1 i))) (if (= i len) (write-attr-val-squoted str out) (if (eqv? (string-ref str i) #\') (write-attr-val-dquoted-and-amped str out) (find-squote (+ 1 i)))))) ((eqv? c #\') (let find-dquote ((i (+ 1 i))) (if (= i len) (write-attr-val-dquoted str out) (if (eqv? (string-ref str i) #\") (write-attr-val-dquoted-and-amped str out) (find-dquote (+ 1 i)))))) (else (find-dquote-and-squote (+ 1 i)))))))))) (collect-and-write-attr-val ;; TODO: Take another look at this. (lambda (lst out) (let ((os #f)) (let do-list ((lst lst)) (for-each (lambda (thing) (let do-thing ((thing thing)) (cond ((string? thing) (or os (set! os (open-output-string))) (display thing os)) ((list? thing) (do-list thing)) ((eq? thing #t) #f) (else (do-thing (cl:funcall foreign-filter thing #t)))))) lst)) (if os (begin (display #\= out) (write-attr-val (%gosc os) out)))))) (do-attr (lambda (attr) (or (list? attr) (%error "write-shtml-as-html" "invalid SHTML attribute:" attr)) (if (not (null? attr)) (let ((name (car attr))) (or (symbol? name) (%error "write-shtml-as-html" "invalid name in SHTML attribute:" attr)) (if (not (is-at? name)) (begin (display #\space out) (display name out) (collect-and-write-attr-val (cdr attr) out) ))))))) (do-thing shtml) (if #f #f))) (define write-shtml-as-html (letrec ((error-foreign-filter (lambda (foreign-object in-attribute-value?) (%error "write-shtml-as-html" (if in-attribute-value? "unhandled foreign object in shtml attribute value:" "unhandled foreign object in shtml:") foreign-object)))) (lambda (shtml . rest) (case (length rest) ((0) (%write-shtml-as-html/fixed shtml (current-output-port) error-foreign-filter)) ((1) (%write-shtml-as-html/fixed shtml (car rest) error-foreign-filter)) ((2) (%write-shtml-as-html/fixed shtml (car rest) (cadr rest))) (else (%error "write-shtml-as-html" "extraneous arguments:" (cddr rest))))))) ;;; @defproc shtml->html shtml ;;; ;;; Yields an HTML encoding of SHTML @var{shtml} as a string. For example: ;;; ;;; @lisp ;;; (shtml->html ;;; (html->shtml ;;; "<P>This is<br<b<I>bold </foo>italic</ b > text.</p>")) ;;; @result{} "<p>This is<br /><b><i>bold italic</i></b> text.</p>" ;;; @end lisp ;;; ;;; Note that, since this procedure constructs a string, it should normally ;;; only be used when the HTML is relatively small. When encoding HTML ;;; documents of conventional size and larger, @code{write-shtml-as-html} is ;;; much more efficient. (define (shtml->html shtml) (let ((os (open-output-string))) (cl:funcall write-shtml-as-html shtml os) (%gosc os))) ;;; @section Tests ;;; The HtmlPrag test suite can be enabled by editing the source code file and ;;; loading @uref{http://www.neilvandyke.org/testeez/, Testeez}. (define lf (string #\newline)) (define (%test) (testeez "HtmlPrag" (test/equal "" (html->shtml "<a>>") `(,shtml-top-symbol (a ">"))) (test/equal "" (html->shtml "<a<>") `(,shtml-top-symbol (a "<" ">"))) (test/equal "" (html->shtml "<>") `(,shtml-top-symbol "<" ">")) (test/equal "" (html->shtml "< >") `(,shtml-top-symbol "<" ">")) (test/equal "" (html->shtml "< a>") `(,shtml-top-symbol (a))) (test/equal "" (html->shtml "< a / >") `(,shtml-top-symbol (a))) (test/equal "" (html->shtml "<a<") `(,shtml-top-symbol (a "<"))) (test/equal "" (html->shtml "<a<b") `(,shtml-top-symbol (a (b)))) (test/equal "" (html->shtml "><a>") `(,shtml-top-symbol ">" (a))) (test/equal "" (html->shtml "</>") `(,shtml-top-symbol)) (test/equal "" (html->shtml "<\">") `(,shtml-top-symbol "<" "\"" ">")) (test/equal "" (html->shtml (string-append "<a>xxx<plaintext>aaa" lf "bbb" lf "c<c<c")) `(,shtml-top-symbol (a "xxx" (plaintext ,(string-append "aaa" lf) ,(string-append "bbb" lf) "c<c<c")))) (test/equal "" (html->shtml "aaa<!-- xxx -->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol " xxx ") "bbb")) (test/equal "" (html->shtml "aaa<! -- xxx -->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol " xxx ") "bbb")) (test/equal "" (html->shtml "aaa<!-- xxx --->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol " xxx -") "bbb")) (test/equal "" (html->shtml "aaa<!-- xxx ---->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol " xxx --") "bbb")) (test/equal "" (html->shtml "aaa<!-- xxx -y-->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol " xxx -y") "bbb")) (test/equal "" (html->shtml "aaa<!----->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol "-") "bbb")) (test/equal "" (html->shtml "aaa<!---->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol "") "bbb")) (test/equal "" (html->shtml "aaa<!--->bbb") `(,shtml-top-symbol "aaa" (,shtml-comment-symbol "->bbb"))) (test/equal "" (html->shtml "<hr>") `(,shtml-top-symbol (hr))) (test/equal "" (html->shtml "<hr/>") `(,shtml-top-symbol (hr))) (test/equal "" (html->shtml "<hr />") `(,shtml-top-symbol (hr))) (test/equal "" (html->shtml "<hr noshade>") `(,shtml-top-symbol (hr (@ (noshade))))) (test/equal "" (html->shtml "<hr noshade/>") `(,shtml-top-symbol (hr (@ (noshade))))) (test/equal "" (html->shtml "<hr noshade />") `(,shtml-top-symbol (hr (@ (noshade))))) (test/equal "" (html->shtml "<hr noshade / >") `(,shtml-top-symbol (hr (@ (noshade))))) (test/equal "" (html->shtml "<hr noshade=1 />") `(,shtml-top-symbol (hr (@ (noshade "1"))))) (test/equal "" (html->shtml "<hr noshade=1/>") `(,shtml-top-symbol (hr (@ (noshade "1/"))))) (test/equal "" (html->shtml "<q>aaa<p/>bbb</q>ccc</p>ddd") `(,shtml-top-symbol (q "aaa" (p) "bbb") "ccc" "ddd")) (test/equal "" (html->shtml "&lt;") `(,shtml-top-symbol "<")) (test/equal "" (html->shtml "&gt;") `(,shtml-top-symbol ">")) (test/equal "" (html->shtml "Gilbert &amp; Sullivan") `(,shtml-top-symbol "Gilbert & Sullivan")) (test/equal "" (html->shtml "Gilbert &amp Sullivan") `(,shtml-top-symbol "Gilbert & Sullivan")) (test/equal "" (html->shtml "Gilbert & Sullivan") `(,shtml-top-symbol "Gilbert & Sullivan")) (test/equal "" (html->shtml "Copyright &copy; Foo") `(,shtml-top-symbol "Copyright " (& ,(string->symbol "copy")) " Foo")) (test/equal "" (html->shtml "aaa&copy;bbb") `(,shtml-top-symbol "aaa" (& ,(string->symbol "copy")) "bbb")) (test/equal "" (html->shtml "aaa&copy") `(,shtml-top-symbol "aaa" (& ,(string->symbol "copy")))) (test/equal "" (html->shtml "&#42;") `(,shtml-top-symbol "*")) (test/equal "" (html->shtml "&#42") `(,shtml-top-symbol "*")) (test/equal "" (html->shtml "&#42x") `(,shtml-top-symbol "*x")) (test/equal "" (html->shtml "&#151") `(,shtml-top-symbol (& 151) ;; ,(string (%a2c 151)) )) (test/equal "" (html->shtml "&#1000") `(,shtml-top-symbol (& 1000))) (test/equal "" (html->shtml "&#x42") `(,shtml-top-symbol "B")) (test/equal "" (html->shtml "&#xA2") `(,shtml-top-symbol (& 162) ;; ,(string (%a2c 162)) )) (test/equal "" (html->shtml "&#xFF") `(,shtml-top-symbol (& 255) ;; ,(string (%a2c 255)) )) (test/equal "" (html->shtml "&#x100") `(,shtml-top-symbol (& 256))) (test/equal "" (html->shtml "&#X42") `(,shtml-top-symbol "B")) (test/equal "" (html->shtml "&42;") `(,shtml-top-symbol "&42;")) (test/equal "" (html->shtml (string-append "aaa&copy;bbb&amp;ccc&lt;ddd&&gt;" "eee&#42;fff&#1000;ggg&#x5a;hhh")) `(,shtml-top-symbol "aaa" (& ,(string->symbol "copy")) "bbb&ccc<ddd&>eee*fff" (& 1000) "gggZhhh")) (test/equal "" (html->shtml (string-append "<IMG src=\"http://e.e/aw/pics/listings/" "ebayLogo_38x16.gif\" border=0 width=\"38\" height=\"16\" " "HSPACE=5 VSPACE=0\">2</FONT>")) `(,shtml-top-symbol (img (@ (src "http://e.e/aw/pics/listings/ebayLogo_38x16.gif") (border "0") (width "38") (height "16") (hspace "5") (vspace "0"))) "2")) (test/equal "" (html->shtml "<aaa bbb=ccc\"ddd>eee") `(,shtml-top-symbol (aaa (@ (bbb "ccc") (ddd)) "eee"))) (test/equal "" (html->shtml "<aaa bbb=ccc \"ddd>eee") `(,shtml-top-symbol (aaa (@ (bbb "ccc") (ddd)) "eee"))) (test/equal "" (html->shtml (string-append "<HTML><Head><Title>My Title</Title></Head>" "<Body BGColor=\"white\" Foo=42>" "This is a <B><I>bold-italic</B></I> test of </Erk>" "broken HTML.<br>Yes it is.</Body></HTML>")) `(,shtml-top-symbol (html (head (title "My Title")) (body (@ (bgcolor "white") (foo "42")) "This is a " (b (i "bold-italic")) " test of " "broken HTML." (br) "Yes it is.")))) (test/equal "" (html->shtml (string-append "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")) `(,shtml-top-symbol (,shtml-decl-symbol ,(string->symbol "DOCTYPE") html ,(string->symbol "PUBLIC") "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"))) (test/equal "" (html->shtml (string-append "<html xmlns=\"http://www.w3.org/1999/xhtml\" " "xml:lang=\"en\" " "lang=\"en\">")) `(,shtml-top-symbol (:html (:@ (:xmlns "http://www.w3.org/1999/xhtml") (:|XML:LANG| "en") (lang "en"))))) (test/equal "" (html->shtml (string-append "<html:html xmlns:html=\"http://www.w3.org/TR/REC-html40\">" "<html:head><html:title>Frobnostication</html:title></html:head>" "<html:body><html:p>Moved to <html:a href=\"http://frob.com\">" "here.</html:a></html:p></html:body></html:html>")) `(,shtml-top-symbol (:html (:@ (:|XMLNS:HTML| "http://www.w3.org/TR/REC-html40")) (:head (:title "Frobnostication")) (:body (:p "Moved to " (:a (:@ (:href "http://frob.com")) "here.")))))) (test/equal "" (html->shtml (string-append "<RESERVATION xmlns:HTML=\"http://www.w3.org/TR/REC-html40\">" "<NAME HTML:CLASS=\"largeSansSerif\">Layman, A</NAME>" "<SEAT CLASS=\"Y\" HTML:CLASS=\"largeMonotype\">33B</SEAT>" "<HTML:A HREF=\"/cgi-bin/ResStatus\">Check Status</HTML:A>" "<DEPARTURE>1997-05-24T07:55:00+1</DEPARTURE></RESERVATION>")) `(,shtml-top-symbol (:reservation (:@ (,(string->symbol "xmlns:HTML") "http://www.w3.org/TR/REC-html40")) (:name (:@ (:class "largeSansSerif")) "Layman, A") (:seat (:@ (:class "Y") (:class "largeMonotype")) "33B") (:a (:@ (:href "/cgi-bin/ResStatus")) "Check Status") (:departure "1997-05-24T07:55:00+1")))) (test/equal "" (html->shtml (string-append "<html><head><title></title><title>whatever</title></head><body>" "<a href=\"url\">link</a><p align=center><ul compact style=\"aa\">" "<p>BLah<!-- comment <comment> --> <i> italic <b> bold <tt> ened </i>" " still &lt; bold </b></body><P> But not done yet...")) `(,shtml-top-symbol (:html (:head (:title) (:title "whatever")) (:body (:a (:@ (:href "url")) "link") (:p (:@ (:align "center")) (:ul (:@ (:compact) (:style "aa")))) (:p "BLah" (,shtml-comment-symbol " comment <comment> ") " " (:i " italic " (:b " bold " (:tt " ened "))) " still < bold ")) (:p " But not done yet...")))) (test/equal "" (html->shtml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>") `(,shtml-top-symbol (,shtml-pi-symbol :xml "version=\"1.0\" encoding=\"UTF-8\""))) (test/equal "" (html->shtml "<?php php_info(); ?>") `(,shtml-top-symbol (,shtml-pi-symbol :php "php_info(); "))) (test/equal "" (html->shtml "<?php php_info(); ?") `(,shtml-top-symbol (,shtml-pi-symbol :php "php_info(); ?"))) (test/equal "" (html->shtml "<?php php_info(); ") `(,shtml-top-symbol (,shtml-pi-symbol :php "php_info(); "))) (test/equal "" (html->shtml "<?foo bar ? baz > blort ?>") `(,shtml-top-symbol (,shtml-pi-symbol :foo "bar ? baz > blort "))) (test/equal "" (html->shtml "<?foo b?>x") `(,shtml-top-symbol (,shtml-pi-symbol :foo "b") "x")) (test/equal "" (html->shtml "<?foo ?>x") `(,shtml-top-symbol (,shtml-pi-symbol :foo "") "x")) (test/equal "" (html->shtml "<?foo ?>x") `(,shtml-top-symbol (,shtml-pi-symbol :foo "") "x")) (test/equal "" (html->shtml "<?foo?>x") `(,shtml-top-symbol (,shtml-pi-symbol :foo "") "x")) (test/equal "" (html->shtml "<?f?>x") `(,shtml-top-symbol (,shtml-pi-symbol :f "") "x")) (test/equal "" (html->shtml "<??>x") `(,shtml-top-symbol (,shtml-pi-symbol #f "") "x")) (test/equal "" (html->shtml "<?>x") `(,shtml-top-symbol (,shtml-pi-symbol #f ">x"))) (test/equal "" (html->shtml "<foo bar=\"baz\">blort") `(,shtml-top-symbol (:foo (:@ (:bar "baz")) "blort"))) (test/equal "" (html->shtml "<foo bar='baz'>blort") `(,shtml-top-symbol (:foo (:@ (:bar "baz")) "blort"))) (test/equal "" (html->shtml "<foo bar=\"baz'>blort") `(,shtml-top-symbol (:foo (:@ (:bar "baz'>blort"))))) (test/equal "" (html->shtml "<foo bar='baz\">blort") `(,shtml-top-symbol (:foo (:@ (:bar "baz\">blort"))))) (test/equal "" (html->shtml (string-append "<p>A</p>" "<script>line0 <" lf "line1" lf "<line2></script>" "<p>B</p>")) `(,shtml-top-symbol (:p "A") (:script ,(string-append "line0 <" lf) ,(string-append "line1" lf) "<line2>") (:p "B"))) (test/equal "" (html->shtml "<xmp>a<b>c</XMP>d") `(,shtml-top-symbol (:xmp "a<b>c") "d")) (test/equal "" (html->shtml "<XMP>a<b>c</xmp>d") `(,shtml-top-symbol (:xmp "a<b>c") "d")) (test/equal "" (html->shtml "<xmp>a<b>c</foo:xmp>d") `(,shtml-top-symbol (:xmp "a<b>c") "d")) (test/equal "" (html->shtml "<foo:xmp>a<b>c</xmp>d") `(,shtml-top-symbol (:xmp "a<b>c") "d")) (test/equal "" (html->shtml "<foo:xmp>a<b>c</foo:xmp>d") `(,shtml-top-symbol (:xmp "a<b>c") "d")) (test/equal "" (html->shtml "<foo:xmp>a<b>c</bar:xmp>d") `(,shtml-top-symbol (:xmp "a<b>c") "d")) (test/equal "" (html->shtml "<xmp>a</b>c</xmp>d") `(,shtml-top-symbol (:xmp "a</b>c") "d")) (test/equal "" (html->shtml "<xmp>a</b >c</xmp>d") `(,shtml-top-symbol (:xmp "a</b >c") "d")) (test/equal "" (html->shtml "<xmp>a</ b>c</xmp>d") `(,shtml-top-symbol (:xmp "a</ b>c") "d")) (test/equal "" (html->shtml "<xmp>a</ b >c</xmp>d") `(,shtml-top-symbol (:xmp "a</ b >c") "d")) (test/equal "" (html->shtml "<xmp>a</b:x>c</xmp>d") `(,shtml-top-symbol (:xmp "a</b:x>c") "d")) (test/equal "" (html->shtml "<xmp>a</b::x>c</xmp>d") `(,shtml-top-symbol (:xmp "a</b::x>c") "d")) (test/equal "" (html->shtml "<xmp>a</b:::x>c</xmp>d") `(,shtml-top-symbol (:xmp "a</b:::x>c") "d")) (test/equal "" (html->shtml "<xmp>a</b:>c</xmp>d") `(,shtml-top-symbol (:xmp "a</b:>c") "d")) (test/equal "" (html->shtml "<xmp>a</b::>c</xmp>d") `(,shtml-top-symbol (:xmp "a</b::>c") "d")) (test/equal "" (html->shtml "<xmp>a</xmp:b>c</xmp>d") `(,shtml-top-symbol (:xmp "a</xmp:b>c") "d")) (test-define "expected output for next two tests" expected `(,shtml-top-symbol (:p "real1") ,lf (:xmp ,lf ,(string-append "alpha" lf) ,(string-append "<P>fake</P>" lf) ,(string-append "bravo" lf)) (:p "real2"))) (test/equal "" (html->shtml (string-append "<P>real1</P>" lf "<XMP>" lf "alpha" lf "<P>fake</P>" lf "bravo" lf "</XMP " lf "<P>real2</P>")) expected) (test/equal "" (html->shtml (string-append "<P>real1</P>" lf "<XMP>" lf "alpha" lf "<P>fake</P>" lf "bravo" lf "</XMP" lf "<P>real2</P>")) expected) (test/equal "" (html->shtml "<xmp>a</xmp>x") `(,shtml-top-symbol (:xmp "a") "x")) (test/equal "" (html->shtml (string-append "<xmp>a" lf "</xmp>x")) `(,shtml-top-symbol (:xmp ,(string-append "a" lf)) "x")) (test/equal "" (html->shtml "<xmp></xmp>x") `(,shtml-top-symbol (:xmp) "x")) (test/equal "" (html->shtml "<xmp>a</xmp") `(,shtml-top-symbol (:xmp "a"))) (test/equal "" (html->shtml "<xmp>a</xm") `(,shtml-top-symbol (:xmp "a</xm"))) (test/equal "" (html->shtml "<xmp>a</x") `(,shtml-top-symbol (:xmp "a</x"))) (test/equal "" (html->shtml "<xmp>a</") `(,shtml-top-symbol (:xmp "a</"))) (test/equal "" (html->shtml "<xmp>a<") `(,shtml-top-symbol (:xmp "a<"))) (test/equal "" (html->shtml "<xmp>a") `(,shtml-top-symbol (:xmp "a"))) (test/equal "" (html->shtml "<xmp>") `(,shtml-top-symbol (:xmp))) (test/equal "" (html->shtml "<xmp") `(,shtml-top-symbol (:xmp))) (test/equal "" (html->shtml "<xmp x=42 ") `(,shtml-top-symbol (:xmp (:@ (:x "42"))))) (test/equal "" (html->shtml "<xmp x= ") `(,shtml-top-symbol (:xmp (:@ (:x))))) (test/equal "" (html->shtml "<xmp x ") `(,shtml-top-symbol (:xmp (:@ (:x))))) (test/equal "" (html->shtml "<xmp x") `(,shtml-top-symbol (:xmp (:@ (:x))))) (test/equal "" (html->shtml "<script>xxx") `(,shtml-top-symbol (:script "xxx"))) (test/equal "" (html->shtml "<script/>xxx") `(,shtml-top-symbol (:script) "xxx")) (test/equal "" (html->shtml "<html xml:lang=\"en\" lang=\"en\">") `(,shtml-top-symbol (:html (:@ (:|XML:LANG| "en") (:lang "en"))))) (test/equal "" (html->shtml "<a href=/foo.html>") `(,shtml-top-symbol (:a (:@ (:href "/foo.html"))))) (test/equal "" (html->shtml "<a href=/>foo.html") `(,shtml-top-symbol (:a (:@ (:href "/")) "foo.html"))) ;; TODO: Add verbatim-pair cases with attributes in the end tag. (test/equal "" (shtml->html '(:p)) "<p></p>") (test/equal "" (shtml->html '(:p "CONTENT")) "<p>CONTENT</p>") (test/equal "" (shtml->html '(:br)) "<br />") (test/equal "" (shtml->html '(:br "CONTENT")) "<br />") (test/equal "" (shtml->html `(:hr (:@ (:clear "all")))) "<hr clear=\"all\" />") (test/equal "" (shtml->html `(:hr (:@ (:noshade)))) "<hr noshade />") #| (test/equal "" (shtml->html `(:hr (:@ (:noshade #t)))) "<hr noshade />") |# ;; TODO: Maybe lose this test. (test/equal "" (shtml->html `(:hr (:@ (:noshade "noshade")))) "<hr noshade=\"noshade\" />") (test/equal "" (shtml->html `(:hr (:@ (:aaa "bbbccc")))) "<hr aaa=\"bbbccc\" />") (test/equal "" (shtml->html `(:hr (:@ (:aaa "bbb'ccc")))) "<hr aaa=\"bbb'ccc\" />") (test/equal "" (shtml->html `(:hr (:@ (:aaa "bbb\"ccc")))) "<hr aaa='bbb\"ccc' />") (test/equal "" (shtml->html `(:hr (:@ (:aaa "bbb\"ccc'ddd")))) "<hr aaa=\"bbb&quot;ccc'ddd\" />") (test/equal "" (shtml->html '(:& "copy")) "&copy;") (test/equal "" (shtml->html '(:& "rArr")) "&rArr;") (test/equal "" (shtml->html `(:& ,(string->symbol "rArr"))) "&rArr;") (test/equal "" (shtml->html '(:& 151)) "&#151;") (test/equal "" (html->shtml "&copy;") `(,shtml-top-symbol (:& ,(string->symbol "copy")))) (test/equal "" (html->shtml "&rArr;") `(,shtml-top-symbol (:& ,(string->symbol "rArr")))) (test/equal "" (html->shtml "&#151;") `(,shtml-top-symbol (:& 151) ;; ,(string (%a2c 151)) )) (test/equal "" (html->shtml "&#999;") `(,shtml-top-symbol (:& 999))) (test/equal "" (shtml->html `(,shtml-pi-symbol :xml "version=\"1.0\" encoding=\"UTF-8\"")) "<?xml version=\"1.0\" encoding=\"UTF-8\"?>") (test/equal "" (shtml->html `(,shtml-decl-symbol ,(string->symbol "DOCTYPE") :html ,(string->symbol "PUBLIC") "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")) (string-append "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")) (test/equal "" (shtml-entity-value '(:*ENTITY* "shtml-named-char" "rArr")) (string->symbol "rArr")) (test/equal "" (shtml-entity-value '(:& "rArr")) (string->symbol "rArr")) (test/equal "" (shtml-entity-value `(:& ,(string->symbol "rArr"))) (string->symbol "rArr")) (test/equal "" (html->shtml "xxx<![CDATA[abc]]>yyy") `(,shtml-top-symbol "xxx" "abc" "yyy")) (test/equal "" (html->shtml "xxx<![CDATA[ab]c]]>yyy") `(,shtml-top-symbol "xxx" "ab]c" "yyy")) (test/equal "" (html->shtml "xxx<![CDATA[ab]]c]]>yyy") `(,shtml-top-symbol "xxx" "ab]]c" "yyy")) (test/equal "" (html->shtml "xxx<![CDATA[]]]>yyy") `(,shtml-top-symbol "xxx" "]" "yyy")) (test/equal "" (html->shtml "xxx<![CDATAyyy") `(,shtml-top-symbol "xxx" "<![CDATA" "yyy")) (test/equal "parent constraints with div" (html->shtml "<html><div><p>P1</p><p>P2</p></div><p>P3</p>") `(,shtml-top-symbol (:html (:div (:p "P1") (:p "P2")) (:p "P3")))) (test/equal "we no longer convert character references above 126 to string" (html->shtml "&#151;") `(,shtml-top-symbol (:& 151))) ;; TODO: Write more test cases for HTML encoding. ;; TODO: Write test cases for foreign-filter of HTML writing. ;; TODO: Write test cases for attribute values that aren't simple strings. ;; TODO: Document this. ;; ;; (define html-1 "<myelem myattr=\"&\">") ;; (define shtml (html->shtml html-1)) ;; shtml ;; (define html-2 (shtml->html shtml)) ;; html-2 )) (define (add-parent-constraints new-constraints) (set! *parent-constraints* (append *parent-constraints* new-constraints))) ;;; @unnumberedsec History ;;; @table @asis ;;; ;;; @item Version 0.16 --- 2005-12-18 ;;; Documentation fix. ;;; ;;; @item Version 0.15 --- 2005-12-18 ;;; In the HTML parent element constraints that are used for structure ;;; recovery, @code{div} is now always permitted as a parent, as a stopgap ;;; measure until substantial time can be spent reworking the algorithm to ;;; better support @code{div} (bug reported by Corey Sweeney and Jepri). Also ;;; no longer convert to Scheme character any HTML numeric character reference ;;; with value above 126, to avoid Unicode problem with PLT 299/300 (bug ;;; reported by Corey Sweeney). ;;; ;;; @item Version 0.14 --- 2005-06-16 ;;; XML CDATA sections are now tokenized. Thanks to Alejandro Forero Cuervo ;;; for suggesting this feature. The deprecated procedures @code{sxml->html} ;;; and @code{write-sxml-html} have been removed. Minor documentation changes. ;;; ;;; @item Version 0.13 --- 2005-02-23 ;;; HtmlPrag now requires @code{syntax-rules}, and a reader that can read ;;; @code{@@} as a symbol. SHTML now has a special @code{&} element for ;;; character entities, and it is emitted by the parser rather than the old ;;; @code{*ENTITY*} kludge. @code{shtml-entity-value} supports both the new ;;; and the old character entity representations. @code{shtml-entity-value} ;;; now yields @code{#f} on invalid SHTML entity, rather than raising an error. ;;; @code{write-shtml-as-html} now has a third argument, @code{foreign-filter}. ;;; @code{write-shtml-as-html} now emits SHTML @code{&} entity references. ;;; Changed @code{shtml-named-char-id} and @code{shtml-numeric-char-id}, as ;;; previously warned. Testeez is now used for the test suite. Test procedure ;;; is now the internal @code{%test}. Documentation changes. ;;; Notably, much documentation about using HtmlPrag under various particular ;;; Scheme implementations has been removed. ;;; ;;; @item Version 0.12 --- 2004-07-12 ;;; Forward-slash in an unquoted attribute value is now considered a value ;;; constituent rather than an unconsumed terminator of the value (thanks to ;;; Maurice Davis for reporting and a suggested fix). @code{xml:} is now ;;; preserved as a namespace qualifier (thanks to Peter Barabas for ;;; reporting). Output port term of @code{write-shtml-as-html} is now ;;; optional. Began documenting loading for particular implementation-specific ;;; packagings. ;;; ;;; @item Version 0.11 --- 2004-05-13 ;;; To reduce likely namespace collisions with SXML tools, and in anticipation ;;; of a forthcoming set of new features, introduced the concept of ``SHTML,'' ;;; which will be elaborated upon in a future version of HtmlPrag. Renamed ;;; @code{sxml-@var{x}-symbol} to @code{shtml-@var{x}-symbol}, ;;; @code{sxml-html-@var{x}} to @code{shtml-@var{x}}, and ;;; @code{sxml-token-kind} to @code{shtml-token-kind}. @code{html->shtml}, ;;; @code{shtml->html}, and @code{write-shtml-as-html} have been added as ;;; names. Considered deprecated but still defined (see the ``Deprecated'' ;;; section of this documentation) are @code{sxml->html} and ;;; @code{write-sxml-html}. The growing pains should now be all but over. ;;; Internally, @code{htmlprag-internal:error} introduced for Bigloo ;;; portability. SISC returned to the test list; thanks to Scott G. Miller ;;; for his help. Fixed a new character @code{eq?} bug, thanks to SISC. ;;; ;;; @item Version 0.10 --- 2004-05-11 ;;; All public identifiers have been renamed to drop the ``@code{}'' ;;; prefix. The portability identifiers have been renamed to begin with an ;;; @code{htmlprag-internal:} prefix, are now considered strictly ;;; internal-use-only, and have otherwise been changed. @code{parse-html} and ;;; @code{always-empty-html-elements} are no longer public. ;;; @code{test-htmlprag} now tests @code{html->sxml} rather than ;;; @code{parse-html}. SISC temporarily removed from the test list, until an ;;; open source Java that works correctly is found. ;;; ;;; @item Version 0.9 --- 2004-05-07 ;;; HTML encoding procedures added. Added ;;; @code{sxml-html-entity-value}. Upper-case @code{X} in hexadecimal ;;; character entities is now parsed, in addition to lower-case @code{x}. ;;; Added @code{always-empty-html-elements}. Added additional ;;; portability bindings. Added more test cases. ;;; ;;; @item Version 0.8 --- 2004-04-27 ;;; Entity references (symbolic, decimal numeric, hexadecimal numeric) are now ;;; parsed into @code{*ENTITY*} SXML. SXML symbols like @code{*TOP*} are now ;;; always upper-case, regardless of the Scheme implementation. Identifiers ;;; such as @code{sxml-top-symbol} are bound to the upper-case ;;; symbols. Procedures @code{html->sxml-0nf}, ;;; @code{html->sxml-1nf}, and @code{html->sxml-2nf} have ;;; been added. @code{html->sxml} now an alias for ;;; @code{html->sxml-0nf}. @code{parse} has been refashioned ;;; as @code{parse-html} and should no longer be directly. A number ;;; of identifiers have been renamed to be more appropriate when the ;;; @code{} prefix is dropped in some implementation-specific ;;; packagings of @code{make-tokenizer} to ;;; @code{make-html-tokenizer}, @code{parse/tokenizer} to ;;; @code{parse-html/tokenizer}, @code{html->token-list} to ;;; @code{tokenize-html}, @code{token-kind} to ;;; @code{sxml-token-kind}, and @code{test} to ;;; @code{test-htmlprag}. Verbatim elements with empty-element tag ;;; syntax are handled correctly. New versions of Bigloo and RScheme tested. ;;; ;;; @item Version 0.7 --- 2004-03-10 ;;; Verbatim pair elements like @code{script} and @code{xmp} are now parsed ;;; correctly. Two Scheme implementations have temporarily been dropped from ;;; regression testing: Kawa, due to a Java bytecode verifier error likely due ;;; to a Java installation problem on the test machine; and SXM 1.1, due to ;;; hitting a limit on the number of literals late in the test suite code. ;;; Tested newer versions of Bigloo, Chicken, Gauche, Guile, MIT Scheme, PLT ;;; MzScheme, RScheme, SISC, and STklos. RScheme no longer requires the ;;; ``@code{(define get-output-string close-output-port)}'' workaround. ;;; ;;; @item Version 0.6 --- 2003-07-03 ;;; Fixed uses of @code{eq?} in character comparisons, thanks to Scott G. ;;; Miller. Added @code{html->normalized-sxml} and ;;; @code{html->nonnormalized-sxml}. Started to add ;;; @code{close-output-port} to uses of output strings, then reverted due to ;;; bug in one of the supported dialects. Tested newer versions of Bigloo, ;;; Gauche, PLT MzScheme, RScheme. ;;; ;;; @item Version 0.5 --- 2003-02-26 ;;; Removed uses of @code{call-with-values}. Re-ordered top-level definitions, ;;; for portability. Now tests under Kawa 1.6.99, RScheme 0.7.3.2, Scheme 48 ;;; 0.57, SISC 1.7.4, STklos 0.54, and SXM 1.1. ;;; ;;; @item Version 0.4 --- 2003-02-19 ;;; Apostrophe-quoted element attribute values are now handled. A bug that ;;; incorrectly assumed left-to-right term evaluation order has been fixed ;;; (thanks to MIT Scheme for confronting us with this). Now also tests OK ;;; under Gauche 0.6.6 and MIT Scheme 7.7.1. Portability improvement for ;;; implementations (e.g., RScheme 0.7.3.2.b6, Stalin 0.9) that cannot read ;;; @code{@@} as a symbol (although those implementations tend to present other ;;; portability issues, as yet unresolved). ;;; ;;; @item Version 0.3 --- 2003-02-05 ;;; A test suite with 66 cases has been added, and necessary changes have been ;;; made for the suite to pass on five popular Scheme implementations. XML ;;; processing instructions are now parsed. Parent constraints have been added ;;; for @code{colgroup}, @code{tbody}, and @code{thead} elements. Erroneous ;;; input, including invalid hexadecimal entity reference syntax and extraneous ;;; double quotes in element tags, is now parsed better. ;;; @code{token-kind} emits symbols more consistent with SXML. ;;; ;;; @item Version 0.2 --- 2003-02-02 ;;; Portability improvements. ;;; ;;; @item Version 0.1 --- 2003-01-31 ;;; Dusted off old Guile-specific code from April 2001, converted to emit SXML, ;;; mostly ported to R5RS and SRFI-6, added some XHTML support and ;;; documentation. A little preliminary testing has been done, and the package ;;; is already useful for some applications, but this release should be ;;; considered a preview to invite comments. ;;; ;;; @end table
96,213
Common Lisp
.lisp
2,258
31.492471
89
0.497467
j3pic/cl-htmlprag
5
0
1
LGPL-2.1
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
a5196682383afea1dc62f465585d6deda87b57313121297340f60fc4ec79947d
15,523
[ -1 ]
15,524
read-macros.lisp
j3pic_cl-htmlprag/read-macros.lisp
(cl:defpackage :schemish) (cl:in-package :schemish) (cl:intern "+SCHEME-TRUE+") (cl:intern "+SCHEME-FALSE+") (cl:defpackage :schemish-read-macros (:use :common-lisp) (:export :enable-scheme-read-syntax :disable-scheme-read-syntax)) (cl:in-package :schemish-read-macros) (defvar *readtable-stack* nil) (defun push-readtable () (push *readtable* *readtable-stack*) (setf *readtable* (copy-readtable))) (defun pop-readtable () (setf *readtable* (pop *readtable-stack*))) (defun enable-scheme-read-syntax () (push-readtable) (set-dispatch-macro-character #\# #\T (lambda (&rest fuck-you) (declare (ignore fuck-you)) 'schemish::+scheme-true+)) (set-dispatch-macro-character #\# #\F (lambda (&rest fuck-you) (declare (ignore fuck-you)) 'schemish::+scheme-false+))) (defun disable-scheme-read-syntax () (pop-readtable))
874
Common Lisp
.lisp
27
29.111111
45
0.694048
j3pic/cl-htmlprag
5
0
1
LGPL-2.1
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
c90aae3a70af6ffdbc197ebeddbe7c49afaa91af9cbaec31e8a38cfc52235587
15,524
[ -1 ]
15,525
testeez.lisp
j3pic_cl-htmlprag/testeez.lisp
;;; @Package Testeez ;;; @Subtitle Lightweight Unit Test Mechanism for R5RS Scheme ;;; @HomePage http://www.neilvandyke.org/testeez/ ;;; @Author Neil Van Dyke ;;; @Version 0.5 ;;; @Date 2009-05-28 ;;; @PLaneT neil/testeez:1:3 ;; $Id: testeez.ss,v 1.76 2009/05/29 11:42:28 neilpair Exp $ ;;; @legal ;;; Copyright @copyright{} 2005--2009 Neil Van Dyke. This program 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 (LGPL 3), 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 ;;; @indicateurl{http://www.gnu.org/licenses/} for details. For other licenses ;;; and consulting, please contact the author. ;;; @end legal ;;; @section Introduction ;;; ;;; Testeez is a simple lightweight unit test mechanism for R5RS Scheme. It ;;; was written to support regression test suites embedded within the source ;;; code files of the author's portable Scheme libraries. ;;; ;;; @subsection Example ;;; ;;; A series of Testeez tests is listed within the @code{testeez} syntax. For ;;; example: ;;; ;;; @lisp ;;; (testeez ;;; "Foo Station" ;;; ;;; (test/equal "Put two and two together" (+ 2 2) 4) ;;; ;;; (test-define "Bar function" bar (lambda (x) (+ x 42))) ;;; ;;; (test/equal "Bar scene" (bar 69) 0) ;;; ;;; (test/eqv "Full circle" (* (bar -21) 2) 42) ;;; ;;; (test/eqv "Multiple" ;;; (values (+ 2 2) (string #\h #\i) (char-upcase #\p)) ;;; (values 4 "hi" #\P))) ;;; @end lisp ;;; ;;; When evaluated, output like the following (which looks prettier fontified ;;; in Emacs's @code{*scheme*} buffer) is printed: ;;; ;;; @smallexample ;;; ;;; BEGIN "Foo Station" TESTS ;;; ;;; ;; 1. Put two and two together ;;; (+ 2 2) ;;; ;; ==> 4 ;;; ;; Passed. ;;; ;;; ;; DEFINE: Bar function ;;; (define bar (lambda (x) (+ x 42))) ;;; ;;; ;; 2. Bar scene ;;; (bar 69) ;;; ;; ==> 111 ;;; ;; FAILED! Expected: ;;; ;; 0 ;;; ;;; ;; 3. Full circle ;;; (* (bar -21) 2) ;;; ;; ==> 42 ;;; ;; Passed. ;;; ;;; ;; 4. Multiple ;;; (values (+ 2 2) (string #\h #\i) (char-upcase #\p)) ;;; ;; ==> 4 ;;; ;; "hi" ;;; ;; #\P ;;; ;; Passed. ;;; ;;; ;;; END "Foo Station" TESTS: FAILED ;;; ;;; (Total: 4 Passed: 3 Failed: 1) ;;; @end smallexample ;;; ;;; @subsection Shorthand ;;; ;;; The @code{testeez} syntax also supports shorthand or abbreviated forms, for ;;; quick interactive use, such as in an editor buffer while rapid-prototyping ;;; a function, and in a REPL while debugging. For an example of shorthand, ;;; the Scheme expression: ;;; ;;; @lisp ;;; (testeez ((+ 1 2) 3) ((* 6 7) 42)) ;;; @end lisp ;;; ;;; @noindent ;;; is equivalent to: ;;; ;;; @lisp ;;; (testeez "" ;;; (test/equal "" (+ 1 2) 3) ;;; (test/equal "" (* 6 7) 42)) ;;; @end lisp ;;; ;;; Future versions of Testeez will add additional features, such as custom ;;; predicates and handling of errors. ;;; ;;; @subsection Embedding ;;; ;;; By following a simple convention, Testeez tests can be embedded in a Scheme ;;; source file with the code that is tested, while permitting the tests to be ;;; disabled and the dependency on Testeez removed for production code. For ;;; example, to use Testeez in a ``Foo'' library, one can first add a syntax ;;; wrapper around @code{testeez} like so: ;;; ;;; @example ;;; (define-syntax %foo:testeez ;;; (syntax-rules () ;;; ((_ X ...) ;;; ;; Note: Comment-out exactly one of the following two lines. ;;; ;; (error "Tests disabled.") ;;; (testeez X ...) ;;; ))) ;;; @end example ;;; ;;; Then, this wrapper @code{%foo:testeez} can be used in a procedure that ;;; executes the test suite of the ``Foo'' library: ;;; ;;; @lisp ;;; (define (%foo:test) ;;; (%foo:testeez ;;; "Foo Station" ;;; ....)) ;;; @end lisp ;;; @section Interface ;;; The interface consists of the @code{testeez} syntax. (cl:defpackage :%testeez (:use :schemish) (:export :test/equiv :test/eq :test/equal :test/eqv :test-define :test-eval :testeez)) (cl:in-package :%testeez) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (schemish-read-macros:enable-scheme-read-syntax)) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (define (make-data title) (vector title 0 0 0)) (define (data-title o) (vector-ref o 0)) (define (data-total o) (vector-ref o 1)) (define (data-passed o) (vector-ref o 2)) (define (data-failed o) (vector-ref o 3)) (define (set-data-title! o x) (vector-set! o 0 x)) (define (set-data-total! o x) (vector-set! o 1 x)) (define (set-data-passed! o x) (vector-set! o 2 x)) (define (set-data-failed! o x) (vector-set! o 3 x)) (define (print-values-list first-prefix next-prefix val-list) (display first-prefix) (if (null? val-list) (newline) (let loop ((val-list val-list)) (write (car val-list)) (newline) (or (null? (cdr val-list)) (begin (display next-prefix) (loop (cdr val-list))))))) (define (print-result result-list) (print-values-list ";; ==> " ";; " result-list)) (define (start-test data desc expr-quoted) (set-data-total! data (+ 1 (data-total data))) (newline) (display ";; ") (display (data-total data)) (display ". ") (display desc) (newline) (write expr-quoted) (newline)) (define (finish-test data pred pred-rest result-list expected-list) (define (failed) (set-data-failed! data (+ 1 (data-failed data))) (display ";; FAILED! Expected:") (newline) (print-values-list ";; " ";; " expected-list)) (print-result result-list) (let loop ((pred pred) (pred-rest pred-rest) (result-list result-list) (expected-list expected-list)) (if (null? result-list) (if (null? expected-list) (begin (set-data-passed! data (+ 1 (data-passed data))) (display ";; Passed.") (newline)) (failed)) (if (null? expected-list) (failed) (if (cl:funcall pred (car result-list) (car expected-list)) (if (null? pred-rest) (loop pred pred-rest (cdr result-list) (cdr expected-list)) (loop (car pred-rest) (cdr pred-rest) (cdr result-list) (cdr expected-list))) (failed)))))) (define (start-eval desc expr-quoted) (newline) (display ";; EVAL: ") (display desc) (newline) (write expr-quoted) (newline)) (define (start-define desc expr-quoted) (newline) (display ";; DEFINE: ") (display desc) (newline) (write expr-quoted) (newline)) (define (start-tests title) (newline) (display ";;; BEGIN") (and title (begin (display " ") (write title))) (display " TESTS") (newline) (make-data title)) (define (finish-tests data) (let ((total (data-total data)) (passed (data-passed data)) (failed (data-failed data))) ;; TODO: Check that total = passed + failed (newline) (display ";;; END") (let ((title (data-title data))) (and title (begin (display " ") (write title)))) (display " TESTS: ") (display (cond ((zero? failed) "PASSED") ;; ((zero? passed) "ALL FAILED") (else "FAILED"))) (newline) (display ";;; (Total: ") (display total) (display " Passed: ") (display passed) (display " Failed: ") (display failed) (display ")") (newline))) ;;; @defsyntax testeez [ title ] form ... ;;; ;;; The @code{testeez} syntax contains a short string @var{title} and one or ;;; more @var{forms}, of the following syntaxes, which are evaluated in order. ;;; ;;; @table @code ;;; ;;; @item (test/equal @var{desc} @var{expr} @var{expected}) ;;; Execute a test case. @var{desc} is a short title or description of the ;;; test case, @var{expr} is a Scheme expression, and @var{expected} is an ;;; expression for the expected value (or multiple values). The test case ;;; passes iff each value of @var{expr} is @code{equal?} to the corresponding ;;; value of @var{expected}. ;;; ;;; @item (test/eq @var{desc} @var{expr} @var{expected}) ;;; Like @code{test/equal}, except the equivalence predicate is @code{eq?} ;;; rather than @code{equal?}. ;;; ;;; @item (test/eqv @var{desc} @var{expr} @var{expected}) ;;; Like @code{test/equal}, except the equivalence predicate is @code{eqv?} ;;; rather than @code{equal?}. ;;; ;;; @item (test-define @var{desc} @var{name} @var{val}) ;;; Bind a variable. @var{desc} is a short description string, @var{name} is ;;; the identifier, and @var{val} is the value expression. The binding is ;;; visible to the remainder of the enclosing @code{testeez} syntax. ;;; ;;; @item (test-eval @var{desc} @var{expr}) ;;; Evaluate an expression. ;;; ;;; @item (@var{expr} @var{expected}) ;;; Shorthand for @code{(test/equal "" @var{expr} @var{expected})}. This ;;; shorthand is intended for interactive and rapid-prototyping use, not for ;;; released code. ;;; ;;; @end table ;; TODO: Lose the "begin"s. ;; TODO: Expose the custom equivalence predicates, once we're sure we like ;; the syntax. Should add generic predicates first. (cl:defmacro test/equiv (data-var desc expr expected (pred0 &rest rest-preds) &body body) (alexandria:with-gensyms (result-list expected-list) `(begin (start-test ,data-var ,desc ',expr) (let ((,result-list (call-with-values (λ () ,expr) #'list)) (,expected-list (call-with-values (λ () ,expected) #'list))) (finish-test ,data-var (cl:function ,pred0) ,(cons 'list (map (lambda (pred) (cons 'cl:function pred)) rest-preds)) ,result-list ,expected-list)) (body ,data-var ,@body)))) (cl:defmacro test/eq (desc expr expected data-var &body body) `(test/equiv ,data-var ,desc ,expr ,expected (eq?) ,@body)) (cl:defmacro test/equal (desc expr expected data-var &body body) `(test/equiv ,data-var ,desc ,expr ,expected (equal?) ,@body)) (cl:defmacro test/eqv (desc expr expected data-var &body body) `(test/equiv ,data-var ,desc ,expr ,expected (equal?) ,@body)) (cl:defmacro test-define (desc name val data-var &body body) `(begin (start-define ,desc (list 'define ',name ',val)) (let ((,name ,val)) (body ,data-var ,@body)))) (cl:defmacro test-eval (desc expr data-var &body body) (alexandria:with-gensyms (result) `(begin (start-eval ,desc ',expr) (let ((,result (call-with-values (lambda () ,expr) #'list))) (print-result ,result)) (body ,data-var ,@body)))) (cl:defmacro body (data-var &rest forms) (cond ((or (null? forms) (equal? forms '(()))) '(values)) (else (let ((head (car forms)) (tail (cdr forms))) (if (= (length head) 2) `(body ,data-var (test/equal "" ,@head) ,@tail) `(begin ,(append head (cons data-var tail)))))))) (cl:defmacro testeez (title &body body) (if (list? title) `(testeez #f ,title ,@body) (alexandria:with-gensyms (data) `(let ((,data (start-tests ,title))) (body ,data ,@body) (finish-tests ,data)))))) ;;; @unnumberedsec History ;;; @table @asis ;;; @item Version 0.5 --- 2016-05-14 --- ;;; Ported to Common Lisp. ;;; ;;; @item Version 0.5 --- 2009-05-28 --- PLaneT @code{(1 3)} ;;; Added support for void return values. ;;; ;;; @item Version 0.4 --- 2009-03-02 --- PLaneT @code{(1 2)} ;;; License is now LGPL 3. Minor changes for PLT 4. Changed to new Scheme ;;; administration system. There is now a @code{main.ss}. ;;; ;;; @item Version 0.3 --- 2005-05-30 --- PLaneT @code{(1 1)} ;;; Shorthand syntax added. Minor formatting change to test log output. ;;; ;;; @item Version 0.2 --- 2005-03-07 --- PLaneT @code{(1 0)} ;;; Multiple values are now supported. @code{test/eq} and @code{test/eqv} ;;; have been added. Minor formatting changes to test log output. ;;; ;;; @item Version 0.1 --- 2005-01-02 ;;; Initial release. ;;; ;;; @end table
12,322
Common Lisp
.lisp
370
30.110811
91
0.619803
j3pic/cl-htmlprag
5
0
1
LGPL-2.1
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
dc7ed73353293d0fd45ed34fe074edd94b519ba54b628250ec233fcc504c5f97
15,525
[ -1 ]
15,526
cl-htmlprag.asd
j3pic_cl-htmlprag/cl-htmlprag.asd
(defsystem :cl-htmlprag :author ("Neil van Dyke") :maintainer "Jeremy Phelps" :description "A port of Neil Van Dyke's famous HTMLPrag library to Common Lisp." :version "0.24" :license "LGPL 2.1" :depends-on (:optima :parse-number :alexandria) :components ((:file "read-macros") (:file "testeez" :depends-on ("schemish")) (:file "htmlprag" :depends-on ("schemish" "testeez")) (:file "schemish" :depends-on ("read-macros"))))
449
Common Lisp
.asd
12
34.333333
82
0.684211
j3pic/cl-htmlprag
5
0
1
LGPL-2.1
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
1908cd886d29019b53266ee1be2febed37ea53ebb64dd01d8943c4bafd6f8446
15,526
[ -1 ]
15,547
package.lisp
drea8_cl-refal/package.lisp
(defpackage #:cl-refal (:use #:cl) (:documentation "CL-REFAL a Common Lisp embedding and extension of Valentin Turchin's functional programming language REFAL."))
165
Common Lisp
.lisp
3
53.333333
127
0.777778
drea8/cl-refal
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b6bf1d2e40100b0abe0747ca0b4d2a5118f9f6ad02a988dfe77b8f245555bf69
15,547
[ -1 ]
15,548
interpret.lisp
drea8_cl-refal/src/interpret.lisp
;; Common Lisp REFAL Interpreter ;; Valentin Turchin was a Russian cyberneticist who ;; wrote a programming language called "REFAL" around 1966, ;; short for Recursive Evaluation of Functions Language, ;; for his research in physics, automata, natural language translation, ;; artificial intelligence, and complexity theory. ;; Turchin's take on expressing mathematic, logical, and lingustic relations in a ;; simple Sentence term notation is extremely useful and insightful ;; as an exercise in programming language design and information theory ;; in general. The possible extensions for Refal pattern spaces as ;; say semigroups or topological structures is obvious as one ;; implements Refal in a homoiconic language like Lisp. ;; Studying Refal in one respect one is exploring ;; Automata theory heavily, but on the other hand much of what ;; makes Refal unique is the Refal machine reader which relates more ;; to information representation theories of data structures ;; moreso than parsing automata like regular expressions, and ;; in constructing optimized Refal compilers you end up ;; writing automata around traversal of the data spaces rather than ;; beginning with the automata as a runtime in its own right ;; due to the "non-flat" possibility space of data structures ;; readable by Refal-like languages. ;; The compiler writer if they are a good Cyberneticist ;; like Turchin also no longer takes for granted the ;; given "Programmer's Reader" one has learned from education ;; in one's native tongues and symbol systems, ;; that "who is the master that makes the grass green" etc ;; Refal is described thusly on wikipedia in 2019, ;; "The basic data structure of Lisp and Prolog is a linear list built by cons operation in a sequential manner, thus with O(n) access to list's nth element... ;; ...Refal's lists are built and scanned from both ends, with pattern matching working for nested lists as well as the top-level one. In effect, the basic data structure of Refal is a tree rather than a list. This gives freedom and convenience in creating data structures while using only mathematically simple control mechanisms of pattern matching and substitution... In effect, the basic data structure of Refal is a tree rather than a list." ;; Because of its elegance and simplicity, I ;; consider it one of the most 'pure' functinal programming ;; language models. This simplicity and many of ;; Turchin's other design choices make it possibly ;; easier to extend via metaprogramming and compiler ;; construction than Lisp, Haskell, or Prolog. ;; This repository will test this idea. ;; There is a robust implementation online maintained ;; by a Russian technical university but we will ;; analyze the ideas behind Refal by implementing ;; a subset of it in Common Lisp ;; This file interpret.lisp will serve as a ;; introductory tutorial to embedding ;; Refal-like languages in Common Lisp, author uses ;; Steel Bank Common Lisp, Emacs, and SLIME ;; and assumes knowledge of basic Common Lisp ;; I may include notes that seem trivial to the ;; advanced programmer, excuse them they are for ;; my own thoughts or beginner's study. ;; Introduction to Refal ;; A Refal program expression is a recursive graph ;; of Sentences, formed by Left and Right terms ;; that forms a Function mapping from Predicates ;; satisfies on the Left to results returned by their ;; Right term in the same Sentence. ;; This is what the original Refal looks like "BinAdd { '0' '0' = '0'; '0' '1' = '1'; '1' '0' = <BinAdd '0' '1'>; '1' '1' = '10'; }" ;; The default operation in Refal is concatenation, so ;; '0' '0' is equivalent to the Lisp list (or string) '(0 0) or "00" ;; This is what it will look like embedded in Common Lisp Refal '(def binadd ((0 0) 00) ((0 1) 01) ;; note the ((1 0) (binadd 0 1)) ;; symmetry here ((1 1) 10)) ;; and would be called like '(binadd 0 0) ;; from the Refal source material by Valentin Turchin "Refal Function Execution We need to clarify the process of Refal function execution now. 1. A sentence is elected from the left side Patterns for which you can get a function argument by changing the variables in it to some values. If no such Sentence exists, then the program ends with an error of recognition impossible 2. The variables values are fixed when they request to the function argument when they are placed in the left part of the selected sentence, if there are several such sets of variables values (permutations), then its fixed the one in which the leftmost e-variable takes the shortest value. If it does not resolve ambiguities, then the next e-variable is considered and so on. 3. The variables are replaced by their values in the right side of the selected sentence. Then the functions on the right are calculated." ;; to encode Refal Sentence pattern terms, we will ;; write them in Common Lisp cells as '( (l_term0 r_term0) (l_term1 r_term1) ;; ...etc ) ;; In writing our CL refal implementation ;; lets give some sample examples, lets ;; start with a simple binary increment ;; Here is the binary increment pattern in a Lisp SEXP '((00 01) (01 10) (10 11) (11 00)) ;; Note this is a cyclic group, ;; but for now let us focus on it as a Refal function pattern ;; This pattern with an input of 00 returns 01 etc ;; We want a function that takes this kind ;; of Sentence terms structure as parameter data, ;; an input to match it against, and the ;; Pattern Matcher Function object (unique to CL-REFAL) (defun cl-refal-call (patterns input-data pattern-evaluator) (funcall pattern-evaluator input-data patterns)) (defun pattern-evaluator () `(loop for i in patterns if (equal (first i) input) return (second i))) ;; We can test it this way ;; We apply CL-REFAL-CALL (cl-refal-call ;; to the cyclic binary space '((0 1) (1 0)) ;; with input member 1 1 ;; and the basic naive serial pattern matcher function (lambda (input patterns) ;; which goes through each pattern in the cons cells (loop for i in patterns ;; checks for left term equality if (equal (first i) input) ;; and returns the right term if found return (second i)) ) ) ;; evaluate this in SLIME ;; here is the call expression without comments (cl-refal-call '((0 1) (1 0)) 1 (lambda (input patterns) (loop for i in patterns if (equal (first i) input) return (second i)) ) ) ;; We would simplify this in idiomatic Common Lisp as (funcall (lambda (input patterns) (loop for i in patterns if (equal (first i) input) return (second i)) ) 1 '((0 1) (1 0))) ;; The part we are more interested in simplifying and generalizing ;; is the pattern matcher function object; (lambda (input patterns) (loop for i in patterns ;; this Loop control structure/invariant, if (equal (first i) input) ;; this predicate match. return (second i)) ) ;; and this return structure are important ;; What is happening here? ;; In Common Lisp world, the expression means the following to the runtime: ;; define an anonymous function with parameters (input patterns) ;; loop through PATTERNS assuming it is a cons cell ;; , each member perform an binary check on the EQUAL function ;; , and if it matches return the SECOND of that cell ;; This loop block is the most important part, the defining an anonymous ;; function is an idiosyncracy of modular LISP. ;; We could generalize it with a LEFT-TERM and RIGHT-OUT function parameter ;; for a Pattern Matcher function object maker (defun pattern-matcher-maker (left-match right-out) (eval `(lambda (input patterns) (loop for i in patterns if (funcall ,left-match input i) return (funcall ,right-out i))) )) (defun basic-left-match (x cell) (equal (first cell) x)) (defun basic-right-out (cell) (second cell)) ;; We could call these this way: (funcall (pattern-matcher-maker #'basic-left-match #'basic-right-out) 1 '((0 1) (1 0))) ;; We could alter the basic left-right term pattern ;; matcher object this way to match for types rather than value! (defun type-left-match (x cell) (typep x (first cell))) (funcall (pattern-matcher-maker #'type-left-match #'basic-right-out) 1 '((Symbol No) (Number Yes))) ;; This gives us the beginnings of a naive type system... ;; though the observant reader would note the explicit domain and codomains ;; of Refal Sentence term blocks define a strict type for functions at read time. ;; At this point we should really talk about runtimes. ;; Because getting into formal modeling merits the discussion ;; of Performance optimization. ;; Refal terms requiring lists of string checks can ;; be modeled as language acceptors (some set of passing strings) ;; and thus a compiler for Refal understands the string ;; acceptors of term predicates and optimizes for traversal ;; of the ideal runtime for some performance feature. ;; So eventually we want an Automata theoretic model of ;; valid Refal programs and their compilation "morphogenesis", ;; how more complex Refal compilers grow in runtime complexity ;; for optimizing performance features of choice. ;; The runtime complexity grows with the logical-semantic ;; complexity and length of terms in the pattern matching ;; structure of the Refal function patterns and the ;; runtime structure of the Refal pattern matcher object, ;; which merits study in its own right. ;; Before doing so we need to implement the full REFAL syntax, ;; as we have not fully implemented Turchin's original REFAL ;; with string expression and tree matching term expressions, ;; and his other included functions in the Refal standard library. ;; To cover what we want to meta-model in Refal let's go over what ;; Turchin actually included for the language. ;; Thus far we have already matched basic character lists. (funcall (pattern-matcher-maker #'basic-left-match #'basic-right-out) 'a '((a ab) (ab aba) (aba acba))) ;; Let's include the dynamic symbol pattern matching utility Turchin had ;; in the original Refal pattern matcher object function ;; CELL values like '(("A" s.a) s.a) ;; which on X of "Aardvark" would be like "ardvark" ;; expanding the above expr '(("A" s.a) s.a) ;; is the automated equivalent of what would be produced ;; if we could manually write every '((("A" s.0) s.0) (("A" s.1) s.1) ;; ... etc ) ;; term that could be expanded by ;; the s. set ;; s.a delineates a Variable Determinate, The a variable ;; s.b would be a similar dynamic matcher disjunct and on the b variable '((s.a " " s.b) (s.a s.b)) ;; on "a b" return '(a b) ;; on "1 2" return '(1 2) ;; let us remember the format of the original cell pattern matching function: ;; (DEFUN BASIC-LEFT-MATCH (X CELL) (EQUAL (FIRST CELL) X)) ;; First lets examine CELL ;; in the binary addition CELL would be like ;; '(0 1) or '(1 0) or '(00 01) ;; We should define the full grammar of Refal expressions from ;; Turchin's own specifications, hierichally if conveniently possible. ;; see /doc/ for Refal function reference ;; Here is the Refal grammar; ;; the default operation is list concatenation! ;; lets start with flat strings, ;; then later work on Structure Brackets ;; (non flat structures), later graphs and ;; paradiscrete structures '(s.1 s.2 s.3) ;; term forms any three symbols like ;; 'ABC' ;; term pair '((s.1 s.2 s.3) (s.3 s.2)) ;; returns 'CB' from INPUT 'ABC' '(s.A s.A s.A) ;; term returns any three identical symbols like '666' or 'www' '((s.A s.A s.A) s.A) ;; from 'www' returns 'w' '(s.Edge s.Middle s.Edge) ;;- first and last must match, ie 'kek' or '^_^' ;; Note the natural language semantic name binds we have ;; for these variables "edge" "middle" and so forth. ;; Keep these natural language tokens in mind ;; for when we fully expand the semantics of a Refal ;; pattern match reader object. ;; In our analysis of Refal programs, at some point we ;; want to have a model of the "programmer's reader", ;; capable of comprehension of symbolic tokens like ;; "s.Edge" and "s.Middle" in the source outright ;; from human eyeballs following basic Latin alphabet ;; and English comprehension training, or ;; "who is the master that makes the grass green" etc '((s.Edge e s.Edge) s.Edge) ;; with INPUTs '404' or '4ab4' returns '4' '(s.first e.middle s.last) ;; accepts any expression containing at least two symbols ;; e.middle could be a further string, in this case procedurally the first and last characters of the list input buffer are first checked (as a type), a Refal Pattern Type ;; e. expressions can also null, for above the middle e.middle can be nulle so ++ or -+ is valid for s.first and s.last values ;; non-abbreviated symbols and strs are literal like '(s.first 'bc) ;; matches any string starting with s.first and terminating with 2 chars bc '(e.Eq e.Eq) ;; is an expression with even length, which can be divided into two identifical halves 'ABCABC' or '8888' or the empty expression (divides into two empty ones) ;; So with our Refal Expression Syntax Space defined, let's translate ;; the definition into a Common Lisp left match predicate function (defun refal-left-match (x cell) ) ;; Advanced CL Refal Extensions ;; ;; Semantic Expansion of Refal Structures ;; Infinite Refal Sentences ;; Continuous Stream Processing in Refal ;; Multi Modal Signals ;; Non-Flat Structure Matching ;; Refal Pattern Matcher and Compiler Morphogenesis ;; CL Refal File Loader (defun cl-refal-defun (refal-sexp) (let ((fun-name (first refal-sexp)) (fun-pattern (rest refal-sexp))) (eval `(defun ,fun-name (x) (funcall (pattern-matcher-maker #'basic-left-match #'basic-right-out) x (quote ,fun-pattern)))))) (defun cl-refal-load (file-path) (setq file-sexp (with-open-file (s file-path) (read s))) (cl-refal-defun file-sexp) )
13,891
Common Lisp
.lisp
318
41.506289
446
0.748549
drea8/cl-refal
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
20cd9082466345c02e914d62615d1f3c06a8a07db13e98a0b7470e009e8a30c0
15,548
[ -1 ]
15,549
patterns.lisp
drea8_cl-refal/src/patterns.lisp
;; Suppose we wanted a MATCH form that worked on patterns like in Rust "let message = match x { 0 | 1 => 0, 2 ..= 9 => 1, _ => 2 };" (defun predicate-match (l r input output) "Comparison predicate forms like '(= 5) or '(> 5)" (let* ((f (first l)) (a (second l))) (if (funcall f input a) r output))) (defun match (input patterns) (let ((output nil)) (loop for p in patterns do (let ((l (first p)) (r (second p))) ;; Process REFAL pattern rewrite form ;; on match of left hand pattern ;; rewrite into right hand output (cond ((not l) (setq output r)) ;; default empty pattern case ((numberp l) (if (eq input l) (setq output r))) ((listp l) (setq output (predicate-match l r input output))) )) finally (return output)) (let ((n 3)) (match n '((0 0) ((>= 1) 1)) ))
901
Common Lisp
.lisp
34
21.558824
70
0.568075
drea8/cl-refal
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
bc9ec85b2699e8dd470d2ab2f38c4b16533c7a377c0851e047d7f9338e09a98d
15,549
[ -1 ]
15,550
cl-refal.asd
drea8_cl-refal/cl-refal.asd
(asdf:defsystem #:cl-refal :description "REFAL embedded in Common Lisp." :author "Drea <[email protected]>" :license "GNU Affero v.3 with written permission from author" :serial t :depends-on () :components ((:file "package") (:file "src/interpret")))
276
Common Lisp
.asd
8
30.5
65
0.682836
drea8/cl-refal
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
20d660eef18e11b4aebfeed9c8590fadd86316141886c4f12907ca6bf2bbb1e0
15,550
[ -1 ]
15,556
metasystems_and_refal.html
drea8_cl-refal/doc/metasystems_and_refal.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)original version by: Nikos Drakos, CBLU, University of Leeds* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <html><head> <meta name="description" content="Dag"> <meta name="keywords" content="Dag"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <link rel="STYLESHEET" href="metasystems_and_refal_files/dag.html"> <link rel="next" href="http://www.refal.net/doc/turchin/dag/node2.html"> <link rel="previous" href="http://www.refal.net/doc/turchin/dag/dag.html"> <link rel="up" href="http://www.refal.net/doc/turchin/dag/dag.html"> <link rel="next" href="http://www.refal.net/doc/turchin/dag/node2.html"> <title>Introduction</title> </head> <body bgcolor="#FBFBFF"> <!--Navigation Panel--> <a name="tex2html31" href="http://www.refal.net/doc/turchin/dag/node2.html"> </a><p><a name="tex2html31" href="http://www.refal.net/doc/turchin/dag/node2.html"></a><a href="http://www.refal.net/doc/turchin/dag/dag.html#CONTENTS"><small>Contents<!--End of Navigation Panel--> </small></a><!--End of Navigation Panel--> <br> <a name="SECTION00010000000000000000"></a><a name="history"></a> <br> <font color="#CC0066"><big><big><big>1. Introduction</big></big></big></font></p> <p>Consider a system <i>S</i> of any kind. Suppose that there is a way to make some number of copies of it, possibly with variations. Suppose that these systems are united into a new system <i>S</i>' which has the systems of the <i>S</i> type as its subsystems, and includes also an additional mechanism which somehow examines, controls, modifies and reproduces the <i>S</i>-subsystems. Then we call <i>S</i>' a <em>metasystem</em> with respect to <i>S</i>, and the creation of <i>S</i>' a <em>metasystem transition</em>. As a result of consecutive metasystem transitions a multilevel hierarchy of control arises, which exhibits complicated forms of behavior. In my book <em>The Phenomenon of Science: a Cybernetic Approach to Evolution</em> [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Tur77">39</a>] I have interpreted the major steps in biological and cultural evolution, including the emergence of the thinking human being, as nothing else but metasystem transitions on a large scale. Even though my Ph.D. was in theoretical physics, I was so excited about my new cybernetic ideas that I shifted from physics to computer science and left the atomic center in Obninsk for the Institute for Applied Mathematics in Moscow. An extra-scientific factor came into play in the late 1960s: I became an active member of the human rights movement. My book was written about 1970, but it could not be published in the Soviet Union solely because of the author's name. It took seven years to smuggle it to the West and have it published in the English language. The first step towards MST in computers was to design an appropriate algorithmic language. I called the first version of such a language <em>meta-algorithmic</em> [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Tur66">36</a>], since it was supposed to serve as a metalanguage for defining semantics of algorithmic languages. Then I simplified it into what was named REFAL (for REcursive Functions Algorithmic Language). Refal was conceived as the universal language of metasystem hierarchies, which is, on one hand, simple enough, so that the machine that executes programs in this language (the <em>Refal machine</em>) could become an object of theoretical analysis -- and, on the other hand, is rich enough to serve as a programming language for writing real-life algorithms, unlike such purely theoretical languages as the language of the Turing machine or Markov's normal algorithms (the latter, by the way, was one of the sources of Refal). Even to this day Refal remains, in my (biassed, no doubt) view, the most successful compromise between these two requirements. An efficient interpreter for Refal was first written in 1968 [<a href="http://www.refal.net/doc/turchin/dag/node13.html#OFT68">26</a>]. At that time Refal was very different from other languages, being a purely functional language with built-in pattern-matching. Now that functional languages are common place, I need only to summarize Refal's distinctive features to make it familiar to the reader. The most distinctive feature of Refal is its data domain. Refal uses <em>expressions</em> for symbol manipulation, not <em>lists</em> (skewed binary trees). Refal expressions can be seen as trees with arbitrary (unfixed) arity of nodes, or sequences of such trees. They are formally defined as: </p> <table width="80%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td width="3%"></td> <td width="93%"><em>term ::= symbol | variable | (expression) | &lt;function expression&gt;</em></td> <td width="4%"></td> </tr> <tr> <td width="3%"></td> <td width="93%"><em>expression ::= empty | term expression</em></td> <td width="4%"></td> </tr> </tbody></table> <p><br> Variables in Refal have their intrinsic types shown by a prefix e.g., <tt>s.1, t.2, e.x</tt>. Thus an <em>s-variable</em> <tt>s.<i>i</i></tt>, where <i>i</i> is the index (name), stands for an arbitrary symbol, a <em>t-variable</em> <tt>t.<i>i</i></tt> - for an arbitrary term, and an <em>e-variable</em> <tt>e.<i>i</i></tt> - for any expression. In the case of an <i>e</i>-variable, the prefix may be dropped: <tt>x</tt> is the same as <tt>e.x</tt>. We use angular brackets to form function calls: <tt>&lt;<i>f</i> <i>x</i>&gt;</tt>. A program in Refal is a sequence of mutually recursive <em>sentences</em> (rewrite rules) which are tried in the order they are written. Here is an example of a function <tt>f</tt> which traverses its argument from left to right and replaces every <tt>'a'</tt> by <tt>'b'</tt>: </p> <table width="60%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td width="95%"><strong><tt>&lt;f 'a'&gt; = 'b'&lt;f x&gt;</tt></strong></td> <td width="5%"></td> </tr> <tr> <td width="95%"><strong><tt>&lt;f s.1 x&gt; = s.1 &lt;f x&gt;</tt></strong></td> <td width="5%"></td> </tr> <tr> <td width="95%"><strong><tt>&lt;f &gt; = </tt></strong></td> <td width="5%"></td> </tr> </tbody></table> <p><br> <tt>&nbsp; </tt>By the year 1970 I was lucky to have gathered a circle of young people, the Refal group, which met regularly, survived my emigration and is still alive and well. As in any informal group, some people went, new people came. I am deeply thankful to all of them, and especially to those most active and persistent: Sergei Romanenko (the first to have come), Nikolai Kondratiev, Elena Travkina, Andrei Klimov, Arkadi Klimov, Viktor Kistlerov, Igor Shchenkov, Sergei Abramov, Alexei Vedenov, Ruten Gurin, Leonid Provorov, Andrei Nemytykh, Vika Pinchuk. I will always remember Alexander Romanenko who died before his time in 1993.</p> <p>Together with a smaller group at the Moscow Engineering and Physics Institute (Stanislav Florentsev, Alexander Krasovsky, Vladimir Khoroshevsky) we made Refal compilers for the most popular machines in the Soviet Union, and Refal became pretty well known in that part of the world (a bibliography on the development and use of Refal compiled a few years ago includes about 200 items). It is not my intention here to focus on Refal, but I want to mention two further outgrowths of Refal: The language FLAC for algebraic manipulation developed by V.Kistlerov [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Kis87">22</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Chm90">4</a>], and Refal Plus by Sergei Romanenko and Ruten Gurin [<a href="http://www.refal.net/doc/turchin/dag/node13.html#GuR91">17</a>], which is a kind of logical closure of the ideas on which Refal is based. In my later work I used the extended version of Refal named Refal-5 [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Tur89">44</a>], which is operational under DOS and UNIX. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The next conceptual station after fixing the language was <em>driving</em> [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Tur71">37</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Tur72">38</a>]. Suppose we have the call <tt>&lt;f 'a'x&gt;</tt> of the function <tt>f</tt> above. Obviously, it can be replaced by <tt>'b'&lt;f x&gt;</tt>, because this is what the Refal machine will do in one step of function evaluation. <em>Partial evaluation</em> took place, which is a simple case of driving. Now take the call <tt>&lt;f x&gt;</tt> where a partial evaluator has nothing to do. Driving, however, is still possible, because it is simulation of one step of computation in any circumstances. When we see equivalent transformation of programs as the use of some equations, our partial evaluation is the use of the equation <tt>&lt;f 'a'x&gt; ='b'&lt;f&nbsp;x&gt;</tt>, and this makes perfect sense. But, given the call <tt>&lt;f&nbsp;x&gt;</tt>, there is no equation in sight that would improve the program. Driving is a product of cybernetic thinking. We create a metamachine, and the first thing it must be able to do with the Refal machine is to simulate its behavior. Thus, the metamachine <em>drives</em> the Refal machine, forcing it to do something for which it was not originally prepared: make computation over expressions with free variables. Such computation should better be called <em>metacomputation</em>; its result is not the value of the function, but a graph of states and transitions of the Refal machine which describes one step of computation towards that value. In our case driving will produce the graph: </p> <table width="60%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td width="6%"></td> <td width="94%"><tt><strong>[1]&lt;f x&gt; x:</strong>'<strong>a'x;&nbsp;[2]</strong>'<strong>b'&lt;f x&gt;</strong></tt></td> </tr> <tr> <td width="6%"></td> <td width="94%"><strong><tt>+ x:s.1 x;&nbsp;[3] s.1&nbsp;&lt;f x&gt;</tt></strong></td> </tr> <tr> <td width="6%"></td> <td width="94%"><strong><tt>+ x:[];&nbsp;[] </tt></strong></td> </tr> </tbody></table> <p><br> where the original call is the root node labeled by <tt>[1]</tt>, and there are three edges, separated by <tt>+</tt>, which lead to three resulting expressions, according to the three cases (sentences) in the definition of <tt>f</tt>. By <i>e</i>:<i>p</i> we denote the operation of matching expression <i>e</i> to pattern <i>p</i>; a pattern is a special kind of an expression (referred to as <em>rigid</em>), which guarantees the uniqueness of the operation. An expression <i>E</i> is rigid if (1) only s-variables may enter <i>E</i> more than once, and (2) no subexpression of <i>E</i> (inlcuding <i>E</i> itself) includes two e-variables separated by an expression. <tt>[]</tt> stands for an empty expression for readability. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; From driving I came to supercompilation (SCP for short). Let me briefly describe this technique of program transformation, leaving aside many details and variations. A supercompiler is an upgrade of a driver. While driving describes one step of the Refal machine, supercompilation may include any number of steps. When a new <em>active</em> (i.e., representing a function call) node <i>C</i> appears in driving, the supercompiler examines its ancestors and with regard to each ancestor <i>C</i>' takes one of the three decisions: </p><dl compact="compact"> <table width="80%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td width="93%">1.&nbsp;&nbsp;&nbsp;&nbsp; Reduce <i>C</i> to <i>C</i>' with a substitution; this can be done only if</td> <td width="7%">&nbsp;<img src="metasystems_and_refal_files/img7.html" alt="img7.gif (308 bytes)" width="55" height="31"></td> </tr> </tbody></table> <dt>2. </dt> <dd>Generalize <i>C</i> and <i>C</i>', i.e., find such <i>C<sup>g</sup></i> that <img src="metasystems_and_refal_files/img7.html" alt="$C\subseteq C^g$" width="55" height="31" border="0" align="MIDDLE"> and <img src="metasystems_and_refal_files/img8.html" alt="$C'\subseteq C^g$" width="58" height="29" border="0" align="MIDDLE">; then erase the driving subtree which starts at <i>C</i>', reduce <i>C</i>' to <i>C<sup>g</sup></i> and go on driving <i>C<sup>g</sup></i>. </dd> <dt>&nbsp;</dt> <dt>3. </dt> <dd>Do nothing on <i>C</i>' (the nodes <i>C</i> and <i>C</i>' are "far from each other"), and examine the next ancestor. If there are no more ancestors to loop back to, go on driving <i>C</i>. </dd> </dl> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Supercompilation ends when the graph becomes self-sufficient i.e., it shows, for every active node, how to make a transition to the next node which corresponds to at least one step of the Refal machine. This graph is a program for computing the function call represented by the initial node. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; Note the difference between the principle of supercompilation and the usual idea of program transformation, where the program is changed step by step by applying some equivalences. In supercompilation we never change the original program. We regard it as a sort of "laws of nature" and construct a model of a computation process governed by these laws. When the model becomes self-sufficient, we simply throw away the unchanged original program. I see supercompilation as a computer implementation of the general principle of human knowledge, which, in my view, is the search for such generalized states in terms of which we can construct a self-sufficient model of some part of the world. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; When we discussed supercompilation in the seminars of the Refal group, I always stressed my belief that metasystem transition is important in itself. If indeed it has been the key at all stages of biological and technical evolution, how can we hope to create really intelligent machines without the use of this principle? We should develop techniques of dealing with repeated metasystem transitions; applications are bound to follow.</p> <p>&nbsp;&nbsp;&nbsp;&nbsp; The first confirmation of this belief came when I figured out that supercompilation of an interpreter is compilation, and supercompilation of the supercompiler that does compilation (second MST) yields a compiled (efficient) compiler. Moreover, making the third MST we can obtain a compiled compiler generator. I was very excited about my discovery, and told Andrei Ershov about it. Ershov at that time worked on partial evaluation - the first MST - but he did not know about the second MST, and he also got excited (Ershov describes our meeting in detail in his 1987 keynote speech [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Ers88">8</a>]). Neither he, nor I knew at that time that Yoshihiko Futamura [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Fut71">9</a>] made this discovery a few years before me. Ershov saw a reference to Futamura's paper, but could not get the journal. In his big paper [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Ers77">7</a>] he referred to my result as "Turchin's theorem of double driving". </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; That was in 1976. Since 1974 I had been jobless, home-searched and periodically interrogated by the KGB. Meanwile a book on Refal and its implementation was written by several members of the Refal group, including myself [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Bas77">3</a>]. My friends managed to get permission for publishing it as a technical material of the institute where I worked before being fired - on the condition that I do not figure in the list of authors. To meet this requirement they decided not to mention any authors at all. The book was thus published anonymously. But I smuggled into it a few pages about my results on automatic production of compilers. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; I emigrated in 1977, and it took some time to take roots in the new environment: a process which can never be fully successful. For a year and a half I stayed at the Courant Institute of NYU and used this time to write a 250 pages report [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Tur80">40</a>], where I summarized the ideas and results of the past years and also sketched some new ideas to turn to them later. Then I got a position at the City College of the City University of New York. </p> <p>&nbsp;&nbsp;&nbsp; I wrote the first supercompiler (SCP-1) in 1981-82 [<a href="http://www.refal.net/doc/turchin/dag/node13.html#TNT82">41</a>] with the help of Bob Nirenberg and my son Dimitri in carrying over the implementation of Refal from Russia to the US and upgrading it. &nbsp; From the examples in [<a href="http://www.refal.net/doc/turchin/dag/node13.html#TNT82">41</a>] one could see that supercompilation includes, but is much stronger as a transformation technique than partial evaluation (which takes place automatically in driving). The examples in [<a href="http://www.refal.net/doc/turchin/dag/node13.html#TNT82">41</a>] included program specialization, but when I tried self-application (2nd MST), I met a dozen of technical difficulties. </p> <p>&nbsp;&nbsp;&nbsp; Partial evaluation is simpler then supercompilation, so automatic generation of a compiler from an interpreter was first achieved by self-application of a partial evaluator (2nd and 3rd MST). This was done by Neil Jones and co-workers at DIKU, Copenhagen [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Jon85">18</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Ses86">27</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Jon88">19</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Jon89">20</a>], and was an important step forward and a great success. Self-applicable partial evaluation became an established field of research. Of the members of the Moscow Refal group, Sergei Romanenko and Andrei Klimov contributed to this field [<a href="http://www.refal.net/doc/turchin/dag/node13.html#KRo87">23</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Rom88">30</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Rom90">31</a>], but I decided to concentrate on further development of techniques of supercompilation, and wrote a stronger and better supercompiler, SCP-2.</p> <p>&nbsp;&nbsp;&nbsp; The fall semester of 1985 I spent at DIKU in Copenhagen invited by Neil Jones. This was a very important visit for me. I got a chance to discuss in detail my ideas on MST and SCP with Neil and other people at DIKU. Among other things, these discussions helped me to finalize and have published my paper on supercompilation [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Tur86">42</a>]. Since then I visited DIKU on several occasions and always had useful discussions and enjoyed the friendly atmosphere there. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; In 1988-89 Robert Glück, then at the Vienna Technical University, joined the MST-SCP Project. He spent a year and a half at the City College working with me on its various aspects. We managed to achieve self-application of SCP-2 in some simple cases, but it became clear that a thorough overhaul of the supercompiler is needed. After returning to Europe, Glück carried over the techniques of metacoding and doing MSTs, which was originally developed for the Refal supercompiler, to partial evaluation and list-based languages. In the early work on partial evaluation by N.Jones with co-workers [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Jon89">20</a>] it was stated that in order to achieve good results in self-application, a preliminary binding time analysis (``off-line'') was necessary. However, Glück showed ([<a href="http://www.refal.net/doc/turchin/dag/node13.html#Glu91">12</a>]) that with a correct use of metacoding, partial evaluation is self-applicable without any binding time analysis: ``on line''. </p> <p>&nbsp;&nbsp;&nbsp; Little by little, more people got involved in the work on MST+SCP. The Moscow Refal group has never ceased discussing and working on these ideas, but now their work began being published in English. Andrei Klimov found a mate in Robert Glück [<a href="http://www.refal.net/doc/turchin/dag/node13.html#GlK93">14</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#GlK94">15</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#GlK95">16</a>]; their paper [<a href="http://www.refal.net/doc/turchin/dag/node13.html#GlK93">14</a>] helped arouse interest towards supercompilation in the partial evaluation community by bridging the two methods. Alexander Romanenko started work on function inversion [<a href="http://www.refal.net/doc/turchin/dag/node13.html#ARo88">28</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#ARo91">29</a>]. Sergei Abramov did an excellent and potentially very important work [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Abr93">1</a>] on program testing on the basis of <em>driving with a neighborhood</em> (see Sec.<a href="http://www.refal.net/doc/turchin/dag/node11.html#neighborhood">3.3</a>), and wrote a monograph on metacomputation other than supercompilation, [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Abr95">2</a>] (it is still in Russian, though). </p> <p>&nbsp;&nbsp;&nbsp; Neil Jones [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Jon94">21</a>] gave a thorough theoretical analysis of driving as compared to partial evaluation. More papers on supercompilation have appeared recently from DIKU [<a href="http://www.refal.net/doc/turchin/dag/node13.html#GlJ94">13</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Soe94">32</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#SoG95">33</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#SGJ94a">34</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#SGJ94b">35</a>]. The role of Glück in that, as one can see from the references, has been of primary importance. </p> <p>&nbsp;&nbsp;&nbsp; Morten Sørensen wrote a Master thesis on supercompilation [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Soe94">32</a>]. Its title, <em>Turchin's Supercompiler Revisited</em>, symbolized the emerging interest to my work. Later Sørensen made a suggestion that the Higman-Kruskal theorem on homeomorphic embedding be used as the criterion for generalization in supercompilation [<a href="http://www.refal.net/doc/turchin/dag/node13.html#SoG95">33</a>], which probably will be judged as one of the most important contributions to the SCP techniques during the last few years; I discuss it in more detail in Sec.<a href="http://www.refal.net/doc/turchin/dag/node4.html#generalization">2.2</a>. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; In 1993 I decided to restrict Refal as the object language of SCP to its <em>flat</em> subset where the right side of a sentence cannot include nested function calls: it is either a passive expression, or a single function call. The purpose, of course, was to simplify the supercompiler for self-application to become possible. I started writing such a supercompiler, SCP-3. In September 1993 Andrei Nemytykh from the Programming Systems Institute (Pereslavl, Russia), came to CCNY for an academic year under a grant from the National Research Council. Working together, we have, at long last, made SCP-3 self-applicable [<a href="http://www.refal.net/doc/turchin/dag/node13.html#TuN95a">46</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#TuN95b">47</a>]. That was in the spring of 1994. Returning to Russia, Nemytykh continued the work on SCP-3 with Vika Pinchuk. I do not speak more on this because SCP-3 with some examples of its performance is presented in a separate paper at this symposium [<a href="http://www.refal.net/doc/turchin/dag/node13.html#NPT96">25</a>]. </p> <p>&nbsp;&nbsp;&nbsp; In the summer of 1993 Futamura invited me to spend a month in Tokyo to discuss supercompilation in relation to his concept of <em>generalized partial computation</em> [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Fut88">10</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Fut91">11</a>]. There are common aspects, indeed. In both approaches the information about the states of a computing machine goes beyond listing the values of some variables. The main difference is that Futamura relies on some unspecified theorem proving, while my point is to do everything by supercompilation, including theorem proving. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; In July 1995, invited by José Meseguer, I spent a pleasant week at Stanford Research Institute in California explaining and discussing the details of SCP and MST. Meseguer and his graduate student Manuel Clavel are working on reflective logics and languages in the frame of Meseguer's theory of general logics [<a href="http://www.refal.net/doc/turchin/dag/node13.html#Mes89">24</a>,<a href="http://www.refal.net/doc/turchin/dag/node13.html#Cla96">5</a>]. They set a goal of extending the techniques of supercompilation to their systems in order to improve their efficiency, and I know that they have already made some progress along this path. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; My review of events and ideas concerning MST and SCP is, no doubt, incomplete, and so is my bibliography. I ask for forgiveness in advance. </p> <p>&nbsp;&nbsp;&nbsp;&nbsp; In Sec.2&nbsp; I discuss a few important aspects of supercompilation. In Sec.3 I give an outline of a few ideas which have not yet been properly translated into computer programs. My exposition is very informal and sketchy. I try to do it through a few simple examples. The field of MST+SCP has its own formalism, which I, obviously, cannot systematically present here. Yet I hope that the reader unfamiliar with it will still be able to figure out what it is all about, without going into formal details. </p> <p>&nbsp;&nbsp;&nbsp; A word on terminology. In 1987 I suggested <em>metacomputation</em> as an umbrella term covering all computations which include at least one metasystem transition. By this definition, partial evaluation is also a variety of metacomputation, and the term could be used for identifying such meetings as this seminar. However, partial evaluation people have been in no hurry to use it. In contrast, it is readily used by people in the field I denote in this paper as MST plus SCP (sounds barbarian, of course). Thus, for the time being, at least, </p> <div align="center"><center> <table width="60%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td width="100%"><p align="center"><big><em>metacomputation&nbsp; = MST + SCP</em></big></p></td> </tr> </tbody></table> </center></div> <hr> <!--Navigation Panel--> <p><a href="http://www.refal.net/doc/turchin/dag/dag.html#CONTENTS"><small>Contents<!--End of Navigation Panel--> </small></a>&nbsp;<!--End of Navigation Panel--> <small><a href="http://www.refal.net/doc/turchin/dag/node3.html">Next</a></small></p> </body></html>
27,495
Common Lisp
.l
326
82.693252
432
0.7527
drea8/cl-refal
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
165da6154ab960c86ebfddf8ed15368d20ce2a29aa71264bcdb2136881557222
15,556
[ -1 ]
15,557
learn-refal.txt
drea8_cl-refal/doc/learn-refal.txt
REFAL Recursive Functions Algorithms Language Refal is a functional programming language oriented towards symbolic computations, including string processing, language translation, artificial intelligence, and compiler research. Refal is one of the oldest functional languages, first conceived of in 1966 and first implemented in 1968, invented by Russian cyberneticist Valentin Turchin who used it for research in Supercompilers and Metacompilers. This file will be using the Refal-5λ implementation of REFAL 5 created at Bauman Moscow State Technical University Department of Computer Science and Technologies. To compile run "srefc source.ref". On this machine the compiler is at "simple-refal/bin/srefc" Let us examine the following program * Single Line Comment /* Multi Line Comment */ $ENTRY Go { = <Prout 'Hello, World!'>; } Any program in Refal is a set of functions. The 'Go' function is defined here. The function definition is written as the name of the function followed by a Block (the function body is enclosed in braces {,}. Any Refal program must have a single function definition named 'Go' or 'GO', the program execution process is the function Go with an empty argument. Hieroglyphic `$ENTRY` will be clarified in the next sections. Just need to know that the key word `$ENTRY` must precede the `Go` (or `GO`) program entry point. There is a single Sentence in the second line. A Sentence is a rule, which define how to put up the function value on the argument subset. A function can consist of several Sentences, each ends with a semicolon ';'. A Semicolon may not be used at the end of the last sentence. Any sentence consists of two parts * a Pattern on the left, which describes a value subset of the function argument on which the sentence is applied. * a Result on the right, which describe the function value on the subset The left and right parts are divided by '=' NOTE: later we will consider the extended Refal syntax in which sentence syntax will be more complicated. The sentence in the program 'hello.ref' means that it can be applied on the empty function argument only (there is nothing before the equality). The right side describes the function as the result of the 'Prout' function computing. A sequence of signs 'Hello World!' is transferred to it. A function call on Refal is written with angle brackets '<' and '>'. The function name has to be placed after the opening brace. The function Prout computes "emptiness" with any argument. However, its implementation has some side effects. It prints an argument on the screen. Prour is included in the language standard library. Almost all Refal programs are written actually for these side effects. After the function 'Go' computes the result is discarded and the program is completed. In the field of automatic program conversion and verification, for example by Supercompilation, an interesting math function is written in Refal. It is fed to a tool like the Refal 5 supercompiler SCP4 and then the conversion result or function analysis are examined. Research in the field of tool development is one of the most important Refal applications today. Programs with Several Sentences Refal is a language with free syntax. The transition to a new line is exactly the same non-space character as a space or tab. A pair of exceptions, the opening and closing quote marks should be placed in one line (the line break can not be placed inside a sequence of characters) and the line feed character completes a one-line comment by definition. Secondly, each of the characters inside the single quote marks is autonomous. The following entries are equivalent: `'Hello'`, `'Hel' 'lo'`, `'H' 'e' 'l' 'l' 'o'`. Thirdly, the function name can be any sequence of letters, numbers, signs `_` (“dash”) and `-` (“hyphens”), starting with a dash or a letter. For example, `Go`, `Hello`, `A-plus-B`, `_remove_file`, `ANSWER_42`. Lowercase and uppercase letters are different, i.e. the names `hello`, `Hello` and `HELLO` are different. Let's write a function that adds two binary digits. BinAdd { '0' '0' = '0'; '0' '1' = '1'; '1' '0' = <BinAdd '0' '1'>; '1' '1' = '10'; } The left Patterns of the sentences could be written together, like '00'. The definition scope of this function will be pairs of characters '00', '01', '10', '11'. When you try to call this function with an argument outside the definition area, the program crashes (an impossible assimilation error. <<recognition impossible>>). Let's write a function that substracts two digits BinSub { '0' '0' = '0'; '1' '1' = '0'; '1' '0' = '1'; '0' '1' = '-' <BinSub '1' '0'>; } Let's write a function that checks the equality of two binary numbers that are not greater than 2 (ie 10 in binary notation) and not less than -1. We assume that both numbers in the function argument are separated by the '=' sign. IsEqual { '-1=-1' = 'True'; '-1=0' = 'False'; '-1=1' = 'False'; '-1=10' = 'False'; '0=-1' = 'False'; '0=0' = 'True'; '0=1' = 'False'; '0=10' = 'True'; '1=-1' = 'False'; '1=0' = 'False'; '1=1' = 'True'; '1=10' = 'False'; '10=-1' = 'False'; '10=0' = 'False'; '10=1' = 'True'; '10=10' = 'True'; } Yes, it’s boring. Yes, it’s long. Later we will see how to shorten this entry. Let’s write a function Go that demonstrates: * addition commutability * subtraction noncommutability. $ENTRY Go { = <Prout '1+0=0+1? ' <IsEqual <BinAdd '1' '0'> '=' <BinAdd '0' '1'>>> <Prout '1-0=0-1? ' <IsEqual <BinSub '1' '0'> '=' <BinSub '0' '1'>>>; } the printed result is 1+0=0+1? True 1-0=0-1? False We have considered functions that have fixed values in the Patterns on the left of the Sentences thus far. The function Domain of such functions are obviously all the enumerated values of the samples. It is clear that it is hell of a lot for writing non-trivial functions with a Finite definition Domain and you have to write a Sentence for each of the Argument values. This led to the fact that even such a simple function as IsEqual required as many as 16 Sentences. We will learn how to write Functions with an Infinite Domain definition in the next section. Variables The left-hand side Pattern defines an argument values Subset at which this sentence is applicable, as noted above. We have considered only cases of subsets consisting of one single element by now. Refal allows us to write in the left parts of expressions (the exact definition of the term "expression" will be given later), which contain uknown fragments, Variables, in addition to explicitly set. The variable Type determines the value's Sets that variables can take. There are three types of variables in Refal. * s-variables or symbol variable * t-variables can be any single term, both a symbol and expression * e-variables can take an expression as sequence of terms The value of an s-variable or symbol variable can be any single symbol. The value of an e-variable or an expression variable can be any fragment of the function argument, including empty. A variable is written as a sign (s, t, e) type, followed by a sign . "point" and the variable name is a sequence of letters and numbers. The variable name is often called the variable index. If the variable appears several times in the expression, then it is called repeated. All its occurences must have the same value. Let's consider some expressions with variables: * s.1 s.2 s.3 - any three symbols, like 'ABC' or '999' or '@#$' * s.A s.A s.A - any three identical symbols like '666' or 'www' * s.Edge s.Middle s.Edge - first and last must match, ie 'kek' or '^_^' * s.first e.middle s.last - any expression containing at least two symbols * s.Edge e.Center s.Edge - ie '++' or 'revolver' * '(' e.Inner ')' enclosed with brackets like '()' or '(ok)' * e.Key '=' e.Value - contains one equal sign at least '=','x = 1', 'A = B == C = D' * e.Eq e.Eq is an expression with even length, which can be divided into two identifical halves 'ABCABC' or '8888' or the empty expression (divides into two empty ones) Variables can appear both in the Pattern and the Value, only variables that are in the left can be used on the right side of the sentence in Refal. Refal Function Execution We need to clarify the process of Refal function execution now. 1. A sentence is elected from the left side Patterns for which you can get a function argument by changing the variables in it to some values. If no such Sentence exists, then the program ends with an error of recognition impossible 2. The variables values are fixed when they request to the function argument when they are placed in the left part of the selected sentence, if there are several such sets of variables values (permutations), then its fixed the one in which the leftmost e-variable takes the shortest value. If it does not resolve ambiguities, then the next e-variable is considered and so on. 3. The variables are replaced by their values in the right side of the selected sentence. Then the functions on the right are calculated. The process is considered more in detail in the next chapter. Structure Brackets A purely mathematically studied Refal subset is sufficient for writing any complex algorithm. But this is not enough in practice, thus far we have been only using 'flat' strings only, wheras many non-trivial algorithms require hiearchically organized data. What is a data hiearchy? It is an opportunity to work with some piece of data as one object, by abstracting from its internal complex structure. In order to work in Refal with an expression as a single object, it is enclosed in parenthesis, which are called structure brackets. Such an object called bracket term can be the part of another expression, which can be also enclosed in brackets. Hierarchical nested data are built in Refal this way. The symbols we considered before are also terms. In this way, a Refal expression consists of terms each of which can be either a symbol or a bracket term that contains another expression in Refal. Angled brackets are called Evaluation, activation, or call brackets. Round brackets are Structure Brackets, the expression ('abc') 'def' (('ghi' 'j' ('klm') ()) 'nop' ((('rst'))) consists of 9 terms. The first term is bracketed. It contains an expression of three symbol terms, the next three form the string 'def', the next is a bracketed one again consisting of three bracketed terms and one symbol. Its last bracketed term contains an empty expression (). The brackets must form the correct bracket structure on both the left and right sides of the sentences in a Refal expression. In doing so, on the right side of the statements round and angle brackets can not overlap each other. Let us clarify our understanding of variables from a perspective of new knowledge. * e-variables can take a sequence of terms * t-variables can be any single term, both a symbol and an expression in brackets Let’s depict Pushkin's genealogy in the form of a Refal expression. Each character of the family tree will be represented in the form of a bracket term that contains the character's name and two terms: father and mother. If the ancestor is known it will be depicted as the same character, if not – in its place will be located the symbol '?'. Thus, each character can be mapped to the form sample of the form (e.Name t.Father t.Mother) Note. In fact, the A.S. Pushkin bloodline is known much deeper. For the sake of clarity some ancestors were skipped at different levels of the hierarchy here. Let's write a function that takes the family tree and the ancestor branch in the form of a chain of 'MFFM…' characters – where 'M' means mother, 'F' is father and finds the corresponding ancestor. For example, 'F' is father, 'FF' is the paternal grandfather, 'MM' is the maternal grandmother, 'FM' is the paternal grandmother, 'FMM' is the paternal maternal grandmother, the empty expression is the character itself. FindAncestor { /* advancing on the father line */ (e.Name t.Father t.Mother) 'F' e.Branch = <FindAncestor t.Father e.Branch>; /* advancing on the mother line */ (e.Name t.Father t.Mother) 'M' e.Branch = <FindAncestor t.Mother e.Branch>; /* an unknown character has unknown the ancestors */ '?' e.Branch = '?'; /* Branch ended – the person you are looking for is the current */ (e.Name t.Father t.Mother) /* empty branch */ = e.Name; } In other words, in order to find an ancestor on the father by the bloodline (the branch starts with 'F…'), you should take the father's bloodline (t.Father field) and look for the ancestor in it (throwing the branch 'F'from the beginning) – this is what makes the first sentence. The second sentence is likewise. If the bloodline is unknown at some stage, then any ancestor will be unknown. This case processes the third sentence. If the branch is empty (an empty branch is specified or it is emptied in a few iterations), then the last fourth sentence (the root of the current bloodline) is the person you are looking for. Let's write a program that prints some of Pushkin's ancestors (pushkin.ref). $ENTRY Go { = <Prout <FindAncestor <Pushkin> 'FF'>> <Prout <FindAncestor <Pushkin> 'FFF'>> <Prout <FindAncestor <Pushkin> 'MFF'>> <Prout <FindAncestor <Pushkin> 'MFM'>> <Prout <FindAncestor <Pushkin> 'F'>> <Prout <FindAncestor <Pushkin> 'FM'>> <Prout <FindAncestor <Pushkin> 'FMF'>> <Prout <FindAncestor <Pushkin> 'FMFM'>> } FindAncestor { /* advancing on the father line */ (e.Name t.Father t.Mother) 'F' e.Branch = <FindAncestor t.Father e.Branch>; /* advancing on the mother line */ (e.Name t.Father t.Mother) 'M' e.Branch = <FindAncestor t.Mother e.Branch>; /* an unknown character has unknown the ancestors */ '?' e.Branch = '?'; /* Branch ended – the person you are looking for is the current */ (e.Name t.Father t.Mother) = e.Name; /* empty branch */ } Pushkin { = ( 'Alexander Sergeyevich Pushkin' ( 'Sergey Lvovich Pushkin' ( 'Lev Aleksandrovich Pushkin' '?' ( 'Evdokia Ivanovna Golovin' '?' '? ) ) ( 'Olga Vasilievna Chicherina' ('Vasily Ivanovich Chicherin??') '?' ) ) ( 'Nadezhda Ossipovna Pushkina (Gannibal)' ( 'Ossip Abramovich Gannibal' ('Abram Petrovich Gannibal (The Moor of Peter the Great)??') ('Christina Regina von Sioberg??') ) ('Maria Alekseevna Pushkina??') ) ) } Other Types of Symbols, Numbers Refal can operate not only with characters, but also other types of symbols. According to Refal, symbol is an object which cannot be spread out on small parts using a pattern. Refal symbols other than characters, are numbers and words. Number symbol or macrodigit is a number between the range of 0 and 2^32 - 1 written in decimal form. Refal includes some arithmetic functions Add Sub Mul Div Mod (remainder of division) Divmod (result of quotient and remainder) Compare Numb (converts chain of characters into decimal num) Symb (converts number into chain of characters) (see tutorial for long number representation and fitting macrodigits) -> 542 300 422 as radix 2^32 so = 542x((2^32)^2) + 300*(2^32) + 422 Words (see readme 3) Character strings as identifiers for words are enclosed in double quotes "This is one symbol". Abstract Refal-machine, View Field Semantics (see readme 3) Review of Expression Types * object expressions - symbols and round brackets * active/evaluation expression - angular brackets + terms * Pattern expressions - symbols, structural brackets, and variables, in the left of a sentence * Result expression - round and angular brackets, variables, and symbols on right part of expression Higher Order Functions and Refal5l Extensions REFAL 5 Programming Guide from "refal.botuk.ru/book/html" based on the book by Valentin Turchin Unlike Lisp, Refal is based on pattern matching. Due to that, a typical program in Refal is two or three times shorter on average than the analogous program in Lisp and much more readable. When compared with Prolog, Refal is conceptually simpler. Its pattern matching works in the forward direction, not backwards (starting from the goal). There This is a much more natural approch to writing algorithms and makes them much easier to test and debug. Furthermore there is an important difference between data structures of Refal and most other high level languages. The basic structures of Lisp and Prolog are lists which can be read only in one direction. Refal uses more general structures. You can build and read them from left to right and right to light and go up and down by parentheses: Refal can operate on entire data structures at once. Partial evaluation of function calls has lately become an important type of program transformation. Refal-5 includes a feature, the "freezer" which is specifically designed for efficient partial evaluation. Refal is an excellent choice as a language for research in theory of programming languages and program transformation. (see book for input/output, modules) Conditions 5. PROGRAM DEVELOPMENT Cannibals and Missionaries Paths in Graph Translation of Arithmetic Expressions 6. METASYSTEM TRANSITION 6.1 Metafunction Mu The reader might have noticed that in our language as it has been defined up to this point, there were no means to apply a function whose name is not given explicitly but is the value of some variable or a result of computation. According to the syntax of Regal, after an opening activation bracket a symbolic function name (identifier) must necessarily follow. This requirement is introduced for the purpose of efficient implementation, prevents us from using expressions such as: <s.F e.x> which we might write to call a function whose name is determined dynamically as the value of the variable s.F . However, Refal-5 allows us to achieve the same effect by using the expression: <Mu s.F e.X> Here Mu is a built in function, or rather, a Metafunction which calls the function with the name given by the symbol immediately following Mu. The remaining part of the expression becomes the argument of the function. Thus Mu works as if defined by the sentence: Mu { s.F e.X = <s.F e.X> } if it were syntactically admissable. Using Mu we can define various kinds of interpreters which use expressions as programs specifying which of the lower-level functions (functions-executors) must be called. Here is a simple example of an interpreter which sequentially applies a given list of operations to a given argument: Use-seq { (s.F e.1) On e.X = <Use-seq (e.1) On <Mu s.F e.X>>; () On e.X = X; } The modular structure of programs in Regal-5 brings a slight complication to the simple idea of Mu. Suppose you have used the function Mu to define some function Callmu as an external function in another module. It may happen that some function name is used in both modules to define different local functions. Which of the functions must be called then by Mu? Specifically, consider the following two modules: * Mod1 $ENTRY Go { = <Prout 'Mu: ' <Mu F 'ABC>> <Prout 'Callmu: ' <Callmu F 'ABC'>> } $EXTERN Callmu F = { e.1 = 'Mod1' } * Mod2 * it also defines F, which hass diff defin. in Mod1 $ENTRY Callmu { s.F e.X = <Mu s.f e.X>; } F { e.1 = 'Mod2' } We can define two versions of the metafunction Mu: * MuS or Static Mu * MuD or Dynamic Mu With the Static definition, the functional meaning of a symbolic name is defined by the module where the function using MuS, in this case this is Mod2. The general rule is: wherever a call of MuS appears, it can activate only a function visible from this point (either locally defined or entering an $EXTERN list) and the function called will be the one defined at that point. With the Dynamic definition the functional meaning of a symbolic name is as defined at the execution time, ie in the main module: Mod1 in our case. In the Mod1/Mod2 example above, If Mu is defined statically (as MuS) the program will print out Mu: Mod1 Callmu: Mod2 If Mu is defined dynamically (MuD) the printout will be: Mu: Mod1 Callmu: Mod1 There is something to be said both for and gainst each of the ways to define Mu. The dynamic definition seems more natural and it sticks to the general principle: if a function is not visible from the main module it cannot be activated. On the other hand, from the systems viewpoint it is good to be able to call any function of the program. MuS allows this. The dynamic function MuD can be simulated using the static function Mu. We only have to define: $ENTRY MuD { e.1 = <Mu e.1> } in the main module and then use MuD in any module using $EXTERN Having this in mind, Mu as built into Regal is defined statically. 6.2 Metacode Program transformation is one of the important fields where Refal is used, both the programs to be transformed (level 1, object programs) and the transforming programs (level 2) will be typically written in Refal, this makes self-application of transforming programs possible. To write Refal programs that deal with Refal programs, we have to represent object programs by some object expressions because free variables and activation brackets which are used in object programs cannot be objects of transformation in Refal. Suppose we have some program and want to transform every call of a function F1 in it into the call of F2. A sentence like: Subst21 { e.1 <F1 e.X> e.2 = e.1 <F2 e.X> <Subst21 e.2>; } will not work. According to the syntax of Refal, active sub-expressions cannot be used in the left side. But even if we extended Refal to allow such a use, the active sub-expression <F2 e.1> in the right side would be understood as a process, not an object: the evaluation of this call would start before the further evaluation of Subst21, even though we did not want it. Likewise, we cannot use a free variable as an object of transformation, because it will be understood by the Refal machine as a signal for substitution. A mapping of all Refal objects on a subset of object expressions will be referred to as a Metacode. Such a mapping must of course be Injective (one-to-one function that preserves distinctness, never mapping distinct elements of its domain to the same element of its codomain. every element of the function's codomain is the image of at most one element of its domain, and there is a unique inverse transformation) Metacode transformation is the lowering of the metasystem level of the object from a controlling to an expression E, we say that we Downgrade it to the metacode, applying the inverse transformation we say that we Upgrade E from the metacode. When we actually write Refal programs dealing with Refal programs we must choose a certain concrete metacode transformation. But when we speak about downgrading and upgrading expressions, we often want a notation allowing us to leave these transformations unspecified. Thus downgrading to the metacode will be represented by a down arrow V for upgrading we reserve the up arrow ^. When the range of these operations extends to the end of the current sub-expression, we simply put V or ^ in front of it. If it is necessary to delimit the range, we use braces. For example the concatenation of the downgraded E1 with the unchanged E2 is {V E1} E2 while (V E1) E2 is the same as ({V E1}) E2. Obviously ^VE = E and if ^E exists then V^E = E The prupose of metacoding is to map activation brackets and free variables on object expressions. It would be nice to leave object expressions unchanged in the metacode transformation. Unfortunately this is impossible because of the requirement of a unique inverse transformation. Indeed suppose we have such a metacode. Then VV e.1 must be equal to V e.1 because V e.1 is an object expression. It follows that two different objects, e.1 and V e.1 have identical metacodes. We can however minimize the different between an object expression and its metacode. The metacode we are using in the Refal system singles out one symbol namely the asterisk * which is changed in the metacode transformation. All other symbols and object brackets (parentheses) are represented by themselves. The following table defines our metacode. Expression E its metacode vE s.I '*S'I t.I '*T'I e.I '*E'I <F E> '*'((F) vE) (E) (vE) E1 E2 {vE1} vE2 '*' '*V' S (except '*') S Thus v e.x is '*E'X etc When the metacode transformation is applied to an object expression, its result can be computed by calling the Refal function Dn which replaces every '*' by '*V' Dn { '*' e.1 = '*V' <Dn e.1>; s.2 e.1 = s.2 <Dn e.1>; (e.2) e.1 = (<Dn e.2>) <Dn e.1>; = ; } The function Dn is also implemented in the Refal system as a built-in function which downgrades its argument in one step. For any object expression E0 <Dn E0> == vE0 The time required for downgrading or upgrading an object expression is proportional to its length. It is often desirable to delay the actual metacoding of an expression until the moment when its downgraded form is actually used because it well may happen that the whole expression, or its part, will be later upgraded back to its original self. Therefore, we may avoid an unnecessary two-way transformation of an expression if we somehow indicate that the expression must be put in the metacode but do not actually transform it. We use the expression. '*!'(E0) to represent the delayed metacode of E0 . This does not violate the uniqueness of the inverse transformation because the combination '*!' could not have arisen in any other way. Thus the inverse transformation will simply transform '*!'(E0) back into E0. The following rule helps to handle delayed metacoding: for and (not only object) expression E, '*!'(E) is equivalent to <Dn E> Indeed, even if E includes free variables and active sub-expressions, the implied sequence of actions on both sides of this equivalence is the same: first free variables must be replaced by object expressions, then the computation process must start and end, and then the result must be downgraded. The inverse function of Dn is Up. If its argument is the result of a metacode transformation of an object expression E0 then Up returns E0: <Up <Dn E0>> == E0 But we can extend the domain of Up to include the metacodes of any ground expression Egr (ie one that may contain active subexpressions but no free variables). Take a ground expression, like <F 'abc'> and downgrade it into the object expression '*'((F)'abc'). Now if we apply Up to it, it will be upgraded back to the original active expression: <Up '*'((F)'abc')> == <F 'abc'> which will immediately start a computation process. Generally for any ground expression Egr <Up vEgr> == Egr The function Up can be defined in Refal as Up { '*V'e.1 = '*'<Up e.1>; '*'((s.F) e.1)e.2 = <Mu s.F <Up e.1>> <Up e.2>; '*!'(e.2)e.1 = e.2 <Up e.1>; s.2 e.1 = s.2 <Up e.1>; (e.2)e.1 = (<Up e.2>)<Up e.1>; = ; } The evaluation of <Up vEgr> is a simulation of the evaluation of Egr - as one can see from the definition of Up. This function converts the "Frozen" function calls in Egr into their active form, and does this in exactly the same inside-out order as the Refal machine would do. 6.3 Evaluator (REPL) The special function Go is used in the Refal system to put the initial expression in the view field of the Refal machine. When this expression is evaluated, the Refal machine stops and passes control to the operating system of the computer. This is the simplest mode of the interaction between the user and Refal. Sometimes we would prefer a different mode. We would like to give a Refal expression to the machine, have it evaluated, and have the control returned to the user without exiting form the Refal system so that another expression could be evaluated, and so many number of times. If the user is prepared to write the expression he wants evaluated in the metacode, then the solution of this problem is quite simple. We define Go as a call of an interpreting function Job which asks the user to type in an expression, applies Up to it, and when the computation is complete prints out the result and asks for the next expression. However, it would perplex the user to write the desired expressions in the metacode, it is preferable to allow him to write expressions in the same form as they appear in the program. Therefore instead of the function Input, which inputs object expressions, we use another function , let it have the name Inpmet, which reads in an expression and downgrades it in the metacode. Its major difference from Input is that the characters '<' and '>' are taken as activation brackets. Now we should think of how to tie this definition of go to the existing Refal modules. If up were dynamic, there would be no other way than to replace the go of the main module by the Go calling the interpreting function Job described above . This would mean that the program would be usable only in the evaluator mode. Our built-in function Up, however is static. We form the above Go into a seperate module which we call E (for 'Evaluator') and we modify it by changing Up to UpD and declare UpD as an external function. To use any module, like Prog, with the evaluator we have to add to Prog the standard definition: $ENTRY UpD { e.x = <Up e.X> } The beginning of the program E is as follows: * Evaluator E $ENTRY Go { = <Job>; } Job { = <Prout 'Type expression to evaluate. ' 'To end: empty line.'> <Prout 'To end session: empty expression'> <Prout > <Check-end <Inp-met>>; } Check-end { = <Prout 'End of session'>; '*'Error = <Job>; e.X = <Out <UpD e.X>>; } Out {e.X = <Prout 'The result is:'> <Prout e.X> <Prout> <Job>; } $EXTRN UpD;
30,202
Common Lisp
.l
358
81.069832
417
0.756431
drea8/cl-refal
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
0ea5e78ab43ef15fe71017b88a158e06cdedf6abd442039f419dc86137775903
15,557
[ -1 ]
15,558
img7.html
drea8_cl-refal/doc/metasystems_and_refal_files/img7.html
<html> <head><title>404 Not Found</title></head> <body bgcolor="white"> <center><h1>404 Not Found</h1></center> <hr><center>nginx/1.10.3</center> </body> </html>
169
Common Lisp
.l
7
22.142857
42
0.660494
drea8/cl-refal
5
0
0
AGPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b3368e641fc0f99dc60240101640b95b0ace7d1fd81d5f4cd8f7fe1780a1aedd
15,558
[ -1 ]
15,575
main.lisp
pouar_yadfa/main.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa"; coding: utf-8-unix; -*- (in-package #:yadfa) (defun main () (proclaim '(optimize safety (debug 2))) (when yadfa::*immutable* (map () 'asdf:register-immutable-system (asdf:already-loaded-systems))) (pushnew 'yadfa::find-mod asdf:*system-definition-search-functions*) (uiop:register-clear-configuration-hook 'clear-configuration-hook) (asdf:clear-configuration) (setf *random-state* (make-random-state t)) (when (member "slynk" (uiop:command-line-arguments) :test #'string=) (when (or (and (uiop:featurep :slynk) uiop:*image-dumped-p* (not (symbol-value (uiop:find-symbol* '#:*servers* '#:slynk)))) (when (and (asdf:find-system "slynk" nil) (not (asdf:component-loaded-p "slynk"))) (asdf:load-system "slynk"))) (uiop:symbol-call '#:slynk '#:create-server :dont-close t))) (when (member "swank" (uiop:command-line-arguments) :test #'string=) (when (or (and (uiop:featurep :swank) uiop:*image-dumped-p* (not (symbol-value (uiop:find-symbol* '#:*servers* '#:swank)))) (when (and (asdf:find-system "swank" nil) (not (asdf:component-loaded-p "swank"))) (asdf:load-system "swank"))) (uiop:symbol-call '#:swank '#:create-server :dont-close t))) (in-package #:yadfa) (when (member "wait" (uiop:command-line-arguments) :test #'string=) (sleep 2)) (trigger-event 'yadfa-zones::create-rpgmaker-dungeon) (load-mods) (load #P"yadfa:config;yadfarc" :if-does-not-exist nil) (in-package :yadfa-user) (when (member "test" (uiop:command-line-arguments) :test #'string=) (handler-case (progn (asdf:test-system :yadfa) (uiop:quit)) (error () (uiop:quit 1)))) (when (uiop:featurep :mcclim-ffi-freetype) (setf (symbol-value (uiop:find-symbol* '#:*library* '#:freetype2)) (uiop:symbol-call '#:freetype2 '#:make-freetype))) (yadfa-clim:run-listener))
2,009
Common Lisp
.lisp
39
44.692308
127
0.632487
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
8006cb21fd72f81fd4094050cc679098c915b5ab07343c597b3e16e9fac0cc35
15,575
[ -1 ]
15,576
appveyor-build.lisp
pouar_yadfa/appveyor-build.lisp
;; -*- mode: common-lisp; -*- #-quicklisp (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))) (when (probe-file quicklisp-init) (load quicklisp-init))) #+(and gmp sbcl) (require 'sb-gmp) #+(and sbcl gmp) (sb-gmp:install-gmp-funs) (ql:update-client :prompt nil) (ql:update-all-dists :prompt nil) #| (when (and (ql-dist:find-dist "ultralisp") (ql-dist:installedp (ql-dist:find-dist "ultralisp"))) (ql-dist:install-dist "http://dist.ultralisp.org/" :prompt nil)) |# (ql:quickload (loop for i in (asdf:system-depends-on (asdf:find-system :yadfa)) when (stringp i) collect i when (and (listp i) (eq (first i) :feature) (uiop:featurep (second i))) collect (third i))) (declaim (optimize (debug 2) safety)) (setf *read-default-float-format* 'long-float) (ql:quickload :yadfa) (setf yadfa::*immutable* t) (asdf:make :yadfa) (uiop:quit)
954
Common Lisp
.lisp
28
29.892857
113
0.652268
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
27a176373b0785be3fbb35bc00deb8013b267314b10b059cfc46baad95f41f96
15,576
[ -1 ]
15,577
appveyor-build-docs.lisp
pouar_yadfa/appveyor-build-docs.lisp
;; -*- mode: common-lisp; -*- #-quicklisp (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))) (when (probe-file quicklisp-init) (load quicklisp-init))) #+(and gmp sbcl) (require 'sb-gmp) #+(and sbcl gmp) (sb-gmp:install-gmp-funs) (ql:update-client :prompt nil) (ql:update-all-dists :prompt nil) #| (when (and (ql-dist:find-dist "ultralisp") (ql-dist:installedp (ql-dist:find-dist "ultralisp"))) (ql-dist:install-dist "http://dist.ultralisp.org/" :prompt nil)) |# (ql:quickload :yadfa) (in-package :yadfa) (yadfa::main)
603
Common Lisp
.lisp
22
24.272727
65
0.664372
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
ae5359d8c97818aefb2e942bc0c3d6204b2536e9fa612e2e342aa6c49284d2e3
15,577
[ -1 ]
15,578
run.lisp
pouar_yadfa/run.lisp
;; -*- mode: common-lisp; -*- #-quicklisp (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))) (when (probe-file quicklisp-init) (load quicklisp-init))) #+ecl (declaim (optimize (debug 2) safety)) #+ccl (ccl:set-current-compiler-policy (ccl:new-compiler-policy :trust-declarations (lambda (env) (declare (ignore env)) nil))) #+(and sbcl (not sb-gmp)) (macrolet ((a () `(progn ,(when (some #'(lambda (pathname) (handler-case (sb-alien:load-shared-object pathname :dont-save t) (error (e) (declare (ignore e)) nil))) #-(or os-windows os-macosx) '("libgmp.so" "libgmp.so.10" "libgmp.so.3") #+os-macosx '("libgmp.dylib" "libgmp.10.dylib" "libgmp.3.dylib") #+os-windows '("libgmp.dll" "libgmp-10.dll" "libgmp-3.dll")) '(asdf:load-system :sb-gmp))))) (a)) #+sb-gmp (sb-gmp:install-gmp-funs) (when (find "slynk" (uiop:command-line-arguments) :test #'string=) (ql:quickload "slynk") (uiop:symbol-call '#:slynk '#:create-server :dont-close t)) (when (find "swank" (uiop:command-line-arguments) :test #'string=) (ql:quickload "swank") (uiop:symbol-call '#:swank '#:create-server :dont-close t)) (when (find "ft" (uiop:command-line-arguments) :test #'string=) (pushnew :mcclim-ffi-freetype *features*)) (when (find "wait" (uiop:command-line-arguments) :test #'string=) (sleep 2)) (ql:quickload (loop for i in (asdf:system-depends-on (asdf:find-system :yadfa)) when (stringp i) collect i when (and (listp i) (eq (first i) :feature) (uiop:featurep (second i))) collect (third i))) (declaim (optimize (debug 2))) (setf *read-default-float-format* 'long-float) (ql:quickload :yadfa) (in-package :yadfa) (yadfa::main)
2,066
Common Lisp
.lisp
40
39.95
115
0.556049
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
bacd82b14cd365f4049eb7fe7fc4d8b6cf207fdfe325b8cf76a68740520e6f6b
15,578
[ -1 ]
15,579
packages.lisp
pouar_yadfa/packages.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "common-lisp-user"; coding: utf-8-unix; -*- (in-package :cl-user) (uiop:define-package :yadfa-util (:use :cl :iterate) (:export #:shl #:shr #:lambda-list #:do-push #:remove-nth #:insert #:insertf #:substitutef #:type-specifier #:coerced-function #:removef-if #:deletef-if #:append* #:appendf* #:collecting* #:summing* #:in* #:sum* #:defunassert #:lappendf #:random-from-range #:print-unreadable-object-with-prefix) (:documentation "Utility functions that aren't really part of the game's API") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands))) (uiop:define-package :yadfa (:use :cl :yadfa-util :iterate) (:export ;;variables #:*battle* #:*game* #:*cheat-hooks* #:*battle-packages* #:*world-packages* #:*command-packages* ;;structures #:event ;;conditions #:onesie-too-thick #:onesie-locked #:invalid-user-input ;;macros #:defevent #:ensure-zone #:defzone #:ensure-zone* #:defzone* #:defonesie #:make-pocket-zone #:accept-with-effective-frame #:with-effective-frame #:present-with-effective-frame #:updating-present-with-effective-frame #:defmatch #:define-type ;;functions #:finished-events #:unfinished-events #:finish-events #:process-battle #:get-positions-of-type #:trigger-event #:intro-function #:set-player #:set-status-condition #:set-new-battle #:get-inventory-list #:get-zone #:get-destination #:get-path-end #:getf-direction #:remf-direction #:get-diaper-expansion #:pop-from-expansion #:getf-action-from-prop #:filter-items #:total-thickness #:thickest-sort #:thickest #:wet #:mess #:get-event #:move-to-pocket-map #:move-to-secret-underground #:get-warp-point #:get-props-from-zone #:get-items-from-prop #:get-bitcoins-from-prop #:effective-type-effectiveness #:calculate-diaper-usage #:calculate-diaper-usage* #:calculate-level-to-exp #:calculate-exp-yield #:calculate-wear-stats #:calculate-wield-stats #:calculate-stat-delta #:calculate-stat-multiplier #:calculate-stat #:wash #:go-to-sleep #:shopfun #:ally-join #:pushnewmove #:get-move #:process-potty-dance-check #:clear-configuration-hook ;;methods #:describe-diaper-wear-usage #:describe-diaper-inventory-usage #:get-process-potty-action-type #:output-process-potty-text #:get-babyish-padding #:resolve-enemy-spawn-list #:process-battle-accident #:process-potty-dance #:calculate-damage #:event-attributes #:battle-script #:condition-script #:attack #:default-attack #:use-script #:wear-script #:wield-script #:toggle-onesie #:type-match #:coerce-element-type #:coerce-element-types #:fill-bladder #:fill-bowels #:bladder/fill-rate #:bowels/fill-rate #:fart #:fart-result-text ;;constructors #:make-action ;;classes #:status-condition #:stats-view #:base-character #:bladder-character #:bowels-character #:potty-character #:npc #:team-member #:potty-trained-team-member #:element-type #:ally #:ally-rebel #:ally-no-potty-training #:ally-rebel-potty-training #:ally-silent-potty-training #:ally-last-minute-potty-training #:ally-feral #:playable-ally #:player #:zone #:move #:buff #:debuff #:clear-status-mixin #:health-inc-move #:energy-inc-move #:damage-move #:damage-item #:damage-wield #:mess-move-mixin #:wet-move-mixin #:prop #:placable-prop #:item #:consumable #:ammo #:weapon #:clothing #:top #:headpiece #:bottoms #:snap-bottoms #:closed-bottoms #:full-outfit #:closed-full-outfit #:onesie #:onesie/opened #:onesie/closed #:incontinence-product #:padding #:ab-clothing #:undies #:stuffer #:diaper #:pullup #:skirt #:dress #:shirt #:pants #:enemy #:bladder-enemy #:bowels-enemy #:potty-enemy #:battle #:pantsable-character ;;accessors #:name-of #:description-of #:attributes-of #:direction-attributes-of #:target-of #:tail-of #:wings-of #:skin-of #:config-of #:stairs-of #:element-types-of #:last-process-potty-time-of #:statuses-cleared-of #:blocks-turn-of #:duration-of #:stat-delta-of #:stat-multiplier-of #:priority-of #:health-of #:energy-of #:level-of #:malep #:wear-of #:species-of #:time-of #:accumulative-of #:bladder/contents-of #:bladder/fill-rate-of #:bladder/need-to-potty-limit-of #:bladder/potty-dance-limit-of #:bladder/potty-desperate-limit-of #:bladder/maximum-limit-of #:bowels/contents-of #:bowels/fill-rate-of #:bowels/need-to-potty-limit-of #:bowels/potty-dance-limit-of #:bowels/potty-desperate-limit-of #:bowels/maximum-limit-of #:fart-count-of #:moves-of #:exp-of #:user-of #:clothes-of #:base-stats-of #:team-npcs-of #:iv-stats-of #:bitcoins-of #:bitcoins-per-level-of #:inventory-of #:wield-of #:learned-moves-of #:position-of #:warp-on-death-point-of #:enter-text-of #:props-of #:events-of #:continue-battle-of #:underwaterp #:hiddenp #:warp-points-of #:lockedp #:sellablep #:tossablep #:placeablep #:can-potty-p #:potty-trigger-of #:wet-text-of #:mess-text-of #:wear-wet-text-of #:wear-mess-text-of #:must-wear-of #:must-wear*-of #:must-not-wear-of #:must-not-wear*-of #:no-wetting/messing-of #:enemy-spawn-list-of #:team-npc-spawn-list-of #:energy-cost-of #:power-of #:use-power-of #:reload-count-of #:ammo-power-of #:ammo-of #:ammo-type-of #:ammo-capacity-of #:cant-use-p #:items-of #:actions-of #:plural-name-of #:value-of #:default-attack-power-of #:wear-stats-of #:wield-stats-of #:special-actions-of #:thickness-of #:thickness-capacity-of #:thickness-capacity-threshold-of #:waterproofp #:leakproofp #:disposablep #:sogginess-of #:sogginess-capacity-of #:messiness-of #:messiness-capacity-of #:key-of #:onesie-thickness-capacity-of #:onesie-thickness-capacity-threshold-of #:onesie-waterproof-p #:watersport-limit-of #:mudsport-limit-of #:watersport-chance-of #:mudsport-chance-of #:turn-queue-of #:enter-battle-text-of #:enemies-of #:win-events-of #:player-of #:allies-of #:team-of #:events-of #:finished-events-of #:current-events-of #:seen-enemies-of #:action-lambda #:action-p #:fainted-of #:curablep #:deletef-status-conditions #:deletef-status-conditions-if #:status-conditions) (:documentation "Yet Another Diaperfur Adventure") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:sc :serapeum/contrib/hooks) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:ms :marshal) (:f :fmt))) (uiop:define-package :yadfa-bin (:export #:lst #:wear #:unwear #:get-stats #:toggle-onesie #:toss #:toggle-full-repl #:wield #:unwiled #:pokedex #:toggle-lock #:change #:wield #:unwield #:enable-mods #:disable-mods #:reload-files #:get-inventory-of-type) (:documentation "Commands that the player can run anytime")) (uiop:define-package :yadfa-world (:export #:move #:interact #:save-game #:load-game #:go-potty #:tickle #:wash-all-in #:use-item #:add-ally-to-team #:remove-ally-from-team #:swap-team-member #:stats #:place #:reload #:place-prop #:take-prop #:fart) (:documentation "contains the commands when in the open world (assuming that's what it's called) (and not in something like a battle). The player probably shouldn't call these with the package prefix unless they're developing")) (uiop:define-package :yadfa-battle (:export #:fight #:run #:use-item #:stats #:reload) (:documentation "Contains the commands used when battling. The player probably shouldn't call these with the package prefix unless they're developing")) (uiop:define-package :yadfa-moves (:shadow #:pants) (:use :yadfa :yadfa-util :cl :iterate) (:export #:kamehameha #:superglitch #:watersport #:mudsport #:tickle #:tackle #:mush #:mudbomb #:spray #:pants #:fire-breath #:roar #:scratch #:face-sit #:ghost-tickle #:ghost-squish #:ghost-mush #:bite #:teleporting-flood #:teleporting-mess #:boop #:fart #:spank) (:documentation "Contains all the moves in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-items (:shadow #:dress #:onesie #:diaper #:onesie/opened #:onesie/closed #:skirt) (:use :yadfa :yadfa-util :cl :iterate) (:export #:bandit-swimsuit/closed #:revive #:shine-star #:egg-spear #:pacifier #:gold-pacifier #:recovering-pacifier #:healing-pacifier #:energizing-pacifier #:blanket #:plushie #:short-dress #:dress #:sundress #:fursuit #:watertight-fursuit #:koopa-shell #:cheerleader-outfit #:ballerina-dress #:braixen-dress #:skirt #:denim-skirt #:shendyt #:kalasiris #:toddler-dress #:knights-armor #:tshirt #:jeans #:snap-jeans #:baggy-jeans #:cannibal-corpse-tshirt #:black-leather-jacket #:orca-suit #:stretchable-orca-suit #:orca-suit-lite #:stretchable-orca-suit-lite #:boxers #:panties #:mutagen #:antimutagen #:bra #:bikini-top #:tunic #:bandit-uniform-tunic #:bandit-uniform-shirt #:bandit-uniform-sports-bikini-top #:bottle-of-milk #:monster-energy-drink #:spiked-bottle-of-milk #:potion #:cannibal-corp-meat #:maximum-tomato #:holy-hand-grenade #:generic-diapers #:generic-diapers-package #:generic-pullons #:generic-pullons-package #:incontinence-pad #:incontinence-pad-package #:cloth-incontinence-pad #:diaper #:high-capacity-diaper #:black-diaper #:cloth-diaper #:diaper-package-mixin #:ammo-box-mixin #:diaper-package #:midnight-diaper #:midnight-diaper-package #:kurikia-thick-diaper #:thick-cloth-diaper #:thick-diaper #:gem-diaper #:infinity-diaper #:temple-diaper #:cursed-diaper #:temple-pullups #:thick-diaper-package #:kurikia-thick-rubber-diaper #:kurikia-thick-cloth-diaper #:thick-rubber-diaper #:hyper-thick-diaper #:hyper-thick-cloth-diaper #:hyper-thick-rubber-diaper #:pullups #:pullups-package #:cloth-pullups #:rubber-pullups #:swim-diaper-cover #:disposable-swim-diaper #:disposable-swim-diaper-package #:rubber-diaper #:bandit-diaper #:bandit-adjustable-diaper #:bandit-female-diaper #:bandit-swim-diaper-cover #:lower-bandit-swim-diaper-cover #:female-bandit-swim-diaper-cover #:pink-frilly-diaper #:magic-diaper-key #:gold-bar #:gem #:gold-collar #:diaper-corset #:blackjack-uniform-diaper #:cloth-diaper-corset #:rubber-diaper-corset #:collar #:rubber-suit #:magic-diaper-key #:lil-koopalings #:lil-koopalings-package #:ak47 #:7.62×39mm #:box-of-7.62×39mm #:exterminator #:exterminator-ammo #:pink-sword #:hammer-gun #:messing-laser #:wrench #:three-swords #:pocket-map-machine #:warp-device #:navy-shirt #:navy-pants #:navy-skirt #:navy-pullups #:pirate-dress #:pirate-shirt #:macguffin #:itemfinder #:enemy-catcher #:ghost-catcher #:contained-enemies-of #:contained-enemies-max-length-of #:catch-chance-multiplier-of #:catch-chance-delta-of #:contained-enemies #:contained-enemies-max-length #:catch-chance-multiplier #:catch-chance-delta #:device-health #:max-device-health #:device-health-of #:max-device-health-of) (:documentation "Contains all the items in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-battle-commands (:use :yadfa :yadfa-util :cl :iterate) (:export #:catch-enemy) (:documentation "convenience functions for battle") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-world-commands (:use :yadfa :yadfa-util :cl :iterate) (:export #:loot-caught-enemies #:disown-adopted-enemies) (:documentation "convenience functions for battle") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-element-types (:use :cl :yadfa :yadfa-util :iterate) (:export #:normal #:fighting #:flying #:poison #:ground #:rock #:bug #:ghost #:steel #:fire #:water #:grass #:electric #:psychic #:ice #:dragon #:dark #:fairy #:abdl) (:documentation "Element types") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-enemies (:use :cl :yadfa :yadfa-util :iterate) (:export #:magikarp #:egg-pawn #:diapered-raccoon-bandit #:catchable-raccoon-bandit #:rookie-diapered-raccoon-bandit #:female-diapered-raccoon-bandit #:giant-diapered-raccoon-bandit #:navy-officer #:navy-officer* #:diaper-pirate #:diapered-kobold #:diapered-skunk #:diapered-skunk* #:thickly-diaper-pirate #:padded-fursuiter-servant #:fursuiter-servant #:diapered-dragon* #:diapered-dragon #:dergy #:ghost #:werewolf #:domesticated-werewolf #:catchable-enemy #:catch-chance #:catch-chance-rate-of #:raptor #:change-class-target #:change-class-text #:adoptable-enemy #:skunk-boop-mixin) (:documentation "Contains all the enemies in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-props (:use :cl :yadfa :yadfa-util :iterate) (:export #:toilet #:washer #:automatic-changing-table #:checkpoint #:shop #:vending-machine #:debug-shop #:bed #:placable-bed #:placable-toilet #:placable-washer #:pet-bed #:training-potty #:items-for-sale-of #:items-for-sale) (:documentation "Contains all the enemies in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-status-conditions (:use :cl :yadfa :yadfa-util :iterate) (:export #:wetting #:messing #:mushed #:laughing #:skunked #:pantsed #:poisoned) (:documentation "Contains all the status conditions in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-zones (:use :yadfa :yadfa-util :cl :iterate) (:export #:peachs-castle-wannabe #:painting #:back-to-castle #:race-area #:thwomp-area #:home #:debug-map #:bandits-domain #:lukurbo #:ironside #:silver-cape #:bandits-way #:cave-entrance #:descend #:bandits-entrance #:secret-underground #:pirates-cove #:candle-carnival #:sky-base #:star-city #:flying-mansion #:your-ship #:rpgmaker-dungeon #:haunted-house #:haunted-forest #:rocket #:rainbow-slide #:pyramid) (:documentation "Contains all the zone definitions in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-events (:use :yadfa :yadfa-util :cl :iterate) (:export #:enter-bandits-village-1 #:enter-bandits-shop-1 #:enter-bandits-shop-2 #:enter-bandits-shop-3 #:decend-bandits-cave-1 #:obtain-diaper-lock-1 #:enter-bandits-kennel-1 #:get-warp-pipe-summoner-1 #:shopkeeper-floods-himself-1 #:pointless-quest-1 #:ironside-university-joke-1 #:enter-lukurbo-1 #:got-all-shine-stars-1 #:enter-race-area-1 #:win-race-area-1 #:enter-thwomp-area-1 #:win-thwomp-area-1 #:enter-pokemon-area-1 #:win-pokemon-area-1 #:enter-blank-area-1 #:enter-eggman-area-1 #:win-eggman-area-1 #:pirates-cove-1 #:pirates-cove-2 #:secret-underground-pipe-rpgmaker-dungeon #:secret-underground-pipe-lukurbo #:secret-underground-pipe-silver-cape #:secret-underground-pipe-haunted-forest #:secret-underground-pipe-haunted-house #:secret-underground-pipe-candle-carnival #:secret-underground-pipe-sky-base #:secret-underground-pipe-star-city #:enter-silver-cape-1 #:obtain-pirate-ship-1 #:get-location-to-pirate-cove-1 #:get-diaper-locked-1 #:pyramid-puzzle-1 #:infinity-diaper-obtained-1) (:documentation "Contains all the event definitions in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-allies (:use :yadfa :yadfa-util :cl :iterate) (:export #:slynk #:chris #:kristy #:furry #:raptor #:diapered-kobold #:adopted-enemy #:diapered-raccoon-bandit #:found-raccoon-bandit) (:documentation "Contains all the allies in the game") (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-user (:use :cl :iterate) (:documentation "The package that the player typically executes commands from")) (uiop:define-package :yadfa-clim (:use :iterate :yadfa-util :yadfa :clim-lisp) (:documentation "CLIM related stuff") (:export #:stat-view #:+stat-view+ #:draw-bar #:run-listener) (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-blackjack (:use :iterate :yadfa-util :yadfa :clim-lisp) (:export #:run-game) (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-pyramid (:use :iterate :yadfa-util :yadfa :clim-lisp) (:export #:run-game #:stat-view #:+stat-view+ #:process-potty) (:shadow #:area) (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt))) (uiop:define-package :yadfa-puzzle (:use :iterate :yadfa-util :yadfa :clim-lisp :yadfa-pyramid) (:export #:run-game) (:shadow #:run-game) (:local-nicknames (:s :serapeum) (:a :alexandria) (:u :ugly-tiny-infix-macro) (:g :global-vars) (:c :clim) (:ce :clim-extensions) (:cc :conditional-commands) (:f :fmt)))
20,652
Common Lisp
.lisp
798
21.146617
230
0.645023
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
7c8bab8510dc3c46f02a76ea7e0233d1e16fb4a587d11d9cb66bf213a554f77f
15,579
[ -1 ]
15,580
build.lisp
pouar_yadfa/build.lisp
;; -*- mode: common-lisp; -*- #+sbcl (declaim (sb-ext:muffle-conditions sb-kernel:redefinition-warning) (optimize sb-c::recognize-self-calls)) #-quicklisp (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))) (when (probe-file quicklisp-init) (load quicklisp-init))) #+ccl (ccl:set-current-compiler-policy (ccl:new-compiler-policy :trust-declarations (lambda (env) (declare (ignore env)) nil))) #+(and sbcl (not sb-gmp)) (macrolet ((a () `(progn ,(when (some #'(lambda (pathname) (handler-case (sb-alien:load-shared-object pathname :dont-save t) (error (e) (declare (ignore e)) nil))) #-(or os-windows :os-macosx) '("libgmp.so" "libgmp.so.10" "libgmp.so.3") #+:os-macosx '("libgmp.dylib" "libgmp.10.dylib" "libgmp.3.dylib") #+os-windows '("libgmp.dll" "libgmp-10.dll" "libgmp-3.dll")) '(asdf:load-system :sb-gmp))))) (a)) #+sb-gmp (unless (eq (fdefinition 'sb-bignum:multiply-bignums) (fdefinition 'sb-gmp::gmp-mul)) (sb-gmp:install-gmp-funs)) (when (find "slynk" (uiop:command-line-arguments) :test #'string=) (ql:quickload "slynk")) (when (find "swank" (uiop:command-line-arguments) :test #'string=) (ql:quickload "swank")) (when (find "ft" (uiop:command-line-arguments) :test #'string=) (pushnew :mcclim-ffi-freetype *features*)) (setf ql:*quickload-verbose* t) (let ((*compile-verbose* nil) (*compile-print* nil)) (ql:quickload (loop for i in (asdf:system-depends-on (asdf:find-system :yadfa)) when (stringp i) collect i when (and (listp i) (eq (first i) :feature) (uiop:featurep (second i))) collect (third i))) (declaim (optimize (debug 2) safety)) (ql:quickload :yadfa)) (when (find "immutable" (uiop:command-line-arguments) :test #'string=) (setf yadfa::*immutable* t)) (when (find "docs" (uiop:command-line-arguments) :test #'string=) (declaim (optimize (debug 1) (safety 1))) (ql:quickload :yadfa-reference) (declaim (optimize (debug 2) safety))) (when (probe-file (uiop:merge-pathnames* (make-pathname :name "yadfa") (asdf:component-pathname (asdf:find-system "yadfa")))) (delete-file (uiop:merge-pathnames* (make-pathname :name "yadfa") (asdf:component-pathname (asdf:find-system "yadfa"))))) (asdf:make :yadfa :force (when (find "force" (uiop:command-line-arguments) :test #'string=) t))
2,698
Common Lisp
.lisp
47
46.574468
125
0.589811
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
8df07f45509a3e8a9b189623245ad4a35f2cb6fe93535758b4047c35260d6661
15,580
[ -1 ]
15,581
consumable.lisp
pouar_yadfa/data/items/consumable.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defclass bottle-of-milk (consumable) () (:default-initargs :name "Bottle of milk" :description "A baby bottle filled with milk. Fills up your health and your bladder." :value 50 :consumable t)) (defmethod use-script ((item bottle-of-milk) (user base-character) (target base-character)) (incf (bladder/contents-of target) 100) (if (> (health-of target) 0) (progn (format t "~a regained health~%" (name-of target)) (incf (health-of target) 20)) (f:fmt t (name-of user) " makes the unconscious " (name-of target) " suckle on the " (name-of item) " like a sleeping infant" #\Newline))) (defclass mutagen (consumable) ((element-types :initarg :element-types :accessor element-types-of))) (defmethod use-script ((item mutagen) (user base-character) (target base-character)) (let* ((types (mapcar 'coerce-element-type (element-types-of item))) (old (mapcar 'coerce-element-type (element-types-of target))) (new (union old types :key 'type-of :test 'eq)) (difference (set-difference new old :key 'type-of :test 'eq))) (if difference (flet ((format-type (type) (f:fmt t (name-of target) " gained the " (:esc (let* ((class (class-of type)) (name (name-of class))) (if name (:fmt (:a name)) (:fmt (:s (class-name class)))))) " type" #\Newline))) (setf (element-types-of target) new) (iter (for i in difference) (format-type i))) (f:fmt t "It had no effect on " (name-of target) #\Newline)))) (defclass antimutagen (consumable) ((element-types :initarg :element-types :accessor element-types-of))) (defmethod use-script ((item antimutagen) (user base-character) (target base-character)) (let* ((types (mapcar 'coerce-element-type (element-types-of item))) (old (mapcar 'coerce-element-type (element-types-of target))) (new (set-difference old types :key 'type-of :test 'eq)) (difference (set-difference old new :key 'type-of :test 'eq))) (if difference (flet ((format-type (type) (f:fmt t (name-of target) " lost the " (:esc (let* ((class (class-of type)) (name (name-of class))) (if name (:fmt (:a name)) (:fmt (:s (class-name class)))))) " type" #\Newline))) (setf (element-types-of target) new) (iter (for i in difference) (format-type i))) (f:fmt t "It had no effect on " (name-of target) #\Newline)))) (defclass monster-energy-drink (consumable) () (:default-initargs :name "Monster Energy Drink" :description "WARNING! NOT MEANT FOR HUMAN (or furry) CONSUMPTION. Fills up your energy and your bladder." :value 100 :consumable t)) (s:defmethods monster-energy-drink (item) (:method cant-use-p (item (user base-character) (target base-character) action &key &allow-other-keys) (when (<= (health-of target) 0) (values t `(:format-control "Does ~a look conscious enough to use that?" :format-arguments (,(name-of target)))))) (:method use-script (item (user base-character) (target base-character)) (declare (ignore item)) (incf (bladder/contents-of target) 175) (incf (energy-of target) 20))) (defclass spiked-bottle-of-milk (consumable) () (:default-initargs :name "Spiked Bottle of milk" :description "A baby bottle filled with laxatives and diuretics. Fills up your bladder and bowels really quickly." :value 50 :consumable t)) (defmethod use-script ((item spiked-bottle-of-milk) (user base-character) (target base-character)) (when (<= (health-of target) 0) (f:fmt t (name-of user) " makes the unconscious " (name-of target) " suckle on the " (name-of item) " like a sleeping infant" #\Newline)) (setf (bladder/contents-of target) (if (< (bladder/contents-of target) (bladder/need-to-potty-limit-of target)) (- (bladder/maximum-limit-of target) (* (bladder/fill-rate-of target) 5)) (+ (bladder/contents-of target) (bladder/potty-dance-limit-of target)))) (setf (bowels/contents-of target) (if (< (bowels/contents-of target) (bowels/need-to-potty-limit-of target)) (- (bowels/maximum-limit-of target) (* (bowels/fill-rate-of target) 5)) (+ (bowels/contents-of target) (bowels/potty-dance-limit-of target))))) (defclass consious-mixin (item) ()) (defmethod cant-use-p ((item consious-mixin) (user base-character) (target base-character) action &key &allow-other-keys) (when (<= (health-of target) 0) (values t `(:format-control "Does ~a look conscious enough to use that?" :format-arguments (,(name-of target))))) (when (>= (health-of target) (calculate-stat target :health)) (values t `(:format-control "~a's health is already full" :format-arguments (,(name-of target)))))) (defclass potion (consious-mixin consumable) () (:default-initargs :name "Potion" :description "Heals 20 HP" :value 50 :consumable t)) (defmethod use-script ((item potion) (user base-character) (target base-character)) (declare (ignore item)) (incf (health-of target) 20)) (defclass revive (consumable) () (:default-initargs :name "Revive" :description "Bring someone back from the dead with this" :value 500 :consumable t)) (s:defmethods revive (item) (:method cant-use-p (item (user base-character) (target base-character) action &key &allow-other-keys) (when (> (health-of target) 0) (values t `(:format-control "Does ~a look unconscious to you?~%" :format-arguments (,(name-of target)))))) (:method use-script (item (user base-character) (target base-character)) (declare (ignore item)) (incf (health-of target) 20))) (defclass cannibal-corp-meat (consious-mixin consumable) () (:default-initargs :name "\"CANNIBAL CORP.\" Brand Meat" :description "Just like in the music video. Heals 50 HP." :value 75 :consumable t)) (defmethod use-script ((item cannibal-corp-meat) (user base-character) (target base-character)) (declare (ignore item)) (incf (bowels/contents-of target) 50) (incf (health-of target) 50)) (defclass maximum-tomato (consious-mixin consumable) () (:default-initargs :name "Maximum Tomato" :description "Restores Full HP" :value 50 :consumable t)) (defmethod use-script ((item maximum-tomato) (user base-character) (target base-character)) (declare (ignore item)) (setf (health-of target) (calculate-stat target :health))) (defclass holy-hand-grenade (consumable damage-item) () (:default-initargs :name "Holy Hand Grenade of Antioch" :description "And Saint Attila raised the hand grenade up on high, saying, “O Lord, bless this thy hand grenade. That with it, thou mayest blow thine enemies to tiny bits, in thy mercy” And the Lord did grin, and the people did feast upon the lambs, and sloths, and carp, and anchovies, and orangutans, and breakfast cereals, and fruit bats, and..." :value 200 :consumable t)) (s:defmethods holy-hand-grenade (item) (:method cant-use-p (item (user base-character) (target base-character) action &key &allow-other-keys) (unless *battle* (values t `(:format-control "You can only use that in battle")))) (:method use-script :around (item (user base-character) (target base-character)) (if (or (and (typep target 'team-member) (cdr (team-of *game*))) (and (typep target 'enemy) (cdr (enemies-of *battle*)))) (progn (format t "~a: One, Two, Five~%" (name-of target)) (format t "~a: Three ~a~%" (name-of (if (typep target 'team-member) (or (second (member target (team-of *game*))) (player-of *game*)) (or (second (member target (enemies-of *battle*))) (first (enemies-of *battle*))))) (if (malep target) "Sir" "Ma'am")) (format t "~a: Three!!!" (name-of target))) (format t "~a: One, Two, Five, I mean Three!!!" (name-of target))) (write-line " *throws hand grenade*") (write-line "*BOOM*") (iter (for i in (if (typep target 'team-member) (enemies-of *battle*) (team-of *game*))) (decf (health-of i) (use-power-of item)))))
8,969
Common Lisp
.lisp
159
46.534591
353
0.608562
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
c8150daa825a8e33723d1ad297b744fbc92f97da29a43c7c2f8522378c9896b8
15,581
[ -1 ]
15,582
debug.lisp
pouar_yadfa/data/items/debug.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defclass test-clothing (clothing) () (:default-initargs :special-actions (list :test (make-action :documentation "test item" :lambda '(lambda (item user) (declare (ignorable item user)) (format t "Testing:~a ~a~%" (name-of user) (name-of item)))))))
524
Common Lisp
.lisp
11
32.090909
101
0.48538
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b58b4449ed5bef827aeeeba8dffc7865094c6b95d4e10888e780e68dc513d6d7
15,582
[ -1 ]
15,583
diaper.lisp
pouar_yadfa/data/items/diaper.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defclass cloth-mixin (incontinence-product) () (:default-initargs :sogginess-capacity 1400 :messiness-capacity 1000 :disposable nil :sellable t :wear-wet-text '(1400 "little yellow streams are leaking down from the leg guards" 350 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(1000 "Poo is leaking out of the leg guards" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass rubber-mixin (incontinence-product) () (:default-initargs :sogginess-capacity 2000 :messiness-capacity 1700 :waterproof t :disposable nil :sellable t :wear-wet-text '(2000 "little yellow streams are leaking down from the leg guards" 350 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(1700 "Poo is leaking out of the leg guards" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass thick-mixin (incontinence-product) () (:default-initargs :sogginess-capacity 4000 :messiness-capacity 1700 :thickness (+ 50 4/5) :thickness-capacity 100 :wear-wet-text '(4000 "little yellow streams are leaking down from the leg guards" 2000 "The front is stained yellow" 1400 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(1700 "Poo is leaking out of the leg guards" 850 "The back is clearly stained brown" 425 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass diaper-package-mixin (item) ((diaper :type symbol :initarg :diaper))) (defmethod use-script ((item diaper-package-mixin) (user base-character) (target base-character)) (format t "You tear open the package and dump all the diapers out of it.~%") (iter (for i from 1 to 20) (push (make-instance (slot-value item 'diaper)) (inventory-of target)))) (defclass generic-diapers (yadfa:diaper undies) () (:default-initargs :sogginess-capacity 100 :messiness-capacity 20 :name "Store Brand Diapers" :plural-name "Store Brand Diapers" :wear-wet-text '(100 "Damn thing is leaking already" 25 "This thing might not last much longer" 1 "Not leaking yet") :wear-mess-text '(20 "This was never designed to hold a mess, and the mess leaking down the leg guards show it" 1 "You can feel a slight mess back there") :description "These are our new Super Absorbent Briefs!!! Built to the top American standards of adult diapers, meaning they're neither super, nor absorbent.")) (defclass generic-diapers-package (diaper-package-mixin) () (:default-initargs :name "Package of Store Brand Diapers" :plural-name "Packages of Store Brand Diapers" :description "These are our new Super Absorbent Briefs!!! Built to the top American standards of adult diapers, meaning they're neither super, nor absorbent." :consumable t :value 200 :diaper 'generic-diapers)) (defclass generic-pullons (pullup undies) () (:default-initargs :sogginess-capacity 100 :messiness-capacity 20 :name "Store Brand Pullons" :plural-name "Store Brand Pullons" :wear-wet-text '(100 "Damn thing is leaking already" 25 "This thing might not last much longer" 1 "Not leaking yet") :wear-mess-text '(20 "This was never designed to hold a mess, and the mess leaking down the leg guards show it" 1 "You can feel a slight mess back there") :description "Our new Super Absorbent Briefs in Pullon form!!! They look just like real underwear!!! And is about as absorbent as real underwear too!!!!")) (defclass generic-pullons-package (diaper-package-mixin) () (:default-initargs :name "Package of Store Brand Pullons" :plural-name "Packages of Store Brand Pullons" :description "Our new Super Absorbent Briefs in Pullon form!!! They look just like real underwear!!! And is about as absorbent as real underwear too!!!!" :consumable t :value 200 :diaper 'generic-pullons)) (defclass incontinence-pad (stuffer) () (:default-initargs :sogginess-capacity 1000 :messiness-capacity 100 :name "Incontinence Pad" :wear-wet-text '( 1000 "It's leaking" 250 "It's swollen with urine" 1 "You can barely tell you wet it") :wear-mess-text '(100 "The mess is falling out of the stuffer" 25 "The mess is about to fall out" 1 "You can feel a slight mess back there") :description "For when you think you're too old for real padding, or if you just want your existing padding to last longer")) (defclass incontinence-pad-package (diaper-package-mixin) () (:default-initargs :name "Package of Incontinence Pads" :plural-name "Packages of Incontinence Pads" :description "For when you think you're too old for real padding, or if you just want your existing padding to last longer" :consumable t :value 200 :diaper 'incontinence-pad)) (defclass cloth-incontinence-pad (cloth-mixin stuffer) () (:default-initargs :sogginess-capacity 1000 :messiness-capacity 100 :name "Cloth Incontinence Pad" :wear-wet-text '(1000 "It's leaking" 250 "It's swollen with urine" 1 "You can barely tell you wet it") :wear-mess-text '(100 "The mess is falling out of the stuffer" 25 "The mess is about to fall out" 0 "You can feel a slight mess back there") :description "For when you think you're too old for real padding, or if you just want your existing padding to last longer. Can be reused")) (defclass diaper (yadfa:diaper undies) () (:default-initargs :sogginess-capacity 1400 :messiness-capacity 1000 :name "Diaper" :description "A poofy diaper that can hold an accident." :wear-wet-text '(1400 "little yellow streams are leaking down from the leg guards" 700 "The front is clearly stained yellow" 350 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(1000 "Poo is leaking out of the leg guards and the back is stained brown" 700 "The back is clearly stained brown" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass high-capacity-diaper (yadfa:diaper undies) () (:default-initargs :sogginess-capacity 4000 :messiness-capacity 1700 :name "High Capacity Diaper" :description "Has similar capacity to the thick diaper without the extra bulk" :wear-wet-text '(4000 "little yellow streams are leaking down from the leg guards" 700 "The front is stained yellow" 350 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(1700 "Poo is leaking out of the leg guards" 700 "The back is clearly stained brown" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass black-diaper (high-capacity-diaper) () (:default-initargs :name "Black Diaper" :description "A Black diaper with a blood red landing zone")) (defclass thick-diaper (thick-mixin yadfa:diaper undies) () (:default-initargs :name "Thick Diaper" :description "A thick diaper that can hold more than an normal diaper")) (defclass diaper-corset (thick-mixin yadfa:diaper closed-full-outfit) () (:default-initargs :name "Diaper Corset" :description "Full body suit that acts as a diaper. The only thing you need to wear.")) (defclass blackjack-uniform-diaper (diaper-corset) () (:default-initargs :name "Blackjack Uniform Diaper" :description "Full body suit that acts as a diaper based on the diaper corset. Has the player's name on the back and a spade on the crotch that fades when wet so everyone knows who the loser is." :wear-wet-text '(4000 "little yellow streams are leaking down from the leg guards" 2000 "The front is stained yellow" 1400 "It squishes when you walk" 150 "The spade on the front has faded away" 50 "The spade on the front has partially faded" 1 "You can barely tell you wet it") :wear-mess-text '(1700 "Poo is leaking out of the leg guards" 850 "The back is clearly stained brown" 425 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass midnight-diaper (thick-mixin yadfa:diaper) () (:default-initargs :name "Midnight Diaper" :description "A thick black diaper with blue landing zone, blue leg guards, and red tapes")) (defclass thick-diaper-package (diaper-package-mixin) () (:default-initargs :name "Package of Thick Diapers" :plural-name "Packages of Thick Diapers" :description "A package of A thick diapers that can hold more than an normal diapers" :consumable t :value 250 :diaper 'thick-diaper)) (defclass midnight-diaper-package (diaper-package-mixin) () (:default-initargs :name "Package of Midnight Diapers" :plural-name "Packages of Midnight Diapers" :description "A package of thick black diapers with blue landing zone, blue leg guards, and red tapes" :consumable t :value 250 :diaper 'midnight-diaper)) (defclass cloth-diaper (cloth-mixin yadfa:diaper undies) () (:default-initargs :value 200 :name "Cloth Diaper" :description "A poofy diaper that can hold an accident. Can be reused.")) (defclass gem-diaper (yadfa:diaper undies) () (:default-initargs :value 400 :sogginess-capacity 5000 :messiness-capacity 4000 :disposable nil :sellable t :name "Magic Gem Diaper" :description "A diaper from the Spyro universe that has pictures of gems on it who's value represent how much it is used. It starts out with 4 magenta gems on the front and another 4 on the back. Every time it is used, the amount of gems go down, letting you know exactly how full it is.")) (defun describe-gems (count) (flet ((format-pair (pair) (destructuring-bind (color value) pair (f:fmt nil value " " color (:format " gem~P" value)))) (calculate-gems (amount) (declare (type fixnum amount)) (iter (for (the simple-string color) in '("magneta" "yellow" "purple" "green" "red")) (for (the fixnum value) in '(25 10 5 2 1)) (with (the fixnum ret) = 0) (setf ret (iter (with (the fixnum ret) = 0) (while (>= amount value)) (incf ret) (decf amount value) (finally (return ret)))) (when (> ret 0) (collect (list color ret))))) (text-length (text) (s:nlet rec ((count 0) (text text)) (if (>= count 2) count (rec (1+ count) (cdr text)))))) (let* ((text (calculate-gems count)) (text-length (text-length text))) (declare (type list text)) (f:fmt nil (:esc (case text-length (2 (:fmt (:join (", " ", and ") (iter (for i in text) (collect (format-pair i)))))) (1 (:fmt (:join " and " (iter (for i in text) (collect (format-pair i)))))) (0 (:fmt (format-pair (car text)))))))))) (s:defmethods gem-diaper (item (sogginess #'sogginess-of) (messiness #'messiness-of) (sogginess-capacity #'sogginess-capacity-of) (messiness-capacity #'messiness-capacity-of)) (:method describe-diaper-wear-usage (item) (let ((wet-gems (round (- 100 (* (/ sogginess sogginess-capacity) 100)))) (mess-gems (round (- 100 (* (/ messiness messiness-capacity) 100))))) (declare (type fixnum wet-gems mess-gems)) (f:fmt t "The front of the diaper has a picture of " (describe-gems wet-gems) #\Newline (:esc (when (>= sogginess sogginess-capacity) (:fmt "Pee is dripping down your legs" #\Newline))) "The back of the diaper has a picture of " (describe-gems mess-gems) #\Newline (:esc (when (>= messiness messiness-capacity) (:fmt "Poop is leaking down the leg guards" #\Newline)))))) (:method describe-diaper-inventory-usage (item) (let ((wet-gems (round (- 100 (* (/ sogginess sogginess-capacity) 100)))) (mess-gems (round (- 100 (* (/ messiness messiness-capacity) 100))))) (declare (type fixnum wet-gems mess-gems)) (f:fmt t "The front of the diaper has a picture of " (describe-gems wet-gems) #\Newline (:esc (when (>= sogginess sogginess-capacity) (:fmt "It is totally drenched" #\Newline))) "The back of the diaper has a picture of " (describe-gems mess-gems) #\Newline (:esc (when (>= messiness messiness-capacity) (:fmt "Diaper is clearly full" #\Newline))))))) (defclass temple-diaper (cloth-mixin yadfa:diaper) () (:default-initargs :name "Temple Diaper" :description "A diaper with weird Egyptian hieroglyphics on it")) (defclass cursed-diaper (cloth-mixin yadfa:diaper ab-clothing) () (:default-initargs :name "Cursed Diaper" :description "The diaper's tapes have a glow in the shape of a lock in front of them. You can't seem to remove them. Better think of something quick." :locked t :key nil)) (defclass rubber-diaper (rubber-mixin yadfa:diaper) () (:default-initargs :value 250 :name "Rubber Diaper" :description "A poofy rubber diaper that can hold an accident. Can be reused.")) (defclass thick-cloth-diaper (thick-mixin cloth-mixin yadfa:diaper undies) () (:default-initargs :name "Thick Cloth Diaper" :description "A thick diaper that can hold more than an normal diaper. Can be reused.")) (defclass infinity-diaper (thick-mixin cloth-mixin yadfa:diaper) () (:default-initargs :name "Infinity Diaper" :description "A diaper that never leaks. It is very thick and has an Ankh on the front" :leakproof t :waterproof t :value 1000000000 :wear-wet-text '(2000 "The front is stained yellow" 1400 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(850 "The back is clearly stained brown" 425 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass thick-rubber-diaper (thick-mixin rubber-mixin yadfa:diaper) () (:default-initargs :sogginess-capacity 6000 :messiness-capacity 25000 :name "Thick Rubber Diaper" :description "A thick rubber diaper that can hold more than an normal diaper. Can be reused." :wear-wet-text '(6000 "little yellow streams are leaking down from the leg guards" 350 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(2500 "Poo is leaking out of the leg guards" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass cloth-diaper-corset (diaper-corset cloth-mixin) () (:default-initargs :name "Cloth Diaper Corset" :description "Full body suit that acts as a cloth diaper. The only thing you need to wear. Can be reused")) (defclass rubber-diaper-corset (diaper-corset rubber-mixin) () (:default-initargs :name "Rubber Diaper Corset" :description "Full body suit that acts as a rubber diaper. The only thing you need to wear. Can be reused.")) (defclass disposable-swim-diaper (yadfa:diaper) () (:default-initargs :sogginess-capacity 1400 :messiness-capacity 1000 :waterproof t :name "Disposable Swim Diaper" :description "A swim diaper that actually holds just the urine you expel and not all the water in the pool" :wear-wet-text '(1400 "little yellow streams are leaking down from the leg guards" 350 "It squishes when you walk" 1 "You can barely tell you wet it") :wear-mess-text '(1000 "Poo is leaking out of the leg guards" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass disposable-swim-diaper-package (diaper-package-mixin) () (:default-initargs :name "Package of Disposable Swim Diapers" :plural-name "Packages of Disposable Swim Diapers" :description "A package of swim diapers. Unlike most swim diapers, they absorb your waste without absorbing all the water in the pool." :consumable t :value 300 :diaper 'disposable-swim-diaper)) (defclass diaper-package (diaper-package-mixin) () (:default-initargs :name "Package of Diapers" :plural-name "Packages of Diapers" :description "A package of poofy diapers that can hold an accident." :consumable t :value 250 :diaper 'diaper)) (defclass kurikia-thick-diaper (yadfa:diaper) () (:default-initargs :sogginess-capacity 10000 :messiness-capacity 2500 :name "Kurikia Thick Diaper" :value 60 :thickness 300 :thickness-capacity 100 :wear-stats (list :speed -10) :wear-wet-text '(10000 "Pee flows down with every step" 2500 "It sloshes when you walk" 1 "The pee seems to have disappeared into the diaper") :wear-mess-text '(2500 "Poo is leaking out of the diaper" 1000 "It smooshes when you walk" 1 "The diaper holds the mess easily") :description "It's like carrying a giant pillow between your legs forcing you to waddle")) (defclass kurikia-thick-cloth-diaper (kurikia-thick-diaper cloth-mixin) () (:default-initargs :name "Kurikia Thick Cloth Diaper" :value 400 :description "It's like carrying a giant pillow between your legs forcing you to waddle. Can be reused.")) (defclass kurikia-thick-rubber-diaper (kurikia-thick-diaper rubber-mixin) () (:default-initargs :sogginess-capacity 15000 :messiness-capacity 3000 :name "Kurikia Thick Rubber Diaper" :value 400 :wear-wet-text '(15000 "Pee flows down with every step" 2500 "It sloshes when you walk" 1 "The pee seems to have disappeared into the diaper") :wear-mess-text '(3000 "Poo is leaking out of the diaper" 1000 "It smooshes when you walk" 1 "The diaper holds the mess easily") :description "A giant thick waterproof diaper. Yes, the waddle is noticeable")) (defclass hyper-thick-diaper (yadfa:diaper) () (:default-initargs :sogginess-capacity 50000 :messiness-capacity 8000 :name "Hyper Thick Diaper" :value 700 :thickness 1000 :thickness-capacity 380 :wear-stats (list :speed -20) :wear-wet-text '(50000 "Pee flows down with every step" 12500 "It sloshes when you walk" 1 "The pee seems to have disappeared into the diaper") :wear-mess-text '(8000 "Poo is leaking out of the diaper" 2000 "It smooshes when you walk" 1 "The diaper holds the mess easily") :description "When you leak so often that you need a diaper so thick it nearly touches the ground")) (defclass hyper-thick-cloth-diaper (hyper-thick-diaper cloth-mixin) () (:default-initargs :name "Hyper Thick Cloth Diaper" :value 1000 :description "When you leak so often that you need a diaper so thick it nearly touches the ground. Can be reused.")) (defclass hyper-thick-rubber-diaper (hyper-thick-diaper rubber-mixin) () (:default-initargs :sogginess-capacity 60000 :messiness-capacity 9000 :name "Hyper Thick Rubber Diaper" :value 1000 :wear-wet-text '(60000 "Pee flows down with every step" 12500 "It sloshes when you walk" 1 "The pee seems to have disappeared into the diaper") :wear-mess-text '(9000 "Poo is leaking out of the diaper" 2000 "It smooshes when you walk" 1 "The diaper holds the mess easily") :description "For when the Thick Rubber Diaper wasn't thick enough. At least it doubles as a bean bag chair.")) (defclass pullups (pullup undies) () (:default-initargs :sogginess-capacity 800 :messiness-capacity 1000 :name "Pullup" :description "Wear this and pretend to be a big kid" :wear-wet-text '(800 "it is completely drenched, you sure you're ready for these?" 200 "The little pictures on the front have faded" 1 "the pictures haven't faded yet") :wear-mess-text '(1000 "Poo is leaking out of the pullup" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass pullups-package (diaper-package-mixin) () (:default-initargs :name "Package of Pullups" :plural-name "Packages of Pullups" :description "Wear these and pretend to be a big kid." :consumable t :value 250 :diaper 'pullups)) (defclass cloth-pullups (pullup cloth-mixin undies) () (:default-initargs :value 200 :disposable nil :sellable t :name "Cloth Pullup" :description "Wear this and pretend to be a big kid. Can be reused." :wear-wet-text '(800 "it is completely drenched, you sure you're ready for these?" 200 "it is noticeably wet" 1 "the pictures haven't faded yet"))) (defclass temple-pullups (pullup cloth-mixin ab-clothing) () (:default-initargs :value 200 :name "Temple Pullups" :description "A pullup with weird Egyptian hieroglyphics on it" :wear-wet-text '(800 "it is completely drenched, you sure you're ready for these?" 200 "it is noticeably wet" 1 "the pictures haven't faded yet") :wear-mess-text '(1000 "Poo is leaking out of the pullup" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass navy-pullups (pullup cloth-mixin) () (:default-initargs :value 200 :name "Navy Pullup" :description "Has the Navy insignia on the front. The Navy apparently expects you to keep these dry, but keeps them around just in case. They're made of cloth because they don't expect you to use them that often." :wear-wet-text '(800 "it is completely drenched, you sure you're ready for these?" 200 "it is noticeably wet" 1 "the pictures haven't faded yet") :wear-mess-text '(1000 "Poo is leaking out of the pullup" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass rubber-pullups (pullup rubber-mixin) () (:default-initargs :value 200 :name "Rubber Pullup" :description "Wear this and pretend to be a big kid. Can be reused." :wear-wet-text '(800 "it is completely drenched, you sure you're ready for these?" 200 "it is noticeably wet" 1 "the pictures haven't faded yet") :wear-mess-text '(1000 "Poo is leaking out of the pullup" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass swim-diaper-cover (closed-bottoms undies) () (:default-initargs :waterproof t :value 200 :name "Swim diaper cover" :description "Designed to be worn over diapers to avoid embarrassing diaper swelling incidents when in the water. Doesn't hold anything on its own")) (defclass bandit-diaper (yadfa:diaper) () (:default-initargs :sogginess-capacity 1400 :messiness-capacity 1000 :value 200 :disposable nil :sellable t :name "Bandit Diaper" :description "A diaper with the Diapered Raccoon Bandits' insignia on the front. the insignia turns yellow when the wearer wets it so the higher ups know when the lower ranks wet their diapers. Unlike most diapers, these are reusable." :wear-wet-text '(1400 "little yellow streams are leaking down from the leg guards" 350 "The insignia on the front has turned yellow" 1 "The insignia on the front is still blue") :wear-mess-text '(1000 "Poo is leaking out of the leg guards" 250 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass bandit-adjustable-diaper (bandit-diaper undies) () (:default-initargs :name "Bandit Adjustable Diaper" :description "A special diaper that can be pulled down like normal underwear so the wearer can still use the toilet. It has the bandit's insignia on the front which turns yellow when the diaper is used. It has tabs on the sides for easy removal. Unlike most diapers, these are reusable.")) (defclass bandit-female-diaper (kurikia-thick-diaper bandit-diaper ab-clothing) () (:default-initargs :name "Female's Bandit Diaper" :description "A diaper with the Diapered Raccoon Bandits' insignia on the front. the insignia turns yellow when the wearer wets it so the males know when the lower ranks wet their diapers. It is much thicker than what the males wear. Unlike most diapers, these are reusable." :wear-wet-text '(10000 "little yellow streams are leaking down from the leg guards" 2500 "The insignia on the front has turned yellow" 1 "The insignia on the front is still pink") :wear-mess-text '(10000 "Poo is leaking out of the leg guards" 2500 "There is a slight bulge in the back and it smells, but you'll be fine as long as you don't need to sit down" 1 "You can feel a slight mess back there"))) (defclass bandit-swim-diaper-cover (closed-bottoms) () (:default-initargs :waterproof t :value 200 :name "Bandit Swim diaper cover" :description "The higher ups wear these when in the water to prevent their diapers from swelling up. It has the bandits' insignia on it.")) (defclass lower-bandit-swim-diaper-cover (closed-bottoms) () (:default-initargs :waterproof t :value 200 :name "Lower Bandit Swim diaper cover" :description "The lower ranks wear these when in the water to prevent their diapers from swelling up. It is transparent enough to show the state of the diaper and does nothing to hide the poofiness")) (defclass female-bandit-swim-diaper-cover (closed-bottoms) () (:default-initargs :waterproof t :value 200 :thickness-capacity 400 :name "Lower Bandit Swim diaper cover" :description "The females wear these when in the water to prevent their diapers from swelling up. It is transparent enough to show the state of the diaper and does nothing to hide the poofiness. It is much larger than the ones the males wear to accommodate the thicker padding.")) (defclass pink-frilly-diaper (yadfa:diaper ab-clothing undies) () (:default-initargs :sogginess-capacity 5000 :name "Pink Diaper" :thickness (+ 50 4/5) :thickness-capacity 100 :description "A sissy pink frilly diaper. You look adorable with this" :wear-wet-text '(5000 "little yellow streams are leaking down from the leg guards" 2000 "It squishes when you walk" 500 "The hearts on the front have faded" 1 "You can barely tell you wet it"))) (defclass lil-koopalings (yadfa:diaper) () (:default-initargs :sogginess-capacity 1000000 :messiness-capacity 1000000 :thickness 1000 :thickness-capacity 2000 :name "Lil Koopalings Diapers" :description "Ultra thick pamps developed by Ivan Koopa. The color is the same color as the respective main Koopaling's color, while the tapes are the same color as the ring around the respective Koopaling's shell. Their emblem is also on the front and back of the diaper" :wear-wet-text '(1000000 "little yellow streams are leaking down from the leg guards" 500000 "The front is clearly stained yellow" 10000 "It squishes a bit" 1 "You can barely tell you wet it") :wear-mess-text '(1000000 "Poo is leaking out of the leg guards and the back is stained brown" 500000 "The back is clearly stained brown" 500 "You can feel your mess back there but it isn't visible" 1 "You can feel a slight mess back there"))) (defclass lil-koopalings-package (diaper-package-mixin) () (:default-initargs :name "Package of Lil Koopalings Diapers" :plural-name "Packages of Lil Koopalings Diapers" :description "Ultra thick pamps developed by Ivan Koopa. The color is the same color as the respective main Koopaling's color, while the tapes are the same color as the ring around the respective Koopaling's shell. Their emblem is also on the front and back of the diaper" :consumable t :value 200 :diaper 'lil-koopalings))
30,868
Common Lisp
.lisp
570
45.735088
293
0.662288
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
1873bf3525d782c8cb0b0141acc45db1faabe22d9d2d8b0acb2a8b300716cbcd
15,583
[ -1 ]
15,584
weapons.lisp
pouar_yadfa/data/items/weapons.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defclass ammo-box-mixin (item) ((ammo :type symbol :initarg :ammo))) (defmethod use-script ((item ammo-box-mixin) (user base-character) (target base-character)) (f:fmt t (name-of user) " open the box and dump all the ammunition out of it." #\Newline) (iter (for i from 1 to 6) (push (make-instance (slot-value item 'ammo)) (inventory-of target)))) (defclass 7.62×39mm (ammo) () (:default-initargs :name "7.62x39mm Rounds" :plural-name "7.62x39mm Rounds" :value 400 :description "7.62x39mm bullets" :ammo-power 150)) (defclass box-of-7.62×39mm (ammo-box-mixin) () (:default-initargs :name "Box of 7.62x39mm Rounds" :plural-name "Boxes of 7.62x39mm Rounds" :description "Contains 60 rounds of ammunition" :consumable t :value 2000 :ammo '7.62×39mm)) (defclass ak47 (weapon) () (:default-initargs :name "AK-47" :value 6000 :description "Hail a bunch of bullets at these motherfuckers" :ammo-type '7.62×39mm :ammo-capacity 3 :power 40)) (defclass exterminator-ammo (ammo) () (:default-initargs :name "Exterminator Ammo" :plural-name "Exterminator Ammo" :value 100000 :description "Ammo for the Exterminator" :ammo-power 500)) (defclass exterminator (weapon) () (:default-initargs :name "Exterminator" :value 1000000 :description "IT'S DA MOST POWEFUW WEAPON!!!! Too bad it takes forever to fire and reload, can only hold one round at a time, and ammo is super expensive, making it practically useless in battle." :wield-stats (list :speed -100) :ammo-type 'exterminator-ammo :ammo-capacity 1 :power 0)) (defmethod attack ((target base-character) (user base-character) (self exterminator)) (apply #'format t (if (first (ammo-of self)) (list "*BOOOMKSSSHHH!!!!!*~%") (list "~a struggles to whack ~a with ~a ~a but barely taps ~a~%" (name-of user) (name-of target) (if (malep user) "his" "her") (name-of self) (if (malep target) "his" "her"))))) (defclass pink-sword (weapon) () (:default-initargs :name "Pink Sword" :value 3000 :power 80 :description "'Cause it looks cute on the character")) (defclass egg-spear (weapon) () (:default-initargs :name "L̶a̶n̶c̶e̶ \"Egg Spear\"" :value 1000 :power 40 :description "Used by egg pawns, for some reason, it does the exact same amount of damage as an egg pawn without one")) (defclass hammer-gun (weapon) () (:default-initargs :name "Hammer Gun" :value 1000 :power 20 :description "As seen in One Piece")) (defclass wrench (weapon) () (:default-initargs :name "Wrench" :value 500 :power 1 :description "You get to frag enemies using this beauty, won't that be fun?")) (defclass three-swords (weapon) () (:default-initargs :name "Three Swords" :value 10000 :power 150 :description "You're just like Roronoa Zoro with these")) (defmethod attack ((target base-character) (user base-character) (self three-swords)) (format t "Three Sword Style!!!!~%")) (defclass messing-laser (weapon) () (:default-initargs :name "Messing Laser" :description "Causes enemies to mess themselves" :values 8000)) (s:defmethods messing-laser (weapon) (:method attack :around ((target base-character) (user base-character) weapon) (f:fmt t (name-of user) " fires " (if (malep user) "his" "her") " laser at " (name-of target) #\Newline) (use-script weapon user target)) (:method use-script (weapon (user base-character) (target base-character)) (f:fmt t "It has no effect on " (name-of target) #\Newline)) (:method use-script (weapon (user base-character) (target bowels-character)) (f:fmt t (name-of target) " squats down and starts blorting " (if (malep target) "himself" "herself") " uncontrollably." #\Newline) (mess :force-fill-amount (bowels/maximum-limit-of target)) (set-status-condition 'yadfa-status-conditions:messing target)))
4,139
Common Lisp
.lisp
105
34.857143
199
0.674037
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
84e9f5aab7123126b46fe852464c31d9ea49a0f39a42611f446d8a040be0c011
15,584
[ -1 ]
15,585
abdl.lisp
pouar_yadfa/data/items/abdl.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defclass pacifier (headpiece ab-clothing) () (:default-initargs :name "Pacifier" :description "A pacifier you can suck on." :value 250)) (defclass gold-pacifier (headpiece ab-clothing) () (:default-initargs :name "Gold-Pacifier" :description "A pacifier you can suck on. Has a golden mouth shield and a ruby for a handle" :value 10000)) (defclass recovering-pacifier (headpiece ab-clothing) () (:default-initargs :name "Recovering Pacifier" :description "A pacifier you can suck on. Recovers your health and energy when you suck on it" :value 5000)) (defmethod wear-script ((item recovering-pacifier) (user base-character)) (declare (ignorable item)) (incf (health-of user) (/ (calculate-stat user :health) 16)) (incf (health-of user) (/ (calculate-stat user :energy) 16)) (when (> (health-of user) (calculate-stat user :health)) (setf (health-of user) (calculate-stat user :health))) (when (> (energy-of user) (calculate-stat user :energy)) (setf (energy-of user) (calculate-stat user :energy)))) (defclass healing-pacifier (headpiece ab-clothing) () (:default-initargs :name "Healing Pacifier" :description "A pacifier you can suck on. Recovers your health when you suck on it" :value 2500)) (defmethod wear-script ((item healing-pacifier) (user base-character)) (declare (ignorable item)) (incf (health-of user) (/ (calculate-stat user :health) 16)) (when (> (health-of user) (calculate-stat user :health)) (setf (health-of user) (calculate-stat user :health)))) (defclass energizing-pacifier (headpiece ab-clothing) () (:default-initargs :name "Energizing Pacifier" :description "A pacifier you can suck on. Recovers your energy when you suck on it" :value 2500)) (defmethod wear-script ((item energizing-pacifier) (user base-character)) (declare (ignorable item)) (incf (health-of user) (/ (calculate-stat user :energy) 16)) (when (> (energy-of user) (calculate-stat user :energy)) (setf (energy-of user) (calculate-stat user :energy)))) (defclass blanket (item) () (:default-initargs :name "Blanket" :description "A Blanket you can carry around like a toddler" :value 200)) (defclass plushie (item) () (:default-initargs :name "Plushie" :description "A Plushie you can carry around like a toddler" :value 200))
2,446
Common Lisp
.lisp
55
41.381818
97
0.713509
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
d244c49f5c9cf84edb230bbc4a258f161a51b2ef79227e81c32c8d2d7970fcfe
15,585
[ -1 ]
15,586
clothes.lisp
pouar_yadfa/data/items/clothes.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (eval-when (:compile-toplevel :load-toplevel :execute) (defonesie onesie (ab-clothing) () (:default-initargs :name "Onesie" :description "A onesie" :value 400 :onesie-bulge-text '((50 "It fits over your diaper so tightly it looks like the buttons are about to go flying off" 20 "It fits over your diaper quite nicely" 0 "It's so baggy that what you're wearing under there is quite visible") . (100 "You are unable to get the buttons to snap so you just leave the flaps open" #.(* 12 25) "Your padding is clearly visible under there" #.(* 11 25) "The flaps just barely cover the diapers" #.(* 1/2 25) "The flaps hang over covering your padding like a dress" 0 "The flaps hang over covering your underwear like a dress"))))) (defonesie roomy-onesie (ab-clothing) () (:default-initargs :name "Roomy Onesie" :description "A onesie intended to accommodate thicker diapers" :onesie-thickness-capacity (cons (* 16 (+ 25 2/5)) nil) :value 400 :onesie-bulge-text '((60 "It fits over your diaper so tightly it looks like the buttons are about to go flying off" 20 "It fits over your diaper quite nicely" 0 "It's so baggy that what you're wearing under there is quite visible") . (#.(* 16 (+ 25 2/5)) "You are unable to get the buttons to snap so you just leave the flaps open" #.(* 12 25) "Your padding is clearly visible under there" #.(* 11 25) "The flaps just barely cover the diapers" #.(* 1/2 25) "The flaps hang over covering your padding like a dress" 0 "The flaps hang over covering your underwear like a dress")))) (defclass short-dress (yadfa:dress) () (:default-initargs :name "Short Dress" :plural-name "Short Dresses" :value 150 :description "A short breezy dress." :bulge-text '(225 "Your padding is clearly visible under your dress" 200 "Your padding is slightly visible under your dress" 175 "The dress does a good job hiding your padding, as long as you're standing still" #.(+ 162 1/2) "The dress does a good job hiding your padding, unless a gust of wind happens to blow by" #.(* 1/2 25) "The dress does a good job hiding your padding" 0 "It fits quite loosely") :thickness-capacity (* 16 (+ 25 2/5)))) (defclass dress (yadfa:dress) () (:default-initargs :name "Dress" :plural-name "Dresses" :value 150 :description "A cute dress." :bulge-text '(#.(* 4 25) "The bottom of your dress has poofed out humorously" #.(* 3 25) "There is a slight bulge, but it's not too noticeable" #.(* 1/2 25) "The dress does a good job hiding your padding" 0 "It fits snuggly") :thickness-capacity (* 16 (+ 25 2/5)))) (defclass sundress (yadfa:dress) () (:default-initargs :name "Sundress" :plural-name "Sundresses" :value 200 :description "A loose fitting dress." :bulge-text '(480 "Your padding is completely visible" 430 "Your padding is slightly visible under your dress" #.(* 1/2 25) "The dress does a good job hiding your padding" 0 "It fits quite loosely") :thickness-capacity nil)) (defclass toddler-dress (yadfa:dress ab-clothing) () (:default-initargs :name "Toddler's Dress" :plural-name "Toddler Dresses" :value 600 :description "A frilly pink dress fit for a big toddler." :bulge-text '(75 "Your padding is clearly visible under your dress" 50 "Your padding is slightly visible under your dress" 25 "The dress does a good job hiding your padding, as long as you're standing still" 12 "The dress does a good job hiding your padding, unless a gust of wind happens to blow by" 0 "The dress easily covers your underwear") :thickness-capacity nil)) (defclass tshirt (shirt) () (:default-initargs :name "T-Shirt" :value 50 :description "A simple plain t-shirt.")) (defclass black-leather-jacket (shirt) () (:default-initargs :name "Black Leather Jacket" :value 500 :description "Makes you look tough")) (defclass cannibal-corpse-tshirt (tshirt) () (:default-initargs :name "Cannibal Corpse T-Shirt" :value 200 :description "T-Shirt with Cannibal Corpse's logo on it")) (defclass jeans (pants) () (:default-initargs :name "Jeans" :plural-name "Jeans" :value 100 :description "A simple pair of jeans." :bulge-text '(12 "Your padding keeps poking out of the top of your pants" 0 "It fits snuggly"))) (defclass snap-jeans (jeans snap-bottoms) () (:default-initargs :name "Snap Jeans" :plural-name "Snap Jeans" :value 200 :description "These jeans have snaps on them so they simply unsnap when your diaper expands")) (defclass baggy-jeans (jeans) () (:default-initargs :name "Baggy Jeans" :plural-name "Baggy Jeans" :value 150 :description "For when you need to hide that diaper of yours, sorta" :bulge-text '(50 "Your pants puff out humorously" 12 "Your padding is visibly poking out of the top of your pants" 0 "It fits loosely") :thickness-capacity (* 16 (+ 25 2/5)))) (eval-when (:compile-toplevel :load-toplevel :execute) (defonesie rubber-onesie () () (:default-initargs :onesie-waterproof t :value 600 :name "Black Rubber Onesie" :onesie-thickness-capacity (cons (* 16 (+ 25 2/5)) nil) :onesie-bulge-text '((60 "It fits over your diaper so tightly it looks like the buttons are about to go flying off" 50 "It stretches which helps accommodate your thick padding" 20 "It fits over your diaper quite nicely" 0 "It's so baggy that what you're wearing under there is quite visible") . (#.(* 16 (+ 25 2/5)) "You are unable to get the buttons to snap so you just leave the flaps open" #.(* 12 25) "Your padding is clearly visible under there" #.(* 11 25) "The flaps just barely cover the diapers" #.(* 1/2 25) "The flaps hang over covering your padding like a dress" 0 "The flaps hang over covering your underwear like a dress")) :description "An awesome black rubber onesie"))) (defonesie stretchable-rubber-onesie (rubber-onesie) () (:default-initargs :onesie-thickness-capacity (cons nil nil) :onesie-thickness-capacity-threshold (cons nil nil) :onesie-bulge-text '((60 "The onesie has easily stretched to accommodate your padding" 20 "The diaper bulge makes it clear what you're wearing under there" 0 "It fits snuggly") . (#.(* 12 25) "Your padding is clearly visible under there" #.(* 11 25) "The flaps just barely cover the diapers" #.(* 1/2 25) "The flaps hang over covering your padding like a dress" 0 "The flaps hang over covering your underwear like a dress")) :name "Black Rubber Onesie" :description "An awesome black rubber onesie that stretches to fit your humongous diapers")) (defclass orca-suit (closed-full-outfit) () (:default-initargs :waterproof t :value 1000 :thickness-capacity (* 16 (+ 25 2/5)) :bulge-text '(60 "You look like one of those pictures drawn by Kurikia" 20 "The diaper bulge makes it clear what you're wearing under there" 0 "It fits snuggly") :name "Orca Suit" :description "An orca suit similar to the one Gabby wears.")) (defclass stretchable-orca-suit (orca-suit) () (:default-initargs :value 1500 :thickness-capacity nil :thickness-capacity-threshold nil :name "Stretchable Orca Suit" :description "A variant of the Orca Suit that stretches to fit your humongous diapers")) (defclass orca-suit-lite (orca-suit) () (:default-initargs :value 1000 :thickness-capacity (* 16 (+ 25 2/5)) :name "Orca Suit Lite" :description "An orca suit similar to the one Gabby wears, minus the swim boots and arm covers. You don't need 'em")) (defclass stretchable-orca-suit-lite (stretchable-orca-suit orca-suit-lite) () (:default-initargs :name "Stretchable Orca Suit Lite" :description "A variant of the Orca Suit Lite that stretches to fit your humongous diapers")) (defclass boxers (undies closed-bottoms) () (:default-initargs :name "Boxers" :plural-name "Boxers" :description "You sure wearing these is a good idea piddler?" :value 100)) (defclass panties (undies closed-bottoms) () (:default-initargs :name "Panties" :plural-name "Panties" :description "You sure wearing these is a good idea piddler?" :value 100)) (defclass bra (undies) () (:default-initargs :name "Bra" :description "Prevents bouncing and indecent exposure, whether this is a good thing or not depends on your point of view." :value 100)) (defclass bikini-top (shirt) () (:default-initargs :name "Bikini Top" :description "A sports bikini top" :value 50)) (defclass tunic (yadfa:dress) () (:default-initargs :name "Tunic" :value 100 :description "For when a toddler's dress is too sissy." :bulge-text '(75 "Your padding is clearly visible under your tunic" 50 "Your padding is slightly visible under your tunic" 25 "The tunic does a good job hiding your padding, as long as you're standing still" 12 "The tunic does a good job hiding your padding, unless a gust of wind happens to blow by" 0 "The tunic easily covers your underwear") :thickness-capacity nil)) (defclass bandit-uniform-tunic (tunic) () (:default-initargs :name "Bandit Uniform Tunic" :value 200 :description "This tunic has the Diapered Raccoon Bandits' insignia on it. The Diapered Raccoon Bandits usually don't wear pants since it easier to change their diapers without them. The tunics are for the higher ups as it allows them to conceal the state of their diaper. A privilege the lower ranks don't have." :bulge-text '(75 "Your padding is clearly visible under your tunic" 50 "Your padding is slightly visible under your tunic" 12 "The tunic easily covers your padding" 0 "The tunic easily covers your underwear") :thickness-capacity-threshold nil)) (defclass bandit-uniform-shirt (shirt) () (:default-initargs :name "Bandit Uniform Shirt" :value 100 :description "This shirt has the Diapered Raccoon Bandits' insignia on it. It's for the lower ranks as they're not allowed to conceal the state of their diaper, unlike the higher ranks.")) (defclass bandit-uniform-sports-bikini-top (bikini-top) () (:default-initargs :name "Bandit Uniform Sports Bikini Top" :description "A sports bikini top that has the Raccoon Bandits' insignia on it.")) (defonesie bandit-swimsuit () () (:default-initargs :onesie-waterproof t :value 600 :name "Bandit Swimsuit" :onesie-thickness-capacity (cons (* 16 (+ 25 2/5)) nil) :onesie-bulge-text '((60 "It fits over your diaper so tightly it looks like the buttons are about to go flying off" 50 "It stretches which helps accommodate your thick padding" 20 "It fits over your diaper quite nicely" 0 "It's so baggy that what you're wearing under there is quite visible") . (#.(* 16 (+ 25 2/5)) "You are unable to get the buttons to snap so you just leave the flaps open" #.(* 12 25) "Your padding is clearly visible under there" #.(* 11 25) "The flaps just barely cover the diapers" #.(* 1/2 25) "The flaps hang over covering your padding like a dress" 0 "The flaps hang over covering your underwear like a dress")) :description "A one piece swimsuit for the higher ups to wear when in the water. It resembles a woman's one piece swimsuit, but has snaps on the bottom to make diaper changes easier. It has the bandits' insignia on the front. This model has a skirt in order to hide the poofiness of their diaper.")) (defclass skirt (yadfa:skirt) () (:default-initargs :name "Skirt" :value 100 :description "A loose fitting skirt." :bulge-text '(75 "Your padding is clearly visible under your dress" 50 "Your padding is slightly visible under your dress" 25 "The dress does a good job hiding your padding, as long as you're standing still" 12 "The dress does a good job hiding your padding, unless a gust of wind happens to blow by" 0 "It fits quite loosely") :thickness-capacity nil :thickness-capacity-threshold nil)) (defclass navy-skirt (skirt) () (:default-initargs :name "Navy Skirt" :value 200 :description "A loose fitting skirt part of the Navy uniform for girls.")) (defclass denim-skirt (skirt jeans) () (:default-initargs :name "Denim Skirt" :value 100 :description "A skirt made from the same fabric as jeans.")) (defclass navy-shirt (yadfa:shirt) () (:default-initargs :name "Navy Shirt" :value 200 :description "The top half of a Navy uniform")) (defclass pirate-shirt (yadfa:shirt) () (:default-initargs :name "Pirate Shirt" :value 100 :description "The top half of a pirate outfit")) (defclass pirate-dress (short-dress) () (:default-initargs :name "Pirate Dress" :plural-name "Pirate Dresses" :value 100 :description "A Pirate Dress")) (defclass fursuit (closed-full-outfit) () (:default-initargs :name "Fursuit" :value 15000 :thickness-capacity 400 :sogginess-capacity 200 :messiness-capacity 100 :description "A warm and snuggly Fursuit. Makes you cute and huggable." :bulge-text '(200 "The circular bulge around your waist makes it obvious what you're wearing under there." 0 "It's warm and snuggly") :wear-wet-text '(200 "Just wipe off the excess with a towel and you'll be fine." 100 "You're wet and smelly but at least you're not leaving a trail" 10 "Well it's not noticeable" 0 "It's clean"))) (defclass watertight-fursuit (fursuit) () (:default-initargs :name "Watertight Fursuit" :value 25000 :sogginess-capacity 5000 :messiness-capacity 4000 :waterproof t :description "So you're fursuiting, but then all of a sudden you gotta go, but then don't make it, and then end up in a smelly soggy fursuit, and then no one wants to touch you cause you're soggy and smelly. Well with this baby, all those nasty smells and waste stay inside your suit, usually. Now the only one who has to suffer is you. Isn't that great?" :wear-wet-text '(400 "Even though no one else can tell, you're drenched in your own bodily fluids from the waist down." 100 "You're wet and smelly underneath, but at least no one else will notice." 10 "Well it's not noticeable" 0 "It's clean"))) (defclass koopa-shell (closed-full-outfit) () (:default-initargs :name "Koopa Shell" :value 10000 :thickness-capacity 600 :wear-stats (list :speed -1 :defence 20) :description "A hard koopa shell")) (defclass cheerleader-outfit (yadfa:dress) () (:default-initargs :name "Cheerleader Dress" :plural-name "Cheerleader Dresses" :value 150 :description "A pretty cheerleader dress. Looks great with a diaper to show everyone off with." :bulge-text '(25 "The skirt does absolutely nothing to hide your padding" #.(* 1/2 25) "The skirt does a good job hiding your padding, as long as you're standing still" 0 "It fits quite loosely") :thickness-capacity (* 16 (+ 25 2/5)))) (defclass ballerina-dress (yadfa:dress) () (:default-initargs :name "Ballerina Dress" :plural-name "Ballerina Dresses" :value 150 :description "A pretty ballerina dress. Looks great with a diaper to show everyone off with." :bulge-text '(25 "The skirt does absolutely nothing to hide your padding" #.(* 1/2 25) "The skirt does a good job hiding your padding, as long as you're standing still" 0 "It fits quite loosely"))) (defclass braixen-dress (yadfa:dress) () (:default-initargs :name "Braixen Dress" :plural-name "Ballerina Dresses" :value 150 :description "A furry dress that looks like the fur of a Braixen" :bulge-text '(25 "The skirt does absolutely nothing to hide your padding" #.(* 1/2 25) "The skirt does a good job hiding your padding, as long as you're standing still" 0 "It fits quite nicely"))) (defclass shendyt (skirt) () (:default-initargs :name "Shendyt" :description "A skirt like loincloth similar to what the ancient Egyptians wear")) (defclass kalasiris (yadfa:dress) () (:default-initargs :name "Kalasiris" :plural-name "Kalasirises" :value 200 :description "A dress similar to what the ancient Egyptians wear" :bulge-text '(480 "Your padding is completely visible" 430 "Your padding is slightly visible under your dress" #.(* 1/2 25) "The dress does a good job hiding your padding" 0 "It fits quite loosely") :thickness-capacity nil)) (defonesie shortalls (onesie ab-clothing) () (:default-initargs :name "Shortalls" :plural-name "Shortalls" :description "Denim shortalls with snaps on the front")) (defclass rubber-suit (closed-full-outfit) () (:default-initargs :name "Rubber Suit" :value 500 :sogginess-capacity 5000 :messiness-capacity 4000 :thickness-capacity 400 :waterproof t :leakproof t :description "Completely covers your body from the neck down. Is completely leakproof. If you think you're too big for pamps, you can wear these instead." :wear-wet-text '(400 "Even though no one else can tell, you're drenched in your own bodily fluids from the waist down." 100 "You're wet and smelly underneath, but at least no one else will notice." 10 "Well it's not noticeable" 0 "It's clean") :wear-mess-text '(400 "There's a big lump on the back of your seat" 10 "Well it's not noticeable" 0 "It's clean")))
19,077
Common Lisp
.lisp
382
41.918848
358
0.653167
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
0cbe273853fefdd4864722333f4cba1a65b808bff9cbd4f68e5538db17ecc1ee
15,586
[ -1 ]
15,587
misc.lisp
pouar_yadfa/data/items/misc.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defclass gold-bar (item) () (:default-initargs :name "Gold Bar" :description "A Gold Bar" :value 50000)) (defclass gem (item) () (:default-initargs :name "Gem" :description "A Valuable Gem" :value 25000)) (defclass gold-collar (headpiece) () (:default-initargs :name "Gold Collar" :description "A very expensive collar with a gold tag and studded with gems" :value 25000)) (defclass collar (headpiece) () (:default-initargs :name "Collar" :description "A collar that your pet furries can wear. Has an id tag on it for easy identification.")) (defclass magic-diaper-key (item) () (:default-initargs :name "Magic Diaper Key" :tossable nil :sellable nil :description "This mysterious artifact seems to have the ability to prevent others from removing their diapers")) (defclass pocket-map-machine (item) () (:default-initargs :name "Pocket Map Machine" :tossable nil :sellable nil :description "So you're playing Pokémon and you're making your secret base. Then you're like “Damn, I wish I could take this awesome base with me” or “I wish I could create my own decorations for this base instead of only being able to use what Nintendo provides me”. While Pouar can't do anything about Pokémon, he can create a similar feature for this game without these limitations. So here it is, the Pocket Map Machine")) (defmethod use-script ((item pocket-map-machine) (user base-character) (target base-character)) (declare (ignore user)) (move-to-pocket-map item)) (defclass warp-device (item) () (:default-initargs :name "Warp Device" :tossable nil :sellable nil :description "This device can be used to summon a warp pipe to take you to the secret underground")) (defmethod use-script ((item warp-device) (user base-character) (target base-character)) (declare (ignore item user target)) (move-to-secret-underground)) (defclass macguffin (item) () (:default-initargs :name "MacGuffin" :sellable nil :tossable nil :description "Collect as many of these fuckers as you possibly can. Don't ask why, just do it.")) (defclass itemfinder (item) () (:default-initargs :name "Itemfinder" :description "Returns T anytime a hidden item is nearby. It is based on Pouar's ability to detect whatever he has to say is offensive or not. It uses the same algorithm, is about as effective, and has about as many happy customers. Also, if you wrap the function in a not function, it becomes the same algorithm SJWs use to decide whatever they hear is offensive or not.")) (defmethod use-script ((item itemfinder) (user base-character) (target base-character)) (declare (ignore item user target))) (defclass shine-star (item) () (:default-initargs :name "Shine Star" :sellable nil :tossable nil :description "Collect as many of these fuckers as you possibly can. Don't ask why, just do it.")) (defclass enemy-catcher (item) ((contained-enemies% :initarg contained-enemies :accessor contained-enemies-of :initform nil :type list :documentation "list that contains the caught enemies") (contained-enemies-max-length% :initarg contained-enemies-max-length :accessor contained-enemies-max-length-of :initform 1 :type unsigned-byte :documentation "Maximum amount of enemies this can hold") (catch-chance-multiplier% :initarg catch-chance-multiplier :accessor catch-chance-multiplier-of :initform 1 :type (real 0) :documentation "Multiplier of the chance this item might catch an enemy") (catch-chance-delta% :initarg catch-chance-delta :accessor catch-chance-delta-of :initform 0 :type real :documentation "How much of an increase this item might catch an enemy. if the multiplier is also specified, then this gets multiplied too") (device-health% :initarg device-health :accessor device-health-of :initform 1 :type (or unsigned-byte null) :documentation "How many times it can fail to catch the enemy before it gets destroyed. @code{T} means it never gets destroyed") (max-device-health% :initarg max-device-health :accessor max-device-health-of :initform 1 :type (or unsigned-byte null) :documentation "The maximum amount of @var{DEVICE-HEALTH} this item has. @code{T} means it never gets destroyed")) (:default-initargs :name "Enemy Catcher" :description "Use this to catch enemies" :value 500 :power 0)) (s:defmethods enemy-catcher (item) (:method cant-use-p (item (user base-character) (target base-character) action &key &allow-other-keys) (values t `(:format-control "~a can't be used on ~a" :format-arguments `(,(name-of item) ,(name-of target))))) (:method cant-use-p (item (user base-character) (target yadfa-enemies:catchable-enemy) action &key &allow-other-keys) nil)) (defclass ghost-catcher (enemy-catcher) () (:default-initargs :name "Ghost Catcher" :description "Use this to catch ghosts")) ;;; actual class isn't loaded yet, but methods need a class defined, so define a dummy class ;;; which should get replaced later in the loading process (unless (find-class 'yadfa-enemies:ghost nil) (defclass yadfa-enemies:ghost () ())) (s:defmethods ghost-catcher (item) (:method cant-use-p (item (user base-character) (target base-character) action &key &allow-other-keys) (values t `(:format-control "~a can't be used on ~a" :format-arguments `(,(name-of item) ,(name-of target))))) (:method cant-use-p (item (user base-character) (target yadfa-enemies:ghost) action &key &allow-other-keys) nil))
5,709
Common Lisp
.lisp
123
42.780488
429
0.729914
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
55e6b0b2cdbf638cb81934a47d53145b6703ca1334d5ffc542c5e0a195596083
15,587
[ -1 ]
15,588
armor.lisp
pouar_yadfa/data/items/armor.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defclass knights-armor (full-outfit) () (:default-initargs :name "Knight's Armor" :plural-name "Knight's Armor" :value 1000 :description "Steel armor that protects you in battle. Pants not included, you don't need em, especially when you have diapers" :wear-stats '(:defense 50) :thickness-capacity nil))
439
Common Lisp
.lisp
10
40.9
130
0.708625
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
30f28a4bfb47e6c63a70d53ab6cbc705545bf8a871ef1e9f1b815e5617ca127f
15,588
[ -1 ]
15,589
abdl.lisp
pouar_yadfa/data/element-types/abdl.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-element-types"; coding: utf-8-unix; -*- (in-package :yadfa-element-types) (define-type abdl () () (:element-name "ABDL"))
181
Common Lisp
.lisp
5
34.4
94
0.659091
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
ec706dbfcc0c42ea60718094b1b1451ff4f9352460e0db389efe9e167633148d
15,589
[ -1 ]
15,590
pokemon.lisp
pouar_yadfa/data/element-types/pokemon.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-element-types"; coding: utf-8-unix; -*- (in-package :yadfa-element-types) (define-type normal () () (:not-very-effective rock steel) (:no-effect ghost) (:element-name "Normal")) (define-type fighting () () (:not-very-effective flying poison bug psychic fairy) (:no-effect ghost) (:super-effective rock ice dark steel) (:element-name "Fighting")) (define-type flying () () (:not-very-effective rock steel electric) (:super-effective fighting bug grass) (:element-name "Flying")) (define-type poison () () (:not-very-effective poison ground rock ghost) (:super-effective grass fairy) (:no-effect steel) (:element-name "Poison")) (define-type ground () () (:not-very-effective bug grass) (:super-effective poison rock steel fire electric) (:no-effect flying) (:element-name "Ground")) (define-type rock () () (:not-very-effective fight ground steel) (:super-effective flying bug fire ice) (:element-name "Rock")) (define-type bug () () (:not-very-effective fighting flying poison ghost steel fire fairy) (:super-effective grass psychic dark) (:element-name "Bug")) (define-type steel () () (:not-very-effective steel fire water electric) (:super-effective rockice fairy) (:element-name "Steel")) (define-type fire () () (:not-very-effective rock fire water) (:super-effective bug steel grass ice dragon) (:element-name "Fire")) (define-type water () () (:not-very-effective ground rock fire) (:super-effective water grass dragon) (:element-name "Water")) (define-type grass () () (:super-effective ground rock water) (:not-very-effective flying poison bug steel fire grass dragon) (:element-name "Water")) (define-type electric () () (:not-very-effective grass electric dragon) (:no-effect ground) (:super-effective flying water) (:element-name "Electric")) (define-type psychic () () (:not-very-effective steel psychic) (:no-effect dark) (:super-effective fighting poison) (:element-name "Psychic")) (define-type ice () () (:not-very-effective steel fire water ice) (:super-effective flying ground grass dragon) (:element-name "Ice")) (define-type dragon () () (:not-very-effective steel) (:no-effect fairy) (:super-effective dragon) (:element-name "Dragon")) (define-type dark () () (:not-very-effective fighting dark fairy) (:super-effective ghost psychic abdl) (:element-name "Dark")) (define-type fairy () () (:not-very-effective poison steel fire abdl) (:super-effective fighting dragon dark) (:element-name "Fairy"))
2,624
Common Lisp
.lisp
93
25.623656
94
0.702489
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
4f52019e4585d60923f2d252d2ece4e91d44dd384ebceebe6b57915831fe0168
15,590
[ -1 ]
15,591
sky.lisp
pouar_yadfa/data/map/sky.lisp
(in-package :yadfa-zones) (ensure-zone (0 0 0 candle-carnival) :name "Candle Carnival Entrance" :description "Welcome to Candle Carnival. An awesome theme park in the sky" :enter-text "Welcome to Candle Carnival. An awesome theme park in the sky" :events '(yadfa-events:secret-underground-pipe-candle-carnival)) (ensure-zone (0 -1 0 candle-carnival) :name "Candle Carnival Pool" :description "The entrance to the pool" :enter-text "You're swimming in the pool" :underwater t) #.`(progn ,@(iter (for x from -10 to 10) (iter (for y from -2 downto -17) (collect `(ensure-zone (,x ,y 0 candle-carnival) :name "Candle Carnival Pool" :description "This pool makes up most of this floor" :enter-text "You're swimming in the pool" :underwater t))))) (ensure-zone (0 -18 0 candle-carnival) :name "Elevator" :description "An elevator to the upper deck" :enter-text "You enter the elevator" :stairs (list :up) :direction-attributes (list :up (list :exit-text "Going up"))) (ensure-zone (0 -18 1 candle-carnival) :name "Elevator" :description "An elevator to the upper deck" :enter-text "You enter the elevator" :stairs (list :down) :direction-attributes (list :down (list :exit-text "Going down"))) #.`(progn ,@(iter (for i from -10 to 10) (unless (= i -10) (collect `(ensure-zone (i -10 1 candle-carnival) :name "Catwalk" :description "A catwalk over the pool" :enter-text "You're swimming in the pool" :warp-points '(dive (i -10 0 candle-carnival))))))) (ensure-zone (-11 -10 1 candle-carnival) :name "Water slide" :description "A water slide that lets you slide to the bottom" :enter-text "You look down the water slide" :warp-points '(slide-down (-10 -9 0 candle-carnival))) (ensure-zone (11 -10 1 candle-carnival) :name "Power room" :description "Apparently this place is powered by monkeys in hamster wheels" :enter-text "You're inside the power room") (ensure-zone (4 -1 1 candle-carnival) :name "Rocket Pad" :description "A rocket pad" :enter-text "You enter the rocket pad" :warp-points (list 'rocket '(0 0 0 sky-base-landing-pad)) :direction-attributes (list 'rocket (list :exit-text "You fly over to Sky Base then drop off the rocket. The base's anti-gravity slingshot device emits a force that pulls you back up and lands you on a platform like an invisible bungee cord, but one that pulls you to different platforms instead of just one. It seems this is the primary mode of transportation here."))) (ensure-zone (4 -18 0 candle-carnival) :name "Changing room" :description "Apparently this place is powered by monkeys in hamster wheels" :enter-text "You're inside the power room" :props (list :vending-machine (make-instance 'yadfa-props:shop 'yadfa-props:items-for-sale '((yadfa-items:disposable-swim-diaper . (list :value 10)) (yadfa-items:diaper . (list :value 10)))))) (ensure-zone (4 -18 0 candle-carnival) :name "Changing room" :description "A place where you can change your clothes for swimming. There's a vending machine for people to buy diapers from while they're here" :enter-text "You enter the changing room" :props (list :vending-machine (make-instance 'yadfa-props:vending-machine 'yadfa-props:items-for-sale '((yadfa-items:disposable-swim-diaper . (list :value 11)) (yadfa-items:diaper . (list :value 10)) (yadfa-items:pullups . (list :value 5)))))) (ensure-zone (-4 -18 0 candle-carnival) :name "Gift Shop" :description "Here you can buy stuff" :enter-text "You enter the shop" :props (list :shop (make-instance 'yadfa-props:shop 'yadfa-props:items-for-sale '((yadfa-items:disposable-swim-diaper-package) (yadfa-items:swim-diaper-cover) (yadfa-items:blanket) (yadfa-items:plushie) (yadfa-items:pirate-dress) (yadfa-items:pirate-shirt) (yadfa-items:orca-suit-lite))))) (uiop:define-package #:sky-base (:export #:main-office #:living-quarters #:shop #:landing-pad #:nursery #:mansion #:launch-pad) (:documentation "Contains symbols for the sky base")) #.(let ((syms '(sky-base:landing-pad sky-base:living-quarters sky-base:main-office sky-base:shop sky-base:nursery sky-base:mansion sky-base:launch-pad)) (names '("Sky Base Landing Pad" "Sky Base Living Quarters" "Sky Base Main Office" "Sky Base Shop" "Sky Base Nursery" "Sky Base Mansion" "Sky Base Launch Pad"))) `(progn ,@(iter (for sym in syms) (collect `(defparameter ,sym ',sym))) ,@(iter (for sym in syms) (for name in names) (for desc in '("The entrance to Sky Base" "Where many residents of the sky base stay" "The entrance to the main office" "The entrance to Sky Base Shop" "A place for ABDLs to hang out" "Your own personal quarters" "Use this to head to the next area")) (collect `(ensure-zone (0 0 0 ,sym) :name ,name :description ,desc :enter-text ,(format nil "You step on the ~a entrance" name) :direction-attributes ',(iter (for i in syms) (for i-name in names) (unless (eq i sym) (collect i) (collect `(:exit-text ,(format nil "You jump from the ~a to the ~a" name i-name))))) :warp-points ',(iter (for i in syms) (unless (eq i sym) (collect i) (collect `(0 0 0 ,i)))) ,@(when (eq sym 'sky-base:landing-pad) '(:events '(yadfa-events:secret-underground-pipe-sky-base)))))))) (ensure-zone (0 -1 0 sky-base:launch-pad) :name "Rocket Pad" :description "A rocket pad" :enter-text "You enter the rocket pad" :warp-points (list 'rocket '(0 0 0 star-city)) :direction-attributes (list 'rocket (list :exit-text "You fly over to Star City"))) (ensure-zone (0 0 0 star-city) :name "Star City" :description "A city orbiting the planet on a giant platform" :enter-text "You're on the part of the pathway that acts as the city's gangway" :events '(yadfa-events:secret-underground-pipe-star-city)) #.`(progn ,@(iter (with a = ()) (for y from 1 to 21) (alexandria:appendf a (iter (for x from -10 to 10) (when (or (= x 0) (= y 11)) (collect `(ensure-zone (,x ,y 0 star-city) :name "Star City" :description "A city orbiting the planet on a giant platform" :enter-text "You're wondering across the platform"))))) (finally (return a)))) (ensure-zone (-2 3 0 star-city) :name "Star City Hotel Lobby" :description "A luxurious hotel" :enter-text "you're in the hotel lobby" :stairs (list :up)) #.`(progn ,@(iter (for x from -3 downto -7) (collect `(ensure-zone (,x 3 0 star-city) :name "Star City Hotel Hall" :description "A luxurious hotel" :enter-text "you're in the hall")))) (ensure-zone (-3 2 0 star-city) :name "Star City Hotel Diner" :description "A luxurious hotel" :enter-text "Welcome to the diner" :direction-attributes (list :east (list :hidden t) :west (list :hidden t))) (ensure-zone (-4 2 0 star-city) :name "Star City Hotel Shop" :description "A luxurious hotel" :enter-text "Welcome to the shop" :direction-attributes (list :east (list :hidden t) :west (list :hidden t))) (ensure-zone (-5 2 0 star-city) :name "Star City Hotel Spa" :description "A luxurious hotel" :enter-text "Welcome to the spa" :direction-attributes (list :east (list :hidden t) :west (list :hidden t))) (ensure-zone (-6 2 0 star-city) :name "Star City Hotel Gym" :description "A luxurious hotel" :enter-text "Welcome to the gym" :direction-attributes (list :east (list :hidden t) :west (list :hidden t))) (ensure-zone (-7 2 0 star-city) :name "Star City Hotel Pool" :description "Welcome to the pool" :enter-text "you're in the hall" :direction-attributes (list :east (list :hidden t) :west (list :hidden t))) (ensure-zone (-1 3 0 star-city) :name "Star City" :description "A city orbiting the planet on a giant platform" :enter-text "You're wondering across the platform") (ensure-zone (-2 3 1 star-city) :name "Star City Hotel Hallway" :description "A luxurious hotel" :enter-text "you're in the hall" :stairs (list :up :down)) #.`(progn ,@(iter (for x from -1 downto -5) (collect `(ensure-zone (,x 3 1 star-city) :name "Star City Hotel Hall" :description "A luxurious hotel" :enter-text "you're in the hall")))) (ensure-zone (0 22 0 star-city) :name "Star City" :description "A city orbiting the planet on a giant platform" :enter-text "You're wondering across the platform" :warp-points (list 'rainbow-slide '(6 11 0 silver-cape)) :direction-attributes (list 'rainbow-slide (list :exit-text "You slide down the slide back to the planet.")))
12,292
Common Lisp
.lisp
223
35.318386
383
0.483387
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
5cfca3acf142e626095bdccadbf02edd8fef29be7c50b2d1297b22990542a6ab
15,591
[ -1 ]
15,592
lukurbo.lisp
pouar_yadfa/data/map/lukurbo.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 lukurbo) :name "Lukubro Street" :description "You see many diapered furries and diapered fursuiters" :enter-text "You're wondering around the street" :events '(yadfa-events:enter-lukurbo-1 yadfa-events:secret-underground-pipe-lukurbo) :warp-points (list 'rpgmaker-dungeon '(9 5 0 rpgmaker-dungeon)))
498
Common Lisp
.lisp
8
53.125
97
0.655102
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
5dcad655ecf7d0c9fd5600b7444832cdc020b982380dcd962885497580d32314
15,592
[ -1 ]
15,593
rpgmaker-dungeon.lisp
pouar_yadfa/data/map/rpgmaker-dungeon.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (defevent create-rpgmaker-dungeon :lambda (lambda (self) (declare (ignore self)) (let ((width 10) (height 10)) (declare (type fixnum width height)) (labels ((neighbors (x y width height) (declare (type fixnum x y width height)) (remove-if (lambda (x-y) (declare (type list x-y)) (not (and (< -1 (first x-y) width) (< -1 (second x-y) height)))) `((,x ,(1+ y) :south) (,(1- x) ,y :west) (,x ,(1- y) :north) (,(1+ x) ,y :east)))) (remove-wall (width height &optional visited) (labels ((walk (x y width height) (push (list x y) visited) (iter (for (u v w) in (alexandria:shuffle (neighbors x y width height))) (unless (member (list u v) visited :test #'equal) (setf (getf-direction `(,x ,y 0 rpgmaker-dungeon) w :hidden) nil (getf-direction `(,u ,v 0 rpgmaker-dungeon) (getf '(:south :north :north :south :east :west :west :east) w) :hidden) nil) (walk u v width height))))) (walk (random width) (random height) width height)))) (iter (for x from 0 to (1- width)) (iter (for y from 0 to (1- height)) (defzone* `(,x ,y 0 rpgmaker-dungeon) :name "Generic Cookie Cutter Dungeon" :description "Time for an \"adventure\"" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :east (list :hidden t) :west (list :hidden t)) :enemy-spawn-list 'rpgmaker-dungeon))) (remove-wall width height) (setf (getf (warp-points-of (get-zone '(5 9 0 rpgmaker-dungeon))) 'bandits-domain) '(0 31 0 bandits-domain) (getf (warp-points-of (get-zone '(9 5 0 rpgmaker-dungeon))) 'lukurbo) '(0 0 0 lukurbo) (getf (warp-points-of (get-zone '(0 5 0 rpgmaker-dungeon))) 'silver-cape) '(0 0 0 silver-cape) (getf (warp-points-of (get-zone '(5 0 0 rpgmaker-dungeon))) 'haunted-forest) '(0 0 0 haunted-forest))))))
3,222
Common Lisp
.lisp
47
37.531915
108
0.380157
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
96ed3aae3ab3f0feff470c5857bcd23c711380dea13aad8222191ac53b9fd15f
15,593
[ -1 ]
15,594
dirty-chasm.lisp
pouar_yadfa/data/map/dirty-chasm.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones)
114
Common Lisp
.lisp
2
55.5
86
0.657658
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
91dbd4f9ac4cfc1755cc590a18afd95be6a57e6bc537b3082aec3d18c3f15671
15,594
[ -1 ]
15,595
your-ship.lisp
pouar_yadfa/data/map/your-ship.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) #.`(progn ,@(iter (for y from 0 to 2) (iter (for x from (- y) to y) (collect `(ensure-zone (,x ,y 0 your-ship) :name "Emacs" :description "The bow of your ship" :direction-attributes (list :south (list :hidden ,(and (or (= x 1) (= x -1)) (= y 2))) :down (list :hidden t) :up (list :hidden t)))))) ,@(iter (for i from -2 to 2) (collect `(ensure-zone (,i 11 0 your-ship) :name "Emacs" :description "The stern of your ship" :direction-attributes (list :north (list :hidden ,(or (= i 1) (= i -1))) :down (list :hidden t) :up (list :hidden t))))) ,@(iter (for i from 3 to 10) (collect `(ensure-zone (-2 ,i 0 your-ship) :name "Emacs" :description "The port of your ship" :direction-attributes (list :east (list :hidden ,(not (= i 6)))))) (collect `(ensure-zone (2 ,i 0 your-ship) :name "Emacs" :description "The starboard of your ship" :direction-attributes (list :west (list :hidden ,(not (= i 6)))))) (collect `(ensure-zone (0 ,i 0 your-ship) :name "Passage Way" :description "The passage way of your ship" ,@(when (= i 3) '(:stairs (list :up :down))))))) (ensure-zone (0 3 1 your-ship) :name "Bridge" :description "You can steer your ship from here" :props (list :controls (make-instance 'prop :name "Controls" :description "The ships controls" :attributes (list :destinations (list '(0 21 0 silver-cape) '(1 21 0 bandits-domain))) :actions (list :list-places-to-sail (make-action :documentation "List valid destinations" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (format t "~4a~30a~30a" "Index" "Name of destination" "Coordinates") (iter (for i from 0 to (1- (list-length (getf (attributes-of prop) :destinations)))) (format t "~4d~30a~30s" i (name-of (get-zone (nth i (getf (attributes-of prop) :destinations)))) (nth i (getf (attributes-of prop) :destinations)))))) :describe-place (make-action :documentation "display the description of a destination. INDEX is an index from :list-places-to-sail" :lambda '(lambda (prop &rest keys &key index &allow-other-keys) (if (nth index (getf (attributes-of prop) :destinations)) (progn (format t "Name: ~a~%~%Description: ~a~%~%Coordinates: ~s~%~%" (name-of (nth index (getf (attributes-of prop) :destinations))) (description-of (nth index (getf (attributes-of prop) :destinations))) (nth index (getf (attributes-of prop) :destinations)))) (format t "That's not a valid destination~%")))) :set-sail (make-action :documentation "Set sail to a place. INDEX is an index from :list-places-to-sail" :lambda '(lambda (prop &rest keys &key index &allow-other-keys) (if (nth index (getf (attributes-of prop) :destinations)) (progn (remf (warp-points-of (get-zone (getf (warp-points-of (get-zone '(-1 6 0 your-ship))) :exit))) :your-ship) (setf (getf (warp-points-of (get-zone '(-1 6 0 your-ship))) :exit) (nth index (getf (attributes-of prop) :destinations)) (getf (warp-points-of (get-zone (nth index (getf (attributes-of prop) :destinations)))) :your-ship) '(-1 6 0 your-ship))) (format t "That's not a valid destination~%")))))))) (ensure-zone (0 3 -1 your-ship) :name "Hold" :description "You have a chest here that can hold your crap" :props (list :chest (make-instance 'prop :name "Chest" :description "Place all your crap here" :placeable t))) #.`(progn ,@(iter (for i from -1 to 1) (unless (= i 0) (collect `(ensure-zone (,i 6 0 your-ship) :name "Passage Way" :description "The passage way of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t)) :warp-points ,(if (= i -1) '(list :exit '(0 21 0 silver-cape)) ())))))) (ensure-zone (-1 5 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :west (list :hidden t))) (ensure-zone (1 5 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :east (list :hidden t))) (ensure-zone (-1 6 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :west (list :hidden t))) (ensure-zone (1 6 0 your-ship) :name "Galley" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :east (list :hidden t))) (ensure-zone (-1 7 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :west (list :hidden t))) (ensure-zone (1 7 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :east (list :hidden t))) (ensure-zone (-1 8 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :west (list :hidden t))) (ensure-zone (1 8 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :east (list :hidden t))) (ensure-zone (-1 9 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :west (list :hidden t))) (ensure-zone (1 9 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :east (list :hidden t))) (ensure-zone (-1 10 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :west (list :hidden t))) (ensure-zone (1 10 0 your-ship) :name "Cabin" :description "A Cabin of your ship" :direction-attributes (list :north (list :hidden t) :south (list :hidden t) :east (list :hidden t)))
11,940
Common Lisp
.lisp
172
32.813953
172
0.338375
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
f8cef0f03e1539c5ec0dd435b1d5641ba4cc3382f7869a4f88ff9cd92da20a74
15,595
[ -1 ]
15,596
debug-map.lisp
pouar_yadfa/data/map/debug-map.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 debug-map) :name "zone-0-0-0-debug-map" :description "zone-0-0-0-debug-map" :enter-text "zone-0-0-0-debug-map" :warp-points (list '\1 '(1 1 0 debug-map) '\2 '(0 -1 -1 debug-map)) :stairs (list :down) :props (list :dresser (make-instance 'prop :name "Dresser" :description "A dresser" :placeable t :items (nconc (iter (for i from 1 to 20) (collect (make-instance 'yadfa-items:diaper))) (iter (for i from 1 to 20) (collect (make-instance 'yadfa-items:pullups))) (iter (for i from 1 to 5) (collect (make-instance 'yadfa-items:thick-rubber-diaper))) (list (make-instance 'yadfa-items:sundress) (make-instance 'yadfa-items:toddler-dress) (make-instance 'yadfa-items:rubber-onesie)))) :toilet (make-instance 'yadfa-props:toilet) :bed (make-instance 'yadfa-props:bed) :shop (make-instance 'yadfa-props:debug-shop :actions (list :talk (make-action :documentation "Say hi" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (ignore prop keys)) (format t "Hello World~%"))))))) (ensure-zone (0 0 -1 debug-map) :name "zone-0-0--1-debug-map" :description "zone-0-0--1-debug-map" :enter-text "zone-0-0--1-debug-map" :underwater t :stairs (list :up)) (ensure-zone (0 -1 -1 debug-map) :name "zone-0--1--1-debug-map" :description "zone-0--1--1-debug-map" :enter-text "zone-0--1--1-debug-map" :hidden t) (ensure-zone (0 1 0 debug-map) :name "zone-0-1-0-debug-map" :description "zone-0-1-0-debug-map" :enter-text "zone-0-1-0-debug-map" :enemy-spawn-list '((:chance 1 :enemies ((enemy))))) (ensure-zone (1 0 0 debug-map) :name "zone-1-0-0-debug-map" :description "zone-1-0-0-debug-map" :enter-text "zone-1-0-0-debug-map" ) (ensure-zone (1 1 0 debug-map) :name "zone-1-1-0-debug-map" :description "zone-1-1-0-debug-map" :enter-text "zone-1-1-0-debug-map" :events '(yadfa-events::test-battle-1) :warp-points '(\1 (0 0 0 debug-map))) (ensure-zone (1 1 1 debug-map) :name "zone-1-1-1-debug-map" :description "zone-1-1-1-debug-map" :enter-text "zone-1-1-1-debug-map")
3,707
Common Lisp
.lisp
59
34.525424
131
0.394189
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
0897b6ff60d2da9ed4048b6008a154d85bc6e6e403c9b5e1d613998a3244805a
15,596
[ -1 ]
15,597
ironside.lisp
pouar_yadfa/data/map/ironside.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 ironside) :name "Ironside Street" :description "Your typical suburban street. Some furries are driving in cars, some are walking, and some are riding on top of other furries treating them like a horse." :enter-text "You enter the street. You see a sign that says “Keep our city and your pants clean. Always go potty in the toilet and not in your pants and don't leave puddles on the floor. Anyone who doesn't abide by this rule will be assumed to have no potty training whatsoever and will be immediately diapered by the diaper police to prevent further puddles.”" :can-potty 'can-potty :potty-trigger 'trigger-diaper-police :warp-points (list 'home '(0 1 0 home))) (ensure-zone (1 0 0 ironside) :name "Ironside Street" :description "Your typical suburban street. Some furries are driving in cars, some are walking, and some are riding on top of other furries treating them like a horse." :can-potty 'can-potty :potty-trigger 'trigger-diaper-police :enter-text "You enter the street") (ensure-zone (2 0 0 ironside) :name "Ironside Street" :description "Your typical suburban street. Some furries are driving in cars, some are walking, and some are riding on top of other furries treating them like a horse." :can-potty 'can-potty :potty-trigger 'trigger-diaper-police :warp-points (list 'bandits-way '(0 10 0 bandits-domain)) :enter-text "You enter the street") (ensure-zone (0 1 0 downtown) :name "Ironside Crap-Mart" :description "Your local Crap-Mart store. We don't have as big of selection as other stores, but we carry a lot more of what we do actually stock. Our products are built with love, and by love, I mean the sweat and tears of cheap child labor from China. We pass the savings down to you, in theory, but not in practice. We now stock incontinence products that you can depend on, unless you plan to use them, since they can't hold anything worth a crap. Why do people keep buying the ones from across the street?" :enter-text "You enter the Crap-Mart" :can-potty 'can-potty :potty-trigger 'trigger-diaper-police :props (list :shop (make-instance 'yadfa-props:shop 'yadfa-props:items-for-sale (list '(yadfa-items:monster-energy-drink) '(yadfa-items:generic-diapers-package) '(yadfa-items:generic-pullons-package) '(yadfa-items:dress) '(yadfa-items:jeans) '(yadfa-items:tshirt) '(yadfa-items:boxers) '(yadfa-items:panties) '(yadfa-items:knights-armor) '(yadfa-items:potion))) :changing-table (make-instance 'yadfa-props:automatic-changing-table))) (ensure-zone (0 -1 0 ironside) :name "Ironside ABDL-Mart" :description "Welcome to ABDL-Mart" :enter-text "You enter the ABDL-Mart." :can-potty 'can-potty :potty-trigger 'trigger-diaper-police :props (list :shop (make-instance 'yadfa-props:shop 'yadfa-props:items-for-sale (list '(yadfa-items:bottle-of-milk) '(yadfa-items:incontinence-pad-package) '(yadfa-items:diaper-package) '(yadfa-items:pullups-package) '(yadfa-items:toddler-dress) '(yadfa-items:onesie/opened))) :changing-table (make-instance 'yadfa-props:automatic-changing-table))) (ensure-zone (2 1 0 ironside) :name "Ironside University Entrance" :description "An old school university back when universities actually innovated, instead of being dumbed down, commercialized, and simply taught how to use proprietary products." :enter-text "You enter the university" :can-potty 'can-potty :potty-trigger 'trigger-diaper-police) (ensure-zone (2 2 0 ironside) :name "Ironside University" :description "A hallway" :enter-text "You're in the hallway" :can-potty 'can-potty :potty-trigger 'trigger-diaper-police) (ensure-zone (2 3 0 ironside) :name "Ironside University" :description "A hallway" :enter-text "You're in the hallway" :can-potty 'can-potty :potty-trigger 'trigger-diaper-police) (ensure-zone (3 2 0 ironside) :name "6.001/6.037" :description "This is the classroom for Structure and Interpretation of Computer Programs" :enter-text "You enter the classroom" :can-potty 'can-potty :potty-trigger 'trigger-diaper-police :direction-attributes (list :south (list :hidden t)) :props (list :desk (make-instance 'prop :name "Desk" :description "One of the desks in the classroom" :actions (list :sit-through-lecture (make-action :documentation "Sit through a lecture" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (ignore prop keys)) (format t "Instructor: Today's topic is Linear Recursion and Iteration, let's look at the following factorial function~%~%") (write-line "*writes") (write-line "(define (factorial n)") (write-line " (if (= n 1)") (write-line " 1") (write-line " (* n (factorial (- n 1)))))") (format t "on the blackboard, then walks through the process in the following substitution model~%~%(factorial 6)~%") (write-line "(* 6 (factorial 5))") (write-line "(* 6 (* 5 (factorial 4)))") (write-line "(* 6 (* 5 (* 4 (factorial 3))))") (write-line "(* 6 (* 5 (* 4 (* 3 (factorial 2)))))") (write-line "(* 6 (* 5 (* 4 (* 3 (* 2 (factorial 1))))))") (write-line "(* 6 (* 5 (* 4 (* 3 (* 2 1)))))") (write-line "(* 6 (* 5 (* 4 (* 3 2))))") (write-line "(* 6 (* 5 (* 4 6)))") (write-line "(* 6 (* 5 24))") (write-line "(* 6 120)") (write-line "720") (format t "on the blackboard*~%~%") (format t "Instructor: This is a recursive process, but isn't very efficient though, as the interpreter needs to keep track of all the operations, instead we can redefine the function as follows~%~%") (write-line "*writes") (write-line "(define (factorial n)") (write-line " (define (iter product counter)") (write-line " (if (> counter n)") (write-line " product") (write-line " (iter (* counter product)") (write-line " (+ counter 1))))") (write-line " (iter 1 1))") (write-line "on the chalkboard, then walks through the process") (write-line "(factorial 6)") (write-line "(iter 1 1)") (write-line "(iter 1 2)") (write-line "(iter 2 3)") (write-line "(iter 6 4)") (write-line "(iter 24 5)") (write-line "(iter 120 6)") (write-line "(iter 720 7)") (write-line "720") (write-line "on the blackboard*") (format t "Instructor: This is an iterative process, as the interpreter now only needs to keep track of the variables product and counter for each n~%~%") (trigger-event 'yadfa-events:ironside-university-joke-1))))))) (ensure-zone (3 3 0 ironside) :name "Ironside University Dormitory" :description "" :enter-text "" :can-potty 'can-potty :potty-trigger 'trigger-diaper-police :direction-attributes (list :north (list :hidden t)) :props (list :bed (make-instance 'yadfa-props:bed :name "Your bed" :description "Pouar wasn't sure what design to put on the sheets, so he decided to leave that up to the player's interpretation.") :dresser (make-instance 'prop :name "Dresser" :placeable t :description "Has all your clothes and diapers in here, until you take them out.") :checkpoint (make-instance 'yadfa-props:checkpoint) :washer (make-instance 'yadfa-props:washer :name "Washer" :description "A place to wash all the clothes that you've ruined") :diaper-dispenser (make-instance 'prop :name "Diaper Dispenser" :description "Provides diapers for the students here just in case they can't sit at their desks and hold it." :actions (list :get-diaper (make-action :documentation "Get a diaper from the dispenser" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (type prop prop) (ignore prop)) (check-type prop prop) (push (make-instance 'yadfa-items:diaper) (inventory-of (player-of *game*)))))))))
13,289
Common Lisp
.lisp
167
44.269461
524
0.415339
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
f3067482935f909814b436519bf6767b2754437710ef134dd1bab01fce8a521f
15,597
[ -1 ]
15,598
secret-underground.lisp
pouar_yadfa/data/map/secret-underground.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 secret-underground) :name "Secret Underground" :description "You see several warp pipes in here going to various places" :enter-text "You're wandering around in the secret underground" :warp-points (list 'home '(0 1 0 home) 'ironside '(2 0 0 ironside) 'bandits-domain '(-3 21 0 bandits-domain))) (ensure-zone (0 1 0 secret-underground) :name "Secret Underground Path" :description "A path" :enter-text "You're wandering around in the secret underground") (ensure-zone (-1 1 0 secret-underground) :name "Secret Underground Base" :description "A place where you can rest" :enter-text "You're wandering around in the secret underground" :placable t :props (list :changing-table (make-instance 'yadfa-props:automatic-changing-table) :chest (make-instance 'prop :name "Dresser" :placeable t :description "You can store your items here") :checkpoint (make-instance 'yadfa-props:checkpoint) :diaper-dispenser (make-instance 'prop :name "Diaper/Pullup Dispenser" :description "Provides an infinite supply of diapers and pullups" :actions (list :get-diaper (make-action :documentation "Get a diaper from the dispenser, pass :diaper to OUT-ITEM to get a diaper or :pullups to get pullups" :lambda '(lambda (prop &rest keys &key (out-item :diaper) &allow-other-keys) (declare (type prop prop) (type (or (eql :diaper) (eql :pullup)) out-item) (ignore prop)) (check-type prop prop) (check-type out-item '(or (eql :diaper) (eql :pullup))) (push (make-instance (cond ((eq out-item :diaper) 'yadfa-items:diaper) ((eq out-item :pullups) 'yadfa-items:pullups))) (inventory-of (player-of *game*))))))))) (ensure-zone (1 1 0 secret-underground) :name "Secret Underground Shop" :description "A shop where you can buy stuff. Be sure to buy a training potty for your base. You don't want to have an accident now do you?" :enter-text "You enter the shop" :props (list :shop (make-instance 'yadfa-props:shop 'yadfa-props:items-for-sale '((yadfa-props:pet-bed) (yadfa-props:training-potty)))))
4,015
Common Lisp
.lisp
48
42.791667
195
0.391228
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
d41afad1771e5b9a7b0aee5c35877274cc17d26560e0f915dcb29e90947c4370
15,598
[ -1 ]
15,599
pyramid.lisp
pouar_yadfa/data/map/pyramid.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 yadfa-zones:pyramid) :name "Pyramid Entrance" :description "You're at the pyramid entrance" :must-wear 'pyramid :must-not-wear 'pyramid :must-wear* 'pyramid :must-not-wear* 'pyramid) (ensure-zone (1 0 0 yadfa-zones:pyramid) :name "Pyramid Hall" :description "You're at the pyramid entrance" :must-wear 'pyramid :must-not-wear 'pyramid :must-wear* 'pyramid :must-not-wear* 'pyramid :events '(yadfa-events:pyramid-puzzle-1))
725
Common Lisp
.lisp
17
31.705882
86
0.567797
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
4e2bee3df033705bb309dddf32880e79ac4c727d2f01a148f9940ea89269e16e
15,599
[ -1 ]
15,600
pirates-cove.lisp
pouar_yadfa/data/map/pirates-cove.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 pirates-cove) :name "Pirate's Cove Entrance" :description "The entrance to Pirate's Cove" :enter-text "You're inside Pirate's Cove" :enemy-spawn-list (list '(:chance 1/8 :enemies ((yadfa-enemies:diaper-pirate . (list :level (random-from-range 4 8))))))) (ensure-zone (0 1 0 pirates-cove) :name "Pirate's Cove" :description "Where a bunch of pirates live" :enter-text "You're inside Pirate's Cove" :enemy-spawn-list (list '(:chance 1/8 :enemies ((yadfa-enemies:diaper-pirate . (list :level (random-from-range 4 8))))))) (ensure-zone (0 2 0 pirates-cove) :name "Pirate's Cove" :description "Where a bunch of pirates live" :enter-text "You're inside Pirate's Cove" :enemy-spawn-list (list '(:chance 1/8 :enemies ((yadfa-enemies:diaper-pirate . (list :level (random-from-range 4 8))))))) (ensure-zone (0 3 0 pirates-cove) :name "Pirate's Cove" :description "Where a bunch of pirates live" :enter-text "You're inside Pirate's Cove" :events '(yadfa-events:pirates-cove-1) :enemy-spawn-list (list '(:chance 1/8 :enemies ((yadfa-enemies:diaper-pirate . (list :level (random-from-range 4 8))))))) (ensure-zone (1 0 0 pirates-cove) :name "Pirate's Cove Lighthouse" :description "A lighthouse" :enter-text "You're inside Pirate's Cove" :enemy-spawn-list (list '(:chance 1/8 :enemies ((yadfa-enemies:diaper-pirate . (list :level (random-from-range 4 8))))))) #.`(progn ,@(iter (for i from 0 to 10) (collect `(ensure-zone (1 0 ,i pirates-cove) :name "Pirate's Cove Lighthouse" :description "A lighthouse" :enter-text "You're inside Pirate's Cove" :stairs (list ,@(typecase i ((eql 0) '(:up)) ((eql 10) '(:down)) (t '(:up :down)))) :enemy-spawn-list '((:chance 1/8 :enemies ((yadfa-enemies:diaper-pirate . (list :level (random-from-range 4 8)))))) ,@(when (= i 10) '(:events '(yadfa-events:pirates-cove-2)))))))
3,070
Common Lisp
.lisp
50
37.62
122
0.441722
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
5f57015cc01975b81796bd7645b086a9db0f8912c99240ecdfb0d55b19effe01
15,600
[ -1 ]
15,601
peachs-castle-wannabe.lisp
pouar_yadfa/data/map/peachs-castle-wannabe.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 peachs-castle-wannabe) :name "Castle Entrance" :description "The entrance to some crappy version of Peach's Castle" :enter-text "You're at the castle entrance" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :warp-points (list 'silver-cape '(6 11 0 silver-cape))) (ensure-zone (0 -1 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wondering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :props (list :princess (make-instance 'prop :name "Princess T̶o̶a̶d̶s̶t̶o̶o̶l̶ D̶a̶i̶s̶y̶ Peach" :description "The princess of this castle" :actions (list :talk (make-action :documentation "Talk to the princess" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (ignore prop keys)) (cond ((finished-events '(yadfa-events:got-all-shine-stars-1)) (write-line "Peach: You got all the Shine Stars")) ((<= (list-length (filter-items (inventory-of (player-of *game*)) 'yadfa-items:shine-star)) 0) (write-line "Peach: The Shine Stars keep peace and harmony throughout the land, but Bowser has stolen them and is causing discord and chaos and you need to go find them and bring them back") (format nil "~a: Seriously? Is that the best plot Pouar could possibly come up with for this quest?" (name-of (player-of *game*)))) ((< (list-length (filter-items (inventory-of (player-of *game*)) 'yadfa-items:shine-star)) 5) (format nil "Peach: You still have ~d shine stars to collect, hurry before the player gets bored of this stupid quest." (- 5 (list-length (filter-items (inventory-of (player-of *game*)) 'yadfa-items:shine-star))))) (t (write-line "Peach: You got all the Shine Stars, have a MacGuffin for putting up with this crappy quest") (trigger-event 'yadfa-events:got-all-shine-stars-1))))))))) (ensure-zone (0 -2 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :up) :direction-attributes (list :east (list :hidden t) :west (list :hidden t))) (ensure-zone (0 -2 1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :down)) (ensure-zone (0 -3 1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe) (ensure-zone (-1 -3 1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe) (ensure-zone (1 -3 1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe) (ensure-zone (-1 -4 1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :direction-attributes (list :east (list :hidden t) 'painting (list :exit-text "BaBaBa-BaBa-Ba Letsago")) :warp-points (list 'painting '(0 0 0 peachs-castle-wannabe:pokemon-area))) (ensure-zone (1 -4 1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :direction-attributes (list :west (list :hidden t) 'painting (list :exit-text "BaBaBa-BaBa-Ba Letsago")) :warp-points (list 'painting '(0 0 0 peachs-castle-wannabe:blank-area))) (ensure-zone (-1 -1 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe) (ensure-zone (1 -1 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe) (ensure-zone (-1 -2 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :down) :direction-attributes (list :west (list :hidden t) :east (list :hidden t))) (ensure-zone (1 -2 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :down) :direction-attributes (list :east (list :hidden t) :west (list :hidden t))) (ensure-zone (-1 -2 -1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :up)) (ensure-zone (1 -2 -1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :up)) (ensure-zone (-2 -1 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe) (ensure-zone (2 -1 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe) (ensure-zone (-2 -2 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :direction-attributes (list :east (list :hidden t) 'painting (list :exit-text "BaBaBa-BaBa-Ba Letsago")) :warp-points (list 'painting '(0 0 0 peachs-castle-wannabe:race-area))) (ensure-zone (2 -2 0 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :direction-attributes (list :west (list :hidden t) 'painting (list :exit-text "BaBaBa-BaBa-Ba Letsago")) :warp-points (list 'painting '(0 0 0 peachs-castle-wannabe:thwomp-area))) (ensure-zone (0 -2 -1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :down) :props (list :sign (make-instance 'prop :name "Sign" :description "Notice: Due to a koopa making a mess on the floor because we can't be fucked to install toilets, all koopas will be required to wear these leak proof shells because they're cheaper than diapers and hold a lot more. They will be allowed to the underground pipes once a month for emptying. The princess and Bowser on the other hand will be allowed to wear diapers because as royalty we deserve to live in comfort dammit."))) (ensure-zone (0 -1 -1 peachs-castle-wannabe) :name "Castle Hallway" :description "Some crappy version of Peach's Castle" :enter-text "You're wandering around the castle" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :stairs (list :down) :direction-attributes (list 'painting (list :exit-text "BaBaBa-BaBa-Ba Letsago")) :warp-points (list 'painting '(0 0 0 peachs-castle-wannabe:eggman-area))) (ensure-zone (0 0 0 peachs-castle-wannabe:race-area) :name "Race Area Map" :description "Race Area Map" :enter-text "You're wandering around the level" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :events '(yadfa-events:enter-race-area-1) :props (list :truck (make-instance 'prop :name "Truck" :description "It's that truck from Big Rigs: Over The Road Racing. Stop expecting it to move, it's never going to happen."))) (ensure-zone (0 -1 0 peachs-castle-wannabe:race-area) :name "Race Area" :description "Race Area" :enter-text "You're wandering around the level" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :events '(yadfa-events:win-race-area-1) :warp-points (list 'back-to-castle '(-2 -2 0 peachs-castle-wannabe)) :props (list :truck (make-instance 'prop :name "Truck" :description "It's that truck from Big Rigs: Over The Road Racing. Stop expecting it to move, it's never going to happen."))) (ensure-zone (0 0 0 peachs-castle-wannabe:thwomp-area) :name "Thwomp Area" :description "Thwomp Area" :enter-text "You're wandering around the level" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :events '(yadfa-events:enter-thwomp-area-1)) (ensure-zone (0 -1 0 peachs-castle-wannabe:thwomp-area) :name "Thwomp Area" :description "Thwomp Area" :enter-text "You walk around the thwomp and move to the north" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :warp-points (list 'back-to-castle '(2 -2 0 peachs-castle-wannabe)) :events '(yadfa-events:win-thwomp-area-1)) (ensure-zone (0 0 0 peachs-castle-wannabe:pokemon-area) :name "Pokémon Area" :description "Pokémon Area" :enter-text "You're wandering around the level" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :events '(yadfa-events:enter-pokemon-area-1) :warp-points (list 'back-to-castle '(-1 -4 1 peachs-castle-wannabe))) (ensure-zone (0 0 0 peachs-castle-wannabe:blank-area) :name "Pokémon Area" :description "Pokémon Area" :enter-text "You're wandering around the level" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :events '(yadfa-events:enter-blank-area-1) :warp-points (list 'back-to-castle '(1 -4 1 peachs-castle-wannabe))) (ensure-zone (0 0 0 peachs-castle-wannabe:eggman-area) :name "Eggman Area" :description "Eggman Area" :enter-text "You're wandering around the level" :can-potty 'can-potty-peachs-castle-wannabe :potty-trigger 'potty-trigger-peachs-castle-wannabe :events '(yadfa-events:enter-eggman-area-1) :warp-points (list 'back-to-castle '(0 -1 -1 peachs-castle-wannabe)))
15,732
Common Lisp
.lisp
247
45.8583
464
0.56766
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b0fe1a36525911e4c344911aa148961b0179f532ee26fc1898b6513f053c037e
15,601
[ -1 ]
15,602
silver-cape.lisp
pouar_yadfa/data/map/silver-cape.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) #.`(progn ,@(iter (for i from 0 to 20) (collect `(ensure-zone (0 ,i 0 silver-cape) :name "Silver Cape Street" :description "A busy street with various furries moving back and forth" :enter-text "You enter the street" :warp-points ,(when (= i 0) '(list 'rpgmaker-dungeon '(0 5 0 rpgmaker-dungeon))) ,@(cond ((= i 7) '(:direction-attributes (list :east (list :hidden t))))) ,@(when (= i 0) '(:events '(yadfa-events:enter-silver-cape-1 yadfa-events:secret-underground-pipe-silver-cape)))))) ,@(iter (for i from -10 to 10) (unless (= i 0) (collect `(ensure-zone (,i 10 0 silver-cape) :name "Silver Cape Street" :description "A busy street with various furries moving back and forth" :enter-text "You enter the street"))))) (ensure-zone (-1 6 0 silver-cape) :name "Silver Cape Navy HQ Entrance" :description "The entrance to Navy HQ." :enter-text "You're inside Navy HQ. The navy here seems to mostly consist of various aquatic creatures. They're mostly potty trained but still wear pullups just in case they don't make it in time, or if they don't want to hold it any longer. Due to pullups having a lower capacity than diapers, some of them supplement pullups with stuffers.") (ensure-zone (-2 6 -1 silver-cape) :name "Silver Cape Jail" :description "The jail beneath Navy HQ" :enter-text "You're inside Navy HQ" :locked t :stairs (list :up) :events '(yadfa-events:get-location-to-pirate-cove-1)) (ensure-zone (-2 6 0 silver-cape) :name "Silver Cape Navy HQ Lobby" :description "The lobby of Navy HQ" :stairs (list :down) :enter-text "You're inside Navy HQ. A guard doing a potty dance in a soggy pullup is guarding the entrance to the Jail underneath" :props (list :guard (make-instance 'prop :name "Dolphin Navy Guard" :description "The dolphin is hopping around while holding the front of his soggy pullups squishing with each hop" :actions (list :talk (make-action :documentation "Talk to the guard" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (type prop prop) (ignore prop)) (check-type prop prop) (write-line "Dolphin: Welcome to navy HQ") (format t "~a: Why don't you go to the bathroom and change your pullups?~%" (name-of (player-of *game*))) (write-line "Dolphin: I'm not allowed to go to the bathroom during my shift and if I leak again they'll put me back in diapers and put me in the nursery.") (format t "~a: Ok~%" (name-of (player-of *game*))) (setf (getf-action-from-prop (position-of (player-of *game*)) :guard :tickle) (make-action :documentation "Tickle the dolphin" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (type prop prop) (ignore prop)) (write-line "Dolphin: ACK!! NO!! PLEASE!!! DON'T!!!") (write-line "*The dolphin giggles and thrashes about then leaves a puddle on the floor*") (write-line "*One of the Navy orcas take notice and crinkles over*") (write-line "Orca: Looks like the baby dolphin still hasn't learned to not leave puddles everywhere") (write-line "Dolphin: I'm not a baby!!!") (write-line "Orca: Says the baby in leaky pullups. Since you keep leaving puddles, we're putting you back in diapers.") (write-line "*The Orca lays the dolphin on the floor*") (write-line "Dolphin: Please don't change me here!!! Everyone can see me!!!!!") (write-line "*The Orca ignores his pleas and changes his soggy pullups and puts him in a thick diaper then stands him back up. The diaper is so thick that his legs are forced apart. The dolphin hides his face in embarrassment as he is escorted to a nursery*") (write-line "*The Jail beneath the cell is now unguarded and can be entered*") (setf (lockedp (get-zone '(-2 6 -1 silver-cape))) :nil (enter-text-of (get-zone (-2 6 0 silver-cape))) "You're inside Navy HQ.") (remf (get-props-from-zone (position-of (player-of *game*))) :guard)))) (setf (getf-action-from-prop (position-of (player-of *game*)) :guard :give-pad) (make-action :documentation "Give the dolphin a stuffer so he can go without making a puddle" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (type prop prop) (ignore prop)) (block nil (let ((a (iter (for i in (inventory-of (player-of *game*))) (when (and (typep i 'stuffer) (<= (sogginess-of i) 0)) (collect i))))) (unless a (write-line "You don't have a clean stuffer to give her") (return)) (write-line "*You hand the dolphin a stuffer*") (format t "~a: Here, you might want this~%" (name-of (player-of *game*))) (write-line "Dolphin: I'm no infant. I can hold it in.") (write-line "*The dolphin panics as his bladder leaks a little*") (write-line "Dolphin: OK, OK, I'll take them.") (write-line "*The dolphin quickly inserts the stuffer into his pullups and floods himself*") (write-line "Dolphin: Don't tell anyone about this incident and I'll let you through") (write-line "*The Jail beneath can now be entered*") (removef (inventory-of (player-of *game*)) (car a)) (setf (lockedp (get-zone '(-2 6 -1 silver-cape))) :nil (enter-text-of (get-zone (-2 6 0 silver-cape))) "You're inside Navy HQ." (actions-of (getf (get-props-from-zone (position-of (player-of *game*))) :guard)) (list :talk (make-action :documentation "Talk to the guard" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (type prop prop) (ignore prop)) (write-line "Dolphin: Welcome to navy HQ")))) (description-of (getf (get-props-from-zone (position-of (player-of *game*))) :guard)) "A dolphin wearing pullups")))))))))))) (ensure-zone (1 5 0 silver-cape) :name "Silver Cape Pokémon Center" :description "A place to heal your Pokémon" :enter-text "You enter the street" :direction-attributes (list :south (list :hidden t)) :props (list :magic-healing-machine (make-instance 'prop :name "Magic Healing Machine" :description "Heal your Pokémon here" :actions (list :use (make-action :documentation "Heal your Pokémon" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (type prop prop) (ignore prop)) (check-type prop prop) (format t "~a~%" "https://youtu.be/wcg5n2UVMss?t=134") (setf (health-of user) (calculate-stat user :health)) (setf (energy-of user) (calculate-stat user :energy)))))))) (ensure-zone (1 6 0 silver-cape) :name "Quadruple Bypazz" :description "The local fastfood joint" :enter-text "You enter the street" :direction-attributes (list :north (list :hidden t)) :props (list :register (make-instance 'prop :name "Register" :description "Order Here" :actions (list :talk (make-action :documentation "Talk to the cashier" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (type prop prop) (ignore prop)) (check-type prop prop) (write-line "Cashier: Welcome To The Quadruple Bypazz. We recently to moved to automated kiosks for placing your orders, since that is now all the rage nowadays, so we got one designed by the IRS, written in IBM 7074 assembly of course. What you do is you take this form and fill out your order. You fill in your name and payment method, your order number and internal serial number (cause our new automated order system is too crappy to figure this out on its own) credit/debit card information (cause our new automated order system is too crappy to get this from the card reader) and the food you want to order and its prices and sales tax (cause our new automated order system is too crappy to get the menu and pricing information out of it). You then mail this form to our main HQ where we'll manually enter it into the system by hand and you should get your food in about 3 weeks.") (write-line "*You decide ordering isn't worth the hassle*"))))))) (ensure-zone (1 7 0 silver-cape) :name "Bathroom Door" :description "It's always occupied so nyah" :direction-attributes (list :west (list :hidden t)) :enter-text '(lambda () (cond ((>= (bladder/contents-of (player-of *game*)) (bladder/potty-dance-limit-of (player-of *game*))) (alexandria:random-elt '("One of the diapered raccoon bandits waddles by you crinkling clutching the front of his diaper and scurries into the bathroom and locks the door. You groan while doing a potty dance in response." "An orca in pullups rushes by you clutching the front of his pullups and runs into the bathroom and locks the door. You groan while doing a potty dance in response." "A diapered raccoon bandit is whining hopping from foot to foot in front of the locked bathroom door holding the front of his diaper waiting for it to open until he floods his diapers, then waddles away in embarrassment. You nearly piddle yourself from the sound of him piddling." "You see a diapered skunk in front of the locked bathroom door with a look of relief on his face flooding his diapers. You're almost jealous of him." "You head to the bathroom then groan while doing a potty dance when you find that the door is locked." #.(format nil "You see a diapered skunk leaking all over in front of the locked bathroom door with a look of relief on his face flooding his already overflowing diapers and leaving a puddle on the floor.~%~%Diapered Raccoon Bandit holding his nose with both paws: Can you please go be stinky somewhere else?")))) ((>= (bowels/contents-of (player-of *game*)) (bowels/potty-dance-limit-of (player-of *game*))) (alexandria:random-elt '("One of the diapered raccoon bandits waddles by you crinkling clutching the front of his diaper and scurries into the bathroom and locks the door. You groan while doing a potty dance in response." "An orca in pullups rushes by you clutching the front of his pullups and runs into the bathroom and locks the door. You groan while doing a potty dance in response." "A diapered raccoon bandit waiting in front of the bathroom door involuntarily squats down and messes his pamps, then waddles away in embarrassment. You nearly mess yourself from the sound of him messing." "You see a diapered skunk in front of the locked bathroom door squatting down and filling his diapers. You're almost jealous of him." "You head to the bathroom then groan while doing a potty dance when you find that the door is locked." #.(format nil "You see a diapered skunk leaking all over in front of the locked bathroom door squatting down and filling his already overflowing diapers and leaving a mess on the floor.~%~%Diapered Raccoon Bandit holding his nose with both paws: Can you please go be stinky somewhere else?")))) (t (alexandria:random-elt '("One of the diapered raccoon bandits waddles by you crinkling clutching the front of his diaper and scurries into the bathroom and locks the door." "An orca in pullups rushes by you clutching the front of his pullups and runs into the bathroom and locks the door." "A diapered raccoon bandit is whining hopping from foot to foot in front of the locked bathroom door holding the front of his diaper waiting for it to open until he floods his diapers, then waddles away in embarrassment." "A diapered raccoon bandit waiting in front of the bathroom door involuntarily squats down and messes his pamps, then waddles away in embarrassment." "You're standing in front of a locked bathroom door.")))))) (ensure-zone (0 21 0 silver-cape) :name "Silver Cape Dock" :description "A Dock that heads to the ocean" :enter-text "You enter the street" :warp-points (list :your-ship '(-1 6 0 yadfa-zones:your-ship))) (ensure-zone (-6 9 0 silver-cape) :name "Silver Cape Recycling Center" :description "Welcome To Silver Cape Recycling Center. We take all your crap, send it to a recycling plant across the country in a truck belching smoke and pollution, process your crap to turn it into less quality crap in machines belching more smoke and pollution, stockpile it and beg people to buy it, then send it all to ~a's garbage collector. Think of it as a more expensive and less environmentally friendly way to throw your stuff away." :enter-text "Welcome To Silver Cape Recycling Center. We take all your crap, send it to a recycling plant across the country in a truck belching smoke and pollution, process your crap to turn it into less quality crap in machines belching more smoke and pollution, stockpile it and beg people to buy it, then send it all to ~a's garbage collector. Think of it as a more expensive and less environmentally friendly way to throw your stuff away." :props (list :recycling-bin (make-instance 'prop :name "Magic Recycling Bin" :description "Throw your crap here and pretend it gets recycled into itself. Use the :TOSS action instead of YADFA-WORLD:PLACE because this game's \"engine\" is too stupid to figure out what to do with it otherwise." :actions (list :toss (make-action :documentation "Toss your items" :lambda '(lambda (prop &rest keys &key items &allow-other-keys) (declare (type prop prop) (type list items) (ignore keys)) (check-type prop prop) (check-type items list) (block lambda (let ((items (sort (remove-duplicates items) #'<))) (setf items (iter (generate i in items) (for j in (inventory-of (player-of *game*))) (for k upfrom 0) (when (first-iteration-p) (next i)) (when (= k i) (collect j) (next i)))) (unless items (format t "Those items aren't valid") (return-from lambda)) (iter (for i in items) (when (not (tossablep i)) (format t "To avoid breaking the game, we don't accept your ~a~%~%" (name-of i)) (return-from lambda)) (iter (for i in items) (format t "You toss your ~a into the bin and pretend you're saving the planet~%" (name-of i))) (alexandria:deletef (inventory-of (player-of *game*)) items :test (lambda (o e) (member e o)))))))))))) (ensure-zone (6 11 0 silver-cape) :name "To Peach's Castle" :description "Path to a crappy version of Peach's Castle" :enter-text "You're at the entrance to some castle" :warp-points (list 'peachs-castle-wannabe '(0 0 0 peachs-castle-wannabe))) (ensure-zone (-1 14 0 silver-cape) :name "Silver Cape Launch Pad" :description "You're at the launch pad" :enter-text "Come one coma all to a trip to the Candle Carnival. An amusement park in the sky based on a dream Pouar had. For some reason, it looked a lot better in the dream. Still under construction. Use the rocket over there to fly there." :warp-points (list 'rocket '(0 0 0 candle-carnival)) :direction-attributes (list 'rocket (list :exit-text "You fly over to Candle Carnival.")))
26,202
Common Lisp
.lisp
225
61.982222
960
0.404898
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
abf1c82bd205cc5cc41fc0587c2931b20fc904bc0b1da2885355545d0968dbe2
15,602
[ -1 ]
15,603
haunted-forest.lisp
pouar_yadfa/data/map/haunted-forest.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 haunted-forest) :name "Haunted Forest Entrance" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You enter the haunted forest" :events '(yadfa-events:secret-underground-pipe-haunted-forest) :warp-points (list 'rpgmaker-dungeon '(5 0 0 rpgmaker-dungeon))) (ensure-zone (0 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (1 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (-1 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :west (list :hidden t))) (ensure-zone (-2 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :east (list :hidden t))) (ensure-zone (-2 0 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (-1 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :west (list :hidden t) :north (list :hidden t))) (ensure-zone (-2 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :east (list :hidden t))) (ensure-zone (-2 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (-1 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :south (list :hidden t))) (ensure-zone (0 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (1 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (1 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (2 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :south (list :hidden t))) (ensure-zone (1 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (2 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :north (list :hidden t))) (ensure-zone (2 0 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (3 0 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (3 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (3 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (3 -4 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (3 -5 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (5 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :east (list :hidden t))) (ensure-zone (6 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :east (list :hidden t))) (ensure-zone (6 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're in front of a haunted house" :enemy-spawn-list 'haunted-forest :direction-attributes (list :west (list :hidden t) :south (list :hidden t) :east (list :hidden t) 'haunted-house (list :exit-text "You enter the haunted house")) :events '(yadfa-events:secret-underground-pipe-haunted-house) :warp-points (list 'haunted-house '(0 0 0 haunted-house))) (ensure-zone (5 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (5 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (6 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :north (list :hidden t))) (ensure-zone (7 -1 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) (ensure-zone (7 -2 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :west (list :hidden t))) (ensure-zone (7 -3 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest :direction-attributes (list :west (list :hidden t))) (ensure-zone (7 -4 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest) #.`(progn ,@(iter (for i from 3 to 7) (collect `(ensure-zone (,i -5 0 haunted-forest) :name "Haunted Forest" :description "You're in a strange forest. Spooky sounds and scary eyes all around." :enter-text "You're wondering around the haunted forest" :enemy-spawn-list 'haunted-forest))))
11,188
Common Lisp
.lisp
188
46.712766
124
0.616545
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
3cd6f8c2b26261d901a19045dae9cfb9980ef35fad6a3dbaea7f74676aeffd38
15,603
[ -1 ]
15,604
bandits-domain.lisp
pouar_yadfa/data/map/bandits-domain.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) #.`(progn ,@(iter (for i from 10 to 20) (collect `(ensure-zone (0 ,i 0 bandits-domain) :name "Bandit's Way" :description "A path filled with bandits" :enter-text "You follow the path" :warp-points ,(when (= i 10) '(list 'ironside '(2 0 0 ironside))) :enemy-spawn-list 'bandits-way))) ,@(iter (for i from -1 downto -10) (collect `(ensure-zone (,i 21 0 bandits-domain) :name "Bandit's Town" :description "A town run by the Raccoon Bandits" :enter-text "You're wander around Bandit's Town" ,@(when (= i -3) '(:events '(yadfa-events:enter-bandits-shop-2))))))) (ensure-zone (-3 22 0 bandits-domain) :name "Bandit's Shop" :description "A local shop" :enter-text "You enter the Bandit's Shop" :must-wear (cons 'padding '(lambda (user) (declare (ignore user)) (write-line "That area is a diapers only pants free zone. Pants are strictly prohibited and padding is mandatory.") nil)) :must-wear* (cons 'padding '(lambda (user) (declare (ignore user)) (write-line "This area is a diapers only pants free zone. Pants are strictly prohibited and padding is mandatory.") nil)) :must-not-wear (cons '(and closed-bottoms (not incontinence-product)) '(lambda (user) (declare (ignore user)) (write-line "That area is a diapers only pants free zone. Pants are strictly prohibited and padding is mandatory.") nil)) :must-not-wear* (cons '(and closed-bottoms (not incontinence-product)) '(lambda (user) (declare (ignore user)) (write-line "This area is a diapers only pants free zone. Pants are strictly prohibited and padding is mandatory.") nil)) :can-potty '(lambda (prop &key wet mess pants-down user) (declare (ignorable prop wet mess pants-down user)) (not (when (or pants-down (not (filter-items (wear-of user) 'closed-bottoms))) (format t "*The shopkeeper baps ~a on the nose with a newspaper before ~a gets the chance to go*~%" (name-of user) (name-of user)) (format t "Shopkeeper: Bad ~a, no going potty inside~%" (species-of user)) (when (or (>= (bladder/contents-of user) (bladder/potty-dance-limit-of user)) (>= (bowels/contents-of user) (bowels/potty-dance-limit-of user)))) (format t "*~a whines and continues ~a embarrassing potty dance while the shopkeeper watches in amusement*~%~%" (name-of user) (if (malep user) "his" "her")) t))) :potty-trigger '(lambda (had-accident user) (block nil (when (not (filter-items (wear-of user) 'incontinence-product)) (format t "*The shopkeeper baps ~a on the nose with a newspaper*~%" (name-of user)) (format t "Shopkeeper: Bad ~a, no going potty inside~%" (species-of user))) (when (or (getf (car had-accident) :popped) (getf (cdr had-accident) :popped)) (write-string #.(with-output-to-string (s) (format s "*The shopkeeper falls over laughing with his diaper clearly exposed from under his tunic, then gets an embarrassed look on his face when he floods his diaper from the laughter, which is incredibly obvious from the wetness indicator changing color*~%~%") (format s "*A random raccoon in the shop records the shopkeeper flooding his pamps then uploads it to the internet*~%~%"))) (trigger-event 'yadfa-events:shopkeeper-floods-himself-1)) (when (> (getf (car had-accident) :leak-amount) 0) (format t "*The shopkeeper laughs at ~a's misfortune*~%" (name-of user)) (return)) (when (> (getf (cdr had-accident) :leak-amount) 0) (format t "Shopkeeper: Bad ~a!!! No going potty on the floor!!!~%~%" (name-of user)) (apply #'format t "*The Shopkeeper spanks ~a through ~a messy diaper and makes ~a sit in it in timeout*~%" (name-of user) (if (malep user) '("his" "him") '("her" "her"))) (return)) (when (> (getf (car had-accident) :wet-amount) 0) (format t "Shopkeeper: Aww, is ~a using ~a diapers like a baby?~%" (name-of user) (if (malep user) "his" "her")) (return)) (when (> (getf (cdr had-accident) :mess-amount) 0) (format t "Shopkeeper: Looks like ~a made a stinky!!!~%~%" (name-of user)) (format t "*The Shopkeeper mushes ~a's messy diaper who quickly jerks away and then grabs the back of ~a diaper struggling to unmush it*~%" (name-of user) (if (malep user) "his" "her")) (return)))) :props (list :shop (make-instance 'yadfa-props:shop :actions (list :ask-for-bathroom (make-action :documentation "Ask the raccoons if you can use the bathroom." :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (ignore prop keys)) (write-string #.(with-output-to-string (s) (format s "Diapered Raccoon Bandit Shop Owner: Sorry, only I'm allowed in there. Everyone else can just use their diapers. Isn't that right mushbutt?~%~%") (format s "*The Shop Owner slaps the back of the Rookie's diaper*~%~%") (format s "*Rookie yelps then grabs the back of his diaper and struggles to unmush it*~%~%") (format s "*The Shop Owner laughs*~%~%") (format s "Rookie Raccoon: Can I please get a diaper change now?~%~%") (format s "Shop Owner: Keep asking me that and I'll make you sit in it in timeout again.~%~%") (format s "Rookie Raccoon: NO! PLEASE! I'LL BE GOOD!~%~%"))))) :ask-why-youre-allowed-to-shop (make-action :documentation "Ask the raccoons why you're allowed to shop here without the gang attacking you" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (ignore prop keys)) (format t "~a: You know how the gang seems to attack me everywhere I show up?~%~%" (name-of (player-of *game*))) (format t "Shop Owner: Yeah?~%~%") (format t "~a: Well how come they're letting me shop here without attacking me?~%~%" (name-of (player-of *game*))) (format t "Shop Owner: Because money, stupid."))) :ask-what-they-do-with-sold-items (make-action :documentation "Ask the raccoons what they do with the random crap you sell them" :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (ignore prop keys)) (format t "~a: So what the hell do you do with all the random crap we sell you~%~%" (name-of (player-of *game*))) (format t "Shop Owner: We dump it all on ~a's garbage collector. Yes, I know, buying all this crap only to throw it out is dumb. Blame Pouar for designing it this way." (lisp-implementation-type)))) :ask-why-this-shop-exists (make-action :documentation "Ask the raccoons why they need to sell items for profit instead of just stealing everything." :lambda '(lambda (prop &rest keys &key &allow-other-keys) (declare (ignore prop keys)) (format t "~a: So why do you even need this shop? Why not just steal everything?~%~%" (name-of (player-of *game*))) (write-line "Shop Owner: In case you haven't noticed, being stealthy enough to steal everything isn't all that easy when your diaper crinkles with each and every step you take. *crinkles and blushes*")))) 'yadfa-props:items-for-sale '((yadfa-items:gold-pacifier) (yadfa-items:recovering-pacifier) (yadfa-items:healing-pacifier) (yadfa-items:bandit-swimsuit) (yadfa-items:bandit-uniform-tunic) (yadfa-items:bandit-uniform-shirt) (yadfa-items:bandit-uniform-sports-bikini-top) (yadfa-items:monster-energy-drink) (yadfa-items:spiked-bottle-of-milk) (yadfa-items:bandit-diaper) (yadfa-items:bandit-adjustable-diaper) (yadfa-items:bandit-female-diaper) (yadfa-items:bandit-swim-diaper-cover) (yadfa-items:lower-bandit-swim-diaper-cover) (yadfa-items:female-bandit-swim-diaper-cover) (yadfa-items:gold-collar) (yadfa-items:ak47) (yadfa-items:box-of-7.62×39mm) (yadfa-items:pink-sword) (yadfa-items:toddler-dress) (yadfa-props:placable-bed))) :changing-table (make-instance 'yadfa-props:automatic-changing-table) :bed (make-instance 'yadfa-props:bed) :checkpoint (make-instance 'yadfa-props:checkpoint)) :events '(yadfa-events:enter-bandits-shop-1 yadfa-events:obtain-diaper-lock-1 yadfa-events:enter-bandits-shop-3 yadfa-events:get-warp-pipe-summoner-1)) (ensure-zone (-3 23 0 bandits-domain) :name "Bandit's Shop Bathroom" :description "CLOSED FOREVER!!!!! MUAHAHAHAHA!!!!" :locked t) (ensure-zone (-5 22 0 bandits-domain) :name "Bandit's Kennel" :description "A grungy looking kennel where the Raccoon Bandits keep their “pets”. Neglected so much that they literally forgot about their existence" :enter-text "You enter the kennel" :events '(yadfa-events:enter-bandits-kennel-1)) (ensure-zone (0 21 0 bandits-domain) :name "Bandit's Town Entrance" :description "The entrance to Bandit Town" :enter-text "You're at the entrance of Bandit Town" :warp-points (list 'home '(0 1 0 home)) :events '(yadfa-events:enter-bandits-village-1)) #.`(progn ,@(iter (for i from 22 to 30) (collect `(ensure-zone (0 ,i 0 bandits-domain) :name "Bandit's Town" :description "A town run by the Raccoon Bandits" :enter-text "You're wander around Bandit's Town")))) (ensure-zone (0 31 0 bandits-domain) :name "Bandit's Town" :description "A town run by the Raccoon Bandits" :enter-text "You see a sign that says \"To the south lies your generic RPG Maker Dungeon. Get ready for a mediocre adventure!!!! OOOOOOOOO!!!!" :warp-points (list 'rpgmaker-dungeon '(5 9 0 rpgmaker-dungeon)) :hidden t :events '(yadfa-events:secret-underground-pipe-rpgmaker-dungeon)) (ensure-zone (1 21 0 bandits-domain) :name "Bandit's Cove Dock" :description "The dock of Bandit's Cove" :enter-text "You're at a dock") #.`(progn ,@(let ((a ())) (iter (for y from 19 to 23) (alexandria:appendf a (iter (for x from 2 to 6) (collect `(ensure-zone (,x ,y 0 bandits-domain) :name "Bandit's Cove" :description "A cove filled with bandits" :enter-text "You're at a cove run by bandits" :enemy-spawn-list 'bandits-cove))))) a)) (ensure-zone (6 24 0 bandits-domain) :name "Bandit's Cave Entrance" :description "A mysterious cave" :enter-text "You enter the cave" :warp-points (list 'descend '(6 24 -2 bandits-domain))) (ensure-zone (6 24 -2 bandits-domain) :name "Bandit's Cave" :description "A mysterious cave" :enter-text "You enter the cave" :warp-points (list 'cave-entrance '(6 24 0 bandits-domain) 'descend '(6 24 -2 bandits-domain)) :events '(yadfa-events:decend-bandits-cave-1))
18,794
Common Lisp
.lisp
208
46.466346
317
0.383456
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
e84ff092b564ba702429cfec47725a5358b8046e776fb9d971c0d6f72d8b3530
15,604
[ -1 ]
15,605
home.lisp
pouar_yadfa/data/map/home.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (ensure-zone (0 0 0 home) :name "Bedroom" :description "Your house only has a bedroom and a bathroom. Because Pouar was too lazy to code you a real house." :enter-text "You enter your bedroom." :placable t :props (list :bed (make-instance 'yadfa-props:bed :name "Your bed" :description "Pouar wasn't sure what design to put on the sheets, so he decided to leave that up to the player's interpretation.") :dresser (make-instance 'prop :name "Dresser" :placeable t :description "Has all your clothes and diapers in here, until you take them out." :items ()) :checkpoint (make-instance 'yadfa-props:checkpoint))) (ensure-zone (1 0 0 home) :name "Bathroom" :description "Your bathroom" :enter-text "You enter the bathroom" :placable t :props (list :toilet (make-instance 'yadfa-props:toilet :name "Toilet" :description "You can use this so you don't wet or mess yourself") :cupboard (make-instance 'prop :name "Cupboard" :placeable t :description "A cupboard located on the sink" :items (list (make-instance 'yadfa-items:potion))) :washer (make-instance 'yadfa-props:washer :name "Washer" :description "A place to wash all the clothes that you've ruined"))) (ensure-zone (0 1 0 home) :name "Street" :description "Your typical suburban street. Some furries are driving in cars, some are walking, and some are riding on top of other furries treating them like a horse." :enter-text "You enter the street outside your house" :warp-points (list 'ironside '(0 0 0 ironside))) (ensure-zone (0 2 0 home) :name "Pool area" :description "A pool to go swimming in" :enter-text "You enter the pool area" :stairs (list :down)) (ensure-zone (0 2 -1 home) :name "Pool" :description "A pool" :enter-text "You dive in the pool" :stairs (list :up) :underwater t)
2,950
Common Lisp
.lisp
48
37.645833
181
0.468987
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
00c8fde3ff4507141ac0f990d6aaa2c2fc3926cdca1f9ee9506ce69880045ec2
15,605
[ -1 ]
15,606
allies.lisp
pouar_yadfa/data/epilog/allies.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-allies"; coding: utf-8-unix; -*- (in-package :yadfa-allies) (defunassert yadfa-world-commands:disown-adopted-enemies (&optional allies count) (allies (or list type-specifier) count (or null unsigned-byte)) (setf allies (typecase allies (null (accept-with-effective-frame (clim:accepting-values (*query-io* :resynchronize-every-pass t) (clim:accept `(clim:subset-alist ,(iter (for enemy in (allies-of *game*)) (when (typep (class-of enemy) 'adopted-enemy) (collect (cons (name-of enemy) enemy))))) :prompt "Enemies to disown" :stream *query-io* :view clim:+check-box-view+)))) (type-specifier (iter (for enemy in (allies-of *game*)) (for i upfrom 0) (when (and count (>= count i)) (finish)) (when (typep enemy `(and ,allies adopted-enemy)) (collect enemy)))) (list (iter (for enemy in (allies-of *game*)) (generate current in allies) (for index upfrom 0) (cond ((typep current '(not unsigned-byte)) (error "ENEMIES must be a list of unsigned-bytes")) ((and (eql index current) (typep enemy '(not adopted-enemy))) (let ((*package* (find-package :yadfa-user))) (error "ALLY at index ~d isn't an ~w" yadfa-allies::index 'yadfa-allies:adopted-enemy))) ((eql index current) (collect enemy) (next current))))))) (a:removef (allies-of *game*) allies :test (lambda (o e) (member e o))) (a:removef (team-of *game*) allies :test (lambda (o e) (member e o))))
2,330
Common Lisp
.lisp
37
36.945946
125
0.426952
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
4b0959f5e49f201896a4cd32b18394b8be6f8ebb14f23ec287f7b0fc7fe56181
15,606
[ -1 ]
15,607
items.lisp
pouar_yadfa/data/epilog/items.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*- (in-package :yadfa-items) (defmethod use-script ((item enemy-catcher) (user base-character) (target yadfa-enemies:catchable-enemy)) (cond ((>= (list-length (contained-enemies-of item)) (contained-enemies-max-length-of item)) (f:fmt t (name-of item) " can't hold anymore enemies" #\Newline #\Newline)) ((not (< (random 1.0l0) (* (catch-chance-multiplier-of item) (+ (catch-chance-delta-of item) (yadfa-enemies:catch-chance target))))) (f:fmt t "You failed to catch the " (name-of target) #\Newline #\Newline) (cond ((eq (device-health-of item) t) nil) ((<= (device-health-of item) 1) (alexandria:deletef (inventory-of (player-of *game*)) item :count 1)) (t (decf (device-health-of item))))) (t (f:fmt t "You caught the " (name-of target) #\Newline #\Newline) ;; prevent the enemy from going again during the battle (alexandria:deletef (enemies-of *battle*) target) (alexandria:deletef (turn-queue-of *battle*) target) (push target (contained-enemies-of item)) (unless (getf (special-actions-of item) :take-items) (setf (getf (special-actions-of item) :take-items) '(lambda (item user &key &allow-other-keys) (declare (ignore user)) (setf (inventory-of (player-of *game*)) (append (iter (for enemy in (contained-enemies-of item)) (dolist (item (inventory-of enemy)) (collect item)) (dolist (item (wear-of enemy)) (collect item)) (setf (inventory-of enemy) nil (wear-of enemy) nil)) (inventory-of (player-of *game*))))))) (unless (getf (special-actions-of item) :adopt-enemies) (setf (getf (special-actions-of item) :adopt-enemies) '(lambda (item user &allow-other-keys :enemies enemies) (if (iter (for i in (contained-enemies-of item)) (when (typep (class-of i) 'yadfa-enemies:adoptable-enemy) (return t))) (progn (setf enemies (typecase enemies (null (accept-with-effective-frame (clim:accepting-values (*query-io* :resynchronize-every-pass t) (setf enemies (clim:accept `(clim:subset-alist ,(iter (for enemy in (contained-enemies-of item)) (when (typep (class-of i) 'yadfa-enemies:adoptable-enemy) (collect (cons (name-of enemy) enemy))))) :prompt "Enemies to adopt" :stream *query-io* :view clim:+check-box-view+))))) (type-specifier (iter (for enemy in (contained-enemies-of item)) (when (typep i enemies) (collect i)))) (list (iter (for enemy in (contained-enemies-of item)) (generate current in enemies) (for index upfrom 0) (cond ((typep current '(not unsigned-byte)) (error "ENEMIES must be a list of unsigned-bytes")) ((eql index current) (collect enemy) (next current))))) (t (error "ENEMIES must either be a list of unsigned-bytes or a type specifier")))) (alexandria:removef (contained-enemies-of item) enemies :test (lambda (o e) (member e o))) (alexandria:appendf (allies-of *game*) (iter (for i in enemies) (write-line (yadfa-enemies:change-class-text i)) (collect (change-class i (get (class-name i) 'yadfa-enemies:change-class-target)))))) (format t "No enemies in there to adopt")))))))) (defmethod use-script ((item enemy-catcher) (user base-character) (target yadfa-enemies:ghost)) (f:fmt t "You failed to catch " (name-of target) #\Newline #\Newline) (cond ((eq (device-health-of item) t) nil) ((<= (device-health-of item) 1) (alexandria:deletef (inventory-of (player-of *game*)) item :count 1)) (t (decf (device-health-of item))))) (defmethod use-script ((item ghost-catcher) (user base-character) (target yadfa-enemies:ghost)) (cond ((>= (list-length (contained-enemies-of item)) (contained-enemies-max-length-of item)) (f:fmt t (name-of item) " can't hold anymore enemies" #\Newline #\Newline)) ((not (< (random 1.0l0) (* (catch-chance-multiplier-of item) (+ (catch-chance-delta-of item) (yadfa-enemies:catch-chance target))))) (f:fmt t "You failed to catch the " (name-of target) #\Newline #\Newline) (cond ((eq (device-health-of item) t) nil) ((<= (device-health-of item) 1) (alexandria:deletef (inventory-of (player-of *game*)) item :count 1)) (t (decf (device-health-of item))))) (t (f:fmt t "You caught the " (name-of target) #\Newline #\Newline) ;; prevent the enemy from going again during the battle (alexandria:deletef (enemies-of *battle*) target) (alexandria:deletef (turn-queue-of *battle*) target) (push target (contained-enemies-of item))))) (defunassert yadfa-battle-commands:catch-enemy (&optional (target 'yadfa-enemies:catchable-enemy) (item 'enemy-catcher)) (item type-specifier target (or unsigned-byte type-specifier)) "Catches an enemy using. @var{ITEM} which is a type specifier. @var{TARGET} is an index or type specifier of an enemy in battle or a type specifier" (let ((selected-item (find item (inventory-of (player-of *game*)) :test (lambda (type-specifier obj) (and (typep obj `(and enemy-catcher ,type-specifier)) (< (list-length (contained-enemies-of item)) (contained-enemies-max-length-of item)))))) (selected-target (let ((a (typecase target (unsigned-byte (nth target (enemies-of *battle*))) (type-specifier (find target (enemies-of *battle*) :test (lambda (type-specifier obj) (typep obj `(and yadfa-enemies:catchable-enemy ,type-specifier)))))))) (or a (progn (write-line "That target doesn't exist") (return-from yadfa-battle-commands:catch-enemy)))))) (cond ((not item) (format t "You don't have an item with that type specifier that can catch that enemy~%") (return-from yadfa-battle-commands:catch-enemy)) ((typep selected-target '(not yadfa-enemies:catchable-enemy)) (format t "That enemy can't be caught~%") (return-from yadfa-battle-commands:catch-enemy))) (process-battle :item selected-item :selected-target selected-target))) (defunassert yadfa-world-commands:loot-caught-enemies (&optional item) (item (or null unsigned-byte type-specifier)) "Loots the enemies you caught. @var{ITEM} is either a type specifier or an unsiged-byte of the item. Don't specify if you want to loot the enemies of all items" (cond ((null item) (iter (for item in (inventory-of *game*)) (when (typep item 'enemy-catcher) (funcall (coerce (action-lambda (getf (special-actions-of item) :take-items)) 'function) item (player-of *game*) :action :take-items)))) ((typep item 'unsigned-byte) (let* ((inventory-length (list-length (inventory-of (player-of *game*)))) (selected-item (and (< item inventory-length) (nth item (inventory-of (player-of *game*)))))) (cond ((>= item inventory-length) (f:fmt t "You only have " inventory-length " items" #\Newline)) ((not (typep selected-item 'enemy-catcher)) (f:fmt t "That item isn't an enemy catcher" #\Newline)) (t (funcall (coerce (action-lambda (getf (special-actions-of selected-item) :take-items)) 'function) selected-item (player-of *game*) :action :take-items))))) (t (let ((selected-item (find item (inventory-of *game*) :test (lambda (specifier item) (typep item `(and enemy-catcher ,specifier)))))) (if selected-item (funcall (coerce (action-lambda (getf (special-actions-of selected-item) :take-items)) 'function) selected-item (player-of *game*) :action :take-items) (f:fmt t "Either you don't have that item or it isn't an enemy catcher" #\Newline))))))
9,857
Common Lisp
.lisp
140
49.3
162
0.519625
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
cfaeb42dcffa3464593471c5eb7323b323d1d96b5f0543625ab041b458bd63ab
15,607
[ -1 ]
15,608
enemies.lisp
pouar_yadfa/data/epilog/enemies.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defmethod update-instance-for-different-class ((previous yadfa-enemies:raptor) (current yadfa-allies:raptor) &rest initargs &key &allow-other-keys) (declare (ignore initargs)) (call-next-method) (setf (skin-of current) :scales) (setf (tail-of current) '(:medium :scales)) (setf (wings-of current) '()) (setf (learned-moves-of current) '()) (iter (for i in '(yadfa-moves:watersport yadfa-moves:mudsport)) (pushnew (make-instance i) (moves-of current) :key 'type-of)) (when (bitcoins-per-level-of previous) (setf (bitcoins-of current) (* (bitcoins-per-level-of previous) (level-of previous))))) (defmethod update-instance-for-different-class ((previous yadfa-enemies:catchable-raccoon-bandit) (current yadfa-allies:diapered-raccoon-bandit) &rest initargs &key &allow-other-keys) (declare (ignore initargs)) (call-next-method) (setf (skin-of current) :fur) (setf (tail-of current) '(:medium :fur)) (setf (wings-of current) '()) (setf (learned-moves-of current) '()) (iter (for i in '(yadfa-moves:watersport yadfa-moves:mudsport)) (pushnew (make-instance i) (moves-of current) :key 'type-of)) (when (bitcoins-per-level-of previous) (setf (bitcoins-of current) (* (bitcoins-per-level-of previous) (level-of previous))))) (defmethod update-instance-for-different-class ((previous yadfa-enemies:diapered-kobold) (current yadfa-allies:diapered-kobold) &rest initargs &key &allow-other-keys) (declare (ignore initargs)) (call-next-method) (setf (skin-of current) :scales) (setf (tail-of current) '(:medium :scales)) (setf (wings-of current) '()) (setf (learned-moves-of current) '()) (iter (for i in '(yadfa-moves:watersport yadfa-moves:mudsport)) (pushnew (make-instance i) (moves-of current) :key 'type-of)) (when (bitcoins-per-level-of previous) (setf (bitcoins-of current) (* (bitcoins-per-level-of previous) (level-of previous)))))
2,030
Common Lisp
.lisp
35
54.6
183
0.708772
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
f3a20e122ce743de9d982d244264822196d69bc0822ff8d7e443dff95d8f76b5
15,608
[ -1 ]
15,609
blackjack.lisp
pouar_yadfa/data/epilog/blackjack.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-blackjack"; coding: utf-8-unix; -*- (in-package :yadfa-blackjack) (c:define-command-table game-commands) (c:define-command-table playing-commands :inherit-from (game-commands)) (c:define-command-table end-round-commands :inherit-from (game-commands)) (c:define-command-table end-game-commands :inherit-from (game-commands)) (defclass card () ((value :initform nil :type (or symbol fixnum) :initarg :value :accessor value-of) (suit :initform nil :type symbol :initarg :suit :accessor suit-of) (side :initform :up :type keyword :initarg :side :accessor side-of))) (defvar *back-card-pattern* (c:make-rectangular-tile (clim:make-pattern #2A((0 1) (1 0)) (list c:+red+ c:+white+)) 2 2)) (defvar *player-cards*) (defvar *ai-cards*) (defvar *deck*) (defvar *round*) (defvar *player-clothes*) (defvar *checkpoints*) (defvar *put-on-old-clothes*) (defgeneric print-potty (user checkpoint had-accident amount &key wear) (:method (user checkpoint had-accident amount &key wear) (declare (ignore wear)) t) (:method (user (checkpoint (eql :need-to-potty)) had-accident amount &key wear) (declare (ignore wear)) (format t "*~a crosses ~a legs~%*" (name-of user) (if (malep user) "his" "her"))) (:method (user (checkpoint (eql :potty-dance)) had-accident amount &key wear) (declare (ignore wear)) (format t "*~a does a potty dance in ~a seat*~%" (name-of user) (if (malep user) "his" "her"))) (:method (user (checkpoint (eql :potty-desparate)) had-accident amount &key wear) (declare (ignore wear)) (format t "*~a whines and does a potty dance in ~a seat*~%" (name-of user) (if (malep user) "his" "her"))) (:method (user (checkpoint (eql :lose)) had-accident (amount (eql :dribble)) &key (wear nil wear-p)) (declare (ignorable wear)) (format t "*~a gets up and runs to the bathroom*~%" (name-of user)) (apply 'wet :wetter user :force-wet-amount t :pants-down t (when wear-p `(:clothes ,wear)))) (:method (user (checkpoint (eql :lose)) had-accident (amount (eql :some)) &key wear) (declare (ignore wear)) (format t "*~a floods ~a pamps*~%" (name-of user) (if (malep user) "his" "her"))) (:method (user (checkpoint (eql :lose)) had-accident (amount (eql :all)) &key wear) (declare (ignore wear)) (format t "*~a floods ~a pamps*~%" (name-of user) (if (malep user) "his" "her"))) (:method ((user player) checkpoint had-accident amount &key wear) (declare (ignore wear))) (:method ((user player) (checkpoint (eql :need-to-potty)) had-accident amount &key wear) (declare (ignore wear)) (format t "*You need to pee*~%")) (:method ((user player) (checkpoint (eql :potty-dance)) had-accident amount &key wear) (declare (ignore wear)) (format t "*You start doing a potty dance in your seat*~%") (when (typep (ai-of c:*application-frame*) 'yadfa-enemies:diapered-raccoon-bandit) (format t "~a: What's wrong? Baby gotta potty?.~%" (name-of (ai-of c:*application-frame*))) (format t "~a: Notta baby.~%" (name-of user)) (format t "~a: Then try and keep your diapers dry.~%" (name-of (ai-of c:*application-frame*))))) (:method ((user player) (checkpoint (eql :potty-desparate)) had-accident amount &key wear) (declare (ignore wear)) (format t "*You're doing a potty dance in your seat like a 5 year old struggling to keep your pampers dry*~%") (when (typep (ai-of c:*application-frame*) 'yadfa-enemies:diapered-raccoon-bandit) (format t "*~a watches in amusement.*~%" (name-of (ai-of c:*application-frame*))))) (:method ((user player) (checkpoint (eql :lose)) had-accident (amount (eql :dribble)) &key wear) (format t "*A little dribbles out into your diapers. The dribbles then turn into floods and you completely soak your padding*~%") (wet :wetter user :force-wet-amount t :clothes wear) (when (typep (ai-of c:*application-frame*) 'yadfa-enemies:diapered-raccoon-bandit) (format t "~a: Yep, baby.~%" (name-of (ai-of c:*application-frame*))))) (:method ((user player) (checkpoint (eql :lose)) had-accident (amount (eql :some)) &key wear) (format t "*You get a look of embarrassment on your face as you flood your pamps*~%") (wet :wetter user :force-wet-amount t :clothes wear) (when (typep (ai-of c:*application-frame*) 'yadfa-enemies:diapered-raccoon-bandit) (format t "~a: Aww, baby went potty.~%" (name-of (ai-of c:*application-frame*))) (format t "*the ~a gives his diaper a proud pat showing that ~a's still dry.*~%" (name-of (ai-of c:*application-frame*)) (if (malep (ai-of c:*application-frame*)) "he" "she")) (when (eq (getf *checkpoints* (ai-of c:*application-frame*)) :potty-desparate) (format t "~a's proud smile quickly turns into an expression of embarrassment.~%" (name-of (ai-of c:*application-frame*))) (format t "~a: Uh oh~%" (name-of (ai-of c:*application-frame*))) (format t "*~a rushes to the bathroom holding the front of ~a diaper.*~%" (name-of (ai-of c:*application-frame*)) (if (malep (ai-of c:*application-frame*)) "his" "her")) (format t "*After using the bathroom ~a looks at ~a diaper and notices that ~a wet it a bit.*~%" (name-of (ai-of c:*application-frame*)) (if (malep (ai-of c:*application-frame*)) "his" "her") (if (malep (ai-of c:*application-frame*)) "he" "she")) (format t "~a: Eh, close enough.~%" (name-of (ai-of c:*application-frame*))) (format t "*~a puts the damp diaper back on*~%" (name-of (ai-of c:*application-frame*))))))) (declaim (type vector *player-cards* *ai-cards* *deck*) (type list *player-clothes*) (type (member :playing :end-game :end-round) *round*) (type boolean *put-on-old-clothes*)) (cc:define-conditional-application-frame game-frame () (:enable-commands (playing-commands) :disable-commands (end-game-commands end-round-commands)) ((ai :initform nil :initarg :ai :accessor ai-of)) (:command-table (game-frame :inherit-from (playing-commands end-game-commands end-round-commands))) (:pane (c:vertically () (c:make-clim-stream-pane :name 'game :scroll-bars nil :incremental-redisplay t :display-time :command-loop :display-function 'draw-game :width 640 :height 200 :max-height 300) (c:make-clim-stream-pane :name 'gadgets :scroll-bars nil :incremental-redisplay nil :background climi::*3d-normal-color* :display-time :command-loop :display-function 'draw-gadgets :width 640 :max-height 80) (c:make-clim-interactor-pane :display-time :command-loop :name 'int :width 1200)))) (defmethod c:run-frame-top-level ((frame game-frame) &key) (let ((*player-cards* (make-array 12 :fill-pointer 0 :initial-element nil :element-type '(or null card))) (*ai-cards* (make-array 12 :fill-pointer 0 :initial-element nil :element-type '(or null card))) (*deck* (make-array 48 :fill-pointer 48 :element-type 'card :initial-contents (iter (for value in '(2 3 4 5 6 7 8 9 :king :queen :jack :ace)) (dolist (suit '(:diamond :club :heart :spade)) (collect (make-instance 'card :value value :suit suit)))))) (*round* :playing) (*player-clothes* (list (make-instance 'yadfa-items:blackjack-uniform-diaper))) *checkpoints* *put-on-old-clothes*) (declare (special *player-cards* *player-clothes* *ai-cards* *checkpoints* *deck* *round*) (type vector *player-cards* *ai-cards* *deck*) (type list *player-clothes*) (type (member :playing :end-game :end-round) *round*) (type boolean *put-on-old-clothes*)) (handler-case (call-next-method) (c:frame-exit () (if *put-on-old-clothes* (push *player-clothes* (inventory-of (player-of *game*))) (progn (setf (inventory-of (player-of *game*)) (nconc (wear-of (player-of *game*)) (inventory-of (player-of *game*)))) (setf (wear-of (player-of *game*)) *player-clothes*))) (eq (getf *checkpoints* (ai-of frame)) :lose))))) (defmacro draw-bar (medium point stat &rest colors) `(multiple-value-bind (x y) (point-position ,point) (c:draw-rectangle* ,medium x y (+ x (* ,stat 400)) (+ y 15) :ink (cond ,@(iter (for i in colors) (collect `(,(car i) ,(intern (format nil "+~a+" (if (typep (car (last i)) 'cons) (caar (last i)) (car (last i)))) "CLIM")))))) (c:draw-rectangle* ,medium x y (+ x 400) (+ y 15) :filled nil) (setf (c:stream-cursor-position ,medium) (values (+ x 400) y)))) (defun deal () (set-mode :playing) (iter (for i in-vector *player-cards*) (vector-push i *deck*)) (iter (for i in-vector *ai-cards*) (vector-push i *deck*)) (setf (fill-pointer *player-cards*) 0 (fill-pointer *ai-cards*) 0) (setf *deck* (alexandria:shuffle *deck*)) (vector-push (vector-pop *deck*) *player-cards*) (vector-push (vector-pop *deck*) *player-cards*) (vector-push (let ((a (vector-pop *deck*))) (setf (side-of a) :down) a) *ai-cards*) (vector-push (vector-pop *deck*) *ai-cards*)) (declaim (ftype (function (vector) fixnum) calculate-total)) (defun calculate-total (cards) (declare (type vector cards)) (let ((ace nil) (total 0)) (declare (type boolean ace) (type fixnum total)) (iter (for i in-vector cards) (when i (typecase (value-of i) (fixnum (incf total (value-of i))) ((member :king :queen :jack) (incf total 10)) ((eql :ace) (setf ace t) (incf total))))) (if (and ace (<= total 10)) (+ total 10) total))) (defun set-mode (key) (declare (type keyword key)) (setf *round* key) (cc:change-entity-enabledness (case *round* (:playing 'com-playing-mode) (:end-round 'com-end-round-mode) (:end-game 'com-end-game-mode)))) (declaim (ftype (function (game-frame stream) (values symbol &optional)) process-potty)) (defun process-potty (frame stream) (declare (type stream stream) (type game-frame frame) (ignore stream)) (labels ((process-potty-checkpoint (user) (a:switch (user :test (lambda (o e) (>= (bladder/contents-of o) (funcall e o)))) ('bladder/need-to-potty-limit-of :need-to-potty) ('bladder/potty-dance-limit-of :potty-dance) ('bladder/potty-desperate-limit-of :potty-desparate) ('bladder/maximum-limit-of :lose))) (process-potty-user (user &optional (clothing nil clothing-p)) (let ((new-checkpoint (process-potty-checkpoint user)) (had-accident (when (>= (bladder/contents-of (player-of *game*)) (bladder/maximum-limit-of (player-of *game*))) (apply 'wet :wetter user :accident t (when clothing-p `(:clothes ,clothing)))))) (unless (eq (getf *checkpoints* user) new-checkpoint) (setf (getf *checkpoints* user) new-checkpoint) (apply 'print-potty user new-checkpoint had-accident (getf had-accident :accident) (when clothing-p `(:clothes ,clothing))) had-accident)))) (macrolet ((thunk (&rest args) `(let ((had-accident (process-potty-user ,@args))) (when had-accident (return-from process-potty (values ,(car args))))))) (thunk (player-of *game*) *player-clothes*) (thunk (ai-of frame))))) (defmethod c:default-frame-top-level ((frame game-frame) &key command-parser command-unparser partial-command-parser prompt) (declare (ignore command-parser command-unparser partial-command-parser prompt)) (deal) (call-next-method)) (c:define-command (com-hit :name t :command-table playing-commands) () (vector-push (vector-pop *deck*) *player-cards*) (let ((total (calculate-total *player-cards*)) (stream (c:frame-standard-output c:*application-frame*))) (format stream "~d~%" total) (when (> total 21) (incf (bladder/contents-of (player-of *game*)) 50) (write-line "bust" stream) (setf (side-of (aref *ai-cards* 0)) :up) (if (process-potty c:*application-frame* stream) (set-mode :end-game) (set-mode :end-round))))) (c:define-command (com-exit-game :name t :command-table end-game-commands) ((put-on-old-clothes boolean :default nil :prompt "Put on old clothes?:")) (locally (declare (type boolean put-on-old-clothes)) (setf *put-on-old-clothes* put-on-old-clothes) (c:frame-exit c:*application-frame*))) (c:define-command (com-give-up :name t :command-table playing-commands) ((go-potty '(c:member-alist (("Run to the toilet" :toilet) ("Flood your pamps" :pamps))) :default :pamps :prompt "<Run to the toilet> | <Flood your pamps>") (put-on-old-clothes boolean :default nil :prompt "Put on old clothes?: ")) (locally (declare (type boolean put-on-old-clothes) (type keyword go-potty)) (let ((pants-down (case go-potty (:toilet t) (:pants nil)))) (declare (type boolean pants-down)) (wet :pants-down pants-down :clothes *player-clothes*) (mess :pants-down pants-down :clothes *player-clothes*)) (setf *put-on-old-clothes* put-on-old-clothes) (c:frame-exit c:*application-frame*))) (serapeum:eval-always (in-package :yadfa-blackjack) (defclass give-up () ())) (c:define-presentation-to-command-translator give-up-with-accept (give-up com-give-up game-frame :gesture :select :documentation "Give Up?" :pointer-documentation "Give Up?") (object frame) (let ((*query-io* (c:frame-query-io frame)) go-potty put-on-old-clothes) (c:accepting-values (*query-io* :own-window t :exit-boxes '((:exit "Accept"))) (fresh-line *query-io*) (setf go-potty (c:accept '(c:member-alist (("Run to the toilet" :toilet) ("Flood your pamps" :pamps))) :prompt "<Run to the toilet> | <Flood your pamps>" :default :pamps :stream *query-io* :view c:+option-pane-view+)) (fresh-line *query-io*) (setf put-on-old-clothes (c:accept 'boolean :prompt "Put on old clothes?:" :default t :stream *query-io* :view c:+toggle-button-view+))) `(,go-potty ,put-on-old-clothes))) (c:define-command (com-stay :name t :command-table playing-commands) () (let ((player-total (calculate-total *player-cards*)) (stream (c:frame-standard-output c:*application-frame*))) (iter (while (<= player-total (calculate-total *ai-cards*) 20)) (vector-push (vector-pop *deck*) *ai-cards*)) (let ((ai-total (calculate-total *ai-cards*))) (cond ((> ai-total 21) (incf (bladder/contents-of (ai-of c:*application-frame*)) 50) (format stream "~a bust~%" (name-of (ai-of c:*application-frame*)))) ((> ai-total player-total) (incf (bladder/contents-of (player-of *game*)) 50) (format stream "~a win~%" (name-of (ai-of c:*application-frame*)))) ((eql ai-total player-total) (write-line "tie" stream)) (t (incf (bladder/contents-of (ai-of c:*application-frame*)) 50) (format stream "~a win~%" (name-of (player-of *game*)))))) (setf (side-of (aref *ai-cards* 0)) :up) (if (process-potty c:*application-frame* stream) (set-mode :end-game) (set-mode :end-round)))) (c:define-command (com-next-round :name t :command-table end-round-commands) () (deal) (set-mode :playing)) (c:define-command (com-clear-history :name t :command-table game-commands) () (c:window-clear (c:frame-standard-output c:*application-frame*))) (cc:define-conditional-command (com-playing-mode) (game-frame :enable-commands (playing-commands) :disable-commands (end-round-commands end-game-commands)) ()) (cc:define-conditional-command (com-end-round-mode) (game-frame :enable-commands (end-round-commands) :disable-commands (playing-commands end-game-commands)) ()) (cc:define-conditional-command (com-end-game-mode) (game-frame :enable-commands (end-game-commands) :disable-commands (playing-commands end-round-commands)) ()) (defclass stat-view (c:view) ()) (defconstant +stat-view+ (make-instance 'stat-view)) (c:define-presentation-method c:present (user (type base-character) medium (view stat-view) &key) (format medium "Name: ~a~%" (name-of user)) (format medium "Bladder: ") (yadfa-clim:draw-bar medium (/ (bladder/contents-of user) (bladder/maximum-limit-of user)) ((>= (bladder/contents-of user) (bladder/potty-desperate-limit-of user)) :red) ((>= (bladder/contents-of user) (bladder/potty-dance-limit-of user)) (:orange :red)) ((>= (bladder/contents-of user) (bladder/need-to-potty-limit-of user)) :yellow) (t :green)) (terpri medium)) (defun draw-game (frame pane) (declare (type game-frame frame) (type c:clim-stream-pane pane)) (labels ((draw-heart (point) (declare (type c:point point)) (c:draw-circle* pane (+ (c:point-x point) 10) (+ (c:point-y point) 10) 10 :ink c:+red+) (c:draw-circle* pane (+ (c:point-x point) 30) (+ (c:point-y point) 10) 10 :ink c:+red+ ) (c:draw-polygon pane (iter (for (x y) on '(0 10 40 10 20 40) by 'cddr) (collect (c:make-point (+ (c:point-x point) x) (+ (c:point-y point) y)))) :ink c:+red+)) (draw-spade (point) (declare (type c:point point)) (c:draw-circle* pane (+ (c:point-x point) 10) (+ (c:point-y point) 20) 10 :ink c:+black+) (c:draw-circle* pane (+ (c:point-x point) 30) (+ (c:point-y point) 20) 10 :ink c:+black+) (c:draw-polygon pane (iter (for (x y) on '(0 15 20 0 40 15 20 20) by 'cddr) (collect (c:make-point (+ (c:point-x point) x) (+ (c:point-y point) y)))) :ink c:+black+) (c:draw-polygon pane (iter (for (x y) on '(10 40 30 40 20 20) by 'cddr) (collect (c:make-point (+ (c:point-x point) x) (+ (c:point-y point) y)))) :ink c:+black+)) (draw-diamond (point) (declare (type c:point point)) (c:draw-polygon pane (iter (for (x y) on '(20 0 0 20 20 40 40 20) by 'cddr) (collect (c:make-point (+ (c:point-x point) x) (+ (c:point-y point) y)))) :ink c:+red+)) (draw-club (point) (declare (type c:point point)) (c:draw-circle* pane (+ (c:point-x point) 10) (+ (c:point-y point) 20) 10 :ink c:+black+) (c:draw-circle* pane (+ (c:point-x point) 30) (+ (c:point-y point) 20) 10 :ink c:+black+) (c:draw-circle* pane (+ (c:point-x point) 20) (+ (c:point-y point) 10) 10 :ink c:+black+) (c:draw-polygon pane (iter (for (x y) on '(10 40 30 40 20 20) by 'cddr) (collect (c:make-point (+ (c:point-x point) x) (+ (c:point-y point) y)))) :ink c:+black+)) (draw-card (card point) (declare (type card card) (type c:point point)) (case (side-of card) (:down (c:draw-rectangle pane point (c:make-point (+ (c:point-x point) 40) (+ (c:point-y point) 40)) :ink *back-card-pattern*)) (:up (let ((text (typecase (value-of card) (fixnum (write-to-string (value-of card))) ((eql :king) "K") ((eql :queen) "Q") ((eql :jack) "J") ((eql :ace) "A") (t "")))) (case (suit-of card) (:diamond (draw-diamond point)) (:spade (draw-spade point)) (:club (draw-club point)) (:heart (draw-heart point))) (c:draw-text* pane text (+ (c:point-x point) 20) (+ (c:point-y point) 20) :ink c:+white+ :align-x :center :align-y :center))))) (draw-row (user cards) (declare (type vector cards) (type base-character user)) (multiple-value-bind (x y) (c:stream-cursor-position pane) (declare (ignore x)) (iter (for i in-vector cards) (for x upfrom 0) (c:updating-output (pane :unique-id `(,user ,x) :id-test 'equal :cache-value `(,i ,(side-of i)) :cache-test 'equal) (draw-card i (c:make-point (+ (* x 40) 10) y)))) (c:stream-increment-cursor-position pane 0 40) (c:updating-output (pane :unique-id user :id-test 'eq :cache-value (bladder/contents-of user)) (c:present user 'base-character :view +stat-view+ :stream pane))))) (setf (c:stream-cursor-position pane) (values 0 0)) (draw-row (ai-of frame) *ai-cards*) (draw-row (player-of *game*) *player-cards*))) (defun draw-gadgets (frame pane) (declare (ignore frame)) (c:formatting-item-list (pane) (let ((table (case *round* (:playing 'playing-commands) (:end-round 'end-round-commands) (:end-game 'end-game-commands)))) (macrolet ((thunk (&rest alist) `(c:map-over-command-table-names (lambda (name symbol) (c:formatting-cell (pane) (case symbol ,@(iter (for i in (append alist '((t `(,(c:gadget-client button)) (c:command :command-table game-frame))))) (destructuring-bind (command object type) i (collect `(,command (c:with-output-as-gadget (pane) (c:make-pane 'c:push-button :label name :client symbol :activate-callback (lambda (button) (declare (ignorable button)) ;; apparently panes don't work as presentations in McCLIM (c:throw-highlighted-presentation (make-instance 'c:standard-presentation :object ,object :single-box t :type ',type) c:*input-context* (make-instance 'c:pointer-button-press-event :sheet nil :x 0 :y 0 :modifier-state 0 :button c:+pointer-left-button+)))))))))))) table :inherited nil))) (thunk ('com-give-up (make-instance 'give-up) give-up)))))) (defun run-game (&optional (enemy 'enemy)) (let ((c:*default-server-path* (if (eq (car (clim:port-server-path (clim:find-port))) :clx-ff) :clx-ttf nil)) (c:*default-text-style* (c:make-text-style :fix :roman :normal))) ;; https://github.com/McCLIM/McCLIM/issues/913 (declare (special c:*default-server-path* c:*default-text-style*)) (c:run-frame-top-level (c:make-application-frame 'game-frame :pretty-name "Blackjack" :ai (make-instance enemy :wear (list (make-instance 'yadfa-items:blackjack-uniform-diaper)))))))
27,613
Common Lisp
.lisp
437
44.679634
173
0.506697
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
e18b1014a97200caa145614fc95aa7c564313aa8cbe19fc795acecf19d7325f5
15,609
[ -1 ]
15,610
fursuiters.lisp
pouar_yadfa/data/enemies/fursuiters.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass padded-fursuiter-servant (potty-enemy) () (:default-initargs :name "Padded Fursuiter Servant" :description "These are basically generic \"servants\" that you can also use as a plushie. Since they're not allowed to take bathroom breaks, they're thickly padded and have special fursuits that keep all the fluids and smells in. Some are too embarrassed to use their diapers for their intended purposes and try so hard to hold it in only to uncontrollably flood and mess themselves. Other's have given up and just use their diapers whenever they have to go." :male (a:random-elt '(t nil)) :species "Fox" :bladder/contents (random 500) :bowels/contents (random 700) :wear (make-instances yadfa-items:fursuit yadfa-items:kurikia-thick-diaper))) (s:defmethods padded-fursuiter-servant (character) (:method process-battle-accident (character attack (item item) reload (selected-target base-character)) (declare (ignore attack item reload selected-target)) (let* ((male (malep character)) (heshe (if male "he" "she")) (himher (if male "him" "her"))) (cond ((or (>= (bladder/contents-of character) (bladder/maximum-limit-of character)) (>= (bowels/contents-of character) (bowels/maximum-limit-of character))) (when (>= (bladder/contents-of character) (bladder/maximum-limit-of character)) (format t "~a lets out a quiet moan as ~a accidentally wets ~aself in battle~%" (name-of character) heshe himher) (wet :wetter character) (set-status-condition 'yadfa-status-conditions:wetting character)) (when (>= (bowels/contents-of character) (bowels/maximum-limit-of character)) (format t "~a involuntarily squats down as ~a accidentally messes ~aself in battle~%" (name-of character) heshe himher) (mess :messer character) (set-status-condition 'yadfa-status-conditions:messing character)) t) ((and (watersport-limit-of character) (<= (- (bladder/maximum-limit-of character) (bladder/contents-of character)) (watersport-limit-of character)) (< (random (watersport-chance-of character)) 1)) (format t "~a floods ~aself in the middle of battle~%" (name-of character) himher) (wet :wetter character)) ((and (mudsport-limit-of character) (<= (- (bowels/maximum-limit-of character) (bowels/contents-of character)) (mudsport-limit-of character)) (< (random (mudsport-chance-of character)) 1)) (format t "~a squats down and messes ~aself in the middle of battle~%" (name-of character) himher) (mess :messer character))))) (:method initialize-instance :after (character &key (watersport-limit nil watersportp) (mudsport-limit nil mudsportp) &allow-other-keys) (declare (ignore watersport-limit mudsport-limit)) (cond ((and watersportp mudsportp) (let ((limits (a:random-elt (list (cons (bladder/need-to-potty-limit-of character) (bowels/need-to-potty-limit-of character)) '(nil))))) (setf (watersport-limit-of character) (car limits) (mudsport-limit-of character) (cdr limits)))) (watersportp (setf (mudsport-limit-of character) (a:random-elt (list (bowels/need-to-potty-limit-of character) nil)))) (mudsportp (setf (watersport-limit-of character) (a:random-elt (list (bladder/need-to-potty-limit-of character) nil))))))) (defclass fursuiter-servant (potty-enemy) () (:default-initargs :name "Fursuiter Servant" :description "Claims that he \"doesn't want to be associated with diapers\" and that he will \"sweat all the fluids out\", so he's kept in one of those watertight fursuits to keep him from making puddles until he changes his mind." :male (a:random-elt '(t nil)) :species "Fox" :bladder/contents (random 500) :bowels/contents (random 700) :wear (make-instances yadfa-items:watertight-fursuit yadfa-items:tshirt yadfa-items:jeans yadfa-items:boxers)))
4,384
Common Lisp
.lisp
64
57.828125
463
0.654861
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
6e66fb0e2027a5e0adcaedf10431cb85b004f3f945ab273be5b03f1b57cb571c
15,610
[ -1 ]
15,611
pirates.lisp
pouar_yadfa/data/enemies/pirates.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass diaper-pirate (potty-enemy) () (:default-initargs :name "Diaper Pirate" :description "A generic pirate that has forgone toilets and will never try to hold it." :species (a:random-elt '("Dolphin" "Orca" "Shark")) :male (a:random-elt '(t nil)) :bladder/contents (random 500) :bowels/contents (random 700) :element-types '#.(coerce-element-types 'yadfa-element-types:water) :watersport-limit 300 :mudsport-limit 400 :inventory (iter (for i from 0 to (random 20)) (collect (make-instance 'yadfa-items:diaper))))) (defmethod initialize-instance :after ((c diaper-pirate) &key (wear nil wearp) &allow-other-keys) (declare (ignore wear)) (unless wearp (setf (wear-of c) nil) (push (make-instance 'yadfa-items:diaper) (wear-of c)) (unless (malep c) (push (make-instance 'yadfa-items:bra) (wear-of c))) (push (make-instance (if (and (not (malep c)) (= (random 2) 0)) 'yadfa-items:pirate-dress 'yadfa-items:pirate-shirt)) (wear-of c)))) (defclass thickly-diaper-pirate (diaper-pirate) () (:default-initargs :description "A variant of the Diaper Pirate that wears 3 layers of padding. A stuffer, a normal diaper, and a super thick diaper." :inventory (nconc (iter (for i from 0 to (random 20)) (collect (make-instance 'yadfa-items:incontinence-pad))) (iter (for i from 0 to (random 20)) (collect (make-instance 'yadfa-items:cloth-diaper))) (iter (for i from 0 to (random 20)) (collect (make-instance 'yadfa-items:thick-rubber-diaper)))))) (defmethod initialize-instance :after ((c thickly-diaper-pirate) &key (wear nil wearp) &allow-other-keys) (declare (ignore wear)) (unless wearp (setf (wear-of c) nil) (a:appendf (wear-of c) (iter (for i in '(yadfa-items:thick-rubber-diaper yadfa-items:cloth-diaper yadfa-items:incontinence-pad)) (collect (make-instance i)))) (unless (malep c) (push (make-instance 'yadfa-items:bra) (wear-of c))) (push (make-instance 'yadfa-items:pirate-shirt) (wear-of c))))
2,318
Common Lisp
.lisp
44
44.795455
134
0.637643
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
8fd5b151587dce64a958286e95479a153f3882a685e6bf6dac646bd689f14fc3
15,611
[ -1 ]
15,612
eggbots.lisp
pouar_yadfa/data/enemies/eggbots.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass egg-pawn (enemy) () (:default-initargs :name "Egg Pawn" :description "One of Eggman's robots" :species "Egg Pawn" :male t :attributes (list :not-ticklish t) :bitcoins-per-level 40 :element-types '#.(coerce-element-types 'yadfa-element-types:steel)))
400
Common Lisp
.lisp
11
33.272727
88
0.686375
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
72903701fd04f688b04557a3cd8c704dcc325e661f1d01bf8cb1e18f4cc7f6f3
15,612
[ -1 ]
15,613
haunted.lisp
pouar_yadfa/data/enemies/haunted.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass ghost (enemy) () (:default-initargs :name "Ghost" :description "Woooo, A Ghost" :species "Ghost" :male t :attributes (list :not-ticklish t) ;; the game can't tell the difference between ghosts and nonghosts when calculating the damage ;; Unlike Pokemon, this game's engine doesn't hardcode special treatment like `(if (ghostp) (do-ghost-stuff) (do-normal-stuff))' ;; so just give him infinity defense and health :base-stats (list :health most-positive-fixnum :attack 0 :defense float-features:long-float-positive-infinity :energy most-positive-fixnum :speed 120) :element-types '#.(coerce-element-types 'yadfa-element-types:ghost) :moves (make-instances yadfa-moves:ghost-tickle yadfa-moves:ghost-mush yadfa-moves:ghost-squish))) (defmethod default-attack ((target team-member) (user ghost)) (declare (ignore target)) (f:fmt t (name-of user) " Acts all scary" #\Newline) (unless (and (<= (random 5) 0) (iter (for i in (if (typep user 'team-member) (enemies-of *battle*) (team-of *game*))) (with j = nil) (when (>= (bladder/contents-of i) (bladder/need-to-potty-limit-of i)) (format t "~a wets ~aself in fear~%" (name-of i) (if (malep i) "him" "her")) (wet :wetter i) (set-status-condition 'yadfa-status-conditions:wetting i) (setf j t)) (when (>= (bowels/contents-of i) (bowels/need-to-potty-limit-of i)) (format t "~a messes ~aself in fear~%" (name-of i) (if (malep i) "him" "her")) (mess :messer i) (set-status-condition 'yadfa-status-conditions:messing i) (setf j t)) (finally (return j)))) (write-line "it had no effect"))) (defclass werewolf (potty-enemy) () (:default-initargs :name "Werewolf" :description "A scary werewolf" :species "Werewolf" :male (a:random-elt '(t nil)) :element-types '#.(coerce-element-types 'yadfa-element-types:dark) :moves (make-instances yadfa-moves:bite yadfa-moves:roar yadfa-moves:scratch))) (defmethod initialize-instance :after ((c werewolf) &key (wear nil wearp) &allow-other-keys) (declare (ignore wear)) (unless wearp (setf (wear-of c) (let (wear (malep (malep c))) (push (make-instance (if malep 'yadfa-items:boxers 'yadfa-items:panties)) wear) (push (make-instance 'yadfa-items:jeans) wear) (unless malep (push (make-instance 'yadfa-items:bra) wear)) wear)))) (defclass domesticated-werewolf (werewolf) () (:default-initargs :name "Domesticated Werewolf" :description "These are kept by the ghosts as pets. The ghosts like to pretend they aren't housebroken, so they aren't allowed inside without diapers." :wear (make-instances yadfa-items:collar yadfa-items:thick-diaper)))
3,342
Common Lisp
.lisp
69
37.362319
154
0.585701
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
73bd22af909f53dc9162cca97a8a70719b42c0f3da33c4e2733cdbe6b267b8a4
15,613
[ -1 ]
15,614
pokemon.lisp
pouar_yadfa/data/enemies/pokemon.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass magikarp (enemy) () (:default-initargs :name "Magikarp" :description "The world's weakest Pokémon until it evolves, but when it does evolve, HOLY SHIT!!!!!!" :species "Magikarp" :male (a:random-elt '(t nil)) :bitcoins-per-level 10 :element-types '#.(coerce-element-types 'yadfa-element-types:water))) (s:defmethods magikarp (user) (:method attack ((target team-member) user (attack null)) (declare (ignore target attack)) (format t "~a uses Splash, obviously it had no effect. What did you think was going to happen?" (name-of user))) (:method battle-script (user (target base-character)) (attack target user nil)))
780
Common Lisp
.lisp
16
45.5
116
0.697644
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
2b5b2cec39bcbb18c5636c9e17ca55a90a0b927a5cbc35d24e3cfec91fe4ce13
15,614
[ -1 ]
15,615
rpgmaker.lisp
pouar_yadfa/data/enemies/rpgmaker.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass diapered-kobold (potty-enemy pantsable-character adoptable-enemy) () (:default-initargs :name "Diapered Kobold" :description "They're apparently from a tribe of kobolds in the area. Their outfits are similar to the ancient Egyptians." :species "Kobold" :male (a:random-elt '(t nil)) :bladder/contents (random 500) :bowels/contents (random 700) :bitcoins-per-level 100 :inventory (iter (for i from 0 to (random 10)) (collect (make-instance 'yadfa-items:cloth-diaper))))) (setf (get 'diapered-kobold 'change-class-target) 'yadfa-allies:diapered-kobold) (defmethod initialize-instance :after ((c diapered-kobold) &key (wear nil wearp) &allow-other-keys) (declare (ignore wear)) (unless wearp (push (let ((a (make-instance 'yadfa-items:thick-cloth-diaper))) (setf (sogginess-of a) (random (sogginess-capacity-of a))) (setf (messiness-of a) (random (messiness-capacity-of a))) a) (wear-of c)) (push (make-instance (if (malep c) 'yadfa-items:shendyt 'yadfa-items:kalasiris)) (wear-of c)))) (defclass diapered-skunk (potty-enemy skunk-boop-mixin) () (:default-initargs :name "Diapered Skunk" :description "They spray their diapers when attacking. Their diapers reek of a smell of urine, feces, and skunk spray." :species "Skunk" :male (a:random-elt '(t nil)) :bladder/contents (random 500) :bowels/contents (random 700) :watersport-chance 3 :mudsport-chance 3 :bitcoins-per-level 100 :inventory (iter (for i from 0 to (random 10)) (collect (make-instance 'yadfa-items:high-capacity-diaper))) :element-types '#.(coerce-element-types 'yadfa-element-types:poison) :moves (make-instances yadfa-moves:spray yadfa-moves:face-sit))) (s:defmethods diapered-skunk (character) (:method initialize-instance :after (character &key (watersport-limit nil watersportp) (mudsport-limit nil mudsportp) (wear nil wearp) &allow-other-keys) (declare (ignore watersport-limit mudsport-limit wear)) (unless wearp (push (let ((a (make-instance 'yadfa-items:high-capacity-diaper))) (setf (sogginess-of a) (+ (bladder/potty-desperate-limit-of character) (random (+ (bladder/maximum-limit-of character) (- (bladder/maximum-limit-of character) (bladder/potty-desperate-limit-of character)))))) (setf (messiness-of a) (+ (bowels/potty-desperate-limit-of character) (random (- (bowels/maximum-limit-of character) (bowels/potty-desperate-limit-of character))))) a) (wear-of character)) (push (make-instance (if (malep character) 'yadfa-items:tshirt 'yadfa-items:bikini-top)) (wear-of character)) (push (make-instance 'yadfa-items:black-leather-jacket) (wear-of character))) (unless watersportp (setf (watersport-limit-of character) (- (bladder/maximum-limit-of character) (bladder/potty-desperate-limit-of character)))) (unless mudsportp (setf (mudsport-limit-of character) (- (bowels/maximum-limit-of character) (bowels/potty-desperate-limit-of character))))) (:method process-battle-accident (character attack (item item) reload (selected-target base-character)) (declare (ignore attack item reload selected-target)) (let* ((watersport-chance (random (watersport-chance-of character))) (mudsport-chance (random (mudsport-chance-of character))) (male (malep character)) (hisher (if male "his" "her")) (name (name-of character)) (bladder/maximum-limit (bladder/maximum-limit-of character)) (bowels/maximum-limit (bowels/maximum-limit-of character)) (mudsport-limit (mudsport-limit-of character)) (watersport-limit (watersport-limit-of character))) (cond ((or (>= (bladder/contents-of character) (bladder/maximum-limit-of character)) (>= (bowels/contents-of character) bowels/maximum-limit) (and watersport-limit (<= (- bladder/maximum-limit (bladder/contents-of character)) watersport-limit) (< watersport-chance 1)) (and mudsport-limit (<= (- bowels/maximum-limit (bowels/contents-of character)) mudsport-limit) (< mudsport-chance 1))) (when (or (>= (bladder/contents-of character) bladder/maximum-limit) (and watersport-limit (<= (- bladder/maximum-limit (bladder/contents-of character)) watersport-limit) (< watersport-chance 1))) (format t "~a gets a look of relief on ~a face as ~a floods ~a pamps~%" name hisher (if male "he" "she") hisher) (wet :wetter character) (set-status-condition 'yadfa-status-conditions:wetting character)) (when (or (>= (bowels/contents-of character) bowels/maximum-limit) (and mudsport-limit (<= (- bowels/maximum-limit (bowels/contents-of character)) mudsport-limit) (< mudsport-chance 1))) (format t "~a squats down and with a heavy grunt pushes a huge load into ~a diapers~%" name hisher) (mess :messer character) (set-status-condition 'yadfa-status-conditions:messing character)) t))))) (defclass diapered-skunk* (potty-enemy skunk-boop-mixin) () (:default-initargs :name "Diapered Skunk" :species "Skunk" :male (a:random-elt '(t nil)) :bladder/contents (random 500) :bowels/contents (random 700) :watersport-chance 3 :mudsport-chance 3 :bitcoins-per-level 100 :element-types '#.(coerce-element-types 'yadfa-element-types:poison) :moves (make-instances yadfa-moves:spray yadfa-moves:face-sit))) (s:defmethods diapered-skunk* (character) (:method initialize-instance :after (character &key (watersport-limit nil watersportp) (mudsport-limit nil mudsportp) (wear nil wearp) (description nil descriptionp) &allow-other-keys) (declare (ignore watersport-limit mudsport-limit wear description)) (unless wearp (push (let ((a (make-instance 'yadfa-items:high-capacity-diaper))) (setf (sogginess-of a) (sogginess-capacity-of a)) (setf (messiness-of a) (messiness-capacity-of a)) a) (wear-of character))) (unless watersportp (setf (watersport-limit-of character) (- (bladder/maximum-limit-of character) (bladder/potty-desperate-limit-of character)))) (unless mudsportp (setf (mudsport-limit-of character) (- (bowels/maximum-limit-of character) (bowels/potty-desperate-limit-of character)))) (unless descriptionp (let* ((male (malep character)) (hisher (if male "his" "her"))) (setf (description-of character) (format nil "If you thought the other skunk was stinky, that's nothing compared to this one. Apparently this skunk never changes ~a pamps at all and just continues to flood, mess, and spray ~a current one. ~a doesn't wear anything else because it just gets covered in too much of ~a own stinky juices." hisher hisher (if male "He" "She") hisher))))) (:method process-battle-accident (character attack (item item) reload (selected-target base-character)) (declare (ignore attack item reload selected-target)) (let* ((watersport-chance (random (watersport-chance-of character))) (mudsport-chance (random (mudsport-chance-of character))) (male (malep character)) (hisher (if male "his" "her")) (name (name-of character)) (bladder/maximum-limit (bladder/maximum-limit-of character)) (bowels/maximum-limit (bowels/maximum-limit-of character)) (mudsport-limit (mudsport-limit-of character)) (watersport-limit (watersport-limit-of character))) (cond ((or (>= (bladder/contents-of character) (bladder/maximum-limit-of character)) (>= (bowels/contents-of character) bowels/maximum-limit) (and watersport-limit (<= (- bladder/maximum-limit (bladder/contents-of character)) watersport-limit) (< watersport-chance 1)) (and mudsport-limit (<= (- bowels/maximum-limit (bowels/contents-of character)) mudsport-limit) (< mudsport-chance 1))) (when (or (>= (bladder/contents-of character) bladder/maximum-limit) (and watersport-limit (<= (- bladder/maximum-limit (bladder/contents-of character)) watersport-limit) (< watersport-chance 1))) (format t "~a gets a look of relief on ~a face as ~a floods ~a already leaky and waterlogged pamps~%" name hisher (if male "he" "she") hisher) (wet :wetter character) (set-status-condition 'yadfa-status-conditions:wetting character)) (when (or (>= (bowels/contents-of character) bowels/maximum-limit) (and mudsport-limit (<= (- bowels/maximum-limit (bowels/contents-of character)) mudsport-limit) (< mudsport-chance 1))) (format t "~a squats down and with a heavy grunt pushes a huge load into ~a already overly full diapers~%" name hisher) (mess :messer character) (set-status-condition 'yadfa-status-conditions:messing character)) t))))) (defclass diapered-dragon (potty-enemy) () (:default-initargs :name "Diapered Dragon" :description "Keeps kobolds as pets. Waits until the last minute because \{,s}he's not some hatchling that has to use the potty all the time\"" :species "Dragon" :male (a:random-elt '(t nil)) :bladder/contents (random 500) :bowels/contents (random 700) :bitcoins-per-level 100 :wear (list (make-instance 'yadfa-items:black-leather-jacket) (make-instance 'yadfa-items:high-capacity-diaper)) :inventory (nconc (iter (for i from 0 to (random 20)) (collect (make-instance 'yadfa-items:high-capacity-diaper))) (iter (for i from 0 to (random 20)) (collect (make-instance 'yadfa-items:kurikia-thick-diaper)))) :element-types '#.(coerce-element-types '(yadfa-element-types:dragon yadfa-element-types:fire yadfa-element-types:flying)) :moves (make-instances yadfa-moves:tickle yadfa-moves:roar yadfa-moves:mush yadfa-moves:fire-breath))) (defclass diapered-dragon* (diapered-dragon pantsable-character) () (:default-initargs :description "Keeps kobolds as pets. Wears pants to hide {his,her} padding. Waits until the last minute because \"{,s}he's not some hatchling that has to use the potty all the time\"" :wear (make-instances yadfa-items:black-leather-jacket yadfa-items:baggy-jeans yadfa-items:high-capacity-diaper))) ;;; Raptors would most likely not have bladders irl, but I already threw ;;; scientific accuracy out the window when I gave them scales instead of feathers. (defclass raptor (potty-enemy adoptable-enemy) () (:default-initargs :name "Raptor" :malep (a:random-elt '(t nil)) :description "Biologically inaccurate velociraptor. The kind you see in Jurassic Park that looks more like a lizard than a prehistoric bird." :moves (make-instances yadfa-moves:roar yadfa-moves:bite) :species "Raptor")) (setf (get 'diapered-kobold 'change-class-target) 'yadfa-allies:raptor) (defmethod change-class-text ((class raptor)) (format nil "~a was adopted and diapered" (name-of class))) (defclass dergy (bladder-enemy) () (:default-initargs :name "Dergy" :description "An alien dragon like species that liquefies its food, so he lacks bowels as everything goes through its bladder. But since all that mass is forced through its bladder now, it fills up much quicker, so they have to go more often and can't hold it in for as long." :species "Dergy" :malep (a:random-elt '(t nil)) :bitcoins-per-level 100 :bladder/fill-rate (* (/ 14000 24 60) 2) :wear (list (make-instance 'yadfa-items:kurikia-thick-rubber-diaper)) :inventory (iter (for i from 0 to (random 20)) (collect (make-instance 'yadfa-items:kurikia-thick-rubber-diaper))) :element-types '#.(coerce-element-types 'yadfa-element-types:dragon) :moves (make-instances yadfa-moves:tickle yadfa-moves:roar yadfa-moves:mush yadfa-moves:fire-breath)))
13,147
Common Lisp
.lisp
218
49.348624
390
0.639078
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
cc11e7500e15096528b5cd60ca63488797977284c115002acfa130827dc9e5c7
15,615
[ -1 ]
15,616
raccoon-bandits.lisp
pouar_yadfa/data/enemies/raccoon-bandits.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass diapered-raccoon-bandit (potty-enemy pantsable-character) () (:default-initargs :name "Diapered Raccoon Bandit" :description "The Diapered Raccoon Bandits are a local AB/DL gang here in this world. Apparently wearing (and using) diapers is extremely embarrassing for them, so they wear tunics to hide them." :species "Raccoon" :male t :bladder/contents (random 500) :bowels/contents (random 700) :wear (make-instances yadfa-items:bandit-uniform-tunic yadfa-items:bandit-adjustable-diaper) :inventory (let ((a ())) (iter (for i from 0 to (random 5)) (push (make-instance 'yadfa-items:bandit-diaper) a)) (iter (for i from 0 to (random 5)) (push (make-instance 'yadfa-items:bandit-adjustable-diaper) a)) (iter (for i from 0 to (random 5)) (push (make-instance 'yadfa-items:bandit-female-diaper) a))) :bitcoins-per-level 40)) (s:defmethods diapered-raccoon-bandit (character) (:method battle-script (character (target base-character)) (let ((moves-with-health (iter (for i in (moves-of character)) (when (and (>= (energy-of character) (energy-cost-of i)) (typep i 'health-inc-move)) (collect i)))) (moves-can-use (iter (for i in (moves-of character)) (when (>= (energy-of character) (energy-cost-of i)) (collect i)))) (move-to-use nil)) (cond ((and (<= (health-of character) (/ (calculate-stat character :health) 4)) moves-with-health) (setf move-to-use (a:random-elt moves-with-health)) (attack target character move-to-use)) (t (when moves-can-use (setf move-to-use (a:random-elt moves-can-use))) (cond ((and (>= (bladder/contents-of target) (bladder/potty-dance-limit-of target)) (= (random 3) 0)) (format t "~a gets a grin on ~a face~%" (name-of character) (if (malep character) "his" "her")) (let ((move-to-use (make-instance 'yadfa-moves:tickle))) (attack target character move-to-use))) ((and (> (getf (calculate-diaper-usage target) :messiness) 0) (= (random 3) 0)) (format t "~a gets a grin on ~a face~%" (name-of character) (if (malep character) "his" "her")) (let ((move-to-use (make-instance 'yadfa-moves:mush))) (attack target character move-to-use))) ((and move-to-use (= (random 4) 0)) (attack target character move-to-use) (decf (energy-of character) (energy-cost-of move-to-use))) ((wield-of character) (attack target character (wield-of character))) (t (attack target character nil))))))) (:method process-battle-accident (character attack (item item) reload (selected-target base-character)) (when (>= (bladder/contents-of character) (bladder/maximum-limit-of character)) (format t "~a lets out a quiet moan as ~a accidentally wets ~aself in battle~%" (name-of character) (if (malep character) "he" "she") (if (malep character) "him" "her")) (let ((wet (wet :wetter character))) (when (> (getf wet :leak-amount) 0) (f:fmt t "A puddle starts to form at " (name-of character) "'s feet" #\Newline))) (set-status-condition 'yadfa-status-conditions:wetting character)) (when (>= (bowels/contents-of character) (bowels/maximum-limit-of character)) (format t "~a involuntarily squats down as ~a accidentally messes ~aself in battle~%" (name-of character) (if (malep character) "he" "she") (if (malep character) "him" "her")) (let ((mess (mess :messer character))) (when (> (getf mess :leak-amount) 0) (f:fmt t (name-of character) " starts to make a mess on the floor" #\Newline))) (set-status-condition 'yadfa-status-conditions:messing character)) (let ((wetting (find-if (lambda (o) (typep o 'yadfa-status-conditions:wetting)) (status-conditions character))) (messing (find-if (lambda (o) (typep o 'yadfa-status-conditions:messing)) (status-conditions character))) (teammember (find-if (lambda (o) (and (typep o 'diapered-raccoon-bandit) (not (eq o character)))) (enemies-of *battle*)))) (cond ((and wetting teammember (= (random 5) 0)) (write-line "Other Raccoon: Now's not the time to go potty") (write-line "Flooding Raccoon Bandit: *whines*")) ((and messing teammember (= (random 5) 0)) (write-line "Other Raccoon: You couldn't wait until after the battle before doing that?") (write-line "Messing Raccoon Bandit: *grunts*")))))) (defclass rookie-diapered-raccoon-bandit (potty-enemy pantsable-character) () (:default-initargs :name "Rookie Diapered Raccoon Bandit" :description "The Diapered Raccoon Bandits are a local AB/DL gang here in this world. Despite how embarrassing diapers are for them, the use of toilets and pants in the gang are a privilege and not a right. The ones without these privileges have “babysitters” to keep track of them, as they're not allowed to change themselves. Despite this, they try their best to not wet and/or mess their diapers in a desperate attempt to make their situation less embarrassing." :species "Raccoon" :male t :bladder/contents (random 500) :bowels/contents (random 700) :wear (list (make-instance 'yadfa-items:bandit-uniform-shirt) (make-instance 'yadfa-items:bandit-diaper :sogginess (let ((a (random 3))) (cond ((= a 0) 0) ((= a 1) (random-from-range 10 50)) ((= a 2) (random-from-range 300 1000)))) :messiness (let ((a (random 2))) (cond ((= a 0) 0) ((= a 1) 8000))))) :bitcoins-per-level 20)) (defclass female-diapered-raccoon-bandit (potty-enemy pantsable-character) () (:default-initargs :name "Female Diapered Raccoon Bandit" :description "The Diapered Raccoon Bandits are a local AB/DL gang here in this world. Apparently gender equality is non-existent in this gang, so the females have the same potty and pants privileges as the rookies, meaning none at all." :species "Raccoon" :male nil :bladder/contents (random 500) :bowels/contents (random 700) :wear (list (make-instance 'yadfa-items:bandit-uniform-sports-bikini-top) (make-instance 'yadfa-items:bandit-female-diaper :sogginess (let ((a (random 3))) (cond ((= a 0) 0) ((= a 1) (random-from-range 10 50)) ((= a 2) (random-from-range 300 1000)))) :messiness (let ((a (random 2))) (cond ((= a 0) 0) ((= a 1) 8000))))) :bitcoins-per-level 20)) (defclass giant-diapered-raccoon-bandit (diapered-raccoon-bandit) () (:default-initargs :name "Giant Diapered Raccoon Bandit" :description "Basically we just took a Diapered Raccoon Bandit and made him bigger. Aren't we so creative at designing bosses?" :bitcoins-per-level 200)) (defclass catchable-raccoon-bandit (diapered-raccoon-bandit catchable-enemy) ()) (setf (get 'catchable-raccoon-bandit 'change-class-target) 'yadfa-allies:diapered-raccoon-bandit)
8,160
Common Lisp
.lisp
124
51.056452
468
0.580926
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
2b5fda4026af48298957e2019460a45c0a8a9e2fc08593b8885bc41e326b80aa
15,616
[ -1 ]
15,617
navy.lisp
pouar_yadfa/data/enemies/navy.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defclass navy-officer (potty-enemy pantsable-character) () (:default-initargs :name "Navy Officer" :description "The Navy is mainly made up of aquatic creatures. They're all toilet trained but may use their pullups if they don't want to hold it any longer." :species (a:random-elt '("Dolphin" "Orca" "Shark")) :male (a:random-elt '(t nil)) :watersport-chance 3 :mudsport-chance 3 :bladder/contents (random 500) :bowels/contents (random 700) :element-types '#.(coerce-element-types 'yadfa-element-types:water) :inventory (iter (for i from 0 to (random 5)) (collect (make-instance 'yadfa-items:navy-pullups))) :bitcoins-per-level 60)) (s:defmethods navy-officer (character) (:method process-battle-accident (character attack (item item) reload (selected-target base-character)) (declare (ignore attack item reload selected-target)) (let* ((male (malep character)) (pamps (iter (for i in (wear-of character)) (let ((i (typecase i (diaper 'diaper) (pullup 'pullup) (closed-bottoms 'closed-bottoms)))) (when i (leave i))))) (pampspronoun (if male (if pamps "his " "him") (if pamps "her " "her"))) (pampsname (case pamps (diaper "diapers") (pullup "pullups") (closed-bottoms "pants") (t "self")))) (cond ((or (>= (bladder/contents-of character) (bladder/maximum-limit-of character)) (>= (bowels/contents-of character) (bowels/maximum-limit-of character))) (let ((heshe (if male "he" "she")) (himher (if male "him" "her"))) (when (>= (bladder/contents-of character) (bladder/maximum-limit-of character)) (format t "~a lets out a quiet moan as ~a accidentally wets ~aself in battle~%" (name-of character) heshe himher) (wet :wetter character) (set-status-condition 'yadfa-status-conditions:wetting character)) (when (>= (bowels/contents-of character) (bowels/maximum-limit-of character)) (format t "~a involuntarily squats down as ~a accidentally messes ~aself in battle~%" (name-of character) heshe himher) (mess :messer character) (set-status-condition 'yadfa-status-conditions:messing character)) t)) ((and (watersport-limit-of character) (<= (- (bladder/maximum-limit-of character) (bladder/contents-of character)) (watersport-limit-of character)) (< (random (watersport-chance-of character)) 1)) (format t "~a slightly blushes and lets go from the front of ~a~a and spreads ~a legs apart and floods them~%" (name-of character) pampspronoun pampsname (if male "his" "her")) (wet :wetter character)) ((and (mudsport-limit-of character) (<= (- (bowels/maximum-limit-of character) (bowels/contents-of character)) (mudsport-limit-of character)) (< (random (mudsport-chance-of character)) 1)) (format t "~a slightly blushes and squats down and messes ~a~a~%" (name-of character) pampspronoun pampsname) (mess :messer character))))) (:method initialize-instance :after (character &key (watersport-limit nil watersportp) (mudsport-limit nil mudsportp) (wear nil wearp) &allow-other-keys) (declare (ignore watersport-limit mudsport-limit wear)) (unless wearp (push (make-instance 'yadfa-items:navy-pullups) (wear-of character)) (when (and (not (malep character)) (= (random 5) 0)) (push (make-instance 'yadfa-items:navy-skirt) (wear-of character))) (unless (malep character) (push (make-instance 'yadfa-items:bra) (wear-of character))) (push (make-instance 'yadfa-items:navy-shirt) (wear-of character))) (unless watersportp (setf (watersport-limit-of character) (- (bladder/maximum-limit-of character) (bladder/potty-desperate-limit-of character)))) (unless mudsportp (setf (mudsport-limit-of character) (- (bowels/maximum-limit-of character) (bowels/potty-desperate-limit-of character)))))) (defclass navy-officer* (navy-officer) () (:default-initargs :description "A variant of the Navy Officer. This variant still wears the standard pullups, but supplements them with stuffers to avoid changing the pullups out and is a bit less likely to try and hold it" :watersport-chance (random-from-range 1 3) :mudsport-chance (random-from-range 1 3) :inventory (nconc (iter (for i from 0 to (random 5)) (collect (make-instance 'yadfa-items:navy-pullups))) (iter (for i from 0 to (random 15)) (collect (make-instance 'yadfa-items:cloth-incontinence-pad)))))) (defmethod initialize-instance :after ((c navy-officer*) &key (watersport-limit nil watersportp) (mudsport-limit nil mudsportp) (wear nil wearp) &allow-other-keys) (declare (ignore watersport-limit mudsport-limit wear)) (unless wearp (push (make-instance 'yadfa-items:cloth-incontinence-pad) (wear-of c)) (push (make-instance 'yadfa-items:navy-pullups) (wear-of c)) (when (and (not (malep c)) (= (random 5) 0)) (push (make-instance 'yadfa-items:navy-skirt) (wear-of c))) (unless (malep c) (push (make-instance 'yadfa-items:bra) (wear-of c))) (push (make-instance 'yadfa-items:navy-shirt) (wear-of c))) (unless watersportp (setf (watersport-limit-of c) (- (bladder/maximum-limit-of c) (a:random-elt (list (bladder/potty-dance-limit-of c) (bladder/need-to-potty-limit-of c)))))) (unless mudsportp (setf (mudsport-limit-of c) (- (bowels/maximum-limit-of c) (a:random-elt (list (bowels/potty-dance-limit-of c) (bowels/need-to-potty-limit-of c)))))))
6,725
Common Lisp
.lisp
117
43.470085
208
0.577482
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
33f4ee2babc2227b20f5145d3243f92dac2d7181716d08f160064d798b8e0e19
15,617
[ -1 ]
15,618
allies.lisp
pouar_yadfa/data/prolog/allies.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-allies"; coding: utf-8-unix; -*- (in-package :yadfa-allies) (defclass adopted-enemy (playable-ally) ())
159
Common Lisp
.lisp
3
52
87
0.685897
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b341e3c187fe5f1754e19663771bdea3702ae20d3711075638334c158aa8bbbb
15,618
[ -1 ]
15,619
map.lisp
pouar_yadfa/data/prolog/map.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-zones"; coding: utf-8-unix; -*- (in-package :yadfa-zones) (uiop:define-package #:peachs-castle-wannabe (:export #:blank-area #:pokemon-area #:thwomp-area #:race-area #:eggman-area)) (defun can-potty (prop &key wet mess pants-down user) (declare (ignorable prop wet mess pants-down user)) (not (when (and (typep prop '(not yadfa-props:toilet)) (or pants-down (null (filter-items (wear-of user) 'incontinence-product)))) (format t "STOP!!! THE SIGN SAYS ~A ISN'T ALLOWED TO DO THAT HERE!!!!! Just hold it all in.~%~%" (string-upcase (name-of user))) (when (or (>= (bladder/contents-of user) (bladder/potty-dance-limit-of user)) (>= (bowels/contents-of user) (bowels/potty-dance-limit-of user))) (format t "*~a whines and continues ~a embarrassing potty dance while the public watches and giggles*~%~%" (name-of user) (if (malep user) "his" "her"))) t))) (defun can-potty-peachs-castle-wannabe (prop &key wet mess pants-down user) (declare (ignorable prop wet mess pants-down user)) (not (when (or pants-down (null (filter-items (wear-of user) 'incontinence-product))) (format t "STOP!!! ~A CAN'T DO THAT HERE!!!! THERE ARE LIKE KIDS HERE!!!!! Just hold it all in~%~%" (string-upcase (name-of user))) (when (or (>= (bladder/contents-of user) (bladder/potty-dance-limit-of user)) (>= (bowels/contents-of user) (bowels/potty-dance-limit-of user))) (format t "*~a whines and continues ~a embarrassing potty dance while the public watches and giggles*~%~%" (name-of user) (if (malep user) "his" "her"))) t))) (defun potty-trigger-peachs-castle-wannabe (had-accident user) (when (or (and (getf (car had-accident) :leak-amount) (> (getf (car had-accident) :leak-amount) 0)) (and (getf (cdr had-accident) :leak-amount) (> (getf (cdr had-accident) :leak-amount) 0))) (format t "Some kid: HEY LOOK!!!! THAT GUY JUST ~A ~ASELF!!!!!~%~%" (if (and (getf (cdr had-accident) :leak-amount) (> (getf (cdr had-accident) :leak-amount) 0)) "MESSED" "WET") (if (malep user) "HIM" "HER")) (apply #'format t "*everybody points and laughs at ~a while ~a hides ~a face with ~a paws in embarrassment*~%~%" (name-of user) (if (malep user) '("he" "his" "his") '("she" "her" "her"))))) (defun change-the-baby (user &rest new-diaper) (let ((b (apply #'make-instance new-diaper))) (iter (for clothes on (wear-of user)) (when (typep (car clothes) 'bottoms) (handler-case (toggle-onesie (car clothes) clothes user) (onesie-locked (c) (setf (lockedp (car (clothes-of c))) nil) (toggle-onesie (car (clothes-of c)) (clothes-of c) (user-of c)))))) (setf (inventory-of (player-of *game*)) (append (inventory-of (player-of *game*)) (filter-items (wear-of user) 'closed-bottoms)) (wear-of user) (remove-if (lambda (a) (typep a 'closed-bottoms)) (wear-of user))) (if (wear-of user) (push b (cdr (last (wear-of user)))) (push b (wear-of user))) (iter (for clothes on (wear-of user)) (let ((nth (car clothes)) (nthcdr (cdr clothes))) (when (or (and (typep nth 'bottoms) (thickness-capacity-of nth) nthcdr (> (total-thickness nthcdr) (thickness-capacity-of nth))) (and (typep nth 'closed-bottoms) (or (>= (sogginess-of nth) (/ (sogginess-capacity-of nth) 4)) (>= (messiness-of nth) (/ (messiness-capacity-of nth) 4))))) (push nth (inventory-of (player-of *game*))) (setf (wear-of user) (s:delq nth (wear-of user)))))))) (defun trigger-diaper-police (had-accident user) (when (or (and (getf (car had-accident) :leak-amount) (> (getf (car had-accident) :leak-amount) 0)) (and (getf (cdr had-accident) :leak-amount) (> (getf (cdr had-accident) :leak-amount) 0))) (format t "*Seems ~a's mess got the attention of the diaper police.*~%~%" (name-of user)) (if (filter-items (wear-of user) 'padding) (progn (format t "Diaper Police: Seems this ~a needs a diaper change. Better change ~a~%~%" (species-of user) (if (malep user) "him" "her")) (format t "~a: Hey!!! Don't change me here!!! Everyone can see me!!!~%~%" (name-of user))) (progn (format t "Seems this ~a isn't potty trained, better diaper ~a~%~%" (species-of user) (if (malep user) "him" "her")) (format t "~a: Hey!!! I don't need diapers!!! Stop!!!~%~%" (name-of user)))) (change-the-baby user 'yadfa-items:kurikia-thick-diaper :locked t) (format t "*The diaper police straps the squirmy and heavily blushy ~a down on a public changing table, strips all of ~a's soggy clothes off (and all the clothes that won't fit over the new diaper), and puts a thick diaper on ~a. All while the local bystanders watch, snicker, giggle, and point*~%~%" (name-of user) (if (malep user) "he" "she") (if (malep user) "him" "her")) (format t "Diaper Police: And to be sure the baby keeps ~a diapers on~%~%" (if (malep user) "his" "her")) (format t "*The diaper police locks the diaper on to prevent ~a from removing it*~%~%" (name-of user)) (format t "*The diaper police unstrap ~a from the table. The diaper is so thick ~a's legs are spread apart forcing ~a to waddle*~%~%" (name-of user) (name-of user) (if (malep user) "him" "her")) (format t "Diaper Police: Aww, it looks like the baby is learning how to walk for the first time~%~%") (format t "*~a whines and covers ~a face with ~a paws in embarrassment*~%~%" (name-of user) (if (malep user) "his" "her") (if (malep user) "his" "her")) (when (trigger-event 'yadfa-events:get-diaper-locked-1) (format t "*~a tugs at the tabs trying to remove them, but they won't budge. Better find a solution before its too late*~%~%" (name-of user))))) #+ecl (named-readtables:in-readtable :fare-quasiquote) (defevent initialize-enemy-spawn-and-wear-lists :lambda (lambda (self) (declare (ignore self)) (serapeum:dict* (enemy-spawn-list-of *game*) 'bandits-way '((:chance 1/15 :enemies ((yadfa-enemies:female-diapered-raccoon-bandit . `(:level ,(random-from-range 2 4))))) (:chance 1/15 :enemies ((yadfa-enemies:rookie-diapered-raccoon-bandit . `(:level ,(random-from-range 2 4)))))) 'bandits-cove '((:chance 1/10 :enemies ((yadfa-enemies:rookie-diapered-raccoon-bandit . `(:level ,(random-from-range 2 5) :wear ,(list (make-instance 'yadfa-items:lower-bandit-swim-diaper-cover) (make-instance 'yadfa-items:bandit-diaper :sogginess (random 1000) :messiness (random 6000))))))) (:chance 1/10 :enemies ((yadfa-enemies:diapered-raccoon-bandit . `(:level ,(random-from-range 2 5) :wear ,(list (make-instance 'yadfa-items:bandit-swimsuit/closed) (make-instance 'bandit-swim-diaper-cover) (make-instance 'yadfa-items:bandit-diaper)))))) (:chance 1/10 :enemies ((yadfa-enemies:female-diapered-raccoon-bandit . `(:level ,(random-from-range 2 5) :wear ,(list (make-instance 'yadfa-items:bandit-uniform-sports-bikini-top) (make-instance 'yadfa-items:female-bandit-swim-diaper-cover) (make-instance 'yadfa-items:bandit-female-diaper :sogginess (random 1000) :messiness (random 6000)))))))) 'haunted-forest '((:chance 1/5 :enemies ((yadfa-enemies:ghost . `(:level ,(random-from-range 3 8)))))) 'rpgmaker-dungeon '((:chance 1/20 :enemies ((yadfa-enemies:rookie-diapered-raccoon-bandit . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:padded-fursuiter-servant . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:fursuiter-servant . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:navy-officer . `(:level ,(random-from-range 2 5))) (yadfa-enemies:navy-officer* . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:diaper-pirate . `(:level ,(random-from-range 2 5))) (yadfa-enemies:thickly-diaper-pirate . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:diapered-raccoon-bandit . `(:level ,(random-from-range 2 5))) (yadfa-enemies:rookie-diapered-raccoon-bandit . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:diapered-raccoon-bandit . `(:level ,(random-from-range 2 5))) (yadfa-enemies:female-diapered-raccoon-bandit . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:diapered-kobold . `(:level ,(random-from-range 2 5))) (yadfa-enemies:diapered-kobold . `(:level ,(random-from-range 2 5))))) (:chance 1/25 :enemies ((yadfa-enemies:diapered-dragon . `(:level ,(random-from-range 4 10))) (yadfa-enemies:diapered-kobold . `(:level ,(random-from-range 2 5) :wear ,(list (make-instance 'yadfa-items:kurikia-thick-diaper)))))) (:chance 1/25 :enemies ((yadfa-enemies:diapered-dragon* . `(:level ,(random-from-range 4 10))) (yadfa-enemies:diapered-kobold . `(:level ,(random-from-range 2 5) :wear ,(list (make-instance 'yadfa-items:kurikia-thick-diaper)))))) (:chance 1/20 :enemies ((yadfa-enemies:diapered-skunk . `(:level ,(random-from-range 2 5))))) (:chance 1/20 :enemies ((yadfa-enemies:diapered-skunk* . `(:level ,(random-from-range 2 5))))))) (serapeum:dict* (must-wear-of *game*) 'pyramid '((or yadfa-items:temple-diaper yadfa-items:cursed-diaper yadfa-items:infinity-diaper) . (lambda (user) (declare (ignore user)) (write-line "Only those who wear the enchanted pamps and only the enchanted pamps may enter.") nil))) (serapeum:dict* (must-wear*-of *game*) 'pyramid '((or yadfa-items:temple-diaper yadfa-items:cursed-diaper yadfa-items:infinity-diaper) . (lambda (user) (declare (ignore user)) (write-line "You can't remove those here.") nil))) (serapeum:dict* (must-not-wear-of *game*) 'pyramid '((not (or yadfa-items:temple-diaper yadfa-items:cursed-diaper yadfa-items:infinity-diaper)) . (lambda (user) (declare (ignore user)) (write-line "Only those who wear the enchanted pamps and only the enchanted pamps may enter.") nil))) (serapeum:dict* (must-not-wear*-of *game*) 'pyramid '((not (or yadfa-items:temple-diaper yadfa-items:cursed-diaper yadfa-items:infinity-diaper)) . (lambda (user) (declare (ignore user)) (write-line "You can't wear those here.") nil))))) #+ecl (named-readtables:in-readtable :standard) (trigger-event 'initialize-enemy-spawn-and-wear-lists)
14,766
Common Lisp
.lisp
216
44.578704
304
0.470034
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
2143dd6a11c68b9c55115b674d639fcff6b337d2ad14c93562f38705d11e8e9d
15,619
[ -1 ]
15,620
enemies.lisp
pouar_yadfa/data/prolog/enemies.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-enemies"; coding: utf-8-unix; -*- (in-package :yadfa-enemies) (defmacro make-instances (&rest symbols) `(list ,@(iter (for symbol in symbols) (collect `(make-instance ',symbol))))) (defclass catchable-enemy (enemy) ((catch-chance-rate% :initarg catch-chance-rate :accessor catch-chance-rate-of :initform 1 :type (real 0 1) :documentation "Chance of @var{CATCH-CHANCE} in 1 that this enemy can be caught where @var{CATCH-CHANCE} is a number between 0 and 1. If it is an object that can be coerced into a function, it is a function that accepts this enemy as an argument that returns a number."))) (defmethod catch-chance ((enemy catchable-enemy)) (/ (* (- (* 3 (calculate-stat enemy :health)) (* 2 (health-of enemy))) (catch-chance-rate-of enemy)) (* 3 (calculate-stat enemy :health)))) (defclass adoptable-enemy (enemy) ()) (defclass skunk-boop-mixin (base-character) ()) (defmethod change-class-text ((class adoptable-enemy)) (format nil "~a was adopted" (name-of class)))
1,079
Common Lisp
.lisp
19
53.157895
276
0.695283
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b689037f15cb6013ebcbdd445a71ad4b908520479798f70172b1cd24eeea197c
15,620
[ -1 ]
15,621
lukurbo.lisp
pouar_yadfa/data/events/lukurbo.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-events"; coding: utf-8-unix; -*- (in-package :yadfa-events) (defevent enter-lukurbo-1 :lambda (lambda (self) (declare (ignore self)) (f:fmt t "*You reach a town where you see a bunch of anthros in fursuits*" #\Newline #\Newline (name-of (player-of *game*)) ": OH BOY A PLUSHIE!!!! *glomps one of them*" "*fursuiter falls backward from being glomped*" #\Newline #\Newline (name-of (player-of *game*)) ": Aren't you adorable?" #\Newline #\Newline "*the fursuiter speaks in charades*" #\Newline #\Newline (name-of (player-of *game*)) ": You don't talk much do you?" #\Newline #\Newline "Random citizen: They're mute, much like the mascots you see in theme parks. Hi, welcome to Lukurbo. We're world famous for our padded servants here, and yes, they double as plushies." #\Newline #\Newline "*You decide to keep one as a pet*" #\Newline #\Newline) (finish-output) (format t "~a: I'm gonna call you ~a *snuggles*~%~%" (name-of (player-of *game*)) (name-of (accept-with-effective-frame (clim:accepting-values (*query-io* :resynchronize-every-pass t :exit-boxes '((:exit "Accept"))) (fresh-line *query-io*) (let ((a (make-instance 'yadfa-allies:furry :name (clim:accept 'string :prompt "Fursuiter Name" :default (second (assoc :name (progn (c2mop:ensure-finalized (find-class 'yadfa-allies:furry)) (c2mop:compute-default-initargs (find-class 'yadfa-allies:furry))))) :view clim:+text-field-view+ :stream *query-io*)))) (do-push a (team-of *game*) (allies-of *game*)) a)))))))
3,409
Common Lisp
.lisp
31
48.193548
223
0.315275
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
bde99bdd10b4f7442a436f57b8b8c69c2df35cc7f1414b7e1c66e72d64673e3c
15,621
[ -1 ]
15,622
debug.lisp
pouar_yadfa/data/events/debug.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-events"; coding: utf-8-unix; -*- (in-package :yadfa-events) (defevent test-battle-1 :lambda (lambda (self) (declare (ignore self)) (f:fmt t "Time to battle" #\Newline) (set-new-battle '((enemy)) :continuable t :win-events '(test-battle-2)))) (defevent test-battle-3 :lambda (lambda (self) (declare (ignore self)) (f:fmt t "You won" #\Newline))) (defevent test-battle-2 :lambda (lambda (self) (declare (ignore self)) (f:fmt t "Time to battle 2" #\Newline) (set-new-battle '((enemy) (enemy)) :continuable t :win-events '(test-battle-3))))
773
Common Lisp
.lisp
22
25.954545
87
0.533955
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
ed039f4ba35a7abba610582a9c2b6e23d2bba2a87e8a83a034c11b8f6ccc7044
15,622
[ -1 ]
15,623
dirty-chasm.lisp
pouar_yadfa/data/events/dirty-chasm.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-events"; coding: utf-8-unix; -*- (in-package :yadfa-events) (defevent pointless-quest-1 :lambda (lambda (self) (declare (ignorable self)) (f:fmt t "The author is running out of ideas, so lets add some filler content" #\Newline #\Newline "*Player starts 20 minute power up sequence by standing there screaming*" #\Newline #\Newline "Damn it, that takes up a lot less time in a text based game. Time to bring out the pointless quests" #\Newline #\Newline "But what quest can we perform? I know, well dome some tasks in the Digimon universe, but there's a catch. That particular universe is in a 90s Linux system. To make things a bit easier, and because Pouar doesn't want to try and implement some of the details because he's lazy, we'll let this Guilmon do some of this stuff for you" #\Newline #\Newline "*Guilmon recompiles the kernel to get video drivers and reboots, fries several monitors trying to get X working, recompiles the kernel and reboots again 20 times trying to find the right sound driver because you can only load one at a time, locks the system up because he forgot to run and configure isapnp before running modprobe, configures and runs isapnp before running modprobe, recompiles the kernel and reboots again to get the drivers for networking, struggles trying to write ppp chat scripts by hand, gives up and runs pppsetup from slackware, buys a new modem because Linux back then didn't support winmodem, goes to Netscape's website to download Netscape Navigator, journeys down over 9000 directories from the ftp cli client to get there, etc, etc, then shoots himself in the head.*" #\Newline #\Newline)))
1,784
Common Lisp
.lisp
10
167.2
840
0.734498
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
87c1b51ffdc4393a4b9b4ee17eb364466ccd1976cb55a52c10929b09ca8bc328
15,623
[ -1 ]
15,624
ironside.lisp
pouar_yadfa/data/events/ironside.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-events"; coding: utf-8-unix; -*- (in-package :yadfa-events) (defevent ironside-university-joke-1 :predicate (lambda (self) (declare (ignore self)) (= (random 3) 0)) :lambda (lambda (self) (declare (ignore self)) (f:fmt t "Diapered *Raccoon Bandit barges in*" #\Newline #\Newline "Diapered *Raccoon Bandit: Hey, is this one of those parenting classes that is looking for a live demonstration?" #\Newline #\Newline "Instructor: No" #\Newline #\Newline "Diapered Raccoon Bandit: Great, today I'm going to give all you aspiring parents a live demonstration on how to change your bab's diaper" #\Newline #\Newline "*Diapered Raccoon Bandit drags in a heavily blushing Rookie Diapered Raccoon Bandit wearing nothing but a soggy mushy diaper and pacigag*" #\Newline #\Newline "Instructor: Just how long is this supposed to take?" #\Newline #\Newline "Diapered Raccoon Bandit: Well considering the University decided to use a bunch of \"Gun Free Zone\" signs instead of security guards or police, I should have a good 45 minutes before anybody shows up to drag me out, but I should be done by then. You'd think after 6 shootings they'd learn their lesson, but eh." #\Newline #\Newline "*The Diapered Raccoon Bandit straps the Rookie down onto the teacher's desk*" #\Newline #\Newline "Diapered Raccoon Bandit: First you want to strap your bab down to keep him from running away and hiding his shame. Be sure to take recordings of this for posterity." #\Newline #\Newline "*The giggling students pull out their smartphones and start recording against the Rookie's will*" #\Newline #\Newline "Diaper Raccoon Bandit: Now you change your blushy bab's diaper and put in a new one like this" #\Newline #\Newline "*The Diapered Raccoon Bandit removes the rookie's diaper soggy messy diaper in front of all the students*" #\Newline #\Newline "Diaper Raccoon Bandit: Don't be afraid if your bab puts up a fuss. It's perfectly normal for him to be thoroughly embarrassed when you change him in public like this for the world to see, but it makes great entertainment at your bab's expense." #\Newline #\Newline "*The Diapered Raccoon Bandit puts a thick clean diaper on the rookie*" #\Newline #\Newline "Diaper Raccoon Bandit: You want to make sure you use diapers that are extremely thick to not just stop leaks, but to force your bab to waddle around and struggle to walk like a toddler. Sometimes your bab will be forced to crawl around on the floor like the bab he is." #\Newline #\Newline "*The Diapered Raccoon Bandit unstraps the rookie and carries him in his arms like an infant*" #\Newline #\Newline "Diaper Raccoon Bandit: And that's all there is to it, now I'm going to leave before the cops get the chance to show up and drag me away. So you're on your own for the rest of your class. Bye." #\Newline #\Newline "*Diapered Raccoon Bandit takes off*" #\Newline #\Newline)))
3,301
Common Lisp
.lisp
26
111.307692
352
0.679389
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
89dc095f06f3e5f2f9254e541b1a3de1a32f557f25ed59469ede696d571e841e
15,624
[ -1 ]
15,625
secret-underground.lisp
pouar_yadfa/data/events/secret-underground.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-events"; coding: utf-8-unix; -*- (in-package :yadfa-events) (defevent secret-underground-pipe-rpgmaker-dungeon :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:rpgmaker-dungeon) '(0 31 0 yadfa-zones:bandits-domain)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:rpgmaker-dungeon) :exit-text) "You jump into the warp pipe and jump out to the other side"))) (defevent secret-underground-pipe-lukurbo :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:lukurbo) '(0 0 0 yadfa-zones:lukurbo)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:lukurbo) :exit-text) "You jump into the warp pipe and jump out to the other side"))) (defevent secret-underground-pipe-silver-cape :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:silver-cape) '(0 0 0 yadfa-zones:silver-cape)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:silver-cape) :exit-text) "You jump into the warp pipe and jump out to the other side"))) (defevent secret-underground-pipe-haunted-forest :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:haunted-forest) '(0 0 0 yadfa-zones:haunted-forest)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:haunted-forest) :exit-text) "You jump into the warp pipe and jump out to the other side"))) (defevent secret-underground-pipe-haunted-house :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:haunted-house) '(6 -2 0 yadfa-zones:haunted-forest)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:haunted-house) :exit-text) "You jump into the warp pipe and jump out to the other side"))) (defevent secret-underground-pipe-candle-carnival :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:candle-carnival) '(0 0 0 yadfa-zones:candle-carnival)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:candle-carnival) :exit-text) "You jump into the warp pipe and jump out to the other side"))) (defevent secret-underground-pipe-sky-base :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:sky-base) '(0 0 0 yadfa-zones:sky-base)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:sky-base) :exit-text) "You jump into the warp pipe and jump out to the other side"))) (defevent secret-underground-pipe-star-city :lambda (lambda (self) (declare (ignore self)) (setf (getf (warp-points-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:star-city) '(0 0 0 yadfa-zones:star-city)) (setf (getf (getf (direction-attributes-of (get-zone '(0 0 0 yadfa-zones:secret-underground))) 'yadfa-zones:star-city) :exit-text) "You jump into the warp pipe and jump out to the other side")))
4,168
Common Lisp
.lisp
58
60.655172
149
0.639173
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
18bd14b800e00f2e337cb2630f2dbe36141ae28847d2b17b65efddc607b4abf7
15,625
[ -1 ]
15,626
pyramid.lisp
pouar_yadfa/data/events/pyramid.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-events"; coding: utf-8-unix; -*- (in-package :yadfa-events) (defevent infinity-diaper-obtained-1) (defevent pyramid-puzzle-1 :lambda (lambda (self) (declare (ignore self)) (cond ((finished-events 'infinity-diaper-obtained-1) (write-line "The entrance seems to have been sealed.")) ((destructuring-bind (&key (sogginess 0) (sogginess-capacity 0) (messiness 0) (messiness-capacity 0)) (calculate-diaper-usage (player-of *game*)) (declare (ignore sogginess-capacity messiness-capacity)) (or (> sogginess 0) (> messiness 0))) (write-line "According to the hieroglyphics, to open the entrance, your pamps must be clean.")) (t (multiple-value-bind (result wear) (funcall 'yadfa-pyramid:run-game) (let* ((bladder-time (/ (- (bladder/need-to-potty-limit-of (player-of *game*)) (bladder/contents-of (player-of *game*))) (bladder/fill-rate-of (player-of *game*)))) (bowels-time (/ (- (bowels/need-to-potty-limit-of (player-of *game*)) (bowels/contents-of (player-of *game*))) (bowels/fill-rate-of (player-of *game*)))) (flood-or-mess (cond ((and (> (bowels/contents-of (player-of *game*)) (bowels/need-to-potty-limit-of (player-of *game*))) (> (bladder/contents-of (player-of *game*)) (bladder/need-to-potty-limit-of (player-of *game*)))) 'both) ((> (bowels/contents-of (player-of *game*)) (bowels/need-to-potty-limit-of (player-of *game*))) 'mess) ((> (bladder/contents-of (player-of *game*)) (bladder/need-to-potty-limit-of (player-of *game*))) 'flood) ((= bladder-time bowels-time) 'both-fill) ((< bladder-time bowels-time) 'bladder-fill) (t 'bowels-fill))) (diapers (find wear '(yadfa-items:cursed-diaper yadfa-items:temple-pullups) :test (lambda (o e) (filter-items o e))))) (unless result (format t "~a~a, You give up ~a your ~a~%" (case diapers (yadfa-items:cursed-diaper "After struggling to remove your pamps") (yadfa-items:temple-pullups "After searching around for a bathroom")) (if (or (> (bladder/contents-of (player-of *game*)) (bladder/potty-dance-limit-of (player-of *game*))) (> (bowels/contents-of (player-of *game*)) (bowels/potty-dance-limit-of (player-of *game*)))) " doing a potty dance like a 5 year old" "") (typecase flood-or-mess ((member both mess both-fill bowels-fill) "reluctantly squat down with a blush on your face and fill") (t "with a blush on your face reluctantly flood")) (case diapers (yadfa-items:cursed-diaper "diapers") (yadfa-items:temple-pullups "pullups. You get even more embarrassed when you realized your pullups transformed back into diapers while you were using them."))) (case diapers ((both-fill bowels-fill) (incf (bowels/contents-of (player-of *game*)) (* bowels-time (bowels/fill-rate-of (player-of *game*)))) (incf (bladder/contents-of (player-of *game*)) (* bowels-time (bladder/fill-rate-of (player-of *game*))))) (bladder-fill (incf (bowels/contents-of (player-of *game*)) (* bladder-time (bowels/fill-rate-of (player-of *game*)))) (incf (bladder/contents-of (player-of *game*)) (* bladder-time (bladder/fill-rate-of (player-of *game*)))))) (wet :clothes wear) (mess :clothes wear)) (typecase result (list (write-line "Ghost hands suddenly appear and grab you and carry you to another room against your will. The ghost hands then set you on a changing table while holding you down to prevent your escape. You can only lay there in embarrassment as They then remove your diaper, then raise your legs up and slide a new one under you. They then lay your legs down and fasten the sides of the diaper, they then lift you up and set you down on the floor and give your padded rump a firm pat.") (setf (position-of (player-of *game*)) '(0 0 0 yadfa-zones:pyramid)) (change-class (first (wear-of (player-of *game*))) 'yadfa-items:temple-diaper) (apply 'reinitialize-instance (first (wear-of (player-of *game*))) (iter (for slot in (c2mop:compute-slots (find-class 'yadfa-items:temple-diaper))) (collect (car (c2mop:slot-definition-initargs slot))) (collect (funcall (c2mop:slot-definition-initfunction slot)))))) (t (format t "Your pullup glows and transforms into a thick diaper with a Ankh on the front. According to the hieroglyphics, this is the infinity diaper, famous for never leaking at all.") (change-class (first (wear-of (player-of *game*))) 'yadfa-items:infinity-diaper) (apply 'reinitialize-instance (first (wear-of (player-of *game*))) (iter (for slot in (c2mop:compute-slots (find-class 'yadfa-items:infinity-diaper))) (collect (car (c2mop:slot-definition-initargs slot))) (collect (funcall (c2mop:slot-definition-initfunction slot))))) (trigger-event 'infinity-diaper-obtained-1)))))))) :repeatable t)
7,004
Common Lisp
.lisp
75
60.533333
516
0.480877
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
941cb6bb234c01cc75bc8ab2f4a6460ce215797c435927b14817f0c2bd5eca06
15,626
[ -1 ]
15,627
pirates-cove.lisp
pouar_yadfa/data/events/pirates-cove.lisp
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-events"; coding: utf-8-unix; -*- (in-package :yadfa-events) (defevent pirates-cove-1 :lambda (lambda (self) (declare (ignorable self)) (let* ((a (make-instance 'yadfa-enemies:diaper-pirate)) (b (make-instance 'yadfa-enemies:thickly-diaper-pirate))) (f:fmt t "*You see one of the Pirate " (species-of a) "s changing an " (species-of b) " into multiple layers of padding*" #\Newline #\Newline "*The " (species-of b) " struggles to stand and waddles with the thick padding spreading " (if (malep b) "his" "her") " legs apart*" #\Newline #\Newline "Padded " (species-of a) ": Aww, looks like the baby " (species-of b) " is taking " (if (malep b) "his" "her") " first steps." #\Newline #\Newline "Thickly Padded " (species-of b) ": Shut it. Hey, isn't that an intruder?" #\Newline #\Newline "Padded " (species-of a) ": Apparently." #\Newline #\Newline) (set-new-battle `((yadfa-enemies:diaper-pirate . (list :level (random-from-range 2 5) :species ,(species-of a) :male ,(malep a))) (yadfa-enemies:thickly-diaper-pirate . (list :level (random-from-range 2 5) :species ,(species-of b) :male ,(malep b)))))))) (defevent pirates-cove-2 :lambda (lambda (self) (declare (ignorable self)) (let* ((a (make-instance 'yadfa-enemies:diaper-pirate)) (coon nil)) (f:fmt t "You find the diapered raccoon bandit back from Navy HQ in a pillory wearing nothing but 2 layers of thoroughly flooded and messy diapers" #\Newline #\Newline "Diapered Raccoon Bandit: OK! I learned my lesson! Can I please get a diaper change now?!?!? >///<" #\Newline #\Newline "*one of the " (species-of a)"s changes the outer layer of his diaper but still leaves him in the flooded and messy inner layer*" #\Newline #\Newline "Diapered Raccoon Bandit: That's not what I meant!!!" #\Newline #\Newline (species-of a) ": You're still being punished for giving out location away. So you're going to stay wet and messy for the rest of your life." #\Newline #\Newline "*The " (species-of a) " decides to spank the raccoon through his messy padding for amusement. Judging from the face the raccoon is making, he doesn't like being mushed and humiliated like that*" #\Newline #\Newline "*You decide to take sympathy on the poor raccoon and rescue him. You knock the " (species-of a) " out while " (if (malep a) "he" "she") "'s distracted from abusing " (if (malep a) "his" "her") " former ally. Then release the raccoon from the stocks and hand him his tunic to help preserve whatever dignity he has left" #\Newline #\Newline "Raccoon: umm, thanks." #\Newline #\Newline (name-of (player-of *game*)) ": got a name?" #\Newline #\Newline) (finish-output) (accept-with-effective-frame (clim:accepting-values (*query-io* :resynchronize-every-pass t :exit-boxes '((:exit "Accept"))) (setf coon (clim:accept 'string :stream *query-io* :prompt "Raccoon Name" :default #.(second (assoc :name (progn (c2mop:ensure-finalized (find-class 'yadfa-allies:slynk)) (c2mop:compute-default-initargs (find-class 'yadfa-allies:slynk))))) :view clim:+text-field-view+)))) (f:fmt t "Raccoon: It's " (name-of coon) #\Newline #\Newline (name-of coon) " decides you can't be all bad since you're the first one to be nice to him (plus the Raccoon Bandits abandoned him) and decides to join your team" #\Newline #\Newline) (do-push coon (team-of *game*) (allies-of *game*)) (when (>= (bladder/contents-of coon) (bladder/need-to-potty-limit-of coon)) (f:fmt t "*" (name-of coon) " grabs the front of his diaper*" #\Newline #\Newline (name-of (player-of *game*)) ": You don't have to go again do you?" #\Newline #\Newline "*" (name-of coon)) (if (>= (bladder/contents-of coon) (bladder/potty-dance-limit-of coon)) (f:fmt t " starts hopping around while holding the front of " (if (malep coon) "his" "her") " diaper*") (f:fmt t " takes " (if (malep coon) "his" "her") " hands off " (if (malep coon) "his" "her") " diaper, fidgets a little and blushes*")) (f:fmt t #\Newline #\Newline (name-of coon) ": No, of course not. I'm not some baby who needs to ask to go to the bathroom all the time" #\Newline #\Newline "*" (name-of coon) " seems too embarrassed to admit when he has to use the toilet. He might change his mind if he gets desperate enough" #\Newline #\Newline)))))
5,957
Common Lisp
.lisp
57
73.526316
360
0.504237
pouar/yadfa
5
1
0
GPL-3.0
9/19/2024, 11:27:22 AM (Europe/Amsterdam)
b6569daed88ec6429bc14730a31b8562f673fc8e3de5007f44c7a17810f32472
15,627
[ -1 ]