Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun find-path (tree elem)
- (labels ((layer (list) (cond ((null list) nil) ;;This goes through a list of children and if and cheks whether one of them returns !nil
- (t (let ((next (find-path (car list) elem)))
- (if (eql next nil) (layer (cdr list)) next))))))
- (cond ((null tree) nil) ;;No tree - no path
- ((eql (car tree) elem) (list (car tree))) ;;We are done here
- (t (let ((result (layer (cdr tree)))) ;;Let's save the result so we don't have to call this twice
- (if (eql result nil) nil (cons (car tree) result))))))) ;;If it is not nil, we are on the way home
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement