emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [PATCH] Add support for tables in Calc src block :var


From: Ihor Radchenko
Subject: Re: [PATCH] Add support for tables in Calc src block :var
Date: Sat, 16 Mar 2024 09:52:48 +0000

Visuwesh <visuweshm@gmail.com> writes:

> Attached patch adds support for passing tables as matrices (or vector)
> to a Calc source block through the :var parameter.  There might be a
> better way to do it than manually construct the data structure expected
> by Calc for a matrix but given that it rarely sees changes in this area,
> it shouldn't be a bother.
> I also added tests for this feature, and other simple tests to ensure
> everything works.  I checked that all the tests passed on my side.

Thanks!
Since you are adding a new feature, may you also add an entry to etc/ORG-NEWS?

> -       (calc-push-list (list (cdr pair)))
> +       (let ((val (cdr pair)))
> +         (calc-push-list
> +          (list (if (listp val)
> +                    (cons 'vec
> +                          (if (null (cdr val))
> +                              (car val)
> +                            (mapcar (lambda (x) (if (listp x) (cons 'vec x) 
> x))
> +                                    val)))
> +                  val))))

It would be nice to add code comments explaining the Calc's internal
format. Ideally, with references to Calc's manual or source code.
Otherwise, this code looks like black magic :)

> +++ b/testing/examples/ob-calc-test.org
> @@ -0,0 +1,57 @@
> +#+TITLE: Tests for ob-calc
> +#+OPTIONS: ^:nil

Thanks a lot for adding many tests!
Would you mind using `org-test-with-temp-text' instead of
`org-test-at-id' as much as possible? Otherwise, looking at tests like

> +(ert-deftest ob-calc/simple-program-mult ()
> +  "Test of simple multiplication."
> +  (org-test-at-id "40e4cd26-fe15-45c0-938b-111e021a5a99"
> +    (org-babel-next-src-block)
> +    (should (equal "2" (org-babel-execute-src-block)))))

it is very difficult to understand what exactly the tests is checking.
`org-test-with-temp-text' would make things a lot more readable as we
would see the calc code being tested right inside the test code.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

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