This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

New to lisp, help with function

2 posts · 1135 views

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

Re: New to lisp, help with function

You absolutely do not need recursion to write this function. For instance you could do something like this:
(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?