Johny22 wrote:I do not know the concept of nested list, can you please explain a little ?
(+ (* a b)(/ c a ))
(defun recur-sum (list)
"sum the numbers in a tree of lists, return (values sum count)"
(let ((sum 0)
(count 0))
(dolist (x list)
(cond
((symbolp x)
(error "Can't add symbol ~A" x))
((null x)) ;; optimization: ignore empty lists
((listp x)
(multiple-value-bind (subsum subcount)
(recur-sum x)
(incf sum subsum)
(incf count subcount)))
((numberp x)
(incf sum x)
(incf count 1))
(t
(error "Can't add ~A ~A" (type-of x) x))))
(values sum count)))
;; test case
(trace recur-sum)
(recur-sum '(1 2 (3 4) 5))
(untrace recur-sum)
(defun nth_var (el l)
(if (null l) '()
(and (delete-if-not #' (lambda (x) alpha-char-p (x)) (l))(delete-if-not #' (lambda (x) alphanumericp (x)) (l))
(nth el (l))
)
)
)
(defun flatten (list)
(loop for i in list if (listp i) append (flatten i) else collect i)
)
(defun flatten (list)
"Flatten the list"
(if (null list) '()
(loop for i in list if (listp i) append (flatten i) else collect i)
)
)
(defun rem_mo (list)
"Remove the math operators"
(if (null list) '()
(delete-if-not #'alphanumericp list)
)
)
(defun nth_var (el list)
"Get the nth variable from the list"
(if (null list) '()
(nth el list)
)
)
Users browsing this forum: Yahoo [Bot] and 3 guests