• #### bug (Funarg problem) in Gauche (Scheme) ?

From HenHanna@21:1/5 to All on Sun May 19 00:41:09 2024
XPost: comp.lang.scheme, fj.comp.lang.lisp

From the Gauche (Scheme) manual:

(cartesian-product ’((a b c) (0 1)))
⇒ ((a 0) (a 1) (b 0) (b 1) (c 0) (c 1)) ___________________________________________________
The Gauche (Scheme) manual describes
string-count and cartesian-product
as built-in functions, but I couldn't use them and ended up defining
them myself.

(define (cartesian-product x)
(if (null? (cdr x))
(map list (car x))
(apply append
(map (lambda (F)
(map (lambda (R) (cons F R)) (cartesian-product (cdr x))))
(car x)))))

(print (cartesian-product '((0 1))) ) ==> ((0) (1))
(print (cartesian-product '((a b)(0 1))) ) ==> ((a 0) (a 1) (b 0) (b 1))

________________________________________

The above code works fine, but when i rename the variable (F) as (x), i
get the following error, and this must be a bug in Gauche (Scheme).

((0) (1))
*** ERROR: pair required, but got a

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From HenHanna@21:1/5 to HenHanna on Sun May 19 03:37:26 2024
XPost: comp.lang.scheme, fj.comp.lang.lisp

On 5/19/2024 12:41 AM, HenHanna wrote:
From the Gauche (Scheme)  manual:

(cartesian-product ’((a b c) (0 1)))
⇒         ((a 0) (a 1) (b 0) (b 1) (c 0) (c 1))
___________________________________________________
The  Gauche (Scheme)  manual  describes
string-count and cartesian-product
as built-in functions, but I couldn't use them and ended up defining
them myself.

(define (cartesian-product x)
(if (null? (cdr x))
(map list (car x))
(apply append
(map (lambda (F)
(map (lambda (R) (cons F R)) (cartesian-product (cdr x))))
(car x)))))

(print (cartesian-product '((0 1))) )      ==> ((0) (1))
(print (cartesian-product '((a b)(0 1))) ) ==> ((a 0) (a 1) (b 0) (b 1))

________________________________________

The above code works fine, but when i rename the variable (F) as (x), i
get the following error, and this must be a bug in  Gauche (Scheme).