I started thinking about how I'd go about implementing this in Perl.
$locations{road}{actions}{north} = sub {
$_[LOCATION] = $locations{woods};
};
$locations{road}{actions}{woods} = $locations{road}{actions}{north};
It's the lack of anonymous functions in C that's pissing me off. Whoever implemented them in Perl ... THANK YOU!
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - [flyingmoose]
I shouldn't have to say this, but any code, unless otherwise stated, is untested
I agree with you 100%, I love anonymous functions too. I first used them in Javascript actually. After that I fiddled with them in python, then I played with a number of functional langauges which all had similar concepts, and lastly I found perl and it was love at first type.
As for your Zork engine, C has function pointers, but I know they are not the same thing. But LISP can do anonymous functions for sure.
#'(lambda (args) (body))
This construct can then be treated similarly to how you'd use an anonymous function in Perl. You'll have to do the equivalent of closures by stuffing information into the data pointer and then binding it inside the function.
Alternately you can use Inline::Perl in CPR mode and then escape to actual Perl functions written in Perl wherever you want...
Nope. Give me funcp's every time.
Update:Fixed error as per hardburn's reply.
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
. . . bypasses a lot of the benefits of using a strongly-typed language
C is not a strongly-typed langauge. Its type system is only useful for hints to the compiler. There are too many ways to subvert it to be anything more. Further, its type errors are just as likely to be annoyances as they are real problems. Rather, C is statically typed, i.e. its types are determined at compile time. Static != strong.
Perl is more strongly typed than C is. Perl's scalars and lists are very seperate types, and are not so trivial to convert into each other. In fact, it doesn't make sense for there to be a generalized solution for doing list -> scalar.
Try OcaML. There's a real type system.
----
send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.
struct Args
{
int stuff;
int stuff2;
};
Then you can just pass this one struct to all of your functions, and they can all have the same function signature/prototype.
Actually it might be better to make a struct with a type field and a union member that contained all the possible arguments rather than having a potentially huge struct. Then again if you're going to do that just pass the type and a void* and cast appropriately.
struct data {
int type;
union {
int i;
char *c;
} value;
};
int the_function(int argc, struct data *argv)
{
....
}
which gives you a single signature for all of your calls.Not exactly clean, but workable...
Michael
Why not write a perl script to generate all the little C functions and the associated dispatch table initilisation?
> It's the lack of anonymous functions in C that's pissing me off
That can be implemented in C++ though, by pushing the language to its limits. Like in the The Boost Lambda Library.
grey.
perlmonks.org content © perlmonks.org and Anonymous Monk, BrowserUk, BUU, dragonchild, Fletch, grey, Hanamaki, hardburn, mpeppler, stvn, tilly
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03