Skip to content

Instantly share code, notes, and snippets.

@MarkLavrynenko
Created March 27, 2015 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkLavrynenko/66dbb178c3994cb6f325 to your computer and use it in GitHub Desktop.
Save MarkLavrynenko/66dbb178c3994cb6f325 to your computer and use it in GitHub Desktop.
Lisp
;(defmacro while (conditions &body body)
; '(loop while , condition
;)
(defun vector-product(x y)
(reduce '+ 0 (map 'list #'* x y)))
(setq a (list (list 1 2) (list 3 4)))
(setq b (make-array '(2 2) :initial-element 2))
; 2 2
; 2 2
;(format t (write-to-string b))
;(setq result (vector-product '(10 20) '(-2 -3)))
;(format t (write-to-string result))
;(setq animals '("lion" "cat" "dog"))
;(defun reverse-list-while (list) (
; let (tmp-list)
; (while list
; (setq tmp-list (cons (car list) tmp-list))
; (setq list (cdr list))
; )
; tmp-list)
;)
;(format t (write-to-string (reverse animals)))
;(format t (write-to-string (reverse-list-while animals)))
;(while (nth animals 0)
; (format t (nth animals 0))
; (setq animals (cdr animals)))
;
(setq ans (make-array '(10) :initial-element 0))
(setq depth -1)
(defun calc-depth(lst)
(let (elem-count)
(unless (atom lst)
(incf depth)
(setq elem-count (list-length lst))
(setf (aref ans depth) (+ elem-count (aref ans depth)))
(format t (write-to-string elem-count))
; (mapcar 'calc-depth lst (make-list elem-count :initial-element (+ depth 1)))
(mapcar 'calc-depth lst)
(decf depth)
)
)
)
(setq data '((67) (3 5 6) ((23) 2) 33))
(calc-depth data)
(format t (write-to-string ans))
(make-list 2 :initial-element 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment