Re: Array slice length confusion

2009-07-09 Thread Tim Matthews

BCS wrote:

Hello Tim,


Anyway I like how you can get a slice of array that is just a view
into the original. If I modify the slice, it modifies the full
original array which can be very useful. If however I modify the
length of the slice which I was doing in an attempt to extend the
view, it becomes it's own array.


[...]


Was this a design choice, bug, undefined behavior, etc...?



you can grab a larger chunk like this


char[] buff1 = something;
char[] buff2 = buff1[10..20];

buff2 = buff2.ptr[0..20];

note this is unsafe and will give you no warnings if you extend past the 
end of buff1;





I know that but I when I said I was trying to extend the view I really 
mean that I was just trying to extend the view. Also depending on what 
news reader you use you should see that it branched off in a particular 
direction to a solution.


Re: Array slice length confusion

2009-07-09 Thread Kagamin
Tim Matthews Wrote:

 I thought a slice would behave slighty different due to some sort of 
 meta data that is a separate area of memory so it doesn't effect D's abi.
 
Current plan is to introduce new type - array - into the language.


Re: D2 using std.proccess.shell

2009-07-09 Thread Lars T. Kyllingstad

Jesse Phillips wrote:

On Tue, 07 Jul 2009 12:04:43 +0200, Lars T. Kyllingstad wrote:


Jesse Phillips wrote:

I don't know if I'm misunderstanding the use of shell() or if this is a
bug. Trying to run some programs with shell error with a could not
close file. Sadly it I can come to any reasonable conclusion as to why.

Example output from running writeln(shell(gcc)) gcc: no input files
std.contracts.ErrnoException: std/stdio.d(336): Could not close file
`gcc' (Success)

Note that the program was executed correctly printing the error
message, and the appended (Success) massage...? Also shell(gcc -v)
works as with proper output and no error.

Similar errors trying to run shell(dmd) unsure if this is related to
the programs not being in /bin.


I think it's a bug in Phobos. Note that you get the exact same result
even if you remove the enclosing writeln(), which means that the
program's standard output stream hasn't been intercepted. Although I'm
unsure about the details, it seems that the std.stdio.File object that
should encapsulate the program's output stream isn't opened correctly,
and thus an exception is thrown when an attempt is made to close it.

Probably you don't get an error for gcc -v because the output of this
command is printed to standard error instead of standard output.

-Lars


Thanks, I try and narrow down when this happens. I first assumed it was 
because running GCC without anything outputs to stderr and not stdout, 
but that wouldn't explain the DMD issue. (ggc -v goes to stdout)



It happens whenever the program you try to run has a nonzero return 
value. I'll file a bug report, if you haven't done it already.


-Lars


Re: Array slice length confusion

2009-07-09 Thread Tim Matthews

Kagamin wrote:

Tim Matthews Wrote:

I thought a slice would behave slighty different due to some sort of 
meta data that is a separate area of memory so it doesn't effect D's abi.



Current plan is to introduce new type - array - into the language.


Do you know the ng posts or where ever that was posted?


Re: Array slice length confusion

2009-07-09 Thread Daniel Keep


Tim Matthews wrote:
 Kagamin wrote:
 Tim Matthews Wrote:

 I thought a slice would behave slighty different due to some sort of
 meta data that is a separate area of memory so it doesn't effect D's
 abi.

 Current plan is to introduce new type - array - into the language.
 
 Do you know the ng posts or where ever that was posted?

Best bet would be to search for T[new].


Regex

2009-07-09 Thread Vladimir Voinkov
std.regex can't be used in compile time function call. It's quite frustrating...


Re: Regex

2009-07-09 Thread BLS

Vladimir Voinkov wrote:

std.regex can't be used in compile time function call. It's quite frustrating...


see dsource.org .. afaik there is a compile time regex project. hth


Re: D2 using std.proccess.shell

2009-07-09 Thread Jesse Phillips
On Thu, 09 Jul 2009 11:20:54 +0200, Lars T. Kyllingstad wrote:

 Jesse Phillips wrote:
 On Tue, 07 Jul 2009 12:04:43 +0200, Lars T. Kyllingstad wrote:
 
 Jesse Phillips wrote:
 I don't know if I'm misunderstanding the use of shell() or if this is
 a bug. Trying to run some programs with shell error with a could not
 close file. Sadly it I can come to any reasonable conclusion as to
 why.

 Example output from running writeln(shell(gcc)) gcc: no input files
 std.contracts.ErrnoException: std/stdio.d(336): Could not close file
 `gcc' (Success)

 Note that the program was executed correctly printing the error
 message, and the appended (Success) massage...? Also shell(gcc -v)
 works as with proper output and no error.

 Similar errors trying to run shell(dmd) unsure if this is related
 to the programs not being in /bin.

 I think it's a bug in Phobos. Note that you get the exact same result
 even if you remove the enclosing writeln(), which means that the
 program's standard output stream hasn't been intercepted. Although I'm
 unsure about the details, it seems that the std.stdio.File object that
 should encapsulate the program's output stream isn't opened correctly,
 and thus an exception is thrown when an attempt is made to close it.

 Probably you don't get an error for gcc -v because the output of
 this command is printed to standard error instead of standard output.

 -Lars
 
 Thanks, I try and narrow down when this happens. I first assumed it was
 because running GCC without anything outputs to stderr and not stdout,
 but that wouldn't explain the DMD issue. (ggc -v goes to stdout)
 
 
 It happens whenever the program you try to run has a nonzero return
 value. I'll file a bug report, if you haven't done it already.
 
 -Lars

Thanks.


Re: Array slice length confusion

2009-07-09 Thread BCS

Hello Tim,


Sorry I misread (lacking sleep).


Been there, done that. :oz




Re: Regex

2009-07-09 Thread Robert Fraser

BLS wrote:

Vladimir Voinkov wrote:
std.regex can't be used in compile time function call. It's quite 
frustrating...


see dsource.org .. afaik there is a compile time regex project. hth


http://www.dsource.org/projects/scregexp

But the generated functions aren't CTFE-compatible AFAIK. A CTFE regex 
engine would be um... tricky to say the least. About 50GB of memory 
tricky (on DMD, LDC has a GC... though, it's still just as slow with 
CTFE). Really, if you need that level of code manipulation, a 
preprocessor is probably a better choice.


mixins

2009-07-09 Thread Ellery Newcomer
From the specs:
It is not an error to have const module variable declarations without
initializers if there is no constructor. This is to support the practice
of having modules serve only as declarations that are not linked in, the
implementation of it will be in another module that is linked in.

How would one actually do this?

Also,

this don't compile:

mixin(gurk());
char[] gurk(){
  return pragma(msg,`hello`);;
}

but this does:

char[] gurk(){
  return pragma(msg,`hello`);;
}
mixin(gurk());

are mixins evaluated in the same pass that builds the symbol table?


pass variable names

2009-07-09 Thread Saaa
Is it possible to get the passed variable name à la:
--
void functio(A...)(ref A a)
{
writefln(typeof(a[0]));
}
int i;
functio(i); // prints i
--
Also how do I fix this:
--
functio(`i`); // Error: i is not an lvalue
-- 




Re: pass variable names

2009-07-09 Thread Saaa
 No.

 You should be able to get the name using an alias:

 void func(alias var)()
 {
writefln(var.stringof);
 }
Can this be combined with the tuple parameter?


 But you can't do it at runtime.

 Also how do I fix this:
 --
 functio(`i`); // Error: i is not an lvalue

 You have to store the literal in a variable.
I needed it to get my function to accept
func( `name_i`, i, `name_ar`, ar, `name_b`, b ..etc..)
only the variables need to be ref.