I am trying to write a procedure to list in order a list of numbers .. I can write a proceudure that works using a recursive procedure but when I try it with an iterative procedure http://pastebin.com/BKzcX8P7 I get an error saying "not a real"
I tried to write the procedure using scheme here http://pastebin.com/pF5QecFc and it works ok so Im wondering what Im doing wrong with common lisp ..
I don't have lots of access to the net at the moment and Im not sure what I should be looking for anyways so any help is really appreciated ..
thanks al
problem with iterative procedure
Re: problem with iterative procedure
First of all, I discourage you to use defun inside of defun. Use labels instead. And the defun creates a globally-recognized function and you have two definitions of helper inside of your code.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
-
- Posts: 11
- Joined: Wed Nov 02, 2011 11:56 pm
Re: problem with iterative procedure
thanks for the hands up .. after a few hiccups getting the parenthesis in the right places I got everything working http://pastebin.com/fJSVdiwu
any other ideas you would care to share on my code welcome.
appreciate the help thanks al.
any other ideas you would care to share on my code welcome.
appreciate the help thanks al.
Re: problem with iterative procedure
I have a couple of notes to say. CL is Lisp-2, you don't have to write lst instead of list. The list function will be still at disposal because od another namespace. The let can have more than one binding clause.
My first iteration of rewriting:
My first iteration of rewriting:
Code: Select all
(defun small- (list)
(loop for elem in list minimize elem))
(defun gen-first-occurence-p (elem &aux (count 0))
(lambda (x)
(if (equalp x elem)
(= (incf count) 1))))
(defun remove- (list remove-me)
(remove-if (gen-first-occurence-p remove-me) list))
(defun order- (list)
(loop for remain = list then (remove- remain minimal)
for minimal = (small- remain)
while remain collect minimal))
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.