├── .gitignore ├── 1-coin-toss ├── README.markdown ├── README.org ├── coin-toss.asd ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 2-rock-paper-scissors ├── .gitignore ├── 2-rock-paper-scissors.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 3-hangman ├── README.markdown ├── README.org ├── hangman.asd ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 4a-tic-tac-toe ├── .gitignore ├── README.markdown ├── README.org ├── src │ └── main.lisp ├── tests │ └── main.lisp └── tic-tac-toe.asd ├── 4b-tic-tac-toe ├── README.markdown ├── README.org ├── src │ └── main.lisp ├── tests │ └── main.lisp └── tic-tac-toe-clos.asd ├── 4c-tic-tac-toe ├── .gitignore ├── 4c-tic-tac-toe.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 5a-condition-system ├── .gitignore ├── README.markdown ├── README.org ├── condition-system.asd ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 5b-condition-system ├── .gitignore ├── 5b-condition-system.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 6a-macros ├── .gitignore ├── 6a-macros.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 6b-macros ├── .gitignore ├── 6b-macros.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 7a-file-io ├── .gitignore ├── 7a-file-io.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 7b-file-io ├── .gitignore ├── 7b-file-io.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 7c-file-io ├── .gitignore ├── 7c-file-io.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 8a-functional-programming ├── .gitignore ├── 8a-functional-programming.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 8b-functional-programming ├── .gitignore ├── 8b-functional-programming.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 8c-functional-programming ├── .gitignore ├── 8c-functional-programming.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 8d-functional-programming ├── .gitignore ├── 8d-functional-programming.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 8e-functional-programming ├── .gitignore ├── 8e-functional-programming.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 8f-functional-programming ├── .gitignore ├── 8f-functional-programming.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 8g-functional-programming ├── .gitignore ├── 8g-functional-programming.asd ├── README.md ├── src │ └── main.lisp └── tests │ └── main.lisp ├── 9a-packages ├── .gitignore ├── 9a-packages.asd ├── README.md ├── src │ ├── main.lisp │ └── stuff.lisp └── tests │ └── main.lisp ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.FASL 2 | *.fasl 3 | *.lisp-temp 4 | *.dfsl 5 | *.pfsl 6 | *.d64fsl 7 | *.p64fsl 8 | *.lx64fsl 9 | *.lx32fsl 10 | *.dx64fsl 11 | *.dx32fsl 12 | *.fx64fsl 13 | *.fx32fsl 14 | *.sx64fsl 15 | *.sx32fsl 16 | *.wx64fsl 17 | *.wx32fsl 18 | 19 | .DS_Store 20 | -------------------------------------------------------------------------------- /1-coin-toss/README.markdown: -------------------------------------------------------------------------------- 1 | # Coin-Toss 2 | 3 | ## Usage 4 | 5 | ## Installation 6 | -------------------------------------------------------------------------------- /1-coin-toss/README.org: -------------------------------------------------------------------------------- 1 | * Coin-Toss 2 | 3 | ** Usage 4 | 5 | ** Installation 6 | -------------------------------------------------------------------------------- /1-coin-toss/coin-toss.asd: -------------------------------------------------------------------------------- 1 | (defsystem "coin-toss" 2 | :version "0.1.0" 3 | :author "" 4 | :license "" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "" 10 | :in-order-to ((test-op (test-op "coin-toss/tests")))) 11 | 12 | (defsystem "coin-toss/tests" 13 | :author "" 14 | :license "" 15 | :depends-on ("coin-toss" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for coin-toss" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /1-coin-toss/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage coin-toss 2 | (:use :cl)) 3 | (in-package :coin-toss) 4 | 5 | (defun toss-coin () 6 | "Generate a random heads or tails" 7 | 8 | (let ((number (random 2 (make-random-state t)))) 9 | (if (= number 0) 10 | "heads" 11 | "tails"))) 12 | 13 | (defun prompt () 14 | "Get user input and loop if it is not 'heads' or 'tails'" 15 | 16 | (format t "Please enter heads or tails: ") 17 | (force-output) 18 | 19 | (let ((guess (string-downcase (read-line)))) 20 | (if (or (string= guess "heads") 21 | (string= guess "tails")) 22 | guess 23 | (prompt)))) 24 | 25 | (defun game () 26 | "Run the actual game" 27 | 28 | (if (string= (prompt) 29 | (toss-coin)) 30 | (format t "You Win!~%") 31 | (format t "You Loose!~%"))) 32 | -------------------------------------------------------------------------------- /1-coin-toss/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage coin-toss/tests/main 2 | (:use :cl 3 | :coin-toss 4 | :rove)) 5 | (in-package :coin-toss/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :coin-toss)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (ok (= 1 1)))) 12 | -------------------------------------------------------------------------------- /2-rock-paper-scissors/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /2-rock-paper-scissors/2-rock-paper-scissors.asd: -------------------------------------------------------------------------------- 1 | (defsystem "2-rock-paper-scissors" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on ("rove") 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "2-rock-paper-scissors/tests")))) 11 | 12 | (defsystem "2-rock-paper-scissors/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("2-rock-paper-scissors" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 2-rock-paper-scissors" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /2-rock-paper-scissors/README.md: -------------------------------------------------------------------------------- 1 | # 2-rock-paper-scissors 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /2-rock-paper-scissors/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 2-rock-paper-scissors 2 | (:use :cl) 3 | (:export #:main)) 4 | 5 | (in-package 2-rock-paper-scissors) 6 | 7 | (defun get-player-choice (options) 8 | (format t "Please enter either -> ~{~A~^, ~}: " options) 9 | (force-output) 10 | 11 | (let ((choice (string-downcase (read-line)))) 12 | (if (member choice options :test #'equal) 13 | choice 14 | (get-player-choice options)))) 15 | 16 | (defun game () 17 | (let* ((options '("rock" "paper" "scissors")) 18 | (cpu-choice (nth (random (length options) (make-random-state t)) options)) 19 | (player-choice (get-player-choice options))) 20 | 21 | (cond 22 | ; when a draw has occured 23 | ((equal cpu-choice player-choice) 24 | (format t "You entered: ~A, CPU entered: ~A. It's a draw!~%" player-choice cpu-choice)) 25 | 26 | ; if user enters rock and cpu enters scissors 27 | ((and (equal player-choice "rock") 28 | (equal cpu-choice "scissors")) 29 | (format t "You entered: ~A, CPU entered: ~A. You win!~%" player-choice cpu-choice)) 30 | 31 | ; if user enters paper and cpu enters rock 32 | ((and (equal player-choice "paper") 33 | (equal cpu-choice "rock")) 34 | (format t "You entered: ~A, CPU entered: ~A. You win!~%" player-choice cpu-choice)) 35 | 36 | ; if user enters scissors and cpu enters rock 37 | ((and (equal player-choice "paper") 38 | (equal cpu-choice "rock")) 39 | (format t "You entered: ~A, CPU entered: ~A. You win!~%" player-choice cpu-choice)) 40 | 41 | (t (format t "You entered: ~A, CPU entered: ~A. You loose!~%" player-choice cpu-choice))))) 42 | 43 | (game) 44 | -------------------------------------------------------------------------------- /2-rock-paper-scissors/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 2-rock-paper-scissors/tests/main 2 | (:use :cl 3 | :2-rock-paper-scissors 4 | :rove)) 5 | (in-package :2-rock-paper-scissors/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :2-rock-paper-scissors)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /3-hangman/README.markdown: -------------------------------------------------------------------------------- 1 | # Hangman 2 | 3 | ## Usage 4 | 5 | ## Installation 6 | -------------------------------------------------------------------------------- /3-hangman/README.org: -------------------------------------------------------------------------------- 1 | * Hangman 2 | 3 | ** Usage 4 | 5 | ** Installation 6 | -------------------------------------------------------------------------------- /3-hangman/hangman.asd: -------------------------------------------------------------------------------- 1 | (defsystem "hangman" 2 | :version "0.1.0" 3 | :author "" 4 | :license "" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "" 10 | :in-order-to ((test-op (test-op "hangman/tests")))) 11 | 12 | (defsystem "hangman/tests" 13 | :author "" 14 | :license "" 15 | :depends-on ("hangman" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for hangman" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /3-hangman/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage hangman 2 | (:use :cl)) 3 | (in-package :hangman) 4 | 5 | (defun pick-sitcom (sitcoms) 6 | (nth (random (length sitcoms) (make-random-state t)) sitcoms)) 7 | 8 | (defun get-letter (guessed-letters) 9 | (format t "Please enter a letter: ") 10 | 11 | (let ((in (read-line))) 12 | (cond 13 | ; If the user just hit enter 14 | ((= 0 (length in)) 15 | (get-letter g:uessed-letters)) 16 | 17 | ; If the first character entered has already been used 18 | ((member (char in 0) guessed-letters) 19 | (get-letter guessed-letters)) 20 | 21 | ; Return the first character 22 | (t (char in 0))))) 23 | 24 | (defun scramble (sitcom guessed-letters) 25 | (flet ((letter-or-underscore (letter) 26 | (if (or (member letter guessed-letters) (equal letter #\Space)) 27 | letter 28 | #\_))) 29 | 30 | (map 'string #'letter-or-underscore sitcom))) 31 | 32 | (defun game-over (lives scrambled-sitcom) 33 | (cond 34 | ((or (string= scrambled-sitcom "") (<= lives 0)) "CPU") 35 | ((eq nil (position #\_ scrambled-sitcom)) "Player") 36 | (t nil))) 37 | 38 | (defun info (scrambled-sitcom lives guessed-letters) 39 | (format nil "Lives: ~A~%Letters: ~{~A~^, ~}~%~A~%" lives guessed-letters scrambled-sitcom)) 40 | 41 | (defun game (&key (sitcom nil) (lives 10) (guessed-letters'())) 42 | (unless sitcom 43 | (let ((sitcom (pick-sitcom '("friends" "the big bang theory" "frasier" "cheers" "how i met your mother" "the it crowd")))) 44 | (game :sitcom sitcom :lives lives :guessed-letters guessed-letters))) 45 | 46 | (let ((game-over (game-over lives (scramble sitcom guessed-letters)))) 47 | (when game-over 48 | (return-from game (format nil "Game over!" game-over))) 49 | 50 | (format t "~A~%" (info (scramble sitcom guessed-letters) lives guessed-letters)) 51 | 52 | (let ((letter (get-letter guessed-letters))) 53 | (if (equal nil (position letter sitcom)) 54 | (game :sitcom sitcom :lives (1- lives) :guessed-letters (cons letter guessed-letters)) 55 | (game :sitcom sitcom :lives lives :guessed-letters (cons letter guessed-letters)))))) 56 | -------------------------------------------------------------------------------- /3-hangman/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage hangman/tests/main 2 | (:use :cl 3 | :hangman 4 | :rove)) 5 | (in-package :hangman/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :hangman)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (ok (= 1 1)))) 12 | -------------------------------------------------------------------------------- /4a-tic-tac-toe/.gitignore: -------------------------------------------------------------------------------- 1 | *.fasl 2 | *.dx32fsl 3 | *.dx64fsl 4 | *.lx32fsl 5 | *.lx64fsl 6 | *.x86f 7 | *~ 8 | .#* 9 | -------------------------------------------------------------------------------- /4a-tic-tac-toe/README.markdown: -------------------------------------------------------------------------------- 1 | # Tic-Tac-Toe 2 | 3 | ## Usage 4 | 5 | ## Installation 6 | -------------------------------------------------------------------------------- /4a-tic-tac-toe/README.org: -------------------------------------------------------------------------------- 1 | * Tic-Tac-Toe 2 | 3 | ** Usage 4 | 5 | ** Installation 6 | -------------------------------------------------------------------------------- /4a-tic-tac-toe/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage tic-tac-toe 2 | (:use :cl) 3 | (:export #:game)) 4 | (in-package :tic-tac-toe) 5 | 6 | (defun display-board (board) 7 | (dotimes (x 3) 8 | (dotimes (y 3) 9 | (if (= y 2) 10 | (format t "~A~%" (aref board x y)) 11 | (format t "~A | " (aref board x y)))) 12 | (format t "~%"))) 13 | 14 | (defun update-board (board coords player) 15 | (setf (aref board (getf coords :x) (getf coords :y)) player)) 16 | 17 | (defun valid-position-p (board coords) 18 | (equal (aref board (getf coords :x) (getf coords :y)) '-)) 19 | 20 | (defun cpu-turn (board) 21 | (let* ((x (random (array-dimension board 0) (make-random-state t))) 22 | (y (random (array-dimension board 0) (make-random-state t))) 23 | (coords `(:x ,x :y ,y))) 24 | (if (valid-position-p board coords) 25 | coords 26 | (cpu-turn board)))) 27 | 28 | (defun player-turn (board) 29 | (format t "Please enter X position: ") 30 | 31 | (let ((x (parse-integer (read-line) :junk-allowed t))) 32 | (unless (member x '(0 1 2)) 33 | (player-turn board)) 34 | 35 | (format t "Please enter Y position: ") 36 | 37 | (let ((y (parse-integer (read-line) :junk-allowed t))) 38 | (unless (member y '(0 1 2)) 39 | (player-turn board)) 40 | 41 | (let ((coords `(:x ,x :y ,y))) 42 | (if (valid-position-p board coords) 43 | coords 44 | (player-turn board)))))) 45 | 46 | (defun game-over-p (board) 47 | (flet ((draw-p (board) 48 | (let ((counter 0)) 49 | (dotimes (x 3) 50 | (dotimes (y 3) 51 | (when (equal '- (aref board x y)) 52 | (incf counter)))) 53 | 54 | (= 0 counter)))) 55 | 56 | (cond 57 | ; Rows 58 | ((and (equal (aref board 0 0) (aref board 0 1)) (equal (aref board 0 0) (aref board 0 2)) (not (equal (aref board 0 0) '-))) t) 59 | ((and (equal (aref board 1 0) (aref board 1 1)) (equal (aref board 1 0) (aref board 1 2)) (not (equal (aref board 1 0) '-))) t) 60 | ((and (equal (aref board 2 0) (aref board 2 1)) (equal (aref board 2 0) (aref board 2 2)) (not (equal (aref board 2 0) '-))) t) 61 | 62 | ; Columns 63 | ((and (equal (aref board 0 0) (aref board 1 0)) (equal (aref board 0 0) (aref board 2 0)) (not (equal (aref board 0 0) '-))) t) 64 | ((and (equal (aref board 0 1) (aref board 1 1)) (equal (aref board 0 1) (aref board 2 1)) (not (equal (aref board 0 1) '-))) t) 65 | ((and (equal (aref board 0 2) (aref board 1 2)) (equal (aref board 0 2) (aref board 2 2)) (not (equal (aref board 0 2) '-))) t) 66 | 67 | ; Diagonals 68 | ((and (equal (aref board 0 0) (aref board 1 1)) (equal (aref board 0 0) (aref board 2 2)) (not (equal (aref board 0 0) '-))) t) 69 | ((and (equal (aref board 0 2) (aref board 1 1)) (equal (aref board 0 2) (aref board 2 0)) (not (equal (aref board 0 2) '-))) t) 70 | 71 | ; Draw state 72 | ((draw-p board) t) 73 | 74 | (t nil)))) 75 | 76 | (defun game () 77 | (let ((board (make-array '(3 3) :initial-element '-))) 78 | (do ((turn-counter (1+ (random 2 (make-random-state t))) (1+ turn-counter))) 79 | ((game-over-p board)) 80 | 81 | (display-board board) 82 | 83 | (if (evenp turn-counter) 84 | (let ((coords (player-turn board))) 85 | (update-board board coords "x")) 86 | 87 | (let ((coords (cpu-turn board))) 88 | (update-board board coords "o")))) 89 | 90 | (display-board board) 91 | (format t "Game over!~%"))) 92 | 93 | (game) 94 | -------------------------------------------------------------------------------- /4a-tic-tac-toe/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage tic-tac-toe/tests/main 2 | (:use :cl 3 | :tic-tac-toe 4 | :rove)) 5 | (in-package :tic-tac-toe/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :tic-tac-toe)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (ok (= 1 1)))) 12 | -------------------------------------------------------------------------------- /4a-tic-tac-toe/tic-tac-toe.asd: -------------------------------------------------------------------------------- 1 | (defsystem "tic-tac-toe" 2 | :version "0.1.0" 3 | :author "" 4 | :license "" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "" 10 | :in-order-to ((test-op (test-op "tic-tac-toe/tests")))) 11 | 12 | (defsystem "tic-tac-toe/tests" 13 | :author "" 14 | :license "" 15 | :depends-on ("tic-tac-toe" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for tic-tac-toe" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /4b-tic-tac-toe/README.markdown: -------------------------------------------------------------------------------- 1 | # Tic-Tac-Toe-Clos 2 | 3 | ## Usage 4 | 5 | ## Installation 6 | -------------------------------------------------------------------------------- /4b-tic-tac-toe/README.org: -------------------------------------------------------------------------------- 1 | * Tic-Tac-Toe-Clos 2 | 3 | ** Usage 4 | 5 | ** Installation 6 | -------------------------------------------------------------------------------- /4b-tic-tac-toe/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage tic-tac-toe-clos 2 | (:use :cl) 3 | (:export #:game)) 4 | (in-package :tic-tac-toe-clos) 5 | 6 | (defun display-board (board) 7 | (dotimes (x 3) 8 | (dotimes (y 3) 9 | (if (= y 2) 10 | (format t "~A~%" (aref board x y)) 11 | (format t "~A | " (aref board x y)))) 12 | (format t "~%"))) 13 | 14 | (defun update-board (board coords player) 15 | (setf (aref board (getf coords :x) (getf coords :y)) player)) 16 | 17 | (defun valid-position-p (board coords) 18 | (eql (aref board (getf coords :x) (getf coords :y)) '-)) 19 | 20 | (defun game-over-p (board) 21 | (flet ((draw-p (board) 22 | (dotimes (x 3) 23 | (dotimes (y 3) 24 | (when (eql '- (aref board x y)) 25 | (return-from draw-p)))) 26 | t)) 27 | 28 | (cond 29 | ; Rows 30 | ((and (eql (aref board 0 0) (aref board 0 1)) (eql (aref board 0 0) (aref board 0 2)) (not (eql (aref board 0 0) '-))) t) 31 | ((and (eql (aref board 1 0) (aref board 1 1)) (eql (aref board 1 0) (aref board 1 2)) (not (eql (aref board 1 0) '-))) t) 32 | ((and (eql (aref board 2 0) (aref board 2 1)) (eql (aref board 2 0) (aref board 2 2)) (not (eql (aref board 2 0) '-))) t) 33 | 34 | ; Columns 35 | ((and (eql (aref board 0 0) (aref board 1 0)) (eql (aref board 0 0) (aref board 2 0)) (not (eql (aref board 0 0) '-))) t) 36 | ((and (eql (aref board 0 1) (aref board 1 1)) (eql (aref board 0 1) (aref board 2 1)) (not (eql (aref board 0 1) '-))) t) 37 | ((and (eql (aref board 0 2) (aref board 1 2)) (eql (aref board 0 2) (aref board 2 2)) (not (eql (aref board 0 2) '-))) t) 38 | 39 | ; Diagonals 40 | ((and (eql (aref board 0 0) (aref board 1 1)) (eql (aref board 0 0) (aref board 2 2)) (not (eql (aref board 0 0) '-))) t) 41 | ((and (eql (aref board 0 2) (aref board 1 1)) (eql (aref board 0 2) (aref board 2 0)) (not (eql (aref board 0 2) '-))) t) 42 | 43 | ; Draw state 44 | ((draw-p board) t) 45 | 46 | (t nil)))) 47 | 48 | (defclass player () 49 | ((icon :initarg :icon :initform (error "Must provide an icon") :reader icon))) 50 | 51 | (defclass human (player) 52 | ()) 53 | 54 | (defclass cpu (player) 55 | ()) 56 | 57 | (defgeneric turn (player board) 58 | (:documentation "Executes a player turn")) 59 | 60 | (defmethod turn ((player human) board) 61 | (flet ((get-pos (character) 62 | (format t "Please enter a ~A: " character) 63 | (force-output) 64 | (parse-integer (read-line) :junk-allowed t))) 65 | (do* ((x (get-pos "X") (get-pos "X")) 66 | (y (get-pos "Y") (get-pos "Y")) 67 | (coords `(:x ,x :y ,y) `(:x ,x :y ,y))) 68 | ((and (member x '(0 1 2)) (member y '(0 1 2)) (valid-position-p board coords)) 69 | coords)))) 70 | 71 | (defmethod turn ((player cpu) board) 72 | (do* ((x (random (array-dimension board 0)) (random (array-dimension board 0))) 73 | (y (random (array-dimension board 0)) (random (array-dimension board 0))) 74 | (coords `(:x ,x :y ,y) `(:x ,x :y ,y))) 75 | ((valid-position-p board coords) 76 | coords))) 77 | 78 | (defun game () 79 | (make-random-state t) 80 | 81 | (let ((board (make-array '(3 3) :initial-element '-)) 82 | (human (make-instance 'human :icon "X")) 83 | (cpu (make-instance 'cpu :icon "O"))) 84 | (do ((turn-counter (1+ (random 2)) (1+ turn-counter))) 85 | ((game-over-p board)) 86 | 87 | (display-board board) 88 | (format t "~%") 89 | (force-output) 90 | 91 | (if (evenp turn-counter) 92 | (update-board board (turn human board) (icon human)) 93 | (update-board board (turn cpu board) (icon cpu)))) 94 | 95 | (display-board board) 96 | (format t "Game Over!~%") 97 | (force-output))) 98 | -------------------------------------------------------------------------------- /4b-tic-tac-toe/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage tic-tac-toe-clos/tests/main 2 | (:use :cl 3 | :tic-tac-toe-clos 4 | :rove)) 5 | (in-package :tic-tac-toe-clos/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :tic-tac-toe-clos)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (ok (= 1 1)))) 12 | -------------------------------------------------------------------------------- /4b-tic-tac-toe/tic-tac-toe-clos.asd: -------------------------------------------------------------------------------- 1 | (defsystem "tic-tac-toe-clos" 2 | :version "0.1.0" 3 | :author "" 4 | :license "" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "" 10 | :in-order-to ((test-op (test-op "tic-tac-toe-clos/tests")))) 11 | 12 | (defsystem "tic-tac-toe-clos/tests" 13 | :author "" 14 | :license "" 15 | :depends-on ("tic-tac-toe-clos" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for tic-tac-toe-clos" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /4c-tic-tac-toe/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /4c-tic-tac-toe/4c-tic-tac-toe.asd: -------------------------------------------------------------------------------- 1 | (defsystem "4c-tic-tac-toe" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on (:meq 6 | :rove) 7 | :components ((:module "src" 8 | :components 9 | ((:file "main")))) 10 | :description "Generate a skeleton for modern project" 11 | :in-order-to ((test-op (test-op "4c-tic-tac-toe/tests")))) 12 | 13 | (defsystem "4c-tic-tac-toe/tests" 14 | :author "nmunro" 15 | :license "BSD3-Clause" 16 | :depends-on ("4c-tic-tac-toe" 17 | "rove") 18 | :components ((:module "tests" 19 | :components 20 | ((:file "main")))) 21 | :description "Test system for 4c-tic-tac-toe" 22 | :perform (test-op (op c) (symbol-call :rove :run c))) 23 | -------------------------------------------------------------------------------- /4c-tic-tac-toe/README.md: -------------------------------------------------------------------------------- 1 | # 4c-tic-tac-toe 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /4c-tic-tac-toe/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 4c-tic-tac-toe 2 | (:use :cl 3 | :meq) 4 | (:export #:game)) 5 | 6 | (in-package 4c-tic-tac-toe) 7 | 8 | (defun display-board (board) 9 | (dotimes (x 3) 10 | (dotimes (y 3) 11 | (if (= y 2) 12 | (format t "~A~%" (aref board x y)) 13 | (format t "~A | " (aref board x y)))) 14 | (format t "~%"))) 15 | 16 | (defun update-board (board coords player) 17 | (setf (aref board (getf coords :x) (getf coords :y)) player)) 18 | 19 | (defun valid-position-p (board coords) 20 | (eql (aref board (getf coords :x) (getf coords :y)) '-)) 21 | 22 | (defun game-over-p (board) 23 | (flet ((draw-p (board) 24 | (dotimes (x 3) 25 | (dotimes (y 3) 26 | (when (eql '- (aref board x y)) 27 | (return-from draw-p)))) 28 | t)) 29 | 30 | (cond 31 | ; Rows 32 | ((and (meq:with-multiple-equal (aref board 0 0) (aref board 0 1) (aref board 0 2)) 33 | (not (eql (aref board 0 0) '-))) 34 | t) 35 | 36 | ((and (meq:with-multiple-equal (aref board 1 0) (aref board 1 1) (aref board 1 2)) 37 | (not (eql (aref board 1 0) '-))) 38 | t) 39 | 40 | ((and (meq:with-multiple-equal (aref board 2 0) (aref board 2 1) (aref board 2 2)) 41 | (not (eql (aref board 2 0) '-))) 42 | t) 43 | 44 | ; Columns 45 | ((and (meq:with-multiple-equal (aref board 0 0) (aref board 1 0) (aref board 2 0)) 46 | (not (eql (aref board 0 0) '-))) 47 | t) 48 | 49 | ((and (meq:with-multiple-equal (aref board 0 1) (aref board 1 1) (aref board 2 1)) 50 | (not (eql (aref board 0 1) '-))) 51 | t) 52 | 53 | ((and (meq:with-multiple-equal (aref board 0 2) (aref board 1 2) (aref board 2 2)) 54 | (not (eql (aref board 0 2) '-))) 55 | t) 56 | 57 | ; Diagonals 58 | ((and (meq:with-multiple-equal (aref board 0 0) (aref board 1 1) (aref board 2 2)) 59 | (not (eql (aref board 0 0) '-))) 60 | t) 61 | 62 | ((and (meq:with-multiple-equal (aref board 0 2) (aref board 1 1) (aref board 2 0)) 63 | (not (eql (aref board 0 2) '-))) 64 | t) 65 | 66 | ; Draw state 67 | ((draw-p board) 68 | t) 69 | 70 | (t 71 | nil)))) 72 | 73 | (defclass player () 74 | ((icon :initarg :icon :initform (error "Must provide an icon") :reader icon))) 75 | 76 | (defclass human (player) 77 | ()) 78 | 79 | (defclass cpu (player) 80 | ()) 81 | 82 | (defgeneric turn (player board) 83 | (:documentation "Executes a player turn")) 84 | 85 | (defmethod turn ((player human) board) 86 | (flet ((get-pos (character) 87 | (format t "Please enter a ~A: " character) 88 | (force-output) 89 | (parse-integer (read-line) :junk-allowed t))) 90 | (do* ((x (get-pos "X") (get-pos "X")) 91 | (y (get-pos "Y") (get-pos "Y")) 92 | (coords `(:x ,x :y ,y) `(:x ,x :y ,y))) 93 | ((and (member x '(0 1 2)) (member y '(0 1 2)) (valid-position-p board coords)) 94 | coords)))) 95 | 96 | (defmethod turn ((player cpu) board) 97 | (do* ((x (random (array-dimension board 0)) (random (array-dimension board 0))) 98 | (y (random (array-dimension board 0)) (random (array-dimension board 0))) 99 | (coords `(:x ,x :y ,y) `(:x ,x :y ,y))) 100 | ((valid-position-p board coords) 101 | coords))) 102 | 103 | (defun game () 104 | (make-random-state t) 105 | 106 | (let ((board (make-array '(3 3) :initial-element '-)) 107 | (human (make-instance 'human :icon "X")) 108 | (cpu (make-instance 'cpu :icon "O"))) 109 | (do ((turn-counter (1+ (random 2)) (1+ turn-counter))) 110 | ((game-over-p board)) 111 | 112 | (display-board board) 113 | (format t "~%") 114 | (force-output) 115 | 116 | (if (evenp turn-counter) 117 | (update-board board (turn human board) (icon human)) 118 | (update-board board (turn cpu board) (icon cpu)))) 119 | 120 | (display-board board) 121 | (format t "Game Over!~%") 122 | (force-output))) 123 | -------------------------------------------------------------------------------- /4c-tic-tac-toe/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 4c-tic-tac-toe/tests/main 2 | (:use :cl 3 | :4c-tic-tac-toe 4 | :rove)) 5 | (in-package :4c-tic-tac-toe/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :4c-tic-tac-toe)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /5a-condition-system/.gitignore: -------------------------------------------------------------------------------- 1 | *.abcl 2 | *.fasl 3 | *.dx32fsl 4 | *.dx64fsl 5 | *.lx32fsl 6 | *.lx64fsl 7 | *.x86f 8 | *~ 9 | .#* 10 | -------------------------------------------------------------------------------- /5a-condition-system/README.markdown: -------------------------------------------------------------------------------- 1 | # Condition-System 2 | 3 | ## Usage 4 | 5 | ## Installation 6 | -------------------------------------------------------------------------------- /5a-condition-system/README.org: -------------------------------------------------------------------------------- 1 | * Condition-System 2 | 3 | ** Usage 4 | 5 | ** Installation 6 | -------------------------------------------------------------------------------- /5a-condition-system/condition-system.asd: -------------------------------------------------------------------------------- 1 | (defsystem "condition-system" 2 | :version "0.1.0" 3 | :author "" 4 | :license "" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "" 10 | :in-order-to ((test-op (test-op "condition-system/tests")))) 11 | 12 | (defsystem "condition-system/tests" 13 | :author "" 14 | :license "" 15 | :depends-on ("condition-system" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for condition-system" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /5a-condition-system/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage condition-system-5a 2 | (:use :cl)) 3 | (in-package :condition-system-5a) 4 | 5 | (define-condition file-io-error (error) 6 | ((message :initarg :message :reader message))) 7 | 8 | (define-condition another-file-io-error (error) 9 | ((message :initarg :message :reader message))) 10 | 11 | (defun fake-io (&key (fail nil fail-p) (message "Nope!")) 12 | (cond 13 | ((not fail-p) 14 | (if (evenp (random 100)) 15 | (error 'file-io-error :message message) 16 | "Success")) 17 | 18 | (fail 19 | (error 'another-file-io-error :message message)) 20 | 21 | (t "success"))) 22 | 23 | (defun read-new-value () 24 | (format t "Enter a new value: ") 25 | (force-output) 26 | (multiple-value-list (eval (read)))) 27 | 28 | (let ((fail t)) 29 | (restart-case (fake-io :fail fail) 30 | (do-nothing () 31 | :report "Return String" 32 | "Done with this") 33 | 34 | (retry-without-errors (new-fail) 35 | :report "Accept User Input" 36 | :interactive read-new-value 37 | (fake-io :fail new-fail)))) 38 | 39 | (handler-case (fake-io :fail t) 40 | (file-io-error () (fake-io :fail nil)) 41 | (another-file-io-error () (fake-io :fail nil))) 42 | -------------------------------------------------------------------------------- /5a-condition-system/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage condition-system/tests/main 2 | (:use :cl 3 | :condition-system 4 | :rove)) 5 | (in-package :condition-system/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :condition-system)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (ok (= 1 1)))) 12 | -------------------------------------------------------------------------------- /5b-condition-system/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /5b-condition-system/5b-condition-system.asd: -------------------------------------------------------------------------------- 1 | (defsystem "5b-condition-system" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on ("rove") 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "5b-condition-system/tests")))) 11 | 12 | (defsystem "5b-condition-system/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("5b-condition-system" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 5b-condition-system" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /5b-condition-system/README.md: -------------------------------------------------------------------------------- 1 | # 5b-condition-system 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /5b-condition-system/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage error-handling 2 | (:use :cl)) 3 | 4 | (in-package :error-handling) 5 | 6 | (define-condition div-zero-error (error) 7 | ((message :initarg :message :reader message))) 8 | 9 | (defun div-fn (a b) 10 | (restart-case 11 | (if (/= b 0) 12 | (/ a b) 13 | (error 'div-zero-error :message "Can't divide by zero")) 14 | 15 | (return-zero () 16 | 0) 17 | 18 | (return-value (value) 19 | value) 20 | 21 | (recalc-using (value) 22 | (div-fn a value)))) 23 | 24 | (defun alpha () 25 | (handler-bind 26 | ((div-zero-error 27 | #'(lambda (err) 28 | (format t "Alpha-Error: ~A~%" (message err)) 29 | (invoke-restart 'return-zero)))) 30 | (div-fn 1 0))) 31 | 32 | (defun beta (val) 33 | (handler-bind 34 | ((div-zero-error 35 | #'(lambda (err) 36 | (format t "Beta-Error: ~A~%" (message err)) 37 | (invoke-restart 'return-value val)))) 38 | (div-fn 1 0))) 39 | 40 | (defun gamma (val) 41 | (handler-bind 42 | ((div-zero-error 43 | #'(lambda (err) 44 | (format t "Gamma-Error: ~A~%" (message err)) 45 | (invoke-restart 'recalc-using val)))) 46 | (div-fn 1 0))) 47 | 48 | (alpha) 49 | (beta 1) 50 | (gamma 2) 51 | -------------------------------------------------------------------------------- /5b-condition-system/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 5b-condition-system/tests/main 2 | (:use :cl 3 | :5b-condition-system 4 | :rove)) 5 | (in-package :5b-condition-system/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :5b-condition-system)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /6a-macros/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /6a-macros/6a-macros.asd: -------------------------------------------------------------------------------- 1 | (defsystem "6a-macros" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on ("rove") 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "6a-macros/tests")))) 11 | 12 | (defsystem "6a-macros/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("6a-macros" 16 | "rove") 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 6a-macros" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /6a-macros/README.md: -------------------------------------------------------------------------------- 1 | # 6a-macros 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /6a-macros/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 6a-macros 2 | (:use :cl) 3 | (:export #:with-multiple-eq 4 | #:with-multiple-eql 5 | #:with-multiple-equal 6 | #:with-multiple-equalp)) 7 | 8 | (in-package 6a-macros) 9 | 10 | (defmacro with-multiple-eq (&rest args) 11 | `(and ,@(mapcar #'(lambda (x) `(eq ,(first args) ,x)) (rest args)))) 12 | 13 | (defmacro with-multiple-eql (&rest args) 14 | `(and ,@(mapcar #'(lambda (x) `(eql ,(first args) ,x)) (rest args)))) 15 | 16 | (defmacro with-multiple-equal (&rest args) 17 | `(and ,@(mapcar #'(lambda (x) `(equal ,(first args) ,x)) (rest args)))) 18 | 19 | (defmacro with-multiple-equalp (&rest args) 20 | `(and ,@(mapcar #'(lambda (x) `(equalp ,(first args) ,x)) (rest args)))) 21 | -------------------------------------------------------------------------------- /6a-macros/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 6a-macros/tests/main 2 | (:use :cl 3 | :6a-macros 4 | :rove)) 5 | (in-package :6a-macros/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :6a-macros)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /6b-macros/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /6b-macros/6b-macros.asd: -------------------------------------------------------------------------------- 1 | (defsystem "6b-macros" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "6b-macros/tests")))) 11 | 12 | (defsystem "6b-macros/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("6b-macros" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 6b-macros" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /6b-macros/README.md: -------------------------------------------------------------------------------- 1 | # 6b-macros 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /6b-macros/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 6b-macros 2 | (:use :cl)) 3 | 4 | (in-package 6b-macros) 5 | 6 | (defmacro read-lines (stream) 7 | (let ((s (gensym))) 8 | `(when ,stream 9 | (loop :for ,s = (read-line ,stream nil) 10 | :while ,s 11 | :collect ,s)))) 12 | 13 | ; Original without macro 14 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/6b-macros/src/main.lisp" :if-does-not-exist nil) 15 | (when in 16 | (loop :for line = (read-line in nil) 17 | :while line 18 | :do (format t "~A~%" line)))) 19 | 20 | ; New with macro 21 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/6b-macros/src/main.lisp" :if-does-not-exist nil) 22 | (format t "~{~A~%~}~%" (read-lines in))) 23 | -------------------------------------------------------------------------------- /6b-macros/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 6b-macros/tests/main 2 | (:use :cl 3 | :6b-macros 4 | :rove)) 5 | (in-package :6b-macros/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :6b-macros)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /7a-file-io/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /7a-file-io/7a-file-io.asd: -------------------------------------------------------------------------------- 1 | (defsystem "7a-file-io" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "7a-file-io/tests")))) 11 | 12 | (defsystem "7a-file-io/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("7a-file-io" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 7a-file-io" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /7a-file-io/README.md: -------------------------------------------------------------------------------- 1 | # 7a-file-io 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /7a-file-io/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 7a-file-io 2 | (:use :cl)) 3 | 4 | (in-package 7a-file-io) 5 | 6 | ; Printing the first line 7 | (let ((in (open #p"~/quicklisp/local-projects/cl-tutorials/7a-file-io/src/main.lisp"))) 8 | (format t "~A~%" (read-line in)) 9 | (close in)) 10 | 11 | ; Printing the first two lines 12 | (let ((in (open #p"~/quicklisp/local-projects/cl-tutorials/7a-file-io/src/main.lisp"))) 13 | (format t "~A~%" (read-line in)) 14 | (close in)) 15 | 16 | ; Printing the whole file 17 | (let ((in (open #p"~/quicklisp/local-projects/cl-tutorials/7a-file-io/src/main.lisp"))) 18 | (loop :for line = (read-line in nil) 19 | :while line 20 | :do (format t "~A~%" line)) 21 | (close in)) 22 | 23 | ; Handling files that don't exist 24 | (let ((in (open #p"~/quicklisp/local-projects/cl-tutorials/7a-file-io/src/main2.lisp" :if-does-not-exist nil))) 25 | (when in 26 | (loop :for line = (read-line in nil) 27 | :while line 28 | :do (format t "~A~%" line)) 29 | (close in))) 30 | 31 | ; Using macros 32 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7a-file-io/src/main.lisp" :if-does-not-exist nil) 33 | (when in 34 | (loop :for line = (read-line in nil) 35 | :while line 36 | :do (format t "~A~%" line)))) 37 | 38 | ; Macros with errors being thrown 39 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7a-file-io/src/main2.lisp") 40 | (when in 41 | (loop :for line = (read-line in nil) 42 | :while line 43 | :do (format t "~A~%" line)))) 44 | 45 | ; Macros reading characters, not lines 46 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7a-file-io/src/main.lisp") 47 | (when in 48 | (loop :for char = (read-char in nil) 49 | :while char 50 | :do (format t "~A~%" char)))) 51 | -------------------------------------------------------------------------------- /7a-file-io/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 7a-file-io/tests/main 2 | (:use :cl 3 | :7a-file-io 4 | :rove)) 5 | (in-package :7a-file-io/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :7a-file-io)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /7b-file-io/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /7b-file-io/7b-file-io.asd: -------------------------------------------------------------------------------- 1 | (defsystem "7b-file-io" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "7b-file-io/tests")))) 11 | 12 | (defsystem "7b-file-io/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("7b-file-io" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 7b-file-io" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /7b-file-io/README.md: -------------------------------------------------------------------------------- 1 | # 7b-file-io 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /7b-file-io/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 7b-file-io 2 | (:use :cl)) 3 | 4 | (in-package 7b-file-io) 5 | 6 | ; Get 15 characters from the stream 7 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7b-file-io/src/main.lisp") 8 | (let ((data (make-array 15 :initial-element nil))) 9 | (read-sequence data in) 10 | (format t "~A~%" data))) 11 | 12 | ; Get all characters from the stream 13 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7b-file-io/src/main.lisp") 14 | (let ((data (make-array (file-length in) :initial-element nil))) 15 | (read-sequence data in) 16 | (format t "~A~%" data))) 17 | 18 | ; Get 15 characters starting from the 15th 19 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7b-file-io/src/main.lisp") 20 | (let ((data (make-array 15 :initial-element nil))) 21 | (file-position in 15) 22 | (read-sequence data in) 23 | (format t "~A~%" data))) 24 | 25 | ; reads macro to simplfy read-sequence 26 | (defmacro reads (stream length &key (offset 0)) 27 | (let ((data (gensym))) 28 | `(let ((,data (make-array ,length :initial-element nil))) 29 | (file-position ,stream ,offset) 30 | (read-sequence ,data ,stream) 31 | ,data))) 32 | 33 | ; read 15 bytes 34 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7b-file-io/src/main.lisp") 35 | (reads in 15)) 36 | 37 | ; read all bytes 38 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7b-file-io/src/main.lisp") 39 | (reads in (file-length in))) 40 | 41 | ; read 15 bytes from offset 15 42 | (with-open-file (in #p"~/quicklisp/local-projects/cl-tutorials/7b-file-io/src/main.lisp") 43 | (reads in 15 :offset 15)) 44 | -------------------------------------------------------------------------------- /7b-file-io/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 7b-file-io/tests/main 2 | (:use :cl 3 | :7b-file-io 4 | :rove)) 5 | (in-package :7b-file-io/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :7b-file-io)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /7c-file-io/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /7c-file-io/7c-file-io.asd: -------------------------------------------------------------------------------- 1 | (defsystem "7c-file-io" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "7c-file-io/tests")))) 11 | 12 | (defsystem "7c-file-io/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("7c-file-io" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 7c-file-io" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /7c-file-io/README.md: -------------------------------------------------------------------------------- 1 | # 7c-file-io 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /7c-file-io/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 7c-file-io 2 | (:use :cl)) 3 | 4 | (in-package 7c-file-io) 5 | 6 | ; Writing using `write', entire string (plus quotes) is written 7 | (with-open-file (out #p"~/out.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 8 | (write (format nil "Hello world!~%") :stream out)) 9 | 10 | ; Writing using `write', everything in the iterable it written 11 | (with-open-file (out #p"~/out.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 12 | (write (list #\H #\e #\l #\l #\o #\Space #\W #\o #\r #\l #\d #\!) :stream out)) 13 | 14 | ; Writing using `write-char', a single char is written to the stream 15 | (with-open-file (out #p"~/out.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 16 | (write-char #\a out)) 17 | 18 | ; Writing using `write-sequence', a sequence is written to the steam (no quotes this time!) 19 | (with-open-file (out #p"~/out.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 20 | (write-sequence (format nil "Hello world!~%") out)) 21 | 22 | ; Writing using `write-sequence', a sequence is written to the steam (doesn't have to be a string) 23 | (with-open-file (out #p"~/out.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 24 | (write-sequence (list #\1 #\2 #\3 #\4 #\5) out)) 25 | 26 | ; Writing using `write-string', a string is written to the steam (no quotes this time!) 27 | (with-open-file (out #p"~/out.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 28 | (write-string (format nil "Hello world!~%") out)) 29 | 30 | ; Writing using `write-line', a string is written to the stream and automatically includes a new line 31 | (with-open-file (out #p"~/out.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 32 | (write-line "Hello world!" out) 33 | (write-line "Goodbye world!" out) 34 | ; Writing only _part_ of a string 35 | (write-line "But wait, there's more..." out :start 4 :end 22)) 36 | 37 | (with-open-file (out #p"~/out2.txt" :direction :output :if-does-not-exist :create :if-exists :supersede :element-type 'unsigned-byte) 38 | (write-byte 72 out) 39 | (write-byte 101 out) 40 | (write-byte 108 out) 41 | (write-byte 108 out) 42 | (write-byte 111 out) 43 | (write-byte 32 out) 44 | (write-byte 119 out) 45 | (write-byte 111 out) 46 | (write-byte 114 out) 47 | (write-byte 108 out) 48 | (write-byte 100 out) 49 | (write-byte 33 out)) 50 | 51 | (with-open-file (out #p"~/out3.txt" :direction :output :if-does-not-exist :create :if-exists :supersede :element-type 'unsigned-byte) 52 | (let ((seq (list 72 101 108 108 111 32 119 111 114 108 100 33))) 53 | (write-sequence seq out))) 54 | 55 | (with-open-file (out #p"~/out4.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 56 | (write-string "Hello world!" out)) 57 | 58 | (with-open-file (out #p"~/out4.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) 59 | (write-string "Hi world!" out)) 60 | 61 | (with-open-file (out #p"~/out5.txt" :direction :output :if-does-not-exist :create :if-exists :overwrite) 62 | (write-string "Hello world!" out)) 63 | 64 | (with-open-file (out #p"~/out5.txt" :direction :output :if-does-not-exist :create :if-exists :overwrite) 65 | (write-string "Hi world!" out)) 66 | -------------------------------------------------------------------------------- /7c-file-io/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 7c-file-io/tests/main 2 | (:use :cl 3 | :7c-file-io 4 | :rove)) 5 | (in-package :7c-file-io/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :7c-file-io)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /8a-functional-programming/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /8a-functional-programming/8a-functional-programming.asd: -------------------------------------------------------------------------------- 1 | (defsystem "8a-functional-programming" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "8a-functional-programming/tests")))) 11 | 12 | (defsystem "8a-functional-programming/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("8a-functional-programming" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 8a-functional-programming" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /8a-functional-programming/README.md: -------------------------------------------------------------------------------- 1 | # 8a-functional-programming 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /8a-functional-programming/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8a-functional-programming 2 | (:use :cl) 3 | (:export #:main)) 4 | 5 | (in-package 8a-functional-programming) 6 | 7 | ;; Using `map' 8 | ;;; Listing and printing a basic list 9 | (let ((l '(1 2 3 4 5))) 10 | (print l)) 11 | 12 | ;;; Mapping over two lists 13 | (let ((l '(1 2 3 4 5)) 14 | (m '(6 7 8 9 10))) 15 | (print (map 'list #'(lambda (x y) `(,(1+ x) ,(1+ y))) l m))) 16 | 17 | ;;; Mapping/transforming the values of a list, specifying the output type of the list 18 | (let ((l '(#\h #\e #\l #\l #\o))) 19 | (print (map 'string #'char-upcase l))) 20 | 21 | ;;; It could just as easily be a list 22 | (let ((l '(#\h #\e #\l #\l #\o))) 23 | (print (map 'list #'char-upcase l))) 24 | 25 | (let ((l '(#\h #\i))) 26 | (print (map 'string #'(lambda (x) x) l))) 27 | 28 | ;;; Creating lists of modified numbers using the 1+ function 29 | (let ((l '(1 2 3 4 5))) 30 | (print (map 'list #'1+ l))) 31 | 32 | ;;; Storing it in a vector works too 33 | (let ((l '(1 2 3 4 5))) 34 | (print (map 'vector #'1+ l))) 35 | 36 | ;; Using `mapcar' 37 | ;;; Creating lists of modified numbers using the 1+ function 38 | (let ((l '(1 2 3 4 5))) 39 | (print (mapcar #'1+ l))) 40 | 41 | ;;; Using a lambda function to square the elements in the list 42 | (let ((l '(1 2 3 4 5))) 43 | (print (mapcar #'(lambda (x) (* x x)) l))) 44 | 45 | ;;; Using a lambda function to cube the elements in the list 46 | (let ((l '(1 2 3 4 5))) 47 | (print (mapcar #'(lambda (x) (* x x x)) l))) 48 | 49 | ;; Using `mapc', results are not returned, instead the original list is returned 50 | ;; results can be placed elsewhere 51 | (defparameter *data* '()) 52 | 53 | (let ((l '(1 2 3 4 5))) 54 | (print (mapc #'(lambda (x) (push (* x x x) *data*)) l))) 55 | 56 | ;; Using `maplist' 57 | (let ((l '(1 2 3 4 5))) 58 | (print (maplist #'(lambda (x) (* x x x)) l))) 59 | 60 | ;; Looping using maplist over two lists 61 | (let ((l '(1 2 3 4 5)) 62 | (m '(6 7 8 9 10))) 63 | (print (maplist #'(lambda (x y) `(,x ,y)) l m))) 64 | 65 | ;; Using `maplist' 66 | (defparameter *data2* '()) 67 | (let ((l '(1 2 3 4 5)) 68 | (m '(6 7 8 9 10))) 69 | (print (maplist #'(lambda (x y) (push (car x) *data2*) 70 | (push (car y) *data2*)) 71 | l m))) 72 | 73 | ;;; Mapcan combines the results using nconc instead of list 74 | (let ((l '(1 2 3 4 5))) 75 | (print (mapcan #'(lambda (x) (* x x)) l))) 76 | 77 | ;; It's easier to see the difference between mapcar and mapcan this way 78 | ;; This produces a list of lists 79 | (let ((l '(1 2 3 4 5)) 80 | (m '(6 7 8 9 10))) 81 | (print (mapcar #'(lambda (x y) `(,x, y)) l m))) 82 | 83 | ;; This produces a list of values 84 | (let ((l '(1 2 3 4 5)) 85 | (m '(6 7 8 9 10))) 86 | (print (mapcan #'(lambda (x y) `(,x, y)) l m))) 87 | 88 | ;; This creates a list of lists where each list is the cdr each time 89 | (let ((l '(1 2 3 4 5)) 90 | (m '(6 7 8 9 10))) 91 | (print (mapcon #'(lambda (x y) `(,x, y)) l m))) 92 | -------------------------------------------------------------------------------- /8a-functional-programming/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8a-functional-programming/tests/main 2 | (:use :cl 3 | :8a-functional-programming 4 | :rove)) 5 | (in-package :8a-functional-programming/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :8a-functional-programming)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /8b-functional-programming/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /8b-functional-programming/8b-functional-programming.asd: -------------------------------------------------------------------------------- 1 | (defsystem "8b-functional-programming" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "8b-functional-programming/tests")))) 11 | 12 | (defsystem "8b-functional-programming/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("8b-functional-programming" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 8b-functional-programming" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /8b-functional-programming/README.md: -------------------------------------------------------------------------------- 1 | # 8b-functional-programming 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /8b-functional-programming/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8b-functional-programming 2 | (:use :cl)) 3 | 4 | (in-package 8b-functional-programming) 5 | 6 | (defclass album () 7 | ((artist :initarg :artist :initform "" :accessor artist) 8 | (name :initarg :name :initform "" :accessor name) 9 | (rating :initarg :rating :initform "" :accessor rating))) 10 | 11 | (defmethod print-object ((object album) stream) 12 | (print-unreadable-object (object stream) 13 | (format stream "~A: ~A (~A/10)" (artist object) (name object) (rating object)))) 14 | 15 | (print (remove 4 '(1 2 3 4 5 6 7 8 9 10))) 16 | (print (remove '(1 2) '((1 2) (3 4) (5 6) (7 8) (9 10)) :test #'equal)) 17 | (print (remove '(1 2) '((1 2) (3 4) (5 6) (7 8) (9 10)) :test-not #'equal)) 18 | (print (remove 1 '(1 1 1 1 2 1 1 1 1) :count 4)) 19 | (print (remove 1 '(1 1 1 1 2 1 1 1 1) :count 4 :from-end t)) 20 | (print (remove 1 '(1 1 1 1 2 1 1 1 1) :count 4 :start 2)) 21 | (print (remove 1 '(1 1 1 1 2 1 1 1 1) :count 4 :start 2 :end 6)) 22 | (print (remove 1 '(1 1 1 1 2 1 1 1 1) :start 2 :end 6)) 23 | 24 | (defparameter *albums* nil) 25 | (defparameter *nums* '(1 2 3 4 5 6 7 8 9 10)) 26 | 27 | (push (make-instance 'album :artist "Green Day" :name "American Idiot" :rating 6) *albums*) 28 | (push (make-instance 'album :artist "Coheed And Cambria" :name "The Second Stage Turbine Blade" :rating 7) *albums*) 29 | (push (make-instance 'album :artist "Fleetwood Mac" :name "Rumours" :rating 9) *albums*) 30 | (print (remove 6 *albums* :test #'>= :key #'rating)) 31 | (print (remove-if #'(lambda (rating) (>= 6 rating)) *albums* :key #'rating)) 32 | 33 | (remove-if #'oddp *nums*) 34 | (remove-if #'(lambda (x) (not (evenp x))) *nums*) 35 | 36 | (remove-if #'evenp *nums*) 37 | (remove-if #'(lambda (x) (not (oddp x))) *nums*) 38 | 39 | (print (delete 6 *albums* :test #'>= :key #'rating)) 40 | (print (delete 6 *albums* :test-not #'>= :key #'rating)) 41 | 42 | (print (delete-if 6 *albums* :test-not #'>= :key #'rating)) 43 | 44 | (print (delete-if #'oddp *nums*)) 45 | (print (delete-if-not #'oddp *nums*)) 46 | -------------------------------------------------------------------------------- /8b-functional-programming/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8b-functional-programming/tests/main 2 | (:use :cl 3 | :8b-functional-programming 4 | :rove)) 5 | (in-package :8b-functional-programming/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :8b-functional-programming)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /8c-functional-programming/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /8c-functional-programming/8c-functional-programming.asd: -------------------------------------------------------------------------------- 1 | (defsystem "8c-functional-programming" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "8c-functional-programming/tests")))) 11 | 12 | (defsystem "8c-functional-programming/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("8c-functional-programming" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 8c-functional-programming" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /8c-functional-programming/README.md: -------------------------------------------------------------------------------- 1 | # 8c-functional-programming 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /8c-functional-programming/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8c-functional-programming 2 | (:use :cl)) 3 | 4 | (in-package 8c-functional-programming) 5 | 6 | ; trivial example 7 | (print (+ 1 2 3 4 5)) 8 | 9 | ; Same example using reduce 10 | (print (reduce #'+ '(1 2 3 4 5))) 11 | 12 | ; another trivial example 13 | (print (- 1 2 3 4 5)) 14 | 15 | ; Same example using reduce 16 | (print (reduce #'- '(1 2 3 4 5))) 17 | 18 | ; Remember these three are the same 19 | (print (reduce #'- '(1 2 3 4 5))) 20 | (print (- 1 2 3 4 5)) 21 | (print (- 1 (- 2 (- 3 (- 4 5))))) ; is 3 22 | 23 | ; but order matters, because math does 24 | (print (- 1 (- 2 (- 3 (- 4 5))))) ; is 3 25 | ; Not the same as 26 | (print (- (- (- (- 1 2) 3) 4) 5)) ; is -13 27 | 28 | ; so gives us -13 29 | (print (reduce #'- '(1 2 3 4 5))) 30 | ; but what if we wanted the 3 that the inverse order gives us? 31 | (print (reduce #'- '(1 2 3 4 5 6 7 8 9 10) :from-end t)) ; we compute from the end instead of the beginning 32 | 33 | (print (reduce #'+ '(1 2 3 4 5 6 7 8 9 10))) ; 55 34 | (print (reduce #'+ '(1 2 3 4 5 6 7 8 9 10) :start 1)) ; 54 35 | (print (reduce #'+ '(1 2 3 4 5 6 7 8 9 10) :end 9)) ; 45 36 | (print (reduce #'+ '(1 2 3 4 5 6 7 8 9 10) :start 1 :end 9)) ; 44 37 | 38 | ; setting initial values 39 | (print (reduce #'+ '() :initial-value 1)) 40 | ; because what if you have only one value? 41 | (print (reduce #'+ '(2))) ; will be 2 42 | 43 | (print (reduce #'+ '(2) :initial-value 1)) ; will be 3, because the initial value was 1 44 | 45 | ; interactions with initial value and a complete list 46 | (print (reduce #'+ (1 2 3 4 5) :initial-value 5)) ; is 20 because prior to 1, the value is 5, so 5 + 1 + 2 + 3 + 4 + 5... 47 | 48 | ; Adding in a :key function 49 | 50 | (defun square (x) 51 | (* x x)) 52 | 53 | (print (reduce #'+ '(1 2 3 4 5) :key #'square)) ; equal to (+ (* 1 1) (* 2 2) (* 3 3) (* 4 4) (* 5 5)) 54 | (+ (* 1 1) (* 2 2) (* 3 3) (* 4 4) (* 5 5)) ; Equal to the above, but _lots_ more logic 55 | 56 | ; if we combine initial-value and key 57 | (print (reduce #'+ '(1 2 3 4 5) :key #'square :initial-value 5)) 58 | ; The initial value does not interact with the 'key' function 59 | 60 | ; lets quit numbers for now 61 | (defun join-str (x y) 62 | (format nil "~A, ~A" x y)) 63 | 64 | (print (reduce #'join-str '("this" "is" "a" "string"))) 65 | -------------------------------------------------------------------------------- /8c-functional-programming/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8c-functional-programming/tests/main 2 | (:use :cl 3 | :8c-functional-programming 4 | :rove)) 5 | (in-package :8c-functional-programming/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :8c-functional-programming)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /8d-functional-programming/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /8d-functional-programming/8d-functional-programming.asd: -------------------------------------------------------------------------------- 1 | (defsystem "8d-functional-programming" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "8d-functional-programming/tests")))) 11 | 12 | (defsystem "8d-functional-programming/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("8d-functional-programming" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 8d-functional-programming" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /8d-functional-programming/README.md: -------------------------------------------------------------------------------- 1 | # 8d-functional-programming 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /8d-functional-programming/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8d-functional-programming 2 | (:use :cl)) 3 | 4 | (in-package 8d-functional-programming) 5 | 6 | (defclass Person () 7 | ((name :initarg :name :initform "" :accessor name) 8 | (age :initarg :age :initform "" :accessor age))) 9 | 10 | (defun make-person (name age) 11 | (make-instance 'Person :name name :age age)) 12 | 13 | (defmethod print-object ((object Person) stream) 14 | (print-unreadable-object (object stream) 15 | (format stream "~A: ~A" (name object) (age object)))) 16 | 17 | (defun pretty-print (person) 18 | (format nil "~A is ~A" (name person) (age person))) 19 | 20 | (defun str-join (a b) 21 | (format nil "~A, ~A" a b)) 22 | 23 | (defparameter people `(,(make-person "Gary" 25) 24 | ,(make-person "Fred" 35))) 25 | 26 | (defun square (x) 27 | (* x x)) 28 | 29 | (print (mapcar #'1+ '(1 2 3 4 5))) 30 | (print (mapcar #'square '(1 2 3 4 5))) 31 | 32 | ; this 33 | (print (reduce #'+ (mapcar #'square '(1 2 3 4 5)))) 34 | 35 | ; is equal to this 36 | (print (+ (square 1) (square 2) (square 3) (square 4) (square 5))) 37 | 38 | ; Using objects 39 | (print (mapcar #'name people)) 40 | (print (mapcar #'age people)) 41 | (print (mapcar #'pretty-print people)) 42 | (print (reduce #'str-join (mapcar #'pretty-print people))) 43 | 44 | (defparameter data '((:url "https://google.com" :hits 5) 45 | (:url "https://duckduckgo.com") 46 | (:url "http://cuil.com" :hits 2) 47 | (:url "http://ask.com" :hits 3))) 48 | 49 | (defun fix-missing-hits (obj) 50 | (if (getf obj :hits) 51 | obj 52 | `(:url ,(getf obj :url) :hits 1))) 53 | 54 | (defun combine (a b) 55 | `(:urls ,(append (getf a :urls (list (getf a :url))) (list (getf b :url))) 56 | :hits ,(+ (getf a :hits) (getf b :hits)))) 57 | 58 | (print (mapcar #'fix-missing-hops data)) 59 | (print (reduce #'combine (mapcar #'fix-missing-hits data))) 60 | -------------------------------------------------------------------------------- /8d-functional-programming/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8d-functional-programming/tests/main 2 | (:use :cl 3 | :8d-functional-programming 4 | :rove)) 5 | (in-package :8d-functional-programming/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :8d-functional-programming)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /8e-functional-programming/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /8e-functional-programming/8e-functional-programming.asd: -------------------------------------------------------------------------------- 1 | (defsystem "8e-functional-programming" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "8e-functional-programming/tests")))) 11 | 12 | (defsystem "8e-functional-programming/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("8e-functional-programming" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 8e-functional-programming" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /8e-functional-programming/README.md: -------------------------------------------------------------------------------- 1 | # 8e-functional-programming 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /8e-functional-programming/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8e-functional-programming 2 | (:use :cl)) 3 | 4 | (in-package 8e-functional-programming) 5 | 6 | ;; 1) What are they? 7 | (print (lambda (x) (* x x))) 8 | 9 | ;; 2) Using them with higher order functions. 10 | (mapcar (lambda (x) (* x x)) '(1 2 3 4 5)) 11 | 12 | (reduce (lambda (a b) (* a b)) '(1 2 3 4 5)) 13 | ;;; is also equal to 14 | (reduce #'* '(1 2 3 4 5)) 15 | 16 | (reduce (lambda (a b) (+ 1 (* a b))) '(1 2 3 4 5)) 17 | 18 | ;; 3) Immediate invokation. 19 | ((lambda (x) (+ x x)) 9) 20 | 21 | ;;; print it out if you want 22 | (let ((result ((lambda (x) (+ x x)) 9))) 23 | (print result)) 24 | 25 | ((lambda (x) (+ x x)) ((lambda (y) (* y y)) 9)) 26 | 27 | ;; 4) Binding to symbols. 28 | (let ((square (lambda (x) (* x x)))) 29 | (apply square '(9))) 30 | 31 | (defun fn () 32 | (lambda (x) (* x x))) 33 | 34 | (defun fn2 () 35 | (lambda (x y) (* x y))) 36 | 37 | (apply (fn) '(8)) 38 | (apply (fn2) '(8 9)) 39 | 40 | ;; 5) Closures. 41 | (defun adder (num) 42 | (lambda (X) (* num x))) 43 | 44 | (let ((add5 (adder 5))) 45 | (apply add5 '(5))) 46 | 47 | ;; 6) Currying 48 | (defun curry (fn &rest args1) 49 | (lambda (&rest args2) 50 | (apply fn (append args1 args2)))) 51 | 52 | (expt 2 3) 53 | 54 | (let ((cexpt (curry #'expt 2))) 55 | (apply cexpt '(3))) 56 | 57 | (defun something (a b c) 58 | (+ a b c)) 59 | 60 | (let ((s (curry #'something 1 2))) 61 | (mapcar s '(1 2 3 4 5))) 62 | 63 | (let* ((s1 (curry #'something 1)) 64 | (s2 (curry s1 2)) 65 | (s3 (curry s2 3))) 66 | (apply s3 '())) 67 | -------------------------------------------------------------------------------- /8e-functional-programming/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8e-functional-programming/tests/main 2 | (:use :cl 3 | :8e-functional-programming 4 | :rove)) 5 | (in-package :8e-functional-programming/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :8e-functional-programming)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /8f-functional-programming/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /8f-functional-programming/8f-functional-programming.asd: -------------------------------------------------------------------------------- 1 | (defsystem "8f-functional-programming" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "8f-functional-programming/tests")))) 11 | 12 | (defsystem "8f-functional-programming/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("8f-functional-programming" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 8f-functional-programming" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /8f-functional-programming/README.md: -------------------------------------------------------------------------------- 1 | # 8f-functional-programming 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /8f-functional-programming/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8f-functional-programming 2 | (:use :cl)) 3 | 4 | (in-package 8f-functional-programming) 5 | 6 | (defun person (name age) 7 | (lambda (property) 8 | (cond 9 | ((string= property 'name) name) 10 | ((string= property 'age) age)))) 11 | 12 | (defun get-property (object property) 13 | (apply object `(,property))) 14 | 15 | (defun set-property (object property value) 16 | (cond 17 | ((string= property 'name) (person value (get-age object))) 18 | ((string= property 'age) (person (get-name object) value)))) 19 | 20 | (defun get-name (object) 21 | (get-property object 'name)) 22 | 23 | (defun set-name (object value) 24 | (set-property object 'name value)) 25 | 26 | (defun get-age (object) 27 | (get-property object 'age)) 28 | 29 | (defun set-age (object value) 30 | (set-property object 'age value)) 31 | 32 | (let ((p (person "Gary" 24))) 33 | (format t "~A is ~A~%" (get-name p) (get-age p)) 34 | (setf p (set-name p "Bob")) 35 | (setf p (set-age p 18)) 36 | (format t "~A is ~A~%" (get-name p) (get-age p))) 37 | -------------------------------------------------------------------------------- /8f-functional-programming/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8f-functional-programming/tests/main 2 | (:use :cl 3 | :8f-functional-programming 4 | :rove)) 5 | (in-package :8f-functional-programming/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :8f-functional-programming)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /8g-functional-programming/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /8g-functional-programming/8g-functional-programming.asd: -------------------------------------------------------------------------------- 1 | (defsystem "8g-functional-programming" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "main")))) 9 | :description "Generate a skeleton for modern project" 10 | :in-order-to ((test-op (test-op "8g-functional-programming/tests")))) 11 | 12 | (defsystem "8g-functional-programming/tests" 13 | :author "nmunro" 14 | :license "BSD3-Clause" 15 | :depends-on ("8g-functional-programming" 16 | :rove) 17 | :components ((:module "tests" 18 | :components 19 | ((:file "main")))) 20 | :description "Test system for 8g-functional-programming" 21 | :perform (test-op (op c) (symbol-call :rove :run c))) 22 | -------------------------------------------------------------------------------- /8g-functional-programming/README.md: -------------------------------------------------------------------------------- 1 | # 8g-functional-programming 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /8g-functional-programming/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8g-functional-programming 2 | (:use :cl)) 3 | 4 | (in-package 8g-functional-programming) 5 | 6 | (defun build (&rest props) 7 | (lambda (prop &optional (setter nil) (value nil)) 8 | (when setter 9 | (setf (getf props prop) val)) 10 | (getf props prop))) 11 | 12 | (defun extend (base &rest props) 13 | (let ((props (append `(:base ,base) props))) 14 | (lambda (prop &optional (setter nil) (val nil)) 15 | (when setter 16 | (setf (getf props prop) val)) 17 | 18 | (let ((local (getf props prop))) 19 | (if local 20 | local 21 | (apply base `(,prop))))))) 22 | 23 | (defun get-property (obj prop) 24 | (apply obj `(,prop))) 25 | 26 | (defun set-property (obj prop val) 27 | (apply obj `(,prop ,t ,val))) 28 | 29 | (defun call (obj f &rest args) 30 | (apply (get-property obj f) (append `(,obj) args))) 31 | 32 | (let* ((obj1 (build :name "NMunro" 33 | :age 2345 34 | :can-throw-axes (lambda (self) (>= (get-property self :age) 18)) 35 | :add (lambda (self num) (+ (get-property self :age) num)))) 36 | (obj2 (extend obj1 :name "Bob" :age 17))) 37 | 38 | (format nil 39 | "Can ~A throw axes: ~A, also can ~A throw axes: ~A, add: ~A~%" 40 | (get-property obj2 :name) 41 | (call obj2 :can-throw-axes) 42 | (get-property obj1 :name) 43 | (call obj1 :can-throw-axes) 44 | (call obj1 :add 5))) 45 | -------------------------------------------------------------------------------- /8g-functional-programming/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 8g-functional-programming/tests/main 2 | (:use :cl 3 | :8g-functional-programming 4 | :rove)) 5 | (in-package :8g-functional-programming/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :8g-functional-programming)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /9a-packages/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,commonlisp,linux 4 | 5 | ### CommonLisp ### 6 | *.FASL 7 | *.fasl 8 | *.lisp-temp 9 | *.dfsl 10 | *.pfsl 11 | *.d64fsl 12 | *.p64fsl 13 | *.lx64fsl 14 | *.lx32fsl 15 | *.dx64fsl 16 | *.dx32fsl 17 | *.fx64fsl 18 | *.fx32fsl 19 | *.sx64fsl 20 | *.sx32fsl 21 | *.wx64fsl 22 | *.wx32fsl 23 | 24 | ### Linux ### 25 | *~ 26 | 27 | # temporary files which can be created if a process still has a handle open of a deleted file 28 | .fuse_hidden* 29 | 30 | # KDE directory preferences 31 | .directory 32 | 33 | # Linux trash folder which might appear on any partition or disk 34 | .Trash-* 35 | 36 | # .nfs files are created when an open file is removed but is still being accessed 37 | .nfs* 38 | 39 | ### macOS ### 40 | # General 41 | .DS_Store 42 | .AppleDouble 43 | .LSOverride 44 | 45 | # Icon must end with two \r 46 | Icon 47 | 48 | 49 | # Thumbnails 50 | ._* 51 | 52 | # Files that might appear in the root of a volume 53 | .DocumentRevisions-V100 54 | .fseventsd 55 | .Spotlight-V100 56 | .TemporaryItems 57 | .Trashes 58 | .VolumeIcon.icns 59 | .com.apple.timemachine.donotpresent 60 | 61 | # Directories potentially created on remote AFP share 62 | .AppleDB 63 | .AppleDesktop 64 | Network Trash Folder 65 | Temporary Items 66 | .apdisk 67 | 68 | # End of https://www.toptal.com/developers/gitignore/api/macos,commonlisp,linux 69 | 70 | 71 | -------------------------------------------------------------------------------- /9a-packages/9a-packages.asd: -------------------------------------------------------------------------------- 1 | (defsystem "9a-packages" 2 | :version "0.0.1" 3 | :author "nmunro" 4 | :license "BSD3-Clause" 5 | :depends-on () 6 | :components ((:module "src" 7 | :components 8 | ((:file "stuff") 9 | (:file "main")))) 10 | :description "Generate a skeleton for modern project" 11 | :in-order-to ((test-op (test-op "9a-packages/tests")))) 12 | 13 | (defsystem "9a-packages/tests" 14 | :author "nmunro" 15 | :license "BSD3-Clause" 16 | :depends-on ("9a-packages" 17 | :rove) 18 | :components ((:module "tests" 19 | :components 20 | ((:file "main")))) 21 | :description "Test system for 9a-packages" 22 | :perform (test-op (op c) (symbol-call :rove :run c))) 23 | -------------------------------------------------------------------------------- /9a-packages/README.md: -------------------------------------------------------------------------------- 1 | # 9a-packages 0.0.1 2 | 3 | ## Author 4 | 5 | nmunro 6 | 7 | ## Licence 8 | 9 | BSD3-Clause 10 | -------------------------------------------------------------------------------- /9a-packages/src/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 9a-packages 2 | (:use :cl) 3 | (:import-from :9a-packages.stuff :greeting) 4 | (:export #:say-hi)) 5 | 6 | (in-package 9a-packages) 7 | 8 | (defun say-hi (name) 9 | (format t "~A!~%" (greeting name))) 10 | -------------------------------------------------------------------------------- /9a-packages/src/stuff.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 9a-packages.stuff 2 | (:use :cl) 3 | (:export #:greeting 4 | #:greeting2 5 | #:greeting3 6 | #:greeting4 7 | #:greeting5 8 | #:greeting6)) 9 | 10 | (in-package 9a-packages.stuff) 11 | 12 | (defun greeting (name) 13 | (format nil "Hi, ~A" name)) 14 | 15 | (defun greeting2 (name) 16 | (format nil "Hi, ~A" name)) 17 | 18 | (defun greeting3 (name) 19 | (format nil "Hi, ~A" name)) 20 | 21 | (defun greeting4 (name) 22 | (format nil "Hi, ~A" name)) 23 | 24 | (defun greeting5 (name) 25 | (format nil "Hi, ~A" name)) 26 | 27 | (defun greeting6 (name) 28 | (format nil "Hi, ~A" name)) 29 | -------------------------------------------------------------------------------- /9a-packages/tests/main.lisp: -------------------------------------------------------------------------------- 1 | (defpackage 9a-packages/tests/main 2 | (:use :cl 3 | :9a-packages 4 | :rove)) 5 | (in-package :9a-packages/tests/main) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :9a-packages)' in your Lisp. 8 | 9 | (deftest test-target-1 10 | (testing "should (= 1 1) to be true" 11 | (format t "Testing~%") 12 | (ok (= 1 1)))) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Neil Munro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cl-tutorials --------------------------------------------------------------------------------