From: Steffen Panning
Subject: how do I know if a function exists
Date: 
Message-ID: <evvaqj$lig$01$1@news.t-online.com>
Hello,

currently I'm trying to find out if a function exists in a package.

I thought find-symbol would do the first part of the trick, but it doesn't:


(defun test () 'a-test)

(find-symbol 'test)
NIL
NIL

(find-symbol 'test 'cl-user)
NIL
NIL

I tried then to work with make-symol and functionp, but - as I thought 
before - this doesn't work too.

Here is the code I'm working on:

;; (simplified) first try:
;; builds av-pairs for clsql;
;; validates each K if validator-pkg:validate-K exists
;; missing: error-behaviour when validator exists and fails;

(defmacro av-pairs (validator-pkg &rest key-list)
   (let ((validator-name (gensym))
	(res-lst        (gensym)))

     `(let ((,res-lst (list)))
       (progn ,@(mapcar (lambda (k)
			 (when validator-pkg
			   (setf validator-name (make-symbol
                              (format nil "~A:validate-~A" validator-pkg 
k))))
			`(when (and (functionp #,validator-name)
				    (funcall #',validator-name ,k))
			     (push (list ',k ,k) ,res-lst )))) key-list))
       ,res-lst)))




the intention of this macro is:

(defun some-fn (a b c)
   (let ((pairs (av-pairs my-validator-pkg a b c)))
    ;; ...
  ))

I don't know how to get this to work. Has anybody an Idea?

thanks for help

steffen






is there a way to get this information?
From: Rainer Joswig
Subject: Re: how do I know if a function exists
Date: 
Message-ID: <joswig-598CD4.11282516042007@news-europe.giganews.com>
In article <···············@news.t-online.com>,
 Steffen Panning <·····@t-online.de> wrote:

> Hello,
> 
> currently I'm trying to find out if a function exists in a package.
> 
> I thought find-symbol would do the first part of the trick, but it doesn't:
> 
> 
> (defun test () 'a-test)
> 
> (find-symbol 'test)
> NIL
> NIL

Do you know how to find the documentation for a Common Lisp
function or macro? The ANSI CL HyperSpec?

The check out FIND-SYMBOL, MAKE-SYMBOL, FUNCTIONP, FBOUNDP.

> 
> (find-symbol 'test 'cl-user)
> NIL
> NIL
> 
> I tried then to work with make-symol and functionp, but - as I thought 
> before - this doesn't work too.
> 
> Here is the code I'm working on:
> 
> ;; (simplified) first try:
> ;; builds av-pairs for clsql;
> ;; validates each K if validator-pkg:validate-K exists
> ;; missing: error-behaviour when validator exists and fails;
> 
> (defmacro av-pairs (validator-pkg &rest key-list)
>    (let ((validator-name (gensym))
> 	(res-lst        (gensym)))
> 
>      `(let ((,res-lst (list)))
>        (progn ,@(mapcar (lambda (k)
> 			 (when validator-pkg
> 			   (setf validator-name (make-symbol
>                               (format nil "~A:validate-~A" validator-pkg 
> k))))
> 			`(when (and (functionp #,validator-name)
> 				    (funcall #',validator-name ,k))
> 			     (push (list ',k ,k) ,res-lst )))) key-list))
>        ,res-lst)))

Why are you writing a macro? Start with a function.
Try out smaller sections of code...

> 
> 
> 
> 
> the intention of this macro is:
> 
> (defun some-fn (a b c)
>    (let ((pairs (av-pairs my-validator-pkg a b c)))
>     ;; ...
>   ))
> 
> I don't know how to get this to work. Has anybody an Idea?
> 
> thanks for help
> 
> steffen
> 
> 
> 
> 
> 
> 
> is there a way to get this information?

-- 
http://lispm.dyndns.org