GNU bug report logs - #46750
calc defmath let* behaviour surprising, inconsistent, or wrong

Previous Next

Package: emacs;

Reported by: Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>

Date: Wed, 24 Feb 2021 13:19:03 UTC

Severity: normal

Done: Mattias Engdegård <mattiase <at> acm.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 46750 in the body.
You can then email your comments to 46750 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#46750; Package emacs. (Wed, 24 Feb 2021 13:19:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 24 Feb 2021 13:19:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>
To: bug-gnu-emacs <at> gnu.org
Subject: calc defmath let* behaviour surprising, inconsistent, or wrong
Date: Wed, 24 Feb 2021 13:40:50 +0100
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#46750; Package emacs. (Mon, 01 Mar 2021 13:02:02 GMT) Full text and rfc822 format available.

Message #8 received at 46750 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>
Cc: 46750 <at> debbugs.gnu.org
Subject: bug#46750: calc defmath let* behaviour surprising, inconsistent, or
 wrong
Date: Mon, 1 Mar 2021 14:01:33 +0100
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.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#46750; Package emacs. (Mon, 01 Mar 2021 20:14:01 GMT) Full text and rfc822 format available.

Message #11 received at 46750 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>
Cc: 46750 <at> debbugs.gnu.org
Subject: Re: bug#46750: calc defmath let* behaviour surprising, inconsistent, 
 or wrong
Date: Mon, 1 Mar 2021 21:12:44 +0100
> 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.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#46750; Package emacs. (Fri, 05 Mar 2021 10:50:01 GMT) Full text and rfc822 format available.

Message #14 received at 46750 <at> debbugs.gnu.org (full text, mbox):

From: Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>
To: Mattias Engdegård <mattiase <at> acm.org>,
 46750 <at> debbugs.gnu.org
Subject: Re: bug#46750: calc defmath let* behaviour surprising, inconsistent, 
 or wrong
Date: Fri, 5 Mar 2021 11:49:44 +0100
Hi Mattias

I can confirm that the calc that's in the current master branch 
(development version for 28.1) fixes my problem. You hinted that there 
were further problems too, but I have only checked that let* now seems 
to work as intended. Also, to be fair, I have checked that only for my 
own use case.

That was speedy work, thank you very much! Now I'll have to decide 
whether to build emacs for Debian myself or whether to wait for Debian 
to adopt emacs >= 28.1.

Cheers

Stephan

On 3/5/21 10:32 AM, Mattias Engdegård wrote:
> 5 mars 2021 kl. 08.57 skrev Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>:
> 
>> My Emacs installation is a mix of standard Debian Emacs and MELPA packages. I have no idea how to install a specific commit of calc, and I don't even know where to find the repo. Could you help me out?
>>
>>   * Where do I find the repo? (Once I have that, I know how to check out a specific commit.)
>>   * What do I have to put into my .emacs to use the calc that's in the directory?
> 
> Ah, you are using Emacs 26.1. The fix has been made in the development version of Emacs, that is to become version 28.1. Instead of trying to combine pieces from different versions it is probably better to build the latest version:
> 
>   git clone -b master git://git.sv.gnu.org/emacs.git
>   cd emacs
> 
> and here you would ideally take a pause reading the build and installation instructions in the source tree, but most likely you would continue with:
> 
>   ./autogen.sh
>   ./configure
>   make
> 
> assuming you have everything needed. You can then run the built emacs without installing (it's in the src/ directory) if you just want to test it.
> 
> Maybe Debian has special provisions for doing this in a cleaner way but I'm no Debian specialist.
> 




Reply sent to Mattias Engdegård <mattiase <at> acm.org>:
You have taken responsibility. (Fri, 05 Mar 2021 10:59:02 GMT) Full text and rfc822 format available.

Notification sent to Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>:
bug acknowledged by developer. (Fri, 05 Mar 2021 10:59:02 GMT) Full text and rfc822 format available.

Message #19 received at 46750-done <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>
Cc: 46750-done <at> debbugs.gnu.org
Subject: Re: bug#46750: calc defmath let* behaviour surprising, inconsistent, 
 or wrong
Date: Fri, 5 Mar 2021 11:58:15 +0100
5 mars 2021 kl. 11.49 skrev Stephan Neuhaus <stephan.neuhaus <at> zhaw.ch>:

> I can confirm that the calc that's in the current master branch (development version for 28.1) fixes my problem. You hinted that there were further problems too, but I have only checked that let* now seems to work as intended. Also, to be fair, I have checked that only for my own use case.

Thanks for checking! Marking the bug as closed then.

> Now I'll have to decide whether to build emacs for Debian myself or whether to wait for Debian to adopt emacs >= 28.1.

Well, Emacs release cycles are not known for their brisk pacing; you would have to wait for quite a while. (And obviously, we don't mind more people testing the development versions!)





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 02 Apr 2021 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 17 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.