Re: using a binary tree container

2011-02-22 Thread Lutger Blijdestijn
Sorry I almost forgot: http://d.puremagic.com/issues/show_bug.cgi?id=5640

The issue with remove is talked about in digitalmars.D and perhaps not 
really specific to RedBlackTree.


Re: Are function pointers compile time constants?

2011-02-22 Thread Kagamin
Simon Wrote:

 You could make function pointers compile time constants if:
 
 You disallow ASR
 You disallow them when compiling to a dll
 You disallow in-lining of any function of which you take the address
 You disallow the linker from rearranging functions
 You disallow the linker from merging duplicate functions.
 You merge the compiler and linker

Interestingly, this data layout is impossible without rearranging:

byte a;
byte[c] b;
byte c;


Re: Read non-UTF8 file

2011-02-22 Thread Nrgyzer
== Auszug aus Stewart Gordon (smjg_1...@yahoo.com)'s Artikel
 What compiler version/platform are you using?  I had to fix some errors 
 before it would
 compile on mine (1.066/2.051 Windows).
 On 19/02/2011 13:42, Nrgyzer wrote:
 snip
  Now... and with writefln(%s, cast(ubyte[]) convertToUTF8(f.readLine())); 
  I get the following:
 
  [195, 131, 164]
  [195, 131, 182]
  [195, 131, 188]
 It took a while for me to make sense of what's going on!
 The expressions (0xC0 | (ch  6)) and (0x80 | (ch  0x3F)) both have type 
 int.  It
 appears that, in D2, if you append an int to a string then it treats the int 
 as a Unicode
 codepoint and automagically converts it to UTF-8.  But why is it doing it on 
 the first
 byte and not the second?  This looks like a bug.
 Casting each UTF-8 byte value to a char
  if (ch  0x80) {
  result ~= cast(char) ch;
  } else {
  result ~= cast(char) (0xC0 | (ch  6));
  result ~= cast(char) (0x80 | (ch  0x3F));
  }
 gives the expected output
 [195, 164]
 [195, 182]
 [195, 188]
 HTH
 Stewart.

I also wondered because I've used the same code in D1 and it worked without any 
problems. Anyway... thanks :)


Re: rdmd problems (OS X Leopard, DMD 2.052)

2011-02-22 Thread Paolo Invernizzi
Hi Magnus,

This is sligthly OT, but... How I loved AnyGui!
It's nice to see you here, in the D bandwagon...

Cheers, 
Paolo Invernizzi

Magnus Lie Hetland Wrote:

 Hi!
 
 When I installed DMD 2.051 on my OS X boxen, the rdmd executable didn't 
 work. I saw others have similar problems online, and concluded that it 
 must have been compiled for a more recent version of OS X (Snow 
 Leopard, I guess) without the necessary compatibility flags.
 
 I found the rdmd sources online [1] and compiled them myself. (Luckily, 
 the other binaries work just fine.) No problems.
 
 Now I'm trying to get DMD 2.052 to work. Same issue with the rdmd 
 executable. I tried to compile the same rdmd.d file with the new 
 compiler/stdlib, but that failed.
 
 $ dmd rdmd.d
 std.contracts has been scheduled for deprecation. Please use 
 std.exception instead.
 std.date and std.dateparse have been scheduled for deprecation. Please 
 use std.datetime instead.
 rdmd.d(34): Error: std.regexp.split at 
 ./../../src/phobos/std/regexp.d(498) conflicts with std.string.split at 
 ./../../src/phobos/std/string.d(69)
 rdmd.d(34): Error: function std.regexp.split (string s, RegExp pattern) 
 is not callable using argument types (string)
 rdmd.d(34): Error: expected 3 function arguments, not 1
 
 I'm sure I can fix this myself -- but I'm guessing there must be a more 
 recent version of the rdmd sources somewhere, assuming that the binary 
 in the distribution was compiled with dmd 2.052...? The version in the 
 trunk at dsource.org seems to be three months old...
 
 For now I just compiled the rdmd.d from dsource.org with dmd 2.051, and 
 use that with dmd 2.052. As rdmd is basically an independent entity, I 
 guess that should work well, but this isn't exactly user-friendly 
 (i.e., having to replace one of the binaries in the distro with one 
 compiled with an older compiler, using sources obtained elsewhere... 
 :-).
 
 Not sure if I'm missing The Way to Do It[tm], or if perhaps I should 
 submit an issue about this?
 
 [1] http://www.digitalmars.com/d/2.0/rdmd.html
 
 -- 
 Magnus Lie Hetland
 http://hetland.org
 



Get n-th

2011-02-22 Thread bearophile
Do you know a much nicer way to take just the n-th item of a lazy range?


import std.stdio, std.array, std.range;
void main() {
auto fib = recurrence!(a[n-1] + a[n-2])(1, 1);
writeln(array(take(fib, 10)).back);
}


In Python I use next(isslice(x, n, n+1)):

 from itertools import islice
 r = (x*x for x in xrange(10)) # lazy
 next(islice(r, 5, 6))
25

Bye,
bearophile


Re: Get n-th

2011-02-22 Thread Jonathan M Davis
On Tuesday 22 February 2011 18:07:46 bearophile wrote:
 Do you know a much nicer way to take just the n-th item of a lazy range?
 
 
 import std.stdio, std.array, std.range;
 void main() {
 auto fib = recurrence!(a[n-1] + a[n-2])(1, 1);
 writeln(array(take(fib, 10)).back);
 }
 
 In Python I use next(isslice(x, n, n+1)):
  from itertools import islice
  r = (x*x for x in xrange(10)) # lazy
  next(islice(r, 5, 6))
 
 25
 
 Bye,
 bearophile

Assuming that it's a forward range rather than an input range:

auto s = range.save;
s.popFrontN(n - 1);
writeln(s.front);

The problem is that you have to process a lazy range before you can get at any 
of its elements, and once you've processed an element, it's no longer in the 
range. So, you pretty much have to save the range and operate on a copy of it. 
At that point, you can remove the elements prior to the one you care about and 
then take the one you care about from the front of the range.

- Jonathan M Davis