all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Cc: emacs-devel@gnu.org
Subject: compute ISBN-10, char-to-int?
Date: Thu, 05 Sep 2019 03:32:55 +0200	[thread overview]
Message-ID: <868sr3le7s.fsf@zoho.eu> (raw)

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




             reply	other threads:[~2019-09-05  1:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05  1:32 Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2019-09-05  6:44 ` compute ISBN-10, char-to-int? 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=868sr3le7s.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.