Skip to content

Instantly share code, notes, and snippets.

@MarkLavrynenko
Created March 29, 2015 12:16
Show Gist options
  • Save MarkLavrynenko/103feabce9e63ad39d22 to your computer and use it in GitHub Desktop.
Save MarkLavrynenko/103feabce9e63ad39d22 to your computer and use it in GitHub Desktop.

Revisions

  1. MarkLavrynenko created this gist Mar 29, 2015.
    31 changes: 31 additions & 0 deletions gistfile1.lisp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    ;Macro study
    (defun range-helper(x)
    (if (= x 0)
    (list x)
    (cons x (range-helper (- x 1)))
    )
    )

    (defun range (x)
    (reverse (range-helper (- x 1)))
    )

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;stupid way
    (defvar ans nil)
    (loop for x in (range 10) if (= 0 (mod x 2)) do
    (setq ans (append ans (list x)))
    )
    (print ans)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wise way
    (defmacro lcomp (expression for var in list conditional condition-test)
    (let ((result (gensym)))
    `(let ((,result nil))
    (loop for ,var in ,list
    ,conditional
    ,condition-test
    do (setq ,result (append ,result (list ,expression))))
    ,result)))

    (setq ans2 (lcomp (+ (* x x) 10) for x in (range 10) if (= 0 (mod x 2))))
    (print ans2)