From b3e94062d6b70534e44e4dea22db44ce9b80ff31 Mon Sep 17 00:00:00 2001
From: Lennart Kramer <lennart.kramer@stud.uni-goettingen.de>
Date: Fri, 24 Feb 2023 15:38:53 +0100
Subject: [PATCH] backport cartesian-product fix for 5.44 maxima version
The redifinition of cartesian-product is incompatible with newer
maxima versions. Since setting the maxima version to an older
version would technically be a breaking change, the fix is
backported to all older versions where maxima 5.44 is used instead.
The changes should also work with older maxima versions.
---
.../maxima/rtest_assessment_simpboth.mac | 2 ++
stack/2021010100/maxima/stack_logic.lisp | 16 ++++++++++------
.../maxima/rtest_assessment_simpboth.mac | 2 ++
stack/2021120900/maxima/stack_logic.lisp | 16 ++++++++++------
.../maxima/rtest_assessment_simpboth.mac | 2 ++
stack/2022060100/maxima/stack_logic.lisp | 16 ++++++++++------
.../maxima/rtest_assessment_simpboth.mac | 2 ++
stack/2022071300/maxima/stack_logic.lisp | 16 ++++++++++------
.../maxima/rtest_assessment_simpboth.mac | 2 ++
stack/2022082900/maxima/stack_logic.lisp | 16 ++++++++++------
.../maxima/rtest_assessment_simpboth.mac | 2 ++
stack/2023010400/maxima/stack_logic.lisp | 16 ++++++++++------
12 files changed, 72 insertions(+), 36 deletions(-)
diff --git a/stack/2021010100/maxima/rtest_assessment_simpboth.mac b/stack/2021010100/maxima/rtest_assessment_simpboth.mac
index 784cb48..0864edc 100644
--- a/stack/2021010100/maxima/rtest_assessment_simpboth.mac
+++ b/stack/2021010100/maxima/rtest_assessment_simpboth.mac
@@ -371,3 +371,5 @@ factorlist(-x^2-5*x+6);
factorlist(x^3-1);
[x-1,x^2+x+1]$
+cartesian_product({1, 2}, {3, 4});
+{[1, 3], [1, 4], [2, 3], [2, 4]}$
diff --git a/stack/2021010100/maxima/stack_logic.lisp b/stack/2021010100/maxima/stack_logic.lisp
index 2a1e162..85b0b52 100644
--- a/stack/2021010100/maxima/stack_logic.lisp
+++ b/stack/2021010100/maxima/stack_logic.lisp
@@ -82,12 +82,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun cartesian-product (l1 l2)
- (if l1
- (append
- (mapcar #'(lambda (e) (cons (car l1) e)) l2)
- (cartesian-product (cdr l1) l2))
- nil))
+; maxima versions >=5.43 have an internal cartesian-product function
+; incompatible with this function, therefore we only define it if
+; previously undefined
+(unless (fboundp 'cartesian-product)
+ (defun cartesian-product (l1 l2)
+ (if l1
+ (append
+ (mapcar #'(lambda (e) (cons (car l1) e)) l2)
+ (cartesian-product (cdr l1) l2))
+ nil)))
(defun replicate (n e)
(if (and (integerp n) (>= n 0))
diff --git a/stack/2021120900/maxima/rtest_assessment_simpboth.mac b/stack/2021120900/maxima/rtest_assessment_simpboth.mac
index 51c5b03..ff1f51b 100644
--- a/stack/2021120900/maxima/rtest_assessment_simpboth.mac
+++ b/stack/2021120900/maxima/rtest_assessment_simpboth.mac
@@ -373,3 +373,5 @@ factorlist(-x^2-5*x+6);
factorlist(x^3-1);
[x-1,x^2+x+1]$
+cartesian_product({1, 2}, {3, 4});
+{[1, 3], [1, 4], [2, 3], [2, 4]}$
diff --git a/stack/2021120900/maxima/stack_logic.lisp b/stack/2021120900/maxima/stack_logic.lisp
index 2a1e162..85b0b52 100644
--- a/stack/2021120900/maxima/stack_logic.lisp
+++ b/stack/2021120900/maxima/stack_logic.lisp
@@ -82,12 +82,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun cartesian-product (l1 l2)
- (if l1
- (append
- (mapcar #'(lambda (e) (cons (car l1) e)) l2)
- (cartesian-product (cdr l1) l2))
- nil))
+; maxima versions >=5.43 have an internal cartesian-product function
+; incompatible with this function, therefore we only define it if
+; previously undefined
+(unless (fboundp 'cartesian-product)
+ (defun cartesian-product (l1 l2)
+ (if l1
+ (append
+ (mapcar #'(lambda (e) (cons (car l1) e)) l2)
+ (cartesian-product (cdr l1) l2))
+ nil)))
(defun replicate (n e)
(if (and (integerp n) (>= n 0))
diff --git a/stack/2022060100/maxima/rtest_assessment_simpboth.mac b/stack/2022060100/maxima/rtest_assessment_simpboth.mac
index 51c5b03..ff1f51b 100644
--- a/stack/2022060100/maxima/rtest_assessment_simpboth.mac
+++ b/stack/2022060100/maxima/rtest_assessment_simpboth.mac
@@ -373,3 +373,5 @@ factorlist(-x^2-5*x+6);
factorlist(x^3-1);
[x-1,x^2+x+1]$
+cartesian_product({1, 2}, {3, 4});
+{[1, 3], [1, 4], [2, 3], [2, 4]}$
diff --git a/stack/2022060100/maxima/stack_logic.lisp b/stack/2022060100/maxima/stack_logic.lisp
index 2a1e162..85b0b52 100644
--- a/stack/2022060100/maxima/stack_logic.lisp
+++ b/stack/2022060100/maxima/stack_logic.lisp
@@ -82,12 +82,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun cartesian-product (l1 l2)
- (if l1
- (append
- (mapcar #'(lambda (e) (cons (car l1) e)) l2)
- (cartesian-product (cdr l1) l2))
- nil))
+; maxima versions >=5.43 have an internal cartesian-product function
+; incompatible with this function, therefore we only define it if
+; previously undefined
+(unless (fboundp 'cartesian-product)
+ (defun cartesian-product (l1 l2)
+ (if l1
+ (append
+ (mapcar #'(lambda (e) (cons (car l1) e)) l2)
+ (cartesian-product (cdr l1) l2))
+ nil)))
(defun replicate (n e)
(if (and (integerp n) (>= n 0))
diff --git a/stack/2022071300/maxima/rtest_assessment_simpboth.mac b/stack/2022071300/maxima/rtest_assessment_simpboth.mac
index 51c5b03..ff1f51b 100644
--- a/stack/2022071300/maxima/rtest_assessment_simpboth.mac
+++ b/stack/2022071300/maxima/rtest_assessment_simpboth.mac
@@ -373,3 +373,5 @@ factorlist(-x^2-5*x+6);
factorlist(x^3-1);
[x-1,x^2+x+1]$
+cartesian_product({1, 2}, {3, 4});
+{[1, 3], [1, 4], [2, 3], [2, 4]}$
diff --git a/stack/2022071300/maxima/stack_logic.lisp b/stack/2022071300/maxima/stack_logic.lisp
index 2a1e162..85b0b52 100644
--- a/stack/2022071300/maxima/stack_logic.lisp
+++ b/stack/2022071300/maxima/stack_logic.lisp
@@ -82,12 +82,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun cartesian-product (l1 l2)
- (if l1
- (append
- (mapcar #'(lambda (e) (cons (car l1) e)) l2)
- (cartesian-product (cdr l1) l2))
- nil))
+; maxima versions >=5.43 have an internal cartesian-product function
+; incompatible with this function, therefore we only define it if
+; previously undefined
+(unless (fboundp 'cartesian-product)
+ (defun cartesian-product (l1 l2)
+ (if l1
+ (append
+ (mapcar #'(lambda (e) (cons (car l1) e)) l2)
+ (cartesian-product (cdr l1) l2))
+ nil)))
(defun replicate (n e)
(if (and (integerp n) (>= n 0))
diff --git a/stack/2022082900/maxima/rtest_assessment_simpboth.mac b/stack/2022082900/maxima/rtest_assessment_simpboth.mac
index 51c5b03..ff1f51b 100644
--- a/stack/2022082900/maxima/rtest_assessment_simpboth.mac
+++ b/stack/2022082900/maxima/rtest_assessment_simpboth.mac
@@ -373,3 +373,5 @@ factorlist(-x^2-5*x+6);
factorlist(x^3-1);
[x-1,x^2+x+1]$
+cartesian_product({1, 2}, {3, 4});
+{[1, 3], [1, 4], [2, 3], [2, 4]}$
diff --git a/stack/2022082900/maxima/stack_logic.lisp b/stack/2022082900/maxima/stack_logic.lisp
index 2a1e162..85b0b52 100644
--- a/stack/2022082900/maxima/stack_logic.lisp
+++ b/stack/2022082900/maxima/stack_logic.lisp
@@ -82,12 +82,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun cartesian-product (l1 l2)
- (if l1
- (append
- (mapcar #'(lambda (e) (cons (car l1) e)) l2)
- (cartesian-product (cdr l1) l2))
- nil))
+; maxima versions >=5.43 have an internal cartesian-product function
+; incompatible with this function, therefore we only define it if
+; previously undefined
+(unless (fboundp 'cartesian-product)
+ (defun cartesian-product (l1 l2)
+ (if l1
+ (append
+ (mapcar #'(lambda (e) (cons (car l1) e)) l2)
+ (cartesian-product (cdr l1) l2))
+ nil)))
(defun replicate (n e)
(if (and (integerp n) (>= n 0))
diff --git a/stack/2023010400/maxima/rtest_assessment_simpboth.mac b/stack/2023010400/maxima/rtest_assessment_simpboth.mac
index 51c5b03..ff1f51b 100644
--- a/stack/2023010400/maxima/rtest_assessment_simpboth.mac
+++ b/stack/2023010400/maxima/rtest_assessment_simpboth.mac
@@ -373,3 +373,5 @@ factorlist(-x^2-5*x+6);
factorlist(x^3-1);
[x-1,x^2+x+1]$
+cartesian_product({1, 2}, {3, 4});
+{[1, 3], [1, 4], [2, 3], [2, 4]}$
diff --git a/stack/2023010400/maxima/stack_logic.lisp b/stack/2023010400/maxima/stack_logic.lisp
index 2a1e162..85b0b52 100644
--- a/stack/2023010400/maxima/stack_logic.lisp
+++ b/stack/2023010400/maxima/stack_logic.lisp
@@ -82,12 +82,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun cartesian-product (l1 l2)
- (if l1
- (append
- (mapcar #'(lambda (e) (cons (car l1) e)) l2)
- (cartesian-product (cdr l1) l2))
- nil))
+; maxima versions >=5.43 have an internal cartesian-product function
+; incompatible with this function, therefore we only define it if
+; previously undefined
+(unless (fboundp 'cartesian-product)
+ (defun cartesian-product (l1 l2)
+ (if l1
+ (append
+ (mapcar #'(lambda (e) (cons (car l1) e)) l2)
+ (cartesian-product (cdr l1) l2))
+ nil)))
(defun replicate (n e)
(if (and (integerp n) (>= n 0))
--
GitLab