William James
9/3/2015 3:52:00 PM
Wade Humeniuk wrote:
> > So some examples:
> > (subtreefun tree oldsymbol newsymbol1 newsymbol2) ===> Subedtree
> > (subtreefun (1 2 (3 4 5) 6 4) '4 'a 'b) ===> (1 2 (3 a b 5) 6 a b)
> >
> >
> > This function does this substitution but for only one new entry, how
> > would an n new entry function look?
> > (defun sub (tree old new)
> > (cond ((null tree) nil)
> > ((equal tree old) new )
> > ((atom tree) tree)
> > (t (cons (sub (car tree) old new)
> > (sub (cdr tree) old new)))))
> >
>
> (defun subtreefun (tree old &rest new)
> (mapcan (lambda (element)
> (typecase element
> (atom (if (eql element old)
> new
> (list element)))
> (list (list (apply #'subtreefun element old new)))))
> tree))
>
>
Consider this line:
(list (list (apply #'subtreefun element old new)))
It seems that the function "list" is being used twice, but
that is not what is happening.
CL (COBOL-Like) is a truly atrocious language---ugly and
clunky and warty beyond belief.
That's why the sports love it so.
> CL-USER 14 > (subtreefun '(1 2 (3 4 5) 6 4) 4 'a 'b)
> (1 2 (3 A B 5) 6 A B)
>
> CL-USER 15 > (subtreefun '(1 2 (3 4 5) 6 4) 4 'a 'b 'c 'x 's)
> (1 2 (3 A B C X S 5) 6 A B C X S)
Gauche Scheme:
(define (sub-in-tree tree old . new)
(append-map
(^x
(cond ((equal? x old) new)
((pair? x) (list (apply sub-in-tree x old new)))
(else (list x))))
tree))
gosh> (sub-in-tree '(1 2 (3 4 5) 6 4) 4 'a 'b)
(1 2 (3 a b 5) 6 a b)
gosh> (sub-in-tree '(1 2 (3 4 (4) 5) 6 4) 4 'a 'b)
(1 2 (3 a b (a b) 5) 6 a b)
gosh> (sub-in-tree '(1 2 (3 4 5) 6 4) '(3 4 5) 'a 'b)
(1 2 a b 6 4)
--
H]e was prosecuted ... for "denying" the gas chambers and the six million
figure. In July 1998 a Swiss court sentenced him to 15 months imprisonment,
and to pay a large fine, because of his writings. Rather than serve the
sentence, in August 2000 Graf went into exile. In 2001 he married a Russian
historian in Moscow. www.revisionists.com/revisionists/graf.html