Task: Come up with an extension to the C programming language. Provide a clear description of the extension, and a code sample that clearly shows what the extension is intended to do.
Prize: (Winning criteria are not specified.) The winner will have his extension featured in the C11 language standard.
My entry: ... Sorry, I think C is perfect in every way already.
Name:
Anonymous2010-07-18 12:26
>>1 My entry: ... Sorry, I think C is perfect in every way already.
>>11
also, int main(void)
{ int a = 23, b = 19;
printf("%d + %d =\n"
" int: %d\n"
" string: %s\n",
a, b,
__perl($, $$, pop + pop)(a, b),
__perl($, $$, pop + pop)(a, b));
return 0; }
produces the same output.
>>25
That's not a date format, that's a datetime format.
Name:
Anonymous2010-07-18 21:06
My entry:
Meta-C (That name is probably already taken)
A built-in scripting language that runs, effectively, as a precompile step. In otherwords
myfile.metac -> script parser -> myfile.c -> normal C compiler -> etc...
The scripting language might be Perl-like or Python-like, I don't know, but it just needs to be something modern with nice regular expression support.
The script delimiters are /@ and @/.
Example of what you could do:
myfile.metac
#include <stdio.h>
int main(int, char**)
{
/@
# (Assuming perl is the embedded language)
my $n = 5;
foreach my $i (1 .. $n)
{
@/
printf("this line prints /@$n@/ times, this is time number /@$i@/\n");
/@
}
@/
return 0;
}
The script parser would expand that to
myfile.c
#include <stdio.h>
int main(int, char**)
{
printf("this line prints 5 times, this is time number 1\n");
return 0;
}
This is a pretty trivial example but the concept is very powerful. You implement most of C++ manually in this way, since nearly everything C++ adds to C is just compile-time crap. But the bonus would be that you would be in control of how things behave, instead of the C++ compiler.
int main(int, char**)
{
printf("this line prints 5 times, this is time number 1\n");
printf("this line prints 5 times, this is time number 2\n");
printf("this line prints 5 times, this is time number 3\n");
printf("this line prints 5 times, this is time number 4\n");
printf("this line prints 5 times, this is time number 5\n");
>>27
Still doing string substitution in this day and age?
I'd imagine we'd be past that and started doing AST manipulations instead!
Name:
Anonymous2010-07-18 21:21
>>30
You mean like with a heredoc? That's a perl file with C in it. This is a C file with perl in it. Subtle difference, maybe. I like this way better and I think this is more readable. It still looks like C.
Name:
Anonymous2010-07-18 21:37
>>32 It still looks like C.
From a bird's eye view it looks more like PHP. By the way, it's not a "C file" -- at least not yet. How can you say you like it better when you aren't even aware of the endless alternatives?
You mean like with a heredoc?
I was thinking of Inline::C but there are many many other methods. If you want a solution nearly as bad as yours I'm sure there's something to be found in Acme. There are also proper pre-processor tools that do what you suggest although, again, not as badly as you'd prefer.
Name:
Anonymous2010-07-18 21:41
i think it would be cool for c to have python variables like lists and dictonarys also indentatin syntax would be nice :)
Name:
Anonymous2010-07-18 21:41
i think it would be cool for c to have python variables like lists and dictonarys also indentatin syntax would be nice :)
>>33 From a bird's eye view it looks more like PHP.
Yeah, that's actually what gave me the idea.
By the way, it's not a "C file"
Yes it is. The OP's post was about extensions to the C language. If this became an extension, then this is what a C file would look like.
There are also proper pre-processor tools that do what you suggest
Really? Like what? I'm genuinely interested.