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 10:31:36 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Dr Rainer Woitok <rainer.woitok@gmail.com> [2023-01-19 20:39]:
> Sorry, I'm late in this discussion.   And to explain why this has not to
> do with Gods but rather with simple mathematics, I need to know a little
> bit about your  math knowledge.

Thanks, though it is not related to my question.

My question is related to why or how is it useful in Lisp.

Apart from "minimizing error handling in some situation" or "sketching
of programs" or "shortening of macros", can you demonstrate me how it
is useful in Lisp?

Let me demonstrate the vague use that was so far discovered:
------------------------------------------------------------


Example of sketching of program:
--------------------------------

User thinks of list, but does not place it:

(let ((my-factor-1 1)
      (my-factor-2 2)
      (my-factor-3 3)
      (my-factor-4 4))
  (+ (*) (* my-factor-3 my-factor-4 )))

then in the next step user does place the elements:

(let ((my-factor-1 1)
      (my-factor-2 2)
      (my-factor-3 3)
      (my-factor-4 4))
  (+ (* my-factor-1 my-factor-2) (* my-factor-3 my-factor-4 )))

I can't say that above is good usage example, as in fact, programmer
may forget that he wrote (*) and may get result without being warned
that factors are missing.


Example of minimizing errors:
-----------------------------

(setq my-list '())

(apply #'* '(2 3 4)) ➜ 24
(apply #'* my-list) ➜ 1

However, in that case programmer could forget to put something in the
list, and raising of error is more important for empty list or missing
arguments, than just yielding 1.

Minimizing errors means neglecting the function and unexpected
results. Function `apply' and `reduce' can as well take any kind of
functions that require zero or more arguments.

When let us say a list has only single element and I wish to `apply'
addition on such list, then I can just give that single element as
result instead of running function on single list element. So that is
matter of programming style and care.

It does not really answer my question where is (*) useful.


Missing example of macro minimization
-------------------------------------

In that example programmer would write shorter macro when function
does not require 2 factors and somewhat longer where function require
two arguments.


Example of fun with (*)
-----------------------

(defun m (n)
  (let ((m))
  (dotimes (b n)
    (setq m (cons "(*)" m)))
  (concat "(+" (string-join m) ")")))

(let ((first 1))
  (insert "\n")
  (while (<= first 10)
    (let ((second 1))
      (while (<= second 10)
        (insert "(*" (m first)(m second) ")\n")
        (setq second (1+ second)))
      (setq first (1+ first)))))


Other example of fun with (*)
-----------------------------

(+ (*) (*) (*) (*) (*) (*)) ➜ 6


Or maybe function was made for mathematics lovers?
--------------------------------------------------

(*) ➜ 1

Just "because" we love mathematics.


The unanswered question:
------------------------

Do you know the actual practical example in any Lisp which will show
how (*) ➜ 1 is useful?

I do not ask how there are some "laws" outside of Lisp and because of
those laws somebody liked them and included in a function. That sounds
capricious.

To find useful function, we may find which program or function CANNOT
be executed (with slight modification) if I would make multiplication
to require 2 factors?



-- 
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]