help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (*) -> 1


From: Jean Louis
Subject: Re: (*) -> 1
Date: Fri, 20 Jan 2023 11:01:52 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Óscar Fuentes <ofv@wanadoo.es> [2023-01-19 19:53]:
> > That explanation sounds like neglect in programming.
> 
> That's your personal opinion. Quite a few programmers think that not
> using strict strongly-typed, statically-typed languages is
> irresponsible, and see, here we are dicussing Lisp.
> 
> BTW, do you consider support for more than two arguments on + and * also
> a neglect in programming?

That is quite alright because:

2 + 3 + 4 = 
2 * 3 * 4 = 

is just fine and useful for human. People add numbers, multiply
numbers. 

What is also useful is when factor is missing, for debugger to raise
the error.

Multiplication with single argument like here:

(* 4) ➜ 4

Should be prevented by simply resulting with that single argument,
instead of trying to multiply what is not necessary.

(let ((my-random-numbers (make-list (1+ (random 3)) (+ 2 (random 5)))))
  my-random-numbers) ➜ (4 4 4)

;; I do not know how to make better example for `plus' function which
;; require 2 addends
(defun plus (addend-1 addend-2 &rest addends)
  (eval `(+ addend-1 addend-2 ,@addends)))

(plus) -- error
(plus 2) -- error
(plus 2 2) ➜ 4
(plus 2 2 3) ➜ 7

Thus in some complex operation, programmer better test what arguments are given 
to `apply'.

(let ((my-random-numbers (make-list (1+ (random 3)) (+ 2 (random 5)))))
  (prog2 
      (message "List: %s" my-random-numbers)
      (cond ((cadr my-random-numbers) (apply #'plus my-random-numbers))
            ((car my-random-numbers) (car my-random-numbers))
            (t (warn "Did not get 2 factors!"))))) ➜ 6

in cases where radnom number of factors is given to multiplication, it
seem to me better to take care of arguments and not at all `apply' or
`reduce' as that way programmer can hardly find out what was actually
the case. 

The explanation that (*) is made only for programmers to minimize
errors sounds rationalizing.

I believe there is some use of (*) which is probably in some old book
or sources of Lisp in first place.

> > ~$ pil
> > : (*)
> > -> NIL
> > : (+)
> > -> NIL
> > : (apply '* '(2 3))
> > -> 6
> 
> What's the output of
> 
> (apply '* '())
> 
> in PicoLisp?

Emacs
-----

(apply '* '(2 2)) ➜ 4
(apply '* '()) ➜ 1

PicoLisp
--------

(apply '* '(2 2)) ➜ 4
(apply '* '())
-> NIL

That is my natural expectation. I find it useful to have NIL as that
would raise my attention that I have not provided arguments to
multiplication.

> > If you have some reference to that reasoning that (*) is related to
> > `apply' from language designer, let me know.
> 
> I have no such references, nor I need them: it is immediately obvious to
> me.
> 
> BTW, I'll say this for the last time:
> 
> In Elisp, + is not the binary addition operator. It is the summation
> operator (aka Σ) for finite sequences.
> 
> In Elisp, * is not the binary multiplication operator. It is the product
> operator (aka Π) for finite sequences.
> 
> Once you internalize this, things will be clearer.

I understand your statement above as following:

- in Elisp, there is no particular practical use for (*) ➜ 1

- there is theoretical only, and representativ use, as (*) ➜ 1 talks
  about summation for finite sequences


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]