ISBN13 check digit: Difference between revisions

Content added Content deleted
Line 210: Line 210:
In this example, we set a for loop value as it progresses.
In this example, we set a for loop value as it progresses.
<lang langur>val .isbn13checkdigit = f(var .s) {
<lang langur>val .isbn13checkdigit = f(var .s) {
var .odd = true
var .alt = true
matching(re/^[0-9]{13}$/, .s = replace(.s, RE/[\- ]/)) and
matching(re/^[0-9]{13}$/, .s = replace(.s, RE/[\- ]/)) and
for[=0] .d in map(f .c-'0', s2cp .s) { _for += if(.odd: .d; .d x 3); .odd = not .odd } rem 10 == 0
for[=0] .d in map(f .c-'0', s2cp .s) { _for += if(.alt=not .alt: .d x 3; .d) } rem 10 == 0
}
}