#!/usr/bin/env guile -s !# ; * Rick van der Zwet ; * 0433373 ; * Scheme programming assigment 1a ; * Licence: BSD ; * $Id: exercise1a.scm 374 2007-12-10 20:18:45Z rick $ ; replace find and replace (define sub_atom (lambda (atom sub) ;write down replacement else procede to next of the list (cond ((null? sub) atom) ((eq? (caar sub) atom) (cadar sub)) (else (sub_atom atom (cdr sub))) ) ) ) (define substitute (lambda (lijst sub) ;if element a return sub if found else element using adding pair (a ; a) to replace sub (if (list? lijst) ;if list and both head and tail recurse both ;else recurse single (if (null? (cdr lijst)) (list (substitute (car lijst) sub)) (cons (substitute (car lijst) sub) (substitute (cdr lijst) sub)) ) ; try to do the replacement (sub_atom lijst sub) ) ) ) (display (equal? (substitute '((a (b c) d) a (f b)) '((a z) (b y)) ) '((z (y c) d) z (f y)) ) )