ttn pushed a commit to branch master
in repository elpa.
commit 9c353106d08249e741e394b49771b3679f999f85
Author: Thien-Thi Nguyen <[email protected]>
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)))))