View previous topic :: View next topic |
Author |
Message |
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Sun Aug 27, 2006 3:55 pm Post subject: August 27th - back (sort of) |
|
|
We got our cable and internet yesterday, so now I'm connected to the world once again. That's the good news. The other good news is that I've been working on some stdlib stuff, and creating/working with the API. It's pretty much a breeze. A lot of the API machinations that you deal with with Lua are because of it being a GC'ed library in a non-GC'ed language, so in order to make sure things don't get accidentally collected, a lot of stuff has to be done through the API. With the MiniD API, about the only time you deal with the API when writing native functions is to get parameters and return results. Just about everything else can be done "directly." The disadvantage right now, of course, is that there's no Pyd-like/luabind-line templated binding system, but that will certainly change.
The bad news is that I start classes this week. Because of that, and because I have an evening class two nights a week and I might be in choir and I'll probably be at the gym three nights a week, I don't know entirely how much free time I'll have to work on MiniD. Hopefully I'll be able to keep on track and work on it here and there, since I should have some free time between classes a couple days. The repo will be a godsend for this kind of stuff - being able to work on it from home and on the go, that is.
So I will update the repo tonight, which will now include a few standard library modules, including string, table, array, and base library functions. Woot. The big problem I'm having right now is figuring out how to iterate through an associative array without making use of foreach. It might involve some nasty non-portable hacks, or making my own hashtable structure. Two things I'd rather not do. |
|
Back to top |
|
|
Gregor
Joined: 05 May 2006 Posts: 72 Location: Portland, OR
|
Posted: Mon Aug 28, 2006 11:28 am Post subject: |
|
|
If I may ask ... why can't you use foreach?
Code: |
import std.stdio;
int main()
{
char[][char[]] a;
a["hi"] = "foo";
for (int i = 0; i < a.keys.length; i++) {
writefln("?s = ?s", a.keys[i], a[a.keys[i]]);
}
return 0;
}
|
(Unless you're not talking about D, but MiniD, in which case ... well, it's your language, isn't it? )
EDIT: PHPBB decided to stick another [/code] on there - I apologize to PHPBB for typing anything myself >_< |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Aug 28, 2006 6:24 pm Post subject: |
|
|
Well, here's the thing: I need to write an iterator function for the MiniD stdlib, so that I can write:
Code: | local t = { foo = "bar", bar = 5 };
foreach(local k, local v; pairs(t))
writefln("t[", k, "] = ", v); |
The problem is that the iterator function has to just keep returning a new value with each successive call. This is very different from how D implements foreach loops, where the body itself becomes a sort of callback, and the container does the actual iterating.
So, in order to make an iterator that doesn't require a D-style foreach loop, I have to do something like the method you suggest, which has the huge disadvantage of having to create a new array to hold all the keys, and then do an AA lookup for each index. By traversing the hashtable directly (either by hacking the internals of D's AA implementation or creating my own implementation that has this functionality), I can do the iteration without creating an array and without really doing any accesses.
I might end up just writing my own hashtable; I made a simple templated one based on the DMD implementation, and with only linear collision linked lists (instead of btrees), it was very nearly as fast as the "native" hashtables. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|