From: ········@gmail.com
Subject: please check my algorithm to remove sub-list.
Date: 
Message-ID: <b67a732e-a8aa-45d3-8602-e3b006e006f9@c19g2000prf.googlegroups.com>
hi there,

I always appreciate your help.
please check my code. The code is used for removing sub-list.

(defun remove-ex (list-value find-value)
	(my-remove-helper list-value find-value nil ) )

(defun my-remove-helper (list-value find-value result )
	(cond ((null list-value ) result )
		((equal find-value (car list-value)) (my-remove-helper (cdr list-
value) find-value result )
		)

		((listp (car list-value)) (my-remove-helper (car list-value) find-
value (append result (list nil)))
		)

		(t ( my-remove-helper (cdr list-value) find-value (append result
(list (car list-value) ) ) ) )
	)
)

my code operates like this ..

------------------------------------------------
[4] USER(236): (remove-ex '(A B C D E F A) 'A)
(B C D E F)


[4] USER(237): (remove-ex '((A B) C D E) '(A B))
(C D E)


[4] USER(238): (remove-ex '(((A B))) '(A B))
(NIL)


[4] USER(239): (remove-ex '((((A B)))) '(A B))
(NIL NIL)
------------------------------------------------

The fourth result is not what I expected. What I expected is ((NIL)).
I think the code below has to make somewhat of change.

------------------------------------------------
((listp (car list-value)) (my-remove-helper (car list-value) find-
value (append result (list nil))))
------------------------------------------------

but I can't find it. I'm very new to LISP and functional language..
Could you help me?? thanks~

From: Gene
Subject: Re: please check my algorithm to remove sub-list.
Date: 
Message-ID: <880c4b23-f7dd-479a-a63b-f917b14d04d9@a70g2000hsh.googlegroups.com>
On Mar 22, 11:47 pm, ········@gmail.com wrote:
> hi there,
>
> I always appreciate your help.
> please check my code. The code is used for removing sub-list.
>
> (defun remove-ex (list-value find-value)
>         (my-remove-helper list-value find-value nil ) )
>
> (defun my-remove-helper (list-value find-value result )
>         (cond ((null list-value ) result )
>                 ((equal find-value (car list-value)) (my-remove-helper (cdr list-
> value) find-value result )
>                 )
>
>                 ((listp (car list-value)) (my-remove-helper (car list-value) find-
> value (append result (list nil)))
>                 )
>
>                 (t ( my-remove-helper (cdr list-value) find-value (append result
> (list (car list-value) ) ) ) )
>         )
> )
>
> my code operates like this ..
>
> ------------------------------------------------
> [4] USER(236): (remove-ex '(A B C D E F A) 'A)
> (B C D E F)
>
> [4] USER(237): (remove-ex '((A B) C D E) '(A B))
> (C D E)
>
> [4] USER(238): (remove-ex '(((A B))) '(A B))
> (NIL)
>
> [4] USER(239): (remove-ex '((((A B)))) '(A B))
> (NIL NIL)
> ------------------------------------------------
>
> The fourth result is not what I expected. What I expected is ((NIL)).
> I think the code below has to make somewhat of change.
>
> ------------------------------------------------
> ((listp (car list-value)) (my-remove-helper (car list-value) find-
> value (append result (list nil))))
> ------------------------------------------------
>
> but I can't find it. I'm very new to LISP and functional language..
> Could you help me?? thanks~

The recursion invariant isn't consistent.  Assuming I've read your
intent, here's an easier way.

(defun remove-ex (tree item)
   (cond ((atom tree) tree)
	 ((equalp (car tree) item)
	  (remove-ex (cdr tree) item))
	 (t (cons (remove-ex (car tree) item)
		  (remove-ex (cdr tree) item)))))
From: Kent M Pitman
Subject: Re: please check my algorithm to remove sub-list.
Date: 
Message-ID: <uiqzerqyz.fsf@nhplace.com>
········@gmail.com writes:

> I always appreciate your help.
> please check my code. The code is used for removing sub-list.

Is this a homework assignment?

People here are often willing to help with these things, but they need
to know if it's homework or not.
From: William James
Subject: Re: please check my algorithm to remove sub-list.
Date: 
Message-ID: <e663275e-15e7-4bb3-8b63-d500f24c4189@s12g2000prg.googlegroups.com>
On Mar 22, 9:47 pm, ········@gmail.com wrote:
> hi there,
>
> I always appreciate your help.
> please check my code. The code is used for removing sub-list.
>
> (defun remove-ex (list-value find-value)
>         (my-remove-helper list-value find-value nil ) )
>
> (defun my-remove-helper (list-value find-value result )
>         (cond ((null list-value ) result )
>                 ((equal find-value (car list-value)) (my-remove-helper (cdr list-
> value) find-value result )
>                 )
>
>                 ((listp (car list-value)) (my-remove-helper (car list-value) find-
> value (append result (list nil)))
>                 )
>
>                 (t ( my-remove-helper (cdr list-value) find-value (append result
> (list (car list-value) ) ) ) )
>         )
> )
>
> my code operates like this ..
>
> ------------------------------------------------
> [4] USER(236): (remove-ex '(A B C D E F A) 'A)
> (B C D E F)
>
> [4] USER(237): (remove-ex '((A B) C D E) '(A B))
> (C D E)
>
> [4] USER(238): (remove-ex '(((A B))) '(A B))
> (NIL)
>
> [4] USER(239): (remove-ex '((((A B)))) '(A B))
> (NIL NIL)
> ------------------------------------------------
>
> The fourth result is not what I expected. What I expected is ((NIL)).
> I think the code below has to make somewhat of change.
>
> ------------------------------------------------
> ((listp (car list-value)) (my-remove-helper (car list-value) find-
> value (append result (list nil))))
> ------------------------------------------------
>
> but I can't find it. I'm very new to LISP and functional language..
> Could you help me?? thanks~

Ruby:

def remove_ex list, find_value
  result = []
  list.each{ |x|
    next  if x == find_value
    result <<
      if x.class == Array
        remove_ex( x, find_value )
      else
        x
      end }
  result
end