all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ISBN-13 checksums worth checking out
@ 2019-11-22  6:26 Emanuel Berg via Users list for the GNU Emacs text editor
  2019-11-22 13:29 ` Amin Bandali
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2019-11-22  6:26 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: emacs-devel

Dear Emacs comrades, yes, my life has derailed
a bit, which explains my absence from the
programming scene.

But today, after a superhuman effort, I finally
did some of it again - and I couldn't have
picked a more urgent topic!

Alright, enough with the suspension, just like
Uri Geller can bend a spoon while still
connected to the Matrix (20 years: 1999-2019),
you guessed it, I added support for
ISBN-13 checksums!

  https://dataswamp.org/~incal/emacs-init/isbn-new.el

The new stuff is at lines 29-51. It seems to...
check out.

Right?

I yank it last (now) if you don't want to
follow the URL.

;;; -*- 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

;; Update: November 2019, support for ISBN-13!

;; here is how the ISBN checksums work:
;;   https://dataswamp.org/~incal/books/isbn.txt
;; (see an example execution/manual computation
;;  of ISBN-10 last in this file)

(require 'cl-lib)

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

(defun isbn-integer-list (isbn num-digits)
  (let*((isbn-list         (string-to-list isbn))
        (isbn-drop-dashes  (remove ?- isbn-list))
        (isbn-drop-surplus (cl-subseq isbn-drop-dashes 0 num-digits))
        (isbn-ints         (cl-map 'list
                                   (lambda (c) (char-to-int c))
                                   isbn-drop-surplus) ))
    isbn-ints) )

(defun checksum-isbn-13 (isbn)
  (let*((isbn-ints (isbn-integer-list isbn 12))
        (sum       0))
    (cl-loop for e in isbn-ints
             for i upfrom 0
             do (cl-incf sum (* e (or (and (zerop (mod i 2)) 1) 3))))
    (- 10 (mod sum 10)) ))

;; ISBN-13 tests:
;; (checksum-isbn-13 "978-91-87861-99-4") ; 4
;; (checksum-isbn-13 "978-91-87861-67-3") ; 3
;; (checksum-isbn-13 "978-91-87861-54-3") ; 3
;; (checksum-isbn-13 "978-91-7515-317-9") ; 9
;; (checksum-isbn-13 "978-91-7515-205-9") ; 3

(defun checksum-isbn-10 (isbn)
  (let*((isbn-ints (isbn-integer-list isbn 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) )))

;; ISBN-10 tests:
;; (checksum-isbn-10 "978-1-85669-6")
;;
;; 10 tests from [1]:
;;
;; (checksum-isbn-10 "91-7054-940-0") ; 0
;; (checksum-isbn-10 "0-201-53992-6") ; 6
;; (checksum-isbn-10 "91-85668-01-X") ; X
;; (checksum-isbn-10 "91-7089-710-7") ; 7
;; (checksum-isbn-10 "9177988515")    ; 5
;; (checksum-isbn-10 "0312168144")    ; 4
;; (checksum-isbn-10 "1-4012-0622-0") ; 0
;; (checksum-isbn-10 "91-510-6483-9") ; 9
;; (checksum-isbn-10 "91-88930-23-8") ; 8
;; (checksum-isbn-10 "1616558717")    ; 7
;;
;; (checksum-isbn-10 "4294967296")
;; invalid, i.e not an ISBN-10  - checksum is 3:
;;   (mod (- 11 (mod (+ (* 4 10)
;;                      (* 2  9)
;;                      (* 9  8)
;;                      (* 4  7)
;;                      (* 9  6)
;;                      (* 6  5)
;;                      (* 7  4)
;;                      (* 2  3)
;;                      (* 9  2))
;;                   11)) 11) ; 3
;;
;; [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] 5+ messages in thread

* Re: ISBN-13 checksums worth checking out
  2019-11-22  6:26 ISBN-13 checksums worth checking out Emanuel Berg via Users list for the GNU Emacs text editor
@ 2019-11-22 13:29 ` Amin Bandali
  2019-11-22 17:05   ` Eric Abrahamsen
  0 siblings, 1 reply; 5+ messages in thread
From: Amin Bandali @ 2019-11-22 13:29 UTC (permalink / raw)
  To: help-gnu-emacs

Super happy to see you here again, Emanuel. :)

Would you consider adding license headers to
the (non-trivial) snippets you post here?  It
would be really helpful for those of us that
like to use them in our Emacs configs in
freedom!

You can see examples of Elisp license headers
in any of the lisp/*.el files in your Emacs
installation directory or in the Emacs git
repository, such as lisp/rot13.el:
https://git.sv.gnu.org/cgit/emacs.git/tree/lisp/rot13.el



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

* Re: ISBN-13 checksums worth checking out
  2019-11-22 13:29 ` Amin Bandali
@ 2019-11-22 17:05   ` Eric Abrahamsen
  2019-11-22 18:37     ` Eric Abrahamsen
  2019-11-23  0:14     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Abrahamsen @ 2019-11-22 17:05 UTC (permalink / raw)
  To: help-gnu-emacs

Amin Bandali <bandali@gnu.org> writes:

> Super happy to see you here again, Emanuel. :)
>
> Would you consider adding license headers to
> the (non-trivial) snippets you post here?  It
> would be really helpful for those of us that
> like to use them in our Emacs configs in
> freedom!

And/or stick things in melpa/elpa! I would find this library useful.



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

* Re: ISBN-13 checksums worth checking out
  2019-11-22 17:05   ` Eric Abrahamsen
@ 2019-11-22 18:37     ` Eric Abrahamsen
  2019-11-23  0:14     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Abrahamsen @ 2019-11-22 18:37 UTC (permalink / raw)
  To: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Amin Bandali <bandali@gnu.org> writes:
>
>> Super happy to see you here again, Emanuel. :)
>>
>> Would you consider adding license headers to
>> the (non-trivial) snippets you post here?  It
>> would be really helpful for those of us that
>> like to use them in our Emacs configs in
>> freedom!
>
> And/or stick things in melpa/elpa! I would find this library useful.

Actually, if you wanted to make an ISBN barcode generator in elisp, that
would be aces :)




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

* Re: ISBN-13 checksums worth checking out
  2019-11-22 17:05   ` Eric Abrahamsen
  2019-11-22 18:37     ` Eric Abrahamsen
@ 2019-11-23  0:14     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2019-11-23  0:14 UTC (permalink / raw)
  To: help-gnu-emacs

Eric Abrahamsen wrote:

>> Super happy to see you here again, Emanuel.
>> :)
>>
>> Would you consider adding license headers to
>> the (non-trivial) snippets you post here?
>> It would be really helpful for those of us
>> that like to use them in our Emacs configs
>> in freedom!
>
> And/or stick things in melpa/elpa! I would
> find this library useful.

Thank you guys, well I have thought about it
because of obvious reasons and advantages to me
and maybe even other people, but never gotten
to it...

But maybe the stars are aligned for this
particular package because it is not intermixed
with configuration and it is such a nerdy
one-purpose thing that it is easy to understand
to anyone.

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




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

end of thread, other threads:[~2019-11-23  0:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-22  6:26 ISBN-13 checksums worth checking out Emanuel Berg via Users list for the GNU Emacs text editor
2019-11-22 13:29 ` Amin Bandali
2019-11-22 17:05   ` Eric Abrahamsen
2019-11-22 18:37     ` Eric Abrahamsen
2019-11-23  0:14     ` Emanuel Berg via Users list for the GNU Emacs text editor

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.