From 6903ec2dd51e394a5c81f8cb5e192ebc445da537 Mon Sep 17 00:00:00 2001 From: Paulo de Tarso Silva Santos Date: Thu, 28 May 2015 09:06:37 -0300 Subject: [PATCH] Update fol.lisp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Transformando o algoritmo do "length-form" em uma recursão de cauda. --- fol.lisp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fol.lisp b/fol.lisp index 7e2a8fd..bc93296 100644 --- a/fol.lisp +++ b/fol.lisp @@ -2,11 +2,12 @@ (and (symbolp x) (equal (char (symbol-name x) 0) #\?))) -(defun length-form (form) - (if (> (length form) 0) +(defun length-form (form &optional (n 0)) + (if (not (null form)) (if (atom (car form)) (if (member (car form) '(implies and or equiv)) - (+ 1 (length-form (cdr form))) - (length-form (cdr form))) - (+ (length-form (car form)) (length-form (cdr form)))) - 0)) + (length-form (cdr form) (+ n 1)) + (length-form (cdr form) n)) + (progn (setf n (+ n (length-form (car form)))) + (length-form (cdr form) n))) + n))