# libera/#lisp - IRC Chatlog

Search

11:49:53
jcowan
As for Scheme not being CL-like, it is far more CL-like than most other Lisps: Interlisp, Picolisp, Clojure. All of them are descendants of Lisp 1.5.

12:11:09
mdhughes_
(- 1) is just equivalent to (- 0 1) of course; it could be implemented as fold from 0, same as +

12:36:00
Alfr
mdhughes_, so you still have to decide based upon how many arguments you get, nothing gained. And then whether you say 0-x or additive inverse of x, doesn't really. I like the second one more, but that may be a personal preference.

12:37:34
aeth
Alfr: anything that + and - are defined to work on, since this is #lisp and not #commonlisp or #scheme :-p

12:37:51
aeth
but we are working on something purely symbolic and much more abstract than anything concrete

12:38:17
aeth
perhaps x and y are true real numbers (or at least, the ones that are computable) rather than floats/rationals/integers

12:40:59
aeth
(which is afaik equivalent to (- (+) A) as long as (+) produces a zero matrix the same size as A)

12:41:52
Alfr
aeth, so, you have +, e, +-inverse? And since you certainly want (+ a b c ..) to be unambiguous, you want + to associative. That group gives you a group, I think.

12:45:12
aeth
yes, we want Abstract Lisp's + to work on groups, while / for more than one argument should be restricted to fields

12:45:18
Alfr
aeth, I also think, that you want to be able to write (+ a b (+ c ..) d ..), so + is also closed. (I always forget this one.)

12:57:51
aeth
I suppose (+ ...) and (+) should only be used when - is defined, and otherwise prefer (* ...) and (*) even if it's not a field. Strange cases include matrices, which would have +, *, and even (/ A) defined, but afaik not (/ A B)

13:00:05
Alfr
Assuming you have (/ A) then you also have (/ B A) by (* (/ A) B) (or equivalently (* B (/ A))).

13:00:34
jcowan
mdhughes_: Load SRFI 1 and mess with fold and fold-right; you will quickly find that neither fold nor fold-right implements variadic -.

13:02:51
mdhughes_
aeth: You would not actually use * to implement negation, that's much slower than (- 0 x), even for floats.

13:14:53
mdhughes_
(define (minus . rest) (fold mm (if (null? (cdr rest)) 0 (car rest)) (if (null? (cdr rest)) rest (cdr rest))))

13:16:23
mdhughes_
Makes sense if you're using cons or other things that take the accumulator right, but it's nonsensical in math.

13:23:49
jcowan
(btw, neither left nor right fold, neither accumulator-first nor accumulator-second, will allow you to correctly implement - as a fold)

13:26:05
jcowan
As a result of historical factors, vector-like SRFIs use the accumulator-first style and all other sequence SRFIs use the accumulator-second style.

13:26:48
jcowan
A good approach for Committee C to clean this up, IMAO, is to use the names fold and fold-right for accumulator-second (SRFI 1) style and the names lfold and rfold for accumulator-first style.

13:30:51
jcowan
Nope. Try the four cases for yourself on lists of one, two, and three values. None of them produce the right answer always.

13:40:38
jcowan
sorry, screwed up both pastes: you need to prepend (define a '(1)) and (define (s- x y) (- y x))

13:41:14
jcowan
in any case, your `minus` function does what I said needs to be done: it special-cases the unary version.

13:42:11
jcowan
irritating: -adic fails for "monadic" (you need "unary"), but -ary fails for "variary" (you need "variadic").

14:58:27
sham1
Well, monadic does work. After all, the APL people seem to be just fine using that word. Same with dyadic, triadic and so on.

15:26:55
jcowan
If you speak of "monadic functions" out of context, though, you'll probably get a WHUT.