summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.lisp57
-rw-r--r--str.lisp23
-rw-r--r--utils.asd1
-rw-r--r--utils.lisp11
4 files changed, 64 insertions, 28 deletions
diff --git a/package.lisp b/package.lisp
index 81821dd..f2e0a24 100644
--- a/package.lisp
+++ b/package.lisp
@@ -1,7 +1,3 @@
-(defpackage #:utils
- (:use #:cl)
- (:export #:with-package))
-
(defpackage #:alien
(:use #:cl)
(:export #:call))
@@ -20,3 +16,56 @@
(:export #:split
#:from-list
#:read-file))
+
+(defpackage #:small-cl
+ (:import-from #:cl
+ #:block
+ #:catch
+ #:eval-when
+ #:flet
+ #:function
+ #:go
+ #:if
+ #:labels
+ #:let
+ #:let*
+ #:load-time-value
+ #:locally
+ #:macrolet
+ #:multiple-value-call
+ #:multiple-value-prog1
+ #:progn
+ #:progv
+ #:quote
+ #:return-from
+ #:setq
+ #:symbol-macrolet
+ #:tagbody
+ #:the
+ #:throw
+ #:unwind-protect)
+ (:export #:block
+ #:catch
+ #:eval-when
+ #:flet
+ #:function
+ #:go
+ #:if
+ #:labels
+ #:let
+ #:let*
+ #:load-time-value
+ #:locally
+ #:macrolet
+ #:multiple-value-call
+ #:multiple-value-prog1
+ #:progn
+ #:progv
+ #:quote
+ #:return-from
+ #:setq
+ #:symbol-macrolet
+ #:tagbody
+ #:the
+ #:throw
+ #:unwind-protect))
diff --git a/str.lisp b/str.lisp
index 5116be4..aee3604 100644
--- a/str.lisp
+++ b/str.lisp
@@ -1,8 +1,8 @@
(in-package #:str)
-(declaim (optimize (speed 3) (safety 1)))
+(declaim (optimize speed))
-(declaim (ftype (function ((or pathname string)) (values string &optional)) read-file))
+(declaim (ftype (function ((or pathname string)) (values simple-string &optional)) read-file))
(defun read-file (path)
(with-open-file (file path)
(let* ((size (file-length file))
@@ -10,17 +10,17 @@
(read-sequence buf file)
buf)))
-(declaim (ftype (function (simple-string simple-string) (values (cons string) &optional)) split))
+(declaim (ftype (function (simple-string simple-string) (values (cons simple-string) &optional)) split))
(defun split (input delimiter)
- (defun split-rec (result start)
- (let ((next (search delimiter input :start2 start)))
- (if next
- (split-rec (queue:add result (subseq input start next)) (min (+ (length delimiter) next)
- (length input)))
- (queue:add result (subseq input start next)))))
- (queue:to-list (split-rec (queue:new) 0)))
+ (labels ((split-rec (result start)
+ (let ((next (search delimiter input :start2 start)))
+ (if next
+ (split-rec (queue:add result (subseq input start next)) (min (the fixnum (+ (length delimiter) next))
+ (the fixnum (length input))))
+ (queue:add result (subseq input start next))))))
+ (queue:to-list (split-rec (queue:new) 0))))
-(declaim (ftype (function ((cons character)) (values simple-string &optional)) from-list))
+(declaim (ftype (function ((or null (cons character))) (values simple-string &optional)) from-list))
(defun from-list (lst)
(let ((str (make-string (length lst)))
(i 0))
@@ -28,4 +28,3 @@
(setf (char str i) item)
(incf i))
str))
-
diff --git a/utils.asd b/utils.asd
index 7a12042..878e309 100644
--- a/utils.asd
+++ b/utils.asd
@@ -2,7 +2,6 @@
:serial t
:components
((:file "package")
- (:file "utils")
(:file "queue")
(:file "alien")
(:file "str")))
diff --git a/utils.lisp b/utils.lisp
deleted file mode 100644
index d0f61d5..0000000
--- a/utils.lisp
+++ /dev/null
@@ -1,11 +0,0 @@
-(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)))