How to modify a function the way I need?
Posted: Sat Aug 22, 2009 5:45 am
Hi all. I have a function which places @ symbol before every negative or evenp element of a list. It look's like this
This is an example for even elements.
This works fine! but I need a to modify it to make possible calls like this
mufunc((LAMBDA (x) (>= x 0)) ‘(1 0 -2 3 0 -4 5)) –> (@ 1 0 -2 @ 3 0 -4 @ 5) - this call for negative elements and it should use lambda and
mufunc(‘EVENP ‘(1 0 -2 3 0 -4 5)) –> (1 @ 0 @ -2 3 @ 0 @ -4 5) - and this for even elements.
I need your help. Help me please
This is an example for even elements.
Code: Select all
(defun mufunc (x)
(cond ((null x) nil)
((evenp (car x)) (cons (intern (format nil "@~a" (car x)))
(mufunc (cdr x))))
(T (cons (car x) (mufunc (cdr x))))))
mufunc((LAMBDA (x) (>= x 0)) ‘(1 0 -2 3 0 -4 5)) –> (@ 1 0 -2 @ 3 0 -4 @ 5) - this call for negative elements and it should use lambda and
mufunc(‘EVENP ‘(1 0 -2 3 0 -4 5)) –> (1 @ 0 @ -2 3 @ 0 @ -4 5) - and this for even elements.
I need your help. Help me please