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.

Functions inside loops

3 posts · 1677 views

Hello, I am writing a code to create a tree in lisp but I am facing the following problem

Here is my code
(defun create_tree (M N D)
(if (> N M)
nil
(loop for i from 1 to D for j from 1 to D
if (< (+ i j) (+ D 1))
(create_tree M N i j)
)
))

This gives a syntax error, however when I comment the "(create_tree M N i j)" line, this works. Please let me know what the problem is...

I believe the problem is calling a function inside a loop. More generally, is it possible to create a function inside a loop?

Thank you
BS

Re: Functions inside loops

The create_tree function is defined to take three arguments (M N D) but inside the loop it is called with four arguments (create_tree M N i j).

- edgar

Re: Functions inside loops

Here is my code
(defun create_tree (M N D)
(if (> N M)
nil
(loop for i from 1 to D for j from 1 to D
if (< (+ i j) (+ D 1))
(create_subtree M N i j)
)
))
Sorry for the trouble. However, I found a way around it using dotimes inside of loop.