unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* verify ISSN (issn-verify.el)
@ 2020-09-11  3:29 Emanuel Berg via Emacs development discussions.
  2020-09-11  4:58 ` 황병희
  2020-09-11  6:32 ` Emanuel Berg via Emacs development discussions.
  0 siblings, 2 replies; 5+ messages in thread
From: Emanuel Berg via Emacs development discussions. @ 2020-09-11  3:29 UTC (permalink / raw)
  To: emacs-devel; +Cc: help-gnu-emacs

;;; issn-verify.el --- verify ISSN -*- lexical-binding: t
;;
;;; Commentary:
;;
;; This Elisp package provides functions to verify
;; ISSN by computing their check digits.
;;
;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;; Created: 2020-09-06
;; Keywords: bib, tex
;; License: GPL3+
;; Package-Requires: ((cl-lib "1.0"))
;; URL: https://dataswamp.org/~incal/emacs-init/issn-verify.el
;; Version: 1.0.0
;;
;; Also see:
;;
;;   https://dataswamp.org/~incal/emacs-init/isbn-verify.el
;;
;; To install this package, with this file in
;; a buffer, do:
;;
;;   M-x load-file RET RET
;;
;; International Standard Serial Number:
;;
;;   ISO 3297, 1975
;;
;; format:
;;
;;   The Ring Magazine: ISSN 0035-5410
;;   d_1d_2d_3d_4-d_5d_6d_7c
;;   d_i for i \in [1, 7] is an integer
;;   c, the check digit, is 0..9 or X for 10
;;
;; compute check digit c:
;;
;;     c' = 8d_1*7d_2*6d_3*5d_4*4d_5*3d_6*2d_7 mod 11
;;
;;         { 0        c' = 0
;;     c = {
;;         { 11 - c'    else
;;
;;; Code:

(require 'cl-lib)

(defun issn--get-digits (issn)
  (when (string-match "[[:digit:]]\\{4\\}-[[:digit:]]\\{3\\}[X[:digit:]]" issn)
    (let*((hyphen-pos 4)
          (issn-lst   (string-to-list issn)) )
      (mapcar (lambda (c) (if (eq ?X c) "X" (- c ?0)))
              (append (cl-subseq issn-lst 0 hyphen-pos)
                      (cl-subseq issn-lst (1+ hyphen-pos)) )))))

(defun issn-verify-issn (issn)
  (let*((issn-lst (issn--get-digits issn))
        (c-prop  (car (last issn-lst)))
        (c-w 0) )
    (cl-loop for d in issn-lst
             for w downfrom 8 to 2
             do (cl-incf c-w (* w d)) )
    (let*((c-prime (mod c-w 11))
          (c       (cond ((= c-prime  0) 0)
                         (t (- 11 c-prime) )))
          (c-x     (if (= 10 c) "X" c)) )
      (if (equal c-prop c-x)
          (message "%s (OK)" c-x)
        (message "NOT OK! is %s, should be %s" c-prop c-x) ))))

;; Bicycle Quarterly   (issn-verify-issn "1941-8809")
;; Bicycling           (issn-verify-issn "1651-9744")
;; Black Belt          (issn-verify-issn "0277-3066")
;; Filter              (issn-verify-issn "1654-9813")
;; Linux Pro           (issn-verify-issn "1471-5678")
;; National Geographic (issn-verify-issn "2535-4124")
;; Outside             (issn-verify-issn "0278-1433")
;; The Ring            (issn-verify-issn "0035-5410")

;; The Economist       (issn-verify-issn "0013-0614") ; NOT OK! is 4, should be 3

(provide 'issn-verify)
;;; issn-verify.el ends here

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




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

* Re: verify ISSN (issn-verify.el)
  2020-09-11  3:29 verify ISSN (issn-verify.el) Emanuel Berg via Emacs development discussions.
@ 2020-09-11  4:58 ` 황병희
  2020-09-11  5:48   ` Emanuel Berg via Emacs development discussions.
  2020-09-11  6:32 ` Emanuel Berg via Emacs development discussions.
  1 sibling, 1 reply; 5+ messages in thread
From: 황병희 @ 2020-09-11  4:58 UTC (permalink / raw)
  To: emacs-devel

Emanuel Berg via "Emacs development discussions." <emacs-devel@gnu.org>
writes:

> ;;; issn-verify.el --- verify ISSN -*- lexical-binding: t
> ;;
> ;;; Commentary:
> ;;
> ;; This Elisp package provides functions to verify
> ;; ISSN by computing their check digits.
> ;;
> ;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
> ;; Created: 2020-09-06
> ;; Keywords: bib, tex
> ;; License: GPL3+
> ;; Package-Requires: ((cl-lib "1.0"))
> ;; URL: https://dataswamp.org/~incal/emacs-init/issn-verify.el
> ;; Version: 1.0.0
> ;;
> ;; Also see:
> ;;
> ;;   https://dataswamp.org/~incal/emacs-init/isbn-verify.el
> ;;
> ;; To install this package, with this file in
> ;; a buffer, do:
> ;;
> ;;   M-x load-file RET RET
> ;;
> ;; International Standard Serial Number:
> ;;
> ;;   ISO 3297, 1975
> ;;
> ;; format:
> ;;
> ;;   The Ring Magazine: ISSN 0035-5410
> ;;   d_1d_2d_3d_4-d_5d_6d_7c
> ;;   d_i for i \in [1, 7] is an integer
> ;;   c, the check digit, is 0..9 or X for 10
> ;;
> ;; compute check digit c:
> ;;
> ;;     c' = 8d_1*7d_2*6d_3*5d_4*4d_5*3d_6*2d_7 mod 11
> ;;
> ;;         { 0        c' = 0
> ;;     c = {
> ;;         { 11 - c'    else
> ;;
> ;;; Code:
>
> (require 'cl-lib)
>
> (defun issn--get-digits (issn)
>   (when (string-match "[[:digit:]]\\{4\\}-[[:digit:]]\\{3\\}[X[:digit:]]" issn)
>     (let*((hyphen-pos 4)
>           (issn-lst   (string-to-list issn)) )
>       (mapcar (lambda (c) (if (eq ?X c) "X" (- c ?0)))
>               (append (cl-subseq issn-lst 0 hyphen-pos)
>                       (cl-subseq issn-lst (1+ hyphen-pos)) )))))
>
> (defun issn-verify-issn (issn)
>   (let*((issn-lst (issn--get-digits issn))
>         (c-prop  (car (last issn-lst)))
>         (c-w 0) )
>     (cl-loop for d in issn-lst
>              for w downfrom 8 to 2
>              do (cl-incf c-w (* w d)) )
>     (let*((c-prime (mod c-w 11))
>           (c       (cond ((= c-prime  0) 0)
>                          (t (- 11 c-prime) )))
>           (c-x     (if (= 10 c) "X" c)) )
>       (if (equal c-prop c-x)
>           (message "%s (OK)" c-x)
>         (message "NOT OK! is %s, should be %s" c-prop c-x) ))))
>
> ;; Bicycle Quarterly   (issn-verify-issn "1941-8809")
> ;; Bicycling           (issn-verify-issn "1651-9744")
> ;; Black Belt          (issn-verify-issn "0277-3066")
> ;; Filter              (issn-verify-issn "1654-9813")
> ;; Linux Pro           (issn-verify-issn "1471-5678")
> ;; National Geographic (issn-verify-issn "2535-4124")
> ;; Outside             (issn-verify-issn "0278-1433")
> ;; The Ring            (issn-verify-issn "0035-5410")
>
> ;; The Economist       (issn-verify-issn "0013-0614") ; NOT OK! is 4, should be 3
>
> (provide 'issn-verify)
> ;;; issn-verify.el ends here

Still i don't know emacs lisp but your codes looks beautiful, wow!!!
Cheer up and thanks Emanuel^^^

Sincerely, Byung-Hee

-- 
^고맙습니다 _和合團結_ 감사합니다_^))//



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

* Re: verify ISSN (issn-verify.el)
  2020-09-11  4:58 ` 황병희
@ 2020-09-11  5:48   ` Emanuel Berg via Emacs development discussions.
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg via Emacs development discussions. @ 2020-09-11  5:48 UTC (permalink / raw)
  To: emacs-devel

Byung-Hee wrote:

> Still i don't know emacs lisp but your codes looks
> beautiful, wow!!!

... ha! :)

> Cheer up and thanks Emanuel^^^

Well, by all means, thank you :)

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




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

* Re: verify ISSN (issn-verify.el)
  2020-09-11  3:29 verify ISSN (issn-verify.el) Emanuel Berg via Emacs development discussions.
  2020-09-11  4:58 ` 황병희
@ 2020-09-11  6:32 ` Emanuel Berg via Emacs development discussions.
  2020-09-12  4:04   ` Emanuel Berg via Emacs development discussions.
  1 sibling, 1 reply; 5+ messages in thread
From: Emanuel Berg via Emacs development discussions. @ 2020-09-11  6:32 UTC (permalink / raw)
  To: emacs-devel; +Cc: help-gnu-emacs

See
https://dataswamp.org/~incal/emacs-init/issn-verify.el
for further (very small) changes...

;;; issn-verify.el --- verify ISSN -*- lexical-binding: t
;;
;;; Commentary:
;;
;; This Elisp package provides functions to verify
;; ISSN by computing their check digits.
;;
;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;; Created: 2020-09-06
;; Keywords: bib, tex
;; License: GPL3+
;; Package-Requires: ((cl-lib "1.0"))
;; URL: https://dataswamp.org/~incal/emacs-init/issn-verify.el
;; Version: 1.1.0
;;
;; Also see:
;;
;;   https://dataswamp.org/~incal/emacs-init/isbn-verify.el
;;
;; To install this package, with this file in
;; a buffer, do:
;;
;;   M-x load-file RET RET
;;
;; International Standard Serial Number:
;;
;;   ISO 3297, 1975
;;
;; format:
;;
;;   The Ring Magazine: ISSN 0035-5410
;;   d_1d_2d_3d_4-d_5d_6d_7c
;;   d_i for i \in [1, 7] is an integer
;;   c, the check digit, is 0..9 or X for 10
;;
;; compute check digit c:
;;
;;     c' = 8d_1*7d_2*6d_3*5d_4*4d_5*3d_6*2d_7 mod 11
;;
;;         { 0        c' = 0
;;     c = {
;;         { 11 - c'    else
;;
;;; Code:

(require 'cl-lib)

(defun issn--get-digits (issn)
  (if (and (= 9 (length issn))
           (zerop (string-match "[[:digit:]]\\{4\\}-[[:digit:]]\\{3\\}[X[:digit:]]" issn)) )
    (let*((issn-lst      (string-to-list issn))
          (dash-pos 4))
      (mapcar (lambda (c) (if (eq ?X c) "X" (- c ?0)))
              (append (cl-subseq issn-lst 0   dash-pos)
                      (cl-subseq issn-lst (1+ dash-pos)) )))
    (error "Malformed ISSN") ))

(defun issn-verify-issn (issn)
  (let*((issn-lst (issn--get-digits issn))
        (c-prop   (car (last issn-lst)))
        (c-w      (cl-loop with cwl = 0
                           for d in issn-lst
                           for w downfrom 8 to 2
                           do (cl-incf cwl (* w d))
                           finally return cwl) )
        (c-prime (mod c-w 11))
        (c       (if (zerop c-prime) 0 (- 11 c-prime) ))
        (c-x     (if (= 10 c) "X" c)) )
    (if (equal c-prop c-x)
        (message "%s (OK)" c-x)
      (message "NOT OK! is %s, should be %s" c-prop c-x) )))

;; Bicycle Quarterly   (issn-verify-issn "1941-8809")  ; 9 (OK)
;; Bicycling           (issn-verify-issn "1651-9744")  ; 4 (OK)
;; Black Belt          (issn-verify-issn "0277-3066")  ; 6 (OK)
;; Filter              (issn-verify-issn "1654-9813")  ; 3 (OK)
;; Linux Pro           (issn-verify-issn "1471-5679")  ; NOT OK! is 9, should be 8
;; National Geographic (issn-verify-issn "2535-41241") ; Malformed ISSN
;; Outside             (issn-verify-issn "0278-433")   ; Malformed ISSN
;; The Economist       (issn-verify-issn "0013-06a4")  ; Malformed ISSN
;; The Ring            (issn-verify-issn "0035x5410")  ; Malformed ISSN

(provide 'issn-verify)
;;; issn-verify.el ends here

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




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

* Re: verify ISSN (issn-verify.el)
  2020-09-11  6:32 ` Emanuel Berg via Emacs development discussions.
@ 2020-09-12  4:04   ` Emanuel Berg via Emacs development discussions.
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg via Emacs development discussions. @ 2020-09-12  4:04 UTC (permalink / raw)
  To: emacs-devel; +Cc: help-gnu-emacs

;;; issn-verify.el --- verify ISSN -*- lexical-binding: t
;;
;;; Commentary:
;;
;; This Elisp package provides functions to verify
;; ISSN by computing their check digits.
;;
;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;; Created: 2020-09-06
;; Keywords: bib, tex
;; License: GPL3+
;; Package-Requires: ((cl-lib "1.0"))
;; URL: https://dataswamp.org/~incal/emacs-init/issn-verify.el
;; Version: 1.0.0
;;
;; Also see:
;;
;;   https://dataswamp.org/~incal/emacs-init/isbn-verify.el
;;
;; To install this package, with this file in
;; a buffer, do:
;;
;;   M-x load-file RET RET
;;
;; International Standard Serial Number:
;;
;;   ISO 3297, 1975
;;
;; format:
;;
;;   The Ring Magazine: ISSN 0035-5410
;;   d_1d_2d_3d_4-d_5d_6d_7c
;;   d_i for i \in [1, 7] is an integer
;;   c, the check digit, is 0..9 or X for 10
;;
;; compute check digit c:
;;
;;     c' = 8d_1*7d_2*6d_3*5d_4*4d_5*3d_6*2d_7 mod 11
;;
;;         { 0        c' = 0
;;     c = {
;;         { 11 - c'    else
;;
;;; Code:

(require 'cl-lib)

(defun issn--get-digits (issn)
  (let ((check-format (string-match "[[:digit:]]\\{4\\}-[[:digit:]]\\{3\\}[X[:digit:]]" issn) ))
    (if (and (= 9 (length issn))
             check-format
             (zerop check-format) )
        (let*((no-dash   (replace-regexp-in-string "-" "" issn))
              (issn-list (string-to-list no-dash))
              (c-prop    (car (last issn-list)))
              (c-prop-x  (if (equal "X" c-prop) c-prop (- c-prop ?0)))
              (7-1st     (butlast issn-list))
              (nums      (mapcar (lambda (c) (- c ?0)) 7-1st)) )
          (append nums `(,c-prop-x)) )
      (error "Malformed ISSN") )))

(defun issn-verify (issn)
  (let*((issn-lst (issn--get-digits issn))
        (c-prop   (car (last issn-lst)))
        (c-w      (cl-loop with cwl = 0
                           for d in issn-lst
                           for w downfrom 8 to 2
                           do (cl-incf cwl (* w d))
                           finally return cwl) )
        (c-prime (mod c-w 11))
        (c       (if (zerop c-prime) 0 (- 11 c-prime) ))
        (c-x     (if (= 10 c) "X" c)) )
    (if (equal c-prop c-x)
        (message "%s (OK)" c-x)
      (message "NOT OK! is %s, should be %s" c-prop c-x) )))

;; Bicycle Quarterly   (issn-verify "1941-8809")  ; 9 (OK)
;; Bicycling           (issn-verify "1651-9744")  ; 4 (OK)
;; Black Belt          (issn-verify "0277-3066")  ; 6 (OK)
;; Filter              (issn-verify "1654-9813")  ; 3 (OK)
;; Linux Pro           (issn-verify "1471-5679")  ; NOT OK! is 9, should be 8
;; National Geographic (issn-verify "2535-41241") ; Malformed ISSN
;; Outside             (issn-verify "0278-433")   ; Malformed ISSN
;; The Economist       (issn-verify "0013-06a4")  ; Malformed ISSN
;; The Ring            (issn-verify "0035x5410")  ; Malformed ISSN

(provide 'issn-verify)
;;; issn-verify.el ends here

-- 
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:[~2020-09-12  4:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-11  3:29 verify ISSN (issn-verify.el) Emanuel Berg via Emacs development discussions.
2020-09-11  4:58 ` 황병희
2020-09-11  5:48   ` Emanuel Berg via Emacs development discussions.
2020-09-11  6:32 ` Emanuel Berg via Emacs development discussions.
2020-09-12  4:04   ` Emanuel Berg via Emacs development discussions.

Code repositories for project(s) associated with this public inbox

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

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).