Re: D-styled data file

2009-04-27 Thread Saaa
Maybe add another keyword to force a full index parse :) 




D-styled data file

2009-04-27 Thread Saaa
I would like to be able to read and write variables which are human 
readable.
It should be as fast as possible and easy to use.

Something like this:

-- file.dat
char[] header = `test header`;

int[6] numbers = [ 1, 2, 3, 4, 5, 6];

// not sure about the array layout yet
// the following layout makes human reading a lot easier if you'd had 
something like float[10][10][10]
// also comments, or any line not starting with a type is ignored
bool[][][] map =
[
[
[true, true],
[false, false],
[false, false]
],
[true, true],
[false, false],
[false, false]
]
]

bool map = bool; // this is ignored to speed up finding a variable

--


--  main.d
module main;

import std.stdio;
import std.file;

void main()
{
char[][] file = read (`file.dat`);

//I'm not sure how this part should work :)
TypeFile file_TF = getTF (file);
// a TypeFile holds known information about the file
// list of : name, type, line number
// It also holds a copy of the file but maybe there can be a less safe 
version
// getTF_unsafe(file);
// which only keeps a reference to the file.


char[] name = file_TF.header; //probably needs a better function name
//parses only the requested variable
//a lot of room for optimizations (indexing until found etc.)

writefln(file_TFnumbers.length); // prints 6
int[] numbers = file_TF.numbers;

numbers[3] = 30;

file_TF.numbers = numbers;
//updates the copy of the char[][]

write(file.dat, file_TF.stringof); // the only keyword
//comments in the original file would be preserved this way
}
--

Any comments, questions or pointers?
Maybe all this is already available?
I would think that the parsing code is already available somewhere.




Re: pyd still usable?

2009-04-27 Thread Jarrett Billingsley
On Mon, Apr 27, 2009 at 11:18 AM, mpt  wrote:
> Which versions of tango+gdc+pyd do I need to get stuff to work? I'd like
> to use D+Python on 32 or 64 bit Linux. I've tried a number of tango/gdc
> bundles and pyd rc/trunk, but there are always compiler and linker errors.
>
> How do you build Tango to a library that can be linked to a dynamic
> library, such as a Python extension?

Unless Kirk has updated it recently, Pyd is still Phobos-only, but the
library-dependent code as far as I know is limited to one module and
something like four functions.


Re: Get the name of a function and the parameters?

2009-04-27 Thread Jarrett Billingsley
On Mon, Apr 27, 2009 at 6:56 AM, Jacob Carlborg  wrote:

> I found that this:
>
> void foo (int x, int y)
> {
> }
>
> void main ()
> {
>    pragma(msg, typeof(&foo).stringof);
> }
>
> gave this result:
>
> void function(int x, int y)
>
> So now I just have to get the names out of there.

Interesting!  I wonder if that changed recently.


pyd still usable?

2009-04-27 Thread mpt
Which versions of tango+gdc+pyd do I need to get stuff to work? I'd like
to use D+Python on 32 or 64 bit Linux. I've tried a number of tango/gdc
bundles and pyd rc/trunk, but there are always compiler and linker errors.

How do you build Tango to a library that can be linked to a dynamic
library, such as a Python extension?



Re: How to check for internet connectivity and download file?

2009-04-27 Thread Tyro[a.c.edwards]

On 4/27/2009 5:14 PM, Unknown W. Brackets wrote:

If you want both HTTP and FTP, it's definitely worth using a library for
it. There are a lot of options, but almost all of them are out of date I
suppose for 2.x...

I've always hated curl, but you might look at how hard it is to get/make
d headers for it. This might work fine for you.


Apparently Kenneth Bogert did some work on curl a while back. cURL 
happens to host it on their site so I'll give it a shot.



HTTP is relatively easy. You can see a sample in
dmd/samples/d/htmlget.d. This isn't exactly a right example, because it
completely ignores Transfer-Encoding, but if you search and replace
HTTP/1.1 with HTTP/1.0, it should be usable although the check for
 is an ugly hack and 100% wrong.


I'll take a look at it. I'm sure there is something there worth learning.


FTP is more work. You have to send and receive commands, so it's slower.
It's also worth maintaining state if you download more than one file
from the same server.

I have a library that does it, but unfortunately it's for 1.x. I'm
planning to update it, but I won't be able to for a little while. I
could explain what you need to do if you want to mess with the socket
stuff...


I'm virtually hopeless when it comes to these things so will happily 
accept assistance in whatever form I can get it. If you are willing to 
explain I will graciously accept the lesson.



But again, it's complicated enough it's not a good idea to do it
yourself imho unless you like reading RFCs (I do, but I'm a strange one.)


Can't say I have much fondness for RFCs but over time that might change. 
As for being a strange one... well I'm as strange as they come so I will 
not be passing judgment anytime soon.



-[Unknown]


Re: Get the name of a function and the parameters?

2009-04-27 Thread Jacob Carlborg

Daniel Keep wrote:


Daniel Keep wrote:

Jacob Carlborg wrote:

Is it possible to get the name of a function and the names of the
function parameters?

I don't believe so, no.

  -- Daniel


I should perhaps qualify, in light of Jarrett's response, that I thought
you meant from inside the function ala __FUNCTION__ or somesuch.

  -- Daniel


Jarrett's solution was exactly what I needed.


Re: Get the name of a function and the parameters?

2009-04-27 Thread Jacob Carlborg

Jarrett Billingsley wrote:

On Sun, Apr 26, 2009 at 12:23 PM, Jacob Carlborg  wrote:

Is it possible to get the name of a function and the names of the function
parameters?


Name of a function?  Yes.

public template NameOfFunc(alias f)
{
version(LDC)
const char[] NameOfFunc = (&f).stringof[1 .. $];
else
const char[] NameOfFunc = (&f).stringof[2 .. $];
}

debug
{
private void _foo_(){}
static assert(NameOfFunc!(_foo_) == "_foo_", "Oh noes, NameOfFunc
needs to be updated.");
}

It has to be used at compile time with an alias of course, but it works.

Name of params?  No, not that I've found.  Sometimes the compiler will
give parameter names of functions declared with tuple parameters in
error messages; I wonder if that could be abused.

Don't you love it?  "Most C++ template features are discovered."  So are D's.


Thanks.

I found that this:

void foo (int x, int y)
{
}

void main ()
{   
pragma(msg, typeof(&foo).stringof);
}

gave this result:

void function(int x, int y)

So now I just have to get the names out of there.


Re: How to check for internet connectivity and download file?

2009-04-27 Thread BLS

Tyro[a.c.edwards] wrote:

I've used Burton Radons' "urllib" in the past to get download files from the 
internet, however the library has atrophied and can no longer be used with DMD v2.029 
(not how long it's been this way because I haven't tried to compile it since 2006).

I'm wondering if someone could point me to an example of how to check for 
internet connectivity and if available download the latest version of a given 
file.

Thanks in advance.
Andrew


What about PING ?
Björn


Re: How to check for internet connectivity and download file?

2009-04-27 Thread Unknown W. Brackets
If you want both HTTP and FTP, it's definitely worth using a library for 
it.  There are a lot of options, but almost all of them are out of date 
I suppose for 2.x...


I've always hated curl, but you might look at how hard it is to get/make 
d headers for it.  This might work fine for you.


HTTP is relatively easy.  You can see a sample in 
dmd/samples/d/htmlget.d.  This isn't exactly a right example, because it 
completely ignores Transfer-Encoding, but if you search and replace 
HTTP/1.1 with HTTP/1.0, it should be usable although the check for 
 is an ugly hack and 100% wrong.


FTP is more work.  You have to send and receive commands, so it's 
slower.  It's also worth maintaining state if you download more than one 
file from the same server.


I have a library that does it, but unfortunately it's for 1.x.  I'm 
planning to update it, but I won't be able to for a little while.  I 
could explain what you need to do if you want to mess with the socket 
stuff...


But again, it's complicated enough it's not a good idea to do it 
yourself imho unless you like reading RFCs (I do, but I'm a strange one.)


-[Unknown]


Tyro[a.c.edwards] wrote:

Unknown W. Brackets Wrote:

Well, checking for internet connectivity is a tricky and 
operating-specific thing.


Would you rather check for connectivity with a specific host?  I gather 
that would be more than appropriate for what you're wanting.


This should do just fine. Afterall it would do no good if I have connectivity 
but cannot reach the intended host.

Are you wanting to download over HTTP, or a different protocol?  If over 
HTTP, there are a ton of libraries that may be useful to you, and 
there's also building your own HTTP request (which is actually pretty 
trivial.)


I'm trying to download over both FTP and HTTP. Not sure if the same process is applicable to both protocols but I'm assuming not. 


If you're using Tango, it has classes in it for these things.


Unfortunately I haven't played with Tango many years now and got away from D1 
as soon D2 forked back in 2007.


-[Unknown]


Tyro[a.c.edwards] wrote:

I've used Burton Radons' "urllib" in the past to get download files from the 
internet, however the library has atrophied and can no longer be used with DMD v2.029 
(not how long it's been this way because I haven't tried to compile it since 2006).

I'm wondering if someone could point me to an example of how to check for 
internet connectivity and if available download the latest version of a given 
file.

Thanks in advance.
Andrew