Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added funcall-if-exists and refactored apply-if-exists

darcs-hash:20080928194942-3cc5d-0ba24076308fd2c74b7ab1b938de8f3c29a5bacd.gz
  • Loading branch information...
commit 3eeed076b7d973db9e5b9e8f28c3249f1dc9f63c 1 parent 36fc50e
@gwkkwg authored
Showing with 21 additions and 2 deletions.
  1. +20 −2 dev/l0-utils.lisp
  2. +1 −0  dev/package.lisp
View
22 dev/l0-utils.lisp
@@ -242,6 +242,22 @@ not sticky."
((ensure (not (dotted-pair-p nil))))))
(defun apply-if-exists (function package &rest args)
+ "If the function `function` can be found in `package`, then apply it
+to `args`.
+
+Returns nil if `package` does not exist or if `function` does not name a
+function in `package`. Otherwise, returns whatever `function` returns."
+ (call-if-exists 'apply function package args))
+
+(defun funcall-if-exists (function package &rest args)
+ "If the function `function` can be found in `package`, then funcall it
+on `args`.
+
+Returns nil if `package` does not exist or if `function` does not name a
+function in `package`. Otherwise, returns whatever `function` returns."
+ (call-if-exists 'funcall function package args))
+
+(defun call-if-exists (call-with function package args)
"If the function `function` can be found in `package`, then call it
with `args`.
@@ -254,8 +270,10 @@ function in `package`. Otherwise, returns whatever `function` returns."
(symbol (symbol-name function)))
package)))
(when (and symbol (fboundp symbol))
- (apply symbol args))))))
-
+ (if (eq call-with 'funcall)
+ (apply #'funcall symbol args)
+ (apply #'apply symbol args)))))))
+
(defun iterate-over-indexes (symbol-counts fn &optional (direction :left))
"Apply fn to lists of indexes generated from symbol counts. The counting is
done so that the first symbol varies most quickly unless the optional direction
View
1  dev/package.lisp
@@ -72,6 +72,7 @@
(:export
#:apply-if-exists
+ #:funcall-if-exists
#:defclass-property
#:deprecated
Please sign in to comment.
Something went wrong with that request. Please try again.