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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/gnugo bba08d3 158/357: [gnugo sgf int] Internalize ‘gn


From: Stefan Monnier
Subject: [elpa] externals/gnugo bba08d3 158/357: [gnugo sgf int] Internalize ‘gnugo/sgf-hang-from-root’.
Date: Sun, 29 Nov 2020 14:51:11 -0500 (EST)

branch: externals/gnugo
commit bba08d396d803201cf2f1deb90f8dfdf75218d55
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>

    [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’.
---
 gnugo.el | 57 +++++++++++++++++++++++++++------------------------------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/gnugo.el b/gnugo.el
index dbbe01a..9279261 100644
--- a/gnugo.el
+++ b/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)))))
 



reply via email to

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