[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

programs writing backquote



    Date: 28 May 85 14:38 PDT
    From: masinter.pa@Xerox.ARPA


    In part of the discussion over nesting depth of backquote, more than one
    person alluded to the possibility that a *program* could write a 3-deep
    nested backquote and that this was generally a good thing.

    However, as far as I can tell, it would be easier for a Snobol program
    to write nested backquotes rather than Lisp, because there is no defined
    S-expression representation of backquotes... the only thing GSSB ( Guy
    Steele's Silver Book) defines is the surface syntax.

    Do I misunderstand? Can someone give a program which creates a Common
    Lisp 3-deep-nested backquote, without resorting to string manipulations?

This doesn't resort to string manipulation, and it produces structure
that is more than 3 deep.  It is quite contrived, but it does satisfy
your requirements.  Just trying to produce this example gave me the
opinion it is hard to write meaningful programs [that write meaningful
programs...] that produce highly nested backquoted structure.

(defun print-using-backquote (exp)
  (pprint (sublis '((list . si:xr-bq-list)
		    (cons . si:xr-bq-cons)
		    (list* . si:xr-bq-list*)
		    (append . si:xr-bq-append))
		  exp)))

(print-using-backquote
  ;; exp starts out being a constructor of an alist.  The data of the
  ;; alist is another alist 
  (do ((exp '(list (list 'a (cons 'ab ab) (cons 'ac ac))
		   (list 'b (cons 'bb bb) (cons 'bc bc))
		   (list 'c (cons 'cb cb) (cons 'cc cc)))
	    (subst exp 'bc exp))
       (count 2 (1- count)))
      ((zerop count) (print-using-backquote exp))))

`((A (AB .,AB) (AC .,AC))
  (B (BB .,BB)
   (`((A (AB .,AB) (AC .,AC))
      (B (BB .,BB)
       (`((A (AB .,AB) (AC .,AC))
          (B (BB .,BB)
           (`((A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC)))
            (A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC))))
          (C (CB .,CB) (CC .,CC)))
        (A (AB .,AB) (AC .,AC))
        (B (BB .,BB)
         (`((A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC)))
          (A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC))))
        (C (CB .,CB) (CC .,CC))))
      (C (CB .,CB) (CC .,CC)))
    (A (AB .,AB) (AC .,AC))
    (B (BB .,BB)
     (`((A (AB .,AB) (AC .,AC))
        (B (BB .,BB)
         (`((A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC)))
          (A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC))))
        (C (CB .,CB) (CC .,CC)))
      (A (AB .,AB) (AC .,AC))
      (B (BB .,BB)
       (`((A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC)))
        (A (AB .,AB) (AC .,AC)) (B (BB .,BB) (BC .,BC)) (C (CB .,CB) (CC .,CC))))
      (C (CB .,CB) (CC .,CC))))
    (C (CB .,CB) (CC .,CC))))
  (C (CB .,CB) (CC .,CC)))