Hacker News new | ask | show | jobs
by kmill 2621 days ago
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.
1 comments

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.