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

Re: [spr7631] Defining a Macro

> I hope the formulation of the problem is now clear enough.

No, you're really confused.

> To resume I like to define a function 'build-rhet-axiom' such that the evaluation
> of (build-rhet-axiom 'dog 'snoopi) returns the expression '[dog [snoopi]].

" '[dog [snoopi]] "  is not an expression, so your request makes no sense.

This is like saying you want a C expression like " i = i + 3; "  in lisp.
It makes no sense.

There is a big difference between textual output and a lisp value.

IF you just want output to send to another program, then
 (format stream "~&[~a [~a]]" arg1 arg2)
will work.

IF RHET is a tool in lisp, then either:

(1) it will provide functions to construct what you want or primitives with
    which to do so.
(2) you have to figure out the structure that it is storing them in.
    There may be a special structure print function which produces output in
    the format "[foo [bar]]", but then this isn't strict Common Lisp, but an
    extension defined by your tool.

    If there are reader extensions to allow "[a [b]]" as input,
      then there may not be explicit functions (as mentioned in (1)),
      but only accessible through the reader, so
        (read-from-string "[a [b]]")
      should work.  Talk to the tool authors about this lack of functionality.

      You might also be able to determine what the reader macro is
      doing by quoting the expression.  For example, 
	'`(x ,(+ 2 3))
      usually expands to something implementation dependent (in
      this case constrained by CL semantics to happen at runtime
      since generally the value can only be known then).
      Similarly, see if typing '[a [b]] produces a form, or if the
      expression is constructed at read time.  If the latter, you
      may be able to get farther by looking at the reader function,
      uncompiling or disassembling if necessary.

   If there are no reader extensions,

      >       (defmacro BUILD-MY-EXPRESSION (arg1 arg2)
      >   	`'(rassert [,arg1 [,arg2]]))
      > didn't work; the evaluation of the form (BUILD-MY-EXPRESSION 'test1 'test2) 
      > returned (rassert [,arg1 [,arg2]]) instead of (rassert [test1 [test2]]).
      > It worked as soon as I replace the square brackets by any other alphabetic
      > character.

      then indeed there is nothing special about the bracket
      characters, and the expression makes just as much sense as

	     (defmacro BUILD-MY-EXPRESSION (arg1 arg2)
	       `'(rassert q,arg1 q,arg2zz))

      for any two characters q and z.  In this case, it should
      *not* work, for any such characters, because the symbol
      "arg2zz" will be undefined.

This statement provides the most information:

> ... the evaluation of the form (BUILD-MY-EXPRESSION 'test1 'test2) 
> returned (rassert [,arg1 [,arg2]]) instead of (rassert [test1 [test2]]).

This shows:
  that "[" is a reader extension,
  which works at read time.

Thus, you can do no substitution of symbols for literals.  The only way
around this is indirectly through the reader (see (2) above).
Also, talk to the implementators to find another way to get the desired
run-time functionality.

Todd Kaufmann