(define (duple n x) (cond ((= n 0) '()) (else (cons x (duple (- n 1) x))))) ; certification? ; it will be convenient to have a standard form for presenting inductive ; data definitions. ; likely the following (BNF form) is familiar to you from prior courses ; ::= () | (number> . ; another example is the BNF grammar for slists: ; ::= () ; ::= . ; ; ::= | ; some examples: ; we try as much as possible to exploit inductive definitions of data in developing ; programs which manipulate this data. ; for example: ; we want to write a program subst which takes three arguments - ; the symbols new and old, and an s-list, slist. All elements ; of slist are examined, and a new list is returned that is similar ; to slist but with all occurrences of old replaced by instances ; of new ; some examples: (define subst (lambda (new old slist) (if (null? slist) '() (cons (subst-in-symbol-expression new old (car slist)) (subst new old (cdr slist)))))) (define subst-in-symbol-expression (lambda (new old se) (if (symbol? se) (if (eq? se old) new se) (subst new old se)))) ; As you can see, the program doesn't work on the list containing numbers. ; If you dig deeper, you can find that is because that the scheme distinguish ; the numbers from symbols. ; Homework ; Change the subst program to make it work even there are some numbers in the ; list ;