This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.contrib.repl-utils :as repl]) | |
(clojure.core/use 'clojure.core) | |
(ns books) | |
(defstruct book :author :title :year :rank) | |
(defmacro makebook [& vs] | |
`(struct-map book ~@vs)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; all code in this function lifted from the clojure-mode function | |
;;; from clojure-mode.el | |
(defun clojure-font-lock-setup () | |
(interactive) | |
(set (make-local-variable 'lisp-indent-function) | |
'clojure-indent-function) | |
(set (make-local-variable 'lisp-doc-string-elt-property) | |
'clojure-doc-string-elt) | |
(set (make-local-variable 'font-lock-multiline) t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (new-reverse ls1) | |
(define (rev-acc ls2 acc) | |
(if (null? ls2) | |
acc | |
(rev-acc (cdr ls2) (cons (car ls2) acc)))) | |
(rev-acc ls1 '())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((lambda (x) | |
((lambda (y) | |
(+ x y)) | |
(* x x))) | |
6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun len-reduce (x) | |
(let ((len 0)) | |
(reduce (lambda (z w) (setf len (1+ len))) | |
(append x '(0))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun pp (sentence) | |
(let ((cstring (format nil "~{ ~s~}." sentence))) | |
(format nil | |
(concatenate 'string "~@(" cstring "~)")))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (same-parity x . w) | |
(define (inner-parity a b) | |
(cond | |
((null? b) b) | |
((or (and (even? a) (even? (car b))) | |
(and (odd? a) (odd? (car b)))) | |
(cons (car b) (inner-parity a (cdr b)))) | |
(else (inner-parity a (cdr b))))) | |
(inner-parity x w)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun find-all (item sequence &rest keyword-args | |
&key (test #'eql) test-not &allow-other-keys) | |
"Find all thos elements of sequence that match item, | |
according to keywords. Doesn't alter sequence." | |
(if test-not | |
(apply #'remove item sequence | |
:test-not (complement test-not) keyword-args) | |
(apply #'remove item sequence | |
:test (complement test) keyword-args))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (freach fn lst) | |
(cond ((null? lst) #t) | |
(else (fn (car lst)) (freach fn (cdr lst))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun freach (fn x) | |
(cond ((null x) t) | |
(t (funcall fn (car x)) (freach fn (cdr x))))) |