markov-analyze inside snd/CM_patterns.scm includes a bug, or more
precisely the version of 'last i used (from snd/stuff.scm?) doesn't
alter its pair when passed to set-cdr!:

   => (define n '(1 2 3 4))
   (1 2 3 4)
   => (set-cdr! (last n) '(5))
   (5)
   => n
   (1 2 3 4)

   => (define n '(1 2 3 4))
   (1 2 3 4)
   => (set-cdr! (last-pair n) '(5))
   (5)
   => n
   (1 2 3 4 5)

Heres a patch:

--- CM_patterns.scm	2015-06-22 10:43:45.179368161 +0200
+++ CM_patterns.scm.new	2015-06-22 10:40:25.513824674 +0200
@@ -1071,6 +1071,10 @@
 ;;; (define aaa (make-markov '((a -> b c d) (b -> a) (c -> d) (d -> (a 3) b c))))
 ;;; (next aaa 30)
 
+(define (last-pair l)
+  (if (pair? (cdr l)) 
+      (last-pair (cdr l)) l))
+
 (define (markov-analyze seq . args) 
   (let* ((morder #f) ; markov order
 	 (result #f) ; what to return
@@ -1098,7 +1102,7 @@
 		      (let ((e (assoc next (cddr entry)))) 
 			(if e 
 			    (set-car! (cdr e) (+ 1 (cadr e)))
-			    (set-cdr! (last (cdr entry))
+			    (set-cdr! (last-pair (cdr entry))
 				      (list (list next 1)))))))))
 	     (before?
 	      (lambda (x y l) 
@@ -1212,7 +1216,7 @@
 			(display sp port)
 			;; s7: trim number to fit field
 			(if (>= n field)
-			    (let ((d (position #\. s)))
+			    (let ((d (char-position #\. s)))
 			      (set! s (substring s 0 (min (+ d 4) n)))
 			      (set! n (string-length s))))
 			;; pad number
Not sure naming this 'last, 'tail or a 'last-pair is right here.
snd/stuff.scm has a 'last (mimicking CL's last, but not allowing
destructive operations on pairs?), CMs .scm uses 'tail, s7 seems to want
to stay close to guile (?), which uses 'last-pair.
_______________________________________________
Cmdist mailing list
[email protected]
https://cm-mail.stanford.edu/mailman/listinfo/cmdist

Reply via email to