From 43e5015c6779edaa3894592b8a166f15cd163fa3 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sat, 2 Jul 2011 11:02:23 -0600 Subject: [PATCH] Add parse-float --- package.lisp | 2 ++ processes.lisp | 31 +++++++++++++++++++++---------- strings.lisp | 11 +++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/package.lisp b/package.lisp index 6432b88..c9ecf42 100644 --- a/package.lisp +++ b/package.lisp @@ -218,6 +218,8 @@ #:print-separated-strings #:lex-string #:split-alphanumeric-string + #:safely-read-from-string + #:parse-float ;; strmatch.lisp #:score-multiword-match diff --git a/processes.lisp b/processes.lisp index 7017ce7..22cde94 100644 --- a/processes.lisp +++ b/processes.lisp @@ -16,8 +16,8 @@ #+cmu (mp:make-process func :name name) #+lispworks (mp:process-run-function name nil func) #+sb-thread (sb-thread:make-thread func :name name) - #+openmcl (ccl:process-run-function name func) - #-(or allegro cmu lispworks sb-thread openmcl) (funcall func) + #+ccl (ccl:process-run-function name func) + #-(or allegro cmu lispworks sb-thread ccl) (funcall func) ) (defun destroy-process (process) @@ -25,29 +25,37 @@ #+allegro (mp:process-kill process) #+sb-thread (sb-thread:destroy-thread process) #+lispworks (mp:process-kill process) - #+openmcl (ccl:process-kill process) + #+ccl (ccl:process-kill process) ) (defun make-lock (name) + "Make a named process lock." + #+abcl (ext:make-thread-lock) #+allegro (mp:make-process-lock :name name) + #+ccl (ccl:make-lock name) #+cmu (mp:make-lock name) #+lispworks (mp:make-lock :name name) #+sb-thread (sb-thread:make-mutex :name name) - #+openmcl (ccl:make-lock name) - ) + #-(or lispworks abcl openmcl allegro sb-thread) + (declare (ignore name)) + #-(or abcl allegro ccl cmu lispworks sb-thread) + nil) + (defmacro with-lock-held ((lock) &body body) + #+abcl + `(ext:with-thread-lock (,lock) ,@body) #+allegro `(mp:with-process-lock (,lock) ,@body) + #+ccl + `(ccl:with-lock-grabbed (,lock) ,@body) #+cmu `(mp:with-lock-held (,lock) ,@body) #+lispworks `(mp:with-lock (,lock) ,@body) #+sb-thread `(sb-thread:with-recursive-lock (,lock) ,@body) - #+openmcl - `(ccl:with-lock-grabbed (,lock) ,@body) - #-(or allegro cmu lispworks sb-thread openmcl) + #-(or abcl allegro ccl cmu lispworks sb-thread) `(progn ,@body) ) @@ -59,16 +67,19 @@ `(mp:with-timeout (,seconds) ,@body) #+sb-thread `(sb-ext:with-timeout ,seconds ,@body) - #+openmcl + #+ccl `(ccl:process-wait-with-timeout "waiting" (* ,seconds ccl:*ticks-per-second*) #'(lambda () ,@body) nil) - #-(or allegro cmu sb-thread openmcl) + #-(or allegro cmu sb-thread ccl) `(progn ,@body) ) (defun process-sleep (n) + "Put thread to sleep for n seconds." #+allegro (mp:process-sleep n) #-allegro (sleep n)) + + diff --git a/strings.lisp b/strings.lisp index 4dcda49..3390581 100644 --- a/strings.lisp +++ b/strings.lisp @@ -718,3 +718,14 @@ for characters in a string" (do ((x (read stream nil eof) (read stream nil eof)) (l nil (cons x l))) ((eq x eof) (nreverse l)))))) + +(defun safely-read-from-string (str &rest read-from-string-args) + "Read an expression from the string STR, with *READ-EVAL* set +to NIL. Any unsafe expressions will be replaced by NIL in the +resulting S-Expression." + (let ((*read-eval* nil)) + (ignore-errors (apply 'read-from-string str read-from-string-args)))) + +(defun parse-float (f) + (let ((*read-default-float-format* 'double-float)) + (coerce (safely-read-from-string f) 'double-float))) -- 2.34.1