Re: c macros -- turing complete?
- From: Brian Downing <see-signature@xxxxxxxxx>
- Date: Tue, 31 Oct 2006 02:05:07 -0600
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>
.
- References:
- c macros -- turing complete?
- From: Jimka
- Re: c macros -- turing complete?
- From: Pascal Bourguignon
- c macros -- turing complete?
- Prev by Date: Re: logo design
- Next by Date: Re: Efficiency of arrays in LISP
- Previous by thread: Re: c macros -- turing complete?
- Next by thread: Re: c macros -- turing complete?
- Index(es):
Relevant Pages
|
|