From cf7dc2892c1f3a474b7c49f35cbab08bfa08ef71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Feb 2023 08:37:05 -0300 Subject: Add with-package to utils --- package.lisp | 10 +++++----- print.lisp | 6 ------ str.lisp | 2 +- utils.asd | 2 +- utils.lisp | 11 +++++++++++ 5 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 print.lisp create mode 100644 utils.lisp 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)) diff --git a/str.lisp b/str.lisp index a8b2a7f..5116be4 100644 --- a/str.lisp +++ b/str.lisp @@ -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) diff --git a/utils.asd b/utils.asd index bd97c0c..7a12042 100644 --- a/utils.asd +++ b/utils.asd @@ -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))) -- cgit v1.2.3