Lali Lambda: sum-carry

This is the continuation of simple Lali[0] snippets.

Here is a logical-ternary function for detecting if summing two digits will create a carry-over.

(defun sum-carry (digit digit-with lst)
  (fill
   ((algo digit) 'n)
   ((algo digit-with) 'n)
   ((has digit lst) 'n)
   ((has digit-with lst) 'n)
   ((leq digit-with (mirror digit lst) lst) 't)
   ('f 'f)))
    

Here is an action (of it) at Lali REPL:

lali> (set 'numerals '(+0 +1 +2 +3 +4 +5 +6 +7 +8 +9))
(+0 +1 +2 +3 +4 +5 +6 +7 +8 +9)
lali> (sum-carry +1 () numerals)
n
lali> (sum-carry +1 'a numerals)
n
lali> (sum-carry 'a +8 numerals)
n
lali> (sum-carry +1 +7 numerals)
f
lali> (sum-carry +1 +8 numerals)
f
lali> (sum-carry +1 +9 numerals)
t
    

All of the functions, of this snippet, are from previous Lali Lambda's articles (except and 'and', and 'fill', and 'defun').

[0] git clone http://tilde.club/~keyboardan/git/lali.git

tags: #lali #lalilambda #lambda #sum #carry


keyboardan

gopher://tilde.club/1/~keyboardan/
http://tilde.club/~keyboardan/