Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute LISP Online

(defvar x (list 1 2 3 4 5))
(defvar y (list 6 7 8 9 10))
(defvar z (list 11 12))
(defun list_reference (items n)
    (if (= n 0)
        (car items)
        (list_reference (cdr items) (- n 1))
        )
    )
(defun list_length (items)
    (if (null items)
        0
        (+ 1 (list_length (cdr items))))
    )

(defvar w (list (list 1 2) (list 3 4)))
(defun count_leaves (tree)
    (if (null tree)
    0
    (if (not (listp tree))
        1
        (+ (count_leaves(car tree)) (count_leaves(cdr tree)))
        )
    )
)
(defun count_leaves (tree)
    (if (null tree)
    0
    (if (not (listp tree))
        1
        (+ (count_leaves(car tree)) (count_leaves(cdr tree)))
        )
    )
)
(defun deep_reverse (_list)
    (if (null _list)
        _list
        (if (listp (car _list))
        (_append(deep_reverse(cdr _list)) (list(deep_reverse (car _list))))
        (_append(deep_reverse(cdr _list)) (list (car _list)))
        )
              
    )
)
(defun _append(list_1 list_2)
    (if (null list_1)
        list_2
        (cons (car list_1) (_append (cdr list_1) list_2)))
    )
(defun reverse_list (_list)
    (if (null _list)
    _list
    (_append(reverse_list (cdr _list)) (list (car _list))))
    )
(print (reverse_list w))
(print (deep_reverse w))

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.