Page 1 of 1

INPUT BUFFERED FILE-STREAM CHARACTER

Posted: Mon Apr 11, 2011 12:15 pm
by notalisper
While writing a function involving dolist i received an error "should be a lambda expression" with the following code:

Code: Select all

(defun removeSortIterative(x l)
	(let ((result 0))
		(dolist (e l result) (if (equals x e) (setq result (result)) (setq result ((append (list e) result)))))))
I did some research and it seemed as though the error was due to the double parentheses as an open parentheses indicates a function and (append (list e) result) is not a function. Therefore I added a function so my code now reads:

Code: Select all

(defun removeSortIterative(x l)
	(let ((result 0))
		(dolist (e l result) (if (equals x e) (setq result (result)) (setq result (append (append (list e) result) nil)))))))
I am now, however, receiving an error that reads "input buffered file-stream character". I would appreciate any help on solving this debacle. I am new to lisp and cannot seem to figure out what's going wrong.

Thanks!

Re: INPUT BUFFERED FILE-STREAM CHARACTER

Posted: Mon Apr 11, 2011 6:56 pm
by nuntius
What does (result) do? (not a standard CL function)

Note its also common to (setq result (if test a b))

Re: INPUT BUFFERED FILE-STREAM CHARACTER

Posted: Tue Apr 12, 2011 9:27 am
by vanekl
Here are three alternatives.

Code: Select all

(defun removeSortIterative(x l)
  (let ((result ()))
    (dolist (e l result)
      (when (not (equal x e))
	(setq result (append result (list e)))))))

(defun removeSortIterative(x list)
  (reduce (lambda (acc e)
	    (when (not (equal x e))
	      (nconc acc (list e))))
	  list :initial-value (list 0)))

(defun removeSortIterative (x list)
  (let ((result ()))
    (map 'nil (lambda (e)
		(when (not (equal x e))
		  (push e result)))
	 list)
    (reverse result)))