New to lisp, help with function

Discussion of Common Lisp

New to lisp, help with function

Postby claudio.r » Tue Nov 29, 2011 3:14 pm

Hi everyone, i'm new to Lisp, comming from other programming languages, so i'm still not getting along with the recursive aspect of lisp.

I need help with a function, i want to verify if a particular list of lists is valid. In this list of lists, the first element as a size of 3, and every element after grows in a proportion of 3*N, with N being the number of the element. as an example, if the list as 4 elements, the first will be size 3, the second 6, the third 9 and the fourth 12.

I know that to verufy this condition i need to use a recursive function, but until now i'm not being able to do it.

This function receives a list and returns a boolean, T or F, case the list being valid or not.

Can someone help me?

Thx in advance,
C. Ribeiro
claudio.r
 
Posts: 1
Joined: Tue Nov 29, 2011 3:03 pm

Re: New to lisp, help with function

Postby smithzv » Sat Dec 03, 2011 12:38 pm

You absolutely do not need recursion to write this function. For instance you could do something like this:

Code: Select all
(defun multiple-of-three-lengths? (list)
  (loop for el in list
        for i from 1
        always (= (length el) (* 3 i))))


Or mess around with the various MAP* functions and probably the EVERY function. Is there a good reason to use recursion for this that I'm not seeing?
smithzv
 
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 5 guests