From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help,gmane.emacs.devel Subject: compute ISBN-10, char-to-int? Date: Thu, 05 Sep 2019 03:32:55 +0200 Message-ID: <868sr3le7s.fsf@zoho.eu> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="129539"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: emacs-devel@gnu.org To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Sep 05 03:33:38 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i5geY-000XbH-Oa for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Sep 2019 03:33:38 +0200 Original-Received: from localhost ([::1]:41816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5geX-0007qA-NH for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Sep 2019 21:33:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57380) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5geN-0007q4-TC for help-gnu-emacs@gnu.org; Wed, 04 Sep 2019 21:33:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5geM-0000g2-Ib for help-gnu-emacs@gnu.org; Wed, 04 Sep 2019 21:33:27 -0400 Original-Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:38432 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i5geL-0000Si-PL for help-gnu-emacs@gnu.org; Wed, 04 Sep 2019 21:33:25 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1i5ge3-000X7V-Uh for help-gnu-emacs@gnu.org; Thu, 05 Sep 2019 03:33:07 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Followup-To: gmane.emacs.help Mail-Copies-To: never Cancel-Lock: sha1:KNZIj8qNnXl9LMu5xlfJbPrsfKg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:121438 gmane.emacs.devel:239858 Archived-At: 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