* bug#46750: calc defmath let* behaviour surprising, inconsistent, or wrong
@ 2021-02-24 12:40 Stephan Neuhaus
2021-03-01 13:01 ` Mattias Engdegård
0 siblings, 1 reply; 5+ messages in thread
From: Stephan Neuhaus @ 2021-02-24 12:40 UTC (permalink / raw)
To: 46750
Dear maintainers
I can't seem to understand the calc documentation, or I may have found a
bug. You decide :-)
My system
"GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
of 2019-09-23, modified by Debian"
I'm trying to define a calc function f() for use in org mode. Here is a
minimal example of what I've tried. It's not the same function, but it
exhibits the same behaviour. Put this text in a buffer with org mode:
#+BEGIN_SRC emacs-lisp
(defmath f(x)
(let* ((m x)
(n (+ m 1)))
n))
#+END_SRC
#+RESULTS:
: calcFunc-f
| x | y |
|-----+--------|
| 1.0 | f(1.) |
| 1.5 | f(1.5) |
| 2.0 | f(2.) |
| 2.5 | f(2.5) |
| 3.0 | f(3.) |
| 3.5 | f(3.5) |
| 4.0 | f(4.) |
| 4.5 | f(4.5) |
| 5.0 | f(5.) |
#+TBLFM: $2=f($1)
Evaluating the source block (C-c C-c on END_SRC) defines f()
successfully. Then hitting C-c C-c on the TBLFM line shoud result in the
y column of the table to be filled with the x column, plus 1, which it
doesn't.
If I directly evaluate x + 1, it works:
#+BEGIN_SRC emacs-lisp
(defmath f(x)
(+ x 1))
#+END_SRC
#+RESULTS:
: calcFunc-f
| x | y |
|-----+-----|
| 1.0 | 2. |
| 1.5 | 2.5 |
| 2.0 | 3. |
| 2.5 | 3.5 |
| 3.0 | 4. |
| 3.5 | 4.5 |
| 4.0 | 5. |
| 4.5 | 5.5 |
| 5.0 | 6. |
#+TBLFM: $2=f($1)
It seems to me that the problem is with the let* special form, which
simply doesn't seem to work. let works:
#+BEGIN_SRC emacs-lisp
(defmath f(x)
(let ((n (+ x 2)))
n))
#+END_SRC
#+RESULTS:
: calcFunc-f
| x | y |
|-----+-----|
| 1.0 | 3. |
| 1.5 | 3.5 |
| 2.0 | 4. |
| 2.5 | 4.5 |
| 3.0 | 5. |
| 3.5 | 5.5 |
| 4.0 | 6. |
| 4.5 | 6.5 |
| 5.0 | 7. |
#+TBLFM: $2=f($1)
I couldn't find anything in the documentation that would forbid me from
using let* in the body of a defmath. I also couldn't find anything that
would explain this behaviour. Now I'm not an expert on Lisp, so it's
entirely possible that I've done something stupid, or missed something
in the documentation, but I can't find out what it might be.
Thank you very much for Emacs. After several years of using other
editors, I'm coming back to Emacs and I don't think I'll leave it again.
Well, except maybe for ed(1). Ed is the standard editor.
Cheers
Stephan
PS: I'm following the instructions in the calc manual for filing a bug.
There is no mention of a mailing list or a bug tracker for me to sign up
to, so I'd be grateful if you could answer this email, otherwise I might
miss requests for more information or the announcement of a resolution.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#46750: calc defmath let* behaviour surprising, inconsistent, or wrong
2021-02-24 12:40 bug#46750: calc defmath let* behaviour surprising, inconsistent, or wrong Stephan Neuhaus
@ 2021-03-01 13:01 ` Mattias Engdegård
2021-03-01 20:12 ` Mattias Engdegård
0 siblings, 1 reply; 5+ messages in thread
From: Mattias Engdegård @ 2021-03-01 13:01 UTC (permalink / raw)
To: Stephan Neuhaus; +Cc: 46750
Thank you Stephan, it does indeed look like a bug.
Now I can't tell you when or whether I have the time to look at it further, but to allay your worries I can assure you that your reporting procedure was flawless. You do not need to sign up anywhere and shall receive news about further developments by email.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#46750: calc defmath let* behaviour surprising, inconsistent, or wrong
2021-03-01 13:01 ` Mattias Engdegård
@ 2021-03-01 20:12 ` Mattias Engdegård
[not found] ` <253704f6-80c2-e689-ba4b-8c139fe14e23@zhaw.ch>
0 siblings, 1 reply; 5+ messages in thread
From: Mattias Engdegård @ 2021-03-01 20:12 UTC (permalink / raw)
To: Stephan Neuhaus; +Cc: 46750
> Thank you Stephan, it does indeed look like a bug.
Not one but quite a few. Apart from the incorrect variable scoping in let* that you noticed, the `defmath`-specific forms `for` and `foreach` had the same problem: even the examples in the manual didn't work.
Moreover, `foreach` didn't work at all as specified -- it is supposed to iterate over list elements but only ran over the list tails. As I was writing tests, it turned out that the facility to quote functions as a means to override the substitution of `calcFunc-`-prefixed names didn't work at all.
These have now been fixed on master (08b11a02f49da5ca0e4e58a32fa853df0c5e0214); please tell me if it helped. Given the number of flaws discovered in this part of the code, I wouldn't be surprised if there are more to be found.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-05 10:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 12:40 bug#46750: calc defmath let* behaviour surprising, inconsistent, or wrong Stephan Neuhaus
2021-03-01 13:01 ` Mattias Engdegård
2021-03-01 20:12 ` Mattias Engdegård
[not found] ` <253704f6-80c2-e689-ba4b-8c139fe14e23@zhaw.ch>
[not found] ` <479B7572-1D85-4D56-B3FF-5DFE6E74BC18@acm.org>
2021-03-05 10:49 ` Stephan Neuhaus
2021-03-05 10:58 ` Mattias Engdegård
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).