help me......please!!!
Write a recursive function EXIFY that takes any S-expression and converts it
to a new on ein which all atoms other than NIL have been replaced by X. Thus
(EXIFY '(A (B C) X Y NIL Z)) should produce (X (X X) X X NIL X).
help me.........thanks.......
���� wrote:
> help me......please!!!
>
> Write a recursive function EXIFY that takes any S-expression and converts it
> to a new on ein which all atoms other than NIL have been replaced by X. Thus
> (EXIFY '(A (B C) X Y NIL Z)) should produce (X (X X) X X NIL X).
>
> help me.........thanks.......
(subst-if 'x #'(lambda (x) (and (atom x) x)) '(a (b) nil))
=> (x (x) nil)
* "someone" == ���� <········@lycos.co.kr> writes:
someone> help me......please!!! Write a recursive function EXIFY
someone> that takes any S-expression and converts it to a new on ein
someone> which all atoms other than NIL have been replaced by X. Thus
someone> (EXIFY '(A (B C) X Y NIL Z)) should produce (X (X X) X X NIL
someone> X).
Show us what you've done so far and where you stuck, and we will help
you.
BTW, please adjust your 'From' line when posting to an international
newsgroup; many of us don't have Korean fonts installed.
--
Eugene
"����" <········@lycos.co.kr> writes:
> Write a recursive function EXIFY that takes any S-expression and
> converts it to a new on ein which all atoms other than NIL have been
> replaced by X. Thus (EXIFY '(A (B C) X Y NIL Z)) should produce (X
> (X X) X X NIL X).
Sure:
(defun atom-not-nil (elem)
(and (atom elem) elem))
(defun exify (list)
(subst-if 'x #'atom-not-nil list))
Oops. Forgot to make the function recursive:
(defun exify (list &optional really-do-it)
(if really-do-it
(subst-if 'x #'atom-not-nil list)
(exify list t)))
There you go. Hope this helps.
Stig Hemmer,
Jack of a Few Trades.
* ���� wrote:
> help me......please!!!
> Write a recursive function EXIFY that takes any S-expression and converts it
> to a new on ein which all atoms other than NIL have been replaced by X. Thus
> (EXIFY '(A (B C) X Y NIL Z)) should produce (X (X X) X X NIL X).
(defgeneric exify (form))
(defmethod exify ((form cons))
(cons (exify (car form))
(exify (cdr form))))
(defmethod exify ((form null))
nil)
(defmethod exify ((form t))
'x)
--tim
"����" <········@lycos.co.kr> writes:
> help me......please!!!
>
> Write a recursive function EXIFY that takes any S-expression and converts it
> to a new on ein which all atoms other than NIL have been replaced by X. Thus
> (EXIFY '(A (B C) X Y NIL Z)) should produce (X (X X) X X NIL X).
>
> help me.........thanks.......
Where's you code? What is your problem?
Regards
Friedrich
--
for e-mail reply remove all after .com
"����" wrote:
> Write a recursive function EXIFY that takes any S-expression and converts it
> to a new on ein which all atoms other than NIL have been replaced by X. Thus
> (EXIFY '(A (B C) X Y NIL Z)) should produce (X (X X) X X NIL X).
Is this perhaps homework? You might take a look with dejanews on the
discussions re homework on this newsgroup in last two weeks...
Here's one implementation, a little censored, though: invent something
to put in place of all the ***'s:
(defun exify (item)
(cond ((**** item) nil)
((**** item) 'x)
((**** item) (**** #'exify item))
(T (warn "odd item ~A" item)))) ;; should never get here...
--