[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Franz lisp question (again)



I was wondering if someone could suggest a solution to the following
problem:

I want a franz lisp function to find all the occurences of an atom in a
list.  So, I write a function anyequalp ...

(defun anyequalp (atm lst)
    (mapcar (function (lambda (x) (and (equal atm x) x))) lst))


This works fine.  I compile the code and get no warnings or errors, and the
code even works.  What I really want are ONLY those elements in the list
that satisfy the predicate.  So, I rewrite the function this way ...

(defun anyequalp (atm lst)
    (mapcan (function (lambda (x) (and (equal atm x) (list x)))) lst))

This works fine (even when compiled), except I really want a non-destructive
version that will put the list together using "append" instead of "nconc".
So, I write the function "mapappend" as ...

(defun mapappend (func lst)
    (apply (function append) (mapcar func lst)))

I substitue "mapappend" for "mapcan" in my function definition for anyequalp.
Things work great.  NOW, I try to compile my code and I get the following
messages (paraphased) ...

anyequalp: Warning: in line lambda (some huge number)
Warning: atm declared special by compiler.

Not suprisingly, when the code runs now, it does not work correctly.  Does
the compiler know about the mapping functions and take special actions with
them?  Is there a way I can get the compiler to accept my version of
mapappend and make it behave like mapcan?  Is this a bug that allows me to
do something with the mapping functions that I'm not supposed to be able to
do?  Can 10000 angels really fit on the end of a pinpoint, or is there
really only room for one?

I realize all this could be avoided by writing the function iteratively, but
I'd like to know why my version doesn't work before I discard the idea.