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

fexprs



The only way to define fexpr's in T is with DEFINE-MACRO.  For details
see Pitman's paper "Special Forms in Lisp" in the proceedings of the
1980 Lisp Conference.

E.g.

	(DEFINE-MACRO (DEFPROP SYMBOL VALUE INDICATOR)
	  `(PUT ',SYMBOL ',INDICATOR ',VALUE))

	(DEFINE-MACRO (OR THIS THAT)
	  `((LAMBDA (P R) (IF P P (R)))
	    ,THIS
	    (LAMBDA () ,THAT)))

	(DEFINE-MACRO (HAIR FOO BAR . BAZ)
	  `(HAIR-AUX ',FOO
		     (LAMBDA () ,BAR)
		     ,@(MAP (LAMBDA (X) `(LAMBDA () ,X))
			    BAZ)))

In these examples, subforms which are to be used as quoted structure
get QUOTE wrapped around them, forms which are to be evaluated
immediately go dorectly into the expansion (like THIS, above), and
forms which aren't to be evaluated immediately get (LAMBDA () ...)
wrapped around them; when the value is needed the closure is called.

The macro definitions themselves (NOT necessarily the forms that they
produce) should be free of side-effects and unaffected by side-effects.
That is, avoid calling things like PRINT and PUT.  They should simply
do source-to-source transformations, nothing more or less.

---- style flame follows ----

In general it is advised that one avoid fexprs/macros entirely
unless there's a very good reason.  ' just isn't that hard to write.
Macros have questionable semantics, and their use can lead to very
difficult-to-understand programs.

And please, avoid using EVAL.  I know of only three places where it's
used correctly (READ-EVAL-PRINT-LOOP, LOAD-INTERPRETED-FILE, and CRAWL).
I'm considering de-releasing it.  Closures always suffice.