emacs-elpa-diffs
[Top][All Lists]
Advanced

[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")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]