# Re: doubling list elements at every level using recursion

On Apr 14, 1:22 pm, pereges <Brol...@xxxxxxxxx> wrote:
Hi, I'm working on this particular problem in my text:

Define a recursive function double that takes a list in which all
atoms are numbers.  The function doubles all numbers at every level in
the list.

G'day. Thought you might like a newLISP response.

(define (double (x))
(if (list? x) (map double x) (if (not (nil? x)) (* x 2))))

(double nil)
(double 3)
(double '(1 2 3))
(double ' (1 (2 3) ((4) (5 6 (7)))))

outputs:

nil
6
(2 4 6)
(2 (4 6) ((8) (10 12 (14))))

Kind regards,
Bruce.
.

## Relevant Pages

• Re: doubling list elements at every level using recursion
... Define a recursive function double that takes a list in which all ... atoms are numbers. ... The function doubles all numbers at every level in ... (defun double (lst) ...
(comp.lang.lisp)
• doubling list elements at every level using recursion
... Define a recursive function double that takes a list in which all ... atoms are numbers. ... (defun double (lst) ... > (double NIL) ...
(comp.lang.lisp)
• recursion
... i'm trying to write this recursive function but i can't manage to get what i need. ... But as now it always returns NIL. ... (defun foo (n) ... (cond ((= n 0) ...
(comp.lang.lisp)
• Re: A question about recursive programming
... recursive function. ... case values.size when 0 nil when 1 valueselse max_helperend end ... The max of a list containing more than one element is the greater of the first element and the max of the rest of the list. ... Regards, ...
(comp.lang.ruby)