# HG changeset patch # User Glenn Morris # Date 1207017725 0 # Node ID 0c5143f2417bf4f35aea86a11453291d12696815 # Parent a4a2b2f631169c6dcf4d141c298237b1232c55e2 (Commentary): Point to calendar.el. (calendar-string-to-mayan-long-count, calendar-goto-mayan-long-count-date): Simplify. diff -r a4a2b2f63116 -r 0c5143f2417b lisp/calendar/cal-mayan.el --- a/lisp/calendar/cal-mayan.el Tue Apr 01 02:41:15 2008 +0000 +++ b/lisp/calendar/cal-mayan.el Tue Apr 01 02:42:05 2008 +0000 @@ -28,28 +28,7 @@ ;;; Commentary: -;; This collection of functions implements the features of calendar.el and -;; diary.el that deal with the Mayan calendar. It was written jointly by - -;; Stewart M. Clamen School of Computer Science -;; clamen@cs.cmu.edu Carnegie Mellon University -;; 5000 Forbes Avenue -;; Pittsburgh, PA 15213 - -;; and - -;; Edward M. Reingold Department of Computer Science -;; (217) 333-6733 University of Illinois at Urbana-Champaign -;; reingold@cs.uiuc.edu 1304 West Springfield Avenue -;; Urbana, Illinois 61801 - -;; Technical details of the Mayan calendrical calculations can be found in -;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold -;; and Nachum Dershowitz, Cambridge University Press (2001), and in -;; ``Calendrical Calculations, Part II: Three Historical Calendars'' -;; by E. M. Reingold, N. Dershowitz, and S. M. Clamen, -;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993), -;; pages 383-404. +;; See calendar.el. ;;; Code: @@ -96,20 +75,17 @@ (defun calendar-string-to-mayan-long-count (str) "Given STR, a string of format \"%d.%d.%d.%d.%d\", return list of numbers." - (let ((c (length str)) - (cc 0) + (let ((end 0) rlc) - (condition-case condition + (condition-case nil (progn - (while (< cc c) - (let* ((start (string-match "[0-9]+" str cc)) - (end (match-end 0)) - (datum (read (substring str start end)))) - (setq rlc (cons datum rlc) - cc end))) + ;; cf split-string. + (while (string-match "[0-9]+" str end) + (setq rlc (cons (string-to-number (match-string 0 str)) rlc) + end (match-end 0))) (unless (= (length rlc) 5) (signal 'invalid-read-syntax nil))) (invalid-read-syntax nil)) - (reverse rlc))) + (nreverse rlc))) (defun calendar-mayan-haab-from-absolute (date) "Convert absolute DATE into a Mayan haab date (a pair)." @@ -361,18 +337,18 @@ "Move cursor to Mayan long count DATE. Echo Mayan date unless NOECHO is non-nil." (interactive - (let (lc) - (while (not lc) - (let ((datum - (calendar-string-to-mayan-long-count - (read-string "Mayan long count (baktun.katun.tun.uinal.kin): " - (calendar-mayan-long-count-to-string - (calendar-mayan-long-count-from-absolute - (calendar-absolute-from-gregorian - (calendar-current-date)))))))) - (if (calendar-mayan-long-count-common-era datum) - (setq lc datum)))) - (list lc))) + (let (datum) + (while (not (setq datum + (calendar-string-to-mayan-long-count + (read-string + "Mayan long count (baktun.katun.tun.uinal.kin): " + (calendar-mayan-long-count-to-string + (calendar-mayan-long-count-from-absolute + (calendar-absolute-from-gregorian + (calendar-current-date)))))) + datum (if (calendar-mayan-long-count-common-era datum) + (list datum))))) + datum)) (calendar-goto-date (calendar-gregorian-from-absolute (calendar-absolute-from-mayan-long-count date)))