CL-Beginner Zoni
CL-Beginner Zoni

Reputation: 55

Convert in to float CL

I want to define a function, which converts the elements of a list in to float.

Thats's my solution, which does not work:

(defun intofloat (list)
  (cond 
   ((null liste) nil)
   ((equal (first list) 'id)
    (float (first list)))
   (t (intofloat (rest list)))))

Maybe there is someone who could help me!

Thanks!

Upvotes: 0

Views: 61

Answers (1)

Chris
Chris

Reputation: 36611

If you are able to use mapcar, this is truly trivial.

* (mapcar #'float '(1 2 3))

(1.0 2.0 3.0)

If you are not allowed to use mapcar, then you should break your problem down and redefine that function first.

(defun my-map (f lst)
  (if (null lst)
      nil
      (let ((hd (car lst))
            (tl (cdr lst)))
        (cons (funcall f hd) (my-map f tl)))))

Upvotes: 1

Related Questions