[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 32/255: consolidating utility functions
From: |
Eric Schulte |
Subject: |
[elpa] 32/255: consolidating utility functions |
Date: |
Sun, 16 Mar 2014 01:02:13 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit e8a9816465823c5a07ac7c543cd1d0ba6f6bf0a3
Author: Eric Schulte <address@hidden>
Date: Thu May 17 10:41:06 2012 -0400
consolidating utility functions
---
sgf.el | 44 ++++++++++++++++++++++++++++++--------------
1 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/sgf.el b/sgf.el
index e40503f..f93ab7d 100644
--- a/sgf.el
+++ b/sgf.el
@@ -80,6 +80,36 @@
(require 'cl)
+;;; Utility
+(defun some (seq comb &optional func)
+ (flet ((this (el) (funcall (or func #'identity) el)))
+ (reduce (lambda (acc el)
+ (case comb
+ (:or (or acc (this el)))
+ (:and (and acc (this el)))))
+ seq :initial-value (case comb (:or nil) (:and t)))))
+
+(defun any (seq &optional func) (some seq :or func))
+(defun all (seq &optional func) (some seq :and func))
+
+(defun aget (key list) (cdr (assoc key list)))
+
+(defun range (a &optional b)
+ (block nil
+ (let (tmp)
+ (unless b
+ (cond ((> a 0) (decf a))
+ ((= a 0) (return nil))
+ ((> 0 a) (incf a)))
+ (setq b a a 0))
+ (if (> a b) (setq tmp a a b b tmp))
+ (let ((res (number-sequence a b)))
+ (if tmp (nreverse res) res)))))
+
+(defun other-color (color)
+ (if (equal color :b) :w :b))
+
+
;;; Parsing
(defmacro parse-many (regexp string &rest body)
(declare (indent 2))
@@ -147,8 +177,6 @@
;;; Processing
-(defun aget (key list) (cdr (assoc key list)))
-
(defvar sgf-property-alist nil
"A-list of property names and the function to interpret their values.")
@@ -218,18 +246,6 @@
(defun board-size (board) (round (sqrt (length board))))
-(defun range (a &optional b)
- (block nil
- (let (tmp)
- (unless b
- (cond ((> a 0) (decf a))
- ((= a 0) (return nil))
- ((> 0 a) (incf a)))
- (setq b a a 0))
- (if (> a b) (setq tmp a a b b tmp))
- (let ((res (number-sequence a b)))
- (if tmp (nreverse res) res)))))
-
(defvar black-piece "X")
(defvar white-piece "O")
- [elpa] 24/255: right and left implemented but buggy, (continued)
- [elpa] 24/255: right and left implemented but buggy, Eric Schulte, 2014/03/15
- [elpa] 23/255: more complex but more intuitive and useful `range', Eric Schulte, 2014/03/15
- [elpa] 21/255: display sgf file as a go board in a buffer, Eric Schulte, 2014/03/15
- [elpa] 25/255: right and left are mainly working, Eric Schulte, 2014/03/15
- [elpa] 29/255: q now quits a sgf display buffer, Eric Schulte, 2014/03/15
- [elpa] 28/255: adding a major mode for board navigation keys, Eric Schulte, 2014/03/15
- [elpa] 27/255: implementation notes, Eric Schulte, 2014/03/15
- [elpa] 31/255: a test to protect against unwanted state changes, Eric Schulte, 2014/03/15
- [elpa] 33/255: removing dead pieces after moves, Eric Schulte, 2014/03/15
- [elpa] 35/255: compiled and caught some minor issues, Eric Schulte, 2014/03/15
- [elpa] 32/255: consolidating utility functions,
Eric Schulte <=
- [elpa] 30/255: saving the board configuration with each sgf step, Eric Schulte, 2014/03/15
- [elpa] 18/255: applying moves to a board, Eric Schulte, 2014/03/15
- [elpa] 37/255: remove debug printf, Eric Schulte, 2014/03/15
- [elpa] 34/255: beginning to stub out tests for dead stone removal, Eric Schulte, 2014/03/15
- [elpa] 38/255: more capture tests, failing multistone captures, Eric Schulte, 2014/03/15
- [elpa] 36/255: passing all tests (at least it did this once), Eric Schulte, 2014/03/15
- [elpa] 26/255: improvements, considering labels and moves, Eric Schulte, 2014/03/15
- [elpa] 40/255: parsing empty properties, Eric Schulte, 2014/03/15
- [elpa] 42/255: more work with tree parsing, Eric Schulte, 2014/03/15
- [elpa] 46/255: TODO: try using load-read-function and try loading these files w/read, Eric Schulte, 2014/03/15