diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-20 08:37:05 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-20 08:37:05 -0300 |
commit | cf7dc2892c1f3a474b7c49f35cbab08bfa08ef71 (patch) | |
tree | 9dfb32e87a531027210032639099f82543930694 | |
parent | a8b56704b52488f2865387d8cded8e5f13cdf919 (diff) | |
download | utils-cf7dc2892c1f3a474b7c49f35cbab08bfa08ef71.tar.gz utils-cf7dc2892c1f3a474b7c49f35cbab08bfa08ef71.zip |
Add with-package to utils
-rw-r--r-- | package.lisp | 10 | ||||
-rw-r--r-- | print.lisp | 6 | ||||
-rw-r--r-- | str.lisp | 2 | ||||
-rw-r--r-- | utils.asd | 2 | ||||
-rw-r--r-- | utils.lisp | 11 |
5 files changed, 18 insertions, 13 deletions
diff --git a/package.lisp b/package.lisp index f4158be..81821dd 100644 --- a/package.lisp +++ b/package.lisp @@ -1,10 +1,10 @@ -(defpackage #:alien - (:use #:cl #:sb-alien) - (:export #:call)) +(defpackage #:utils + (:use #:cl) + (:export #:with-package)) -(defpackage #:print +(defpackage #:alien (:use #:cl) - (:export #:table)) + (:export #:call)) (defpackage #:queue (:use #:cl) diff --git a/print.lisp b/print.lisp deleted file mode 100644 index 1ea7932..0000000 --- a/print.lisp +++ /dev/null @@ -1,6 +0,0 @@ -(in-package #:print) - -(defun table (tbl) - (maphash (lambda (k v) - (format t "~a : ~a~&" k v)) - tbl)) @@ -1,6 +1,6 @@ (in-package #:str) -(declaim (optimize (speed 3) (safety 0))) +(declaim (optimize (speed 3) (safety 1))) (declaim (ftype (function ((or pathname string)) (values string &optional)) read-file)) (defun read-file (path) @@ -2,7 +2,7 @@ :serial t :components ((:file "package") + (:file "utils") (:file "queue") (:file "alien") - (:file "print") (:file "str"))) diff --git a/utils.lisp b/utils.lisp new file mode 100644 index 0000000..d0f61d5 --- /dev/null +++ b/utils.lisp @@ -0,0 +1,11 @@ +(in-package #:utils) + +(defmacro with-package (pkg-sym &body body) + (let ((pkg-name (symbol-name pkg-sym))) + (unless (find-package pkg-name) + (make-package pkg-name)) + (let ((body-as-string (format nil "(cl:progn ~{~s~&~})" body)) + (body-as-form)) + (let ((*package* (find-package pkg-name))) + (setq body-as-form (read-from-string body-as-string))) + body-as-form))) |