[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 02/04: [gnugo sgf int] Internalize ‘gnugo/sgf-hang-from-root’.
From: |
Thien-Thi Nguyen |
Subject: |
[elpa] 02/04: [gnugo sgf int] Internalize ‘gnugo/sgf-hang-from-root’. |
Date: |
Fri, 11 Apr 2014 09:24:59 +0000 |
ttn pushed a commit to branch master
in repository elpa.
commit 9c353106d08249e741e394b49771b3679f999f85
Author: Thien-Thi Nguyen <address@hidden>
Date: Fri Apr 11 10:37:12 2014 +0200
[gnugo sgf int] Internalize ‘gnugo/sgf-hang-from-root’.
* packages/gnugo/gnugo.el (gnugo/sgf-write-file):
...into here, and remove ‘gnugo/sgf-hang-from-root’.
---
packages/gnugo/gnugo.el | 57 ++++++++++++++++++++++------------------------
1 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index dbbe01a..9279261 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -2733,35 +2733,6 @@ A collection is a list of gametrees, each a vector of
four elements:
(apply 'vector ends)
root)))))))
-(defun gnugo/sgf-hang-from-root (tree)
- (let ((ht (gnugo--mkht))
- (leaves (append (gnugo--tree-ends tree) nil)))
- (cl-flet
- ((hang (stack)
- (loop
- with rh ; rectified history
- with bp ; branch point
- for node in stack
- until (setq bp (gethash node ht))
- do (puthash node
- (push node rh) ; good for now: ½τ
- ht)
- finally return
- (if (not bp)
- ;; first run: main line
- rh
- ;; subsequent runs: grafts (value discarded)
- (setcdr bp (nconc
- ;; Maintain order of ‘leaves’.
- (let ((was (cdr bp)))
- (if (gnugo--nodep (car was))
- (list was)
- was))
- (list rh)))))))
- (setq tree (hang (pop leaves)))
- (mapc #'hang leaves)
- tree)))
-
(defun gnugo/sgf-write-file (collection filename)
(let ((aft-newline-appreciated '(:AP :GN :PB :PW :HA :KM :RU :RE))
(me (cons "gnugo.el" gnugo-version))
@@ -2834,7 +2805,33 @@ A collection is a list of gametrees, each a vector of
four elements:
;; take responsibility for our actions
(gnugo--set-root-prop :AP me tree)
;; write it out
- (>>tree (gnugo/sgf-hang-from-root tree)))
+ (let ((ht (gnugo--mkht))
+ (leaves (append (gnugo--tree-ends tree) nil)))
+ (cl-flet
+ ((hang (stack)
+ (loop
+ with rh ; rectified history
+ with bp ; branch point
+ for node in stack
+ until (setq bp (gethash node ht))
+ do (puthash node
+ (push node rh) ; good for now: ½τ
+ ht)
+ finally return
+ (if (not bp)
+ ;; first run: main line
+ rh
+ ;; subsequent runs: grafts (value discarded)
+ (setcdr bp (nconc
+ ;; Maintain order of ‘leaves’.
+ (let ((was (cdr bp)))
+ (if (gnugo--nodep (car was))
+ (list was)
+ was))
+ (list rh)))))))
+ (setq tree (hang (pop leaves)))
+ (mapc #'hang leaves)
+ (>>tree tree))))
(newline)
(write-file filename)))))
- [elpa] branch master updated (2f9b6b0 -> 991d7f6), Thien-Thi Nguyen, 2014/04/11
- [elpa] 01/04: [gnugo sgf int] Consolidate loops., Thien-Thi Nguyen, 2014/04/11
- [elpa] 04/04: [gnugo int] Decruft: Drop gametree IR element: KIDS, Thien-Thi Nguyen, 2014/04/11
- [elpa] 02/04: [gnugo sgf int] Internalize ‘gnugo/sgf-hang-from-root’.,
Thien-Thi Nguyen <=
- [elpa] 03/04: [gnugo int] Reorder gametree IR: ENDS, MNUM, ROOT, KIDS., Thien-Thi Nguyen, 2014/04/11