Re: c macros -- turing complete?



In article <87slh7gk9n.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxx>,
Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx> wrote:
You can do loops including the current file,

You can do loops even without including the current file:

#include "order/interpreter.h"

ORDER_PP
(8let((8B, 8fn(8N,
8cond((8greater(8N, 1),
8separate(8N, 8quote(bottles)))
(8equal(8N, 1),
8quote(1 bottle))
(8else,
8quote(no more bottles))))),
8for_each_in_range
(8fn(8N,
8print(8ap(8B, 8N) (of beer on the wall,) 8space
8ap(8B, 8N) (of beer,) 8space
(take one down, pass it around,) 8space
8ap(8B, 8dec(8N)) (of beer on the wall.))),
100, 1)))

That is a valid preprocessor program that emits tokens printing the
lyrics to "99 bottles of beer on the wall", on one line of course.

It is written in the "Order" preprocessor language. From the
documentation:

Order is a complete programming language designed to be interpreted
using the C preprocessor. Rather than being a general purpose
language, Order is a metalanguage that can be used to generate
sequences of preprocessing tokens.

Order is a high-level functional language with call-by-value
semantics, providing first-class anonymous functions with lexically
scoped variables and supporting partial application of functions. The
Order interpreter is implemented in continuation passing style
and is fully tail recursive. Order is a reflective language
providing first class continuations, first class environments and an
eval-function. Memory management in Order is implicit. Order provides
arbitrary-precision arithmetic on natural numbers, a comprehensive
set of primitive and higher-order functions for an aggregate data
type called sequence and more.

For more, start at the (well-documented) 99 bottles example at:

http://chaos-pp.cvs.sourceforge.net/chaos-pp/order-pp/example/bottles.c?revision=1.10&view=markup

A far more pleasant language for "metaprogramming" than C++ templates
if I do say so myself.

Now back to your regularly scheduled Lisp where we don't have to worry
about crap like this. :-)

-bcd
--
*** Brian Downing <bdowning at lavos dot net>
.



Relevant Pages

  • Re: Cpp Considered Harmful
    ... > One is to present the 'raw' interface of the template to the user. ... easier than they can parse the underlying language itself. ... resulting from the preprocessor, it merely has to preprocess it. ... > Using JBuilder, and the Java counterpart, I can fly through XML ...
    (comp.lang.cpp)
  • Re: Cpp Considered Harmful
    ... ordering, template declaration instantiation, etc.. ... I think you have a serious misunderstanding of the preprocessor. ... Parsing Java is quite a bit simpler than parsing C++. ... >> source code much easier than they can parse the underlying language ...
    (comp.lang.cpp)
  • Re: Cpp Considered Harmful
    ... That is why assertions are preproccessed away in production code. ... What I've seen done with Java IDEs has shown me that they can ... In C++, because of the preprocessor, you cannot really be sure that what ... that you apparently want to enforce coding policy by language design. ...
    (comp.lang.cpp)
  • Re: Ive seen things you people wouldnt believe...
    ... even if they aren't fluent in the language. ... Wine bottles not labeled in English? ...
    (rec.arts.sf.fandom)
  • Re: Boost Workshop at OOPSLA 2004
    ... There is only one replacement for the c++ preprocessor which I would ... the near future: metacode. ... By this I mean the capability to walk the parse tree at compile time ... proposal but a full language extension). ...
    (comp.lang.cpp)