opMixin or mixin function templates with convenience operator?

mipri mipri at minimaltype.com
Fri Dec 13 13:53:00 UTC 2019


On Friday, 13 December 2019 at 13:17:24 UTC, Jacob Carlborg wrote:
> Yet again we have an issue that AST macros can solve but Walter 
> and company prefers to have specialized features instead of 
> generic ones.

This is a valid Forth program:

   : rotchar ( c -- c' )
     dup  [char] a [ char m 1+ ] literal within 13 and
     over [char] A [ char M 1+ ] literal within 13 and +
     over [char] n [ char z 1+ ] literal within -13 and +
     over [char] N [ char Z 1+ ] literal within -13 and + + ;

   : rot13 ( -- )
     begin
       begin 0 parse dup while
         2dup bounds do i c@ rotchar i c! loop evaluate
       repeat 2drop
     refill 0= until ;

   .( hello) rot13 fcnpr .( jbeyq)
   pe olr

Output:

   hello world

Once evaluation hits ROT13, subsequent code is only evaluated
after getting rot13'd. So that FCNPR is actually SPACE ,etc.
Through PARSE and REFILL , ROT13 takes over compiling the rest
of the program. You can even do it recursively,

   rot13 .( ebg13 jbeyg) pe
   ebg13 .( rotated all the way back again!) cr

Common Lisp has similar capabilities with the rarely used
reader macros. Yes, even the "programmable programming
language" has features its adherents are loathe to use.

So generic solutions are not that hard to think of, and the
idea of languages where normal user words can participate in
compilation to this degree have been around for a long time.
The problem is that nobody wants to even think about touching
"other people's code" in the resulting family of languages.

I can't deny that you have some legitimate pattern or gripe but
I think the stated bias is fine.



More information about the Digitalmars-d mailing list