The following procedure causes an infinite loop:
(define (recursive-display . args)
(if (null? args)
#t
(begin
(display (car args))
(recursive-display (cdr args)))))
I'm still learning about Guile so I'm a bit confused why that's the case.
Use
displayto print the value ofargsand look at the output:Your function
recursive-displayhas a variable number of arguments. When you call something like(recursive-display 1 2 3), all arguments passed to this function are wrapped in the list, so variableargshas a value'(1 2 3).Next, you call
(recursive-display (cdr args)). The same rule applies again- all arguments are wrapped in the list, soargshas now value'((2 3)).In all following iterations,
argshas a value'(()).When you add
apply, it will work as expected: