This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :cl-datastructures | |
(:use :cl)) | |
(in-package :cl-datastructures) | |
(defclass linked-list-node () | |
((next :initarg :next :initform nil) | |
(value :initarg :value :initform nil))) | |
(defclass linked-list () | |
((head :initarg :value :initform nil))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun test-collector () | |
"Looks for all the triplets and defines a test for them. In current suite or | |
taking a suite as an argument? " | |
(loop | |
for triplet in (setup-test-tuples | |
(merge-pathnames "requests/valid/*.http" *specs-dir*)) | |
do | |
(let ((http-file (first triplet)) | |
(request-file (second triplet)) | |
(spec-file (third triplet))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Success | |
;;; Less Boilerplate | |
(defmacro define-accessor (name accessor) | |
`(progn | |
(defun ,name (board) | |
,accessor) | |
(defun (setf ,name) (value board) | |
(if (eq (,name board) :empty) | |
(setf ,accessor value) | |
(error 'invalid-move :text "The square is not empty"))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-package :cl-user) | |
(ql:quickload :fiveam) | |
(defun top-left (board) | |
(car board)) | |
(defun (setf top-left) (value board) | |
(setf (car board) value)) | |
(fiveam:test top-left-accessor () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-package :cl-user) | |
;;; Everything now works thanks to Bike and http://stackoverflow.com/questions/11457071/defining-setf-expanders-in-common-lisp | |
;;; Learned something new today | |
(defun top-center (board) | |
(car (cdr board))) | |
(defun (setf top-center) (value board) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""A short example of why you shouldn't use lists or dicts as default. In python | |
default parameteres are bounded when the function definition is executed as | |
part of module loading. So after the function is created the default arguments | |
always point the same object (being list or dict, list in this case.). One | |
should only use inmutable objects as None or strings as default arguments. | |
""" | |
def foo(bar=[]): | |
"""Never do this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun validate-candidate (candidate) | |
(let ((candidate (write-to-string candidate))) | |
(unless (= (length candidate) 4) | |
(error "Test valid only for 4 digit numbers")) | |
(let ((initial-digits (parse-integer (subseq candidate 0 2))) | |
(middle-digits (parse-integer (subseq candidate 1 3))) | |
(final-digits (parse-integer (subseq candidate 2 4)))) | |
(if (= middle-digits (+ initial-digits final-digits)) | |
t | |
nil)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(asdf:defsystem #:qchapi | |
:name "qchapi" | |
:description "A Restful Api for Qcha.es" | |
:author "Javier Olaechea <[email protected]>" | |
:version "20130401" | |
:serial t | |
:license "<3" | |
:depends-on (#:clack | |
#:ningle | |
#:yason |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun create-pairs (lst) | |
"given a list, produces a list of all possible sets of pairings, without duplicates. " | |
(if (eq lst '()) | |
*pair-list* | |
(progn | |
(dolist (item (cdr lst)) | |
(push `(,(car lst) ,item) *pair-list*)) | |
(create-pairs (cdr lst))))) | |
(defvar *pair-list*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class IllegalMove(Exception): | |
pass | |
class TicTacToe(object): | |
player_1_symbol = "O" | |
player_2_symbol = "X" | |
empty_symbol = " " |