Hacker News new | ask | show | jobs
by taradinoc 2619 days ago
>Quasiquotation pretty much doesn't need to exist because of the ! sequence "operator" for splicing lists into lists and forms.

Hmm... I guess I don't know everything quasiquoting is used for in Lisp, but in MDL and ZIL, segments don't really solve the problem that quasiquoting does when it comes to writing macros.

That is, I usually want to use macros to generate code according to a template:

  <PRSI? ,FOO>
should become

  <==? ,PRSI ,FOO>
The way to write that macro is to call FORM to build the form:

  <DEFMAC PRSI? (X)
    <FORM ==? ',PRSI .X>>
But if it's a complex block of code, and the blanks I want to fill in are deeply nested, the template quickly becomes unreadable, because every structure turns into a form, and every form turns into a call to FORM.
1 comments

Yeah, it does not completely replace quasiquotation, but in my experience the main things quasiquotation solves are (1) not having to write quote marks in front of every symbol and (2) not having to append lists yourself. MDL handles the first by making atoms self-evaluating (though the flip side is that you have to use , and . everywhere), and the second is handled by sequences. I agree that something like quasiquotation would make FORM construction in macros nicer to look at, though it is pretty nice that sequences work everywhere and not just inside quasiquotations.

As an example, consider the following possible implementation of PROG1 in terms of LET's implicit PROGN. They both evaluate a sequence of forms in order, but the first returns the value of the first form, and PROGN the last:

   (DEFMACRO PROG1 (form1 &REST forms)
      (LET ((temp (GENSYM)))
         `(LET ((,temp ,form1))
             ,@forms
             ,temp)))
A MDL equivalent would be something like (though I admit I'm entirely going off documentation!):

   <DEFMAC PROG1 (form1 "ARGS" forms "AUX" (temp (ATOM "temp")))
     <FORM PROG ((.temp .form1))
        !.forms
        .temp>>
Without quasiquotation, the Lisp example would be (without capitalization this time---in Lisp symbols are auto-capitalized):

   (defmacro prog1 (form1 &rest forms)
      (let ((temp (gensym)))
         (list* 'let (list (list temp form1))
            (append forms (list temp)))))
I chose this example to demonstrate how sequences alleviate the pain of splicing things into the middle of things.

Backtick is not used in MDL, right? And you're somewhat free to extend the MDL used in Zilf, right? You could get the best of both worlds by adding either a PREFORM type or an REBUILD form. For example:

   `< ... >  or   `< ... `>    ->   #PREFORM  ( ... )
or

   `struct   ->   <REBUILD struct>
The semantics would be that a PREFORM would be evaluated like a LIST, but then it would CHTYPE to FORM. Or, a REBUILD is an FSUBR that expects a structure, and it maps EVAL over the elements of that structure.

The macro would look like

   <DEFMAC PROG1 (form1 "ARGS" forms "AUX" (temp (ATOM "temp")))
     `<PROG ((.temp .form1))
        !.forms
        .temp>>
I don't know all the consequences of this change to MDL, though.
Interesting. I did find an implementation of backquoting in MDL, kind of:

https://github.com/PDP-10/muddle/blob/master/mim/development...

It doesn't run on any available MDL implementation, because it's actually for MIM, an even more obscure and undocumented extension of MDL. ZILF implements some parts of MIM, but doesn't implement READ-TABLEs at all, and the format of the table implied by that code is different from what's documented for MDL.