problem with iterative procedure

Discussion of Common Lisp
Post Reply
MadMuppet006
Posts: 11
Joined: Wed Nov 02, 2011 11:56 pm

problem with iterative procedure

Post by MadMuppet006 » Mon Oct 13, 2014 10:03 pm

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

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: problem with iterative procedure

Post by Goheeca » Tue Oct 14, 2014 1:56 am

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.

MadMuppet006
Posts: 11
Joined: Wed Nov 02, 2011 11:56 pm

Re: problem with iterative procedure

Post by MadMuppet006 » Wed Oct 15, 2014 11:01 pm

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.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: problem with iterative procedure

Post by Goheeca » Thu Oct 16, 2014 2:16 am

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:

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.

Post Reply