Lisp Nesting
(defun nesting (s)
(if (zerop (length s))
1
(let ((stack '()))
(loop for v across s
do (if (char= v #\))
(if (or (null stack) (char/= (pop stack) #\())
(return-from nesting 0))
(push v stack)))
(if (null stack) 1 0))))
This treats the string like a balance counter: open parentheses add one, closing ones remove one.