unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* compute ISBN-10, char-to-int?
@ 2019-09-05  1:32 Emanuel Berg via Users list for the GNU Emacs text editor
  2019-09-05  6:44 ` tomas
  0 siblings, 1 reply; 17+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2019-09-05  1:32 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: emacs-devel

Another quality release from
uXu and THE SECRET EMPIRE, this time there sure
was a long distance before the earlier, if
anyone remembers that one... hm... anyway
perhaps _the next one_ will be ISBN-13?
Or wasn't that NASA:s bad luck number?
Typing this in 2017, when the US astronauts,
since abandoning their space shuttle project,
have been reduced to mere *passengers* onboard
Russian Soyuz crafts? You know what I'm saying?

Anyway, questions:

that `char-to-int' looks a bit strange...

?

;;; -*- lexical-binding: t -*-

;; This file: http://user.it.uu.se/~embe8573/emacs-init/isbn-new.el
;;            https://dataswamp.org/~incal/emacs-init/isbn-new.el

;; Old ISBN stuff, partially still in use: (?)
;;   https://dataswamp.org/~incal/emacs-init/isbn.el

;; NOTE: This isn't a replacement of the old
;;       stuff URLd above, this is an all new
;;       little project to compute ISBN
;;       checksums with Elisp!

;; here is how the ISBN-10 stuff works:
;;   https://dataswamp.org/~incal/books/isbn.txt

(require 'cl-lib)

(defun char-to-int (c)
  (string-to-number (char-to-string c) ))
;; test:
;; (char-to-int ?0)

(defun checksum-isbn-10 (isbn)
  (let*((isbn-list      (string-to-list isbn))
        (isbn-numbers   (remove ?- isbn-list))
        (isbn-numbers-9 (cl-subseq isbn-numbers 0 9))
        (isbn-ints      (cl-map 'list
                                (lambda (e) (char-to-int e))
                                isbn-numbers-9) )
        (sum          0)
        )
    (cl-loop for e in isbn-ints
             for i downfrom 10
             do (cl-incf sum (* e i)) )
    (let ((checksum (mod (- 11 (mod sum 11)) 11)))
      (if (= 10 checksum) "X" checksum) )))


;; 9 test from [1]:
;;
;; (checksum-isbn-10 "91-7054-940-0")  ; 0 (#o0, #x0, ?\C-@)
;; (checksum-isbn-10 "0-201-53992-6")  ; 6 (#o6, #x6, ?\C-f)
;; (checksum-isbn-10 "91-85668-01-X")  ; "X"
;; (checksum-isbn-10 "91-7089-710-7")  ; 7 (#o7, #x7, ?\C-g)
;; (checksum-isbn-10 "9177988515")     ; 5 (#o5, #x5, ?\C-e)
;; (checksum-isbn-10 "0312168144")     ; 4 (#o4, #x4, ?\C-d)
;; (checksum-isbn-10 "1-4012-0622-0")  ; 0 (#o0, #x0, ?\C-@)
;; (checksum-isbn-10 "91-510-6483-9")  ; 9 (#o11, #x9, ?\C-i)
;; (checksum-isbn-10 "91-88930-23-8")  ; 8 (#o10, #x8, ?\C-h)
;;
;;
;; [1] https://dataswamp.org/~incal/books/books.bib

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-09-10  1:20 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-05  1:32 compute ISBN-10, char-to-int? Emanuel Berg via Users list for the GNU Emacs text editor
2019-09-05  6:44 ` tomas
2019-09-05 17:28   ` Emanuel Berg via Users list for the GNU Emacs text editor
2019-09-05 18:08   ` Eli Zaretskii
2019-09-05 19:03     ` tomas
2019-09-05 19:16       ` Emanuel Berg via Users list for the GNU Emacs text editor
2019-09-06  6:58         ` Eli Zaretskii
2019-09-06  8:32           ` tomas
2019-09-06 15:07             ` Emanuel Berg via Users list for the GNU Emacs text editor
2019-09-06 18:02               ` Eli Zaretskii
2019-09-07 17:13       ` Stefan Monnier
2019-09-07 17:20         ` Eli Zaretskii
2019-09-07 17:45           ` Stefan Monnier
2019-09-07 18:30             ` Eli Zaretskii
2019-09-07 19:01               ` Stefan Monnier
2019-09-09 17:47         ` Emanuel Berg via Users list for the GNU Emacs text editor
2019-09-10  1:20           ` Perry Smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).