How to use -H?

2011-09-03 Thread Sean Eskapp
I'm trying to create import libraries for use in other projects, using the -H
flag, but dmd is still trying to create an executable. How do I specify that
all I want are the interface files?


Re: How to use -H?

2011-09-03 Thread Sean Eskapp
== Quote from David Nadlinger (s...@klickverbot.at)'s article
 On 9/3/11 8:17 PM, Sean Eskapp wrote:
  I'm trying to create import libraries for use in other projects, using the 
  -H
  flag, but dmd is still trying to create an executable. How do I specify that
  all I want are the interface files?
 Does -o- work as you want?
 David

Yes, it does! Turns out the linker errors I was getting were due to Code::Blocks
being bad at D.


Re: Public imports with D interface files?

2011-09-03 Thread Sean Eskapp
I wasn't including it on the command line; I thought I didn't need to. That 
fixed
it, thanks!

== Quote from David Nadlinger (s...@klickverbot.at)'s article
 Are you specifying std_ext/typetuple.di or whatever it is called when
 compiling the main module? The public import probably triggers creation
 of a module constructor as it really creates aliases for the symbols
 from the imported module.
 David
 On 9/4/11 3:17 AM, Sean Eskapp wrote:
  I'm compiling a very simple D interface file:
 
   module std_ext.typetuple;
 
   public import std.typetuple
 
   class TypeArray(T...)
   {
   }
 
  Compiling it as such:
   dmd -debug -unittest -D -Dddocs -w -H -o- std_ext/typetuple.d
 
  And including it as such:
 
   import std_ext.typetuple;
 
   void main()
   {
   TypeArray!(int, double) blah;
   }
 
  I get a linker error Symbol Undefined _D7std_ext9typetuple12__ModuleInfoZ
 
  Removing the public import removes this error. How can I fix this?



Is integer overflow defined?

2011-09-01 Thread Sean Eskapp
Is integer overflow defined (for instance, as being mod 2^size)? Can I
reliably say that -long.min == 0L?


Re: Is integer overflow defined?

2011-09-01 Thread Sean Eskapp
== Quote from Timon Gehr (timon.g...@gmx.ch)'s article
 On 09/01/2011 06:20 PM, Sean Eskapp wrote:
  Is integer overflow defined (for instance, as being mod 2^size)?
 I am quite sure that all operations are defined as operations on two's
 complement integers, which would mean overflow is defined, but I cannot
 find the respective part of the specification...
   Can I reliably say that -long.min == 0L?
 Well no, -long.min == long.min .
 according to TDPL p53., that fact is defined. (unary minus: -x == ~x+1)

Ah, good points, thanks!


struct opEquals does not work with parameter of same type - bug or feature?

2011-08-29 Thread Sean Eskapp
I am trying to build a struct with equality testing, using this code:

struct Foo
{
const bool opEquals(Foo f)
{
return true;
}
}

This gives me the error that the parameter should be of type ref const Foo.
Fine.

struct Foo
{
const bool opEquals(ref const Foo f)
{
return true;
}
}

This, however, does not work with code like:

Foo bar()
{
return Foo();
}

assert(Foo() == bar());

function Foo.opEquals(ref const const(Foo) f) const is not callable using
argument types (Foo) and bar() is not an lvalue.

How can I do this?


Re: struct opEquals does not work with parameter of same type - bug or feature?

2011-08-29 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Monday, August 29, 2011 22:41:26 Sean Eskapp wrote:
  I am trying to build a struct with equality testing, using this code:
 
  struct Foo
  {
  const bool opEquals(Foo f)
  {
  return true;
  }
  }
 
  This gives me the error that the parameter should be of type ref const
  Foo. Fine.
 
  struct Foo
  {
  const bool opEquals(ref const Foo f)
  {
  return true;
  }
  }
 
  This, however, does not work with code like:
 
  Foo bar()
  {
  return Foo();
  }
 
  assert(Foo() == bar());
 
  function Foo.opEquals(ref const const(Foo) f) const is not callable using
  argument types (Foo) and bar() is not an lvalue.
 
  How can I do this?
 http://d.puremagic.com/issues/show_bug.cgi?id=3659
 http://stackoverflow.com/questions/6986175/const-ref-and-rvalue-in-d
 - Jonathan M Davis

Ah, thanks!


Re: Why aren't function attributes inferred?

2011-08-20 Thread Sean Eskapp
== Quote from Timon Gehr (timon.g...@gmx.ch)'s article
 On 08/20/2011 06:50 PM, Sean Eskapp wrote:
  Since the compiler can clearly tell when a function is not const, safe, 
  pure,
  or nothrow, why can't they just be assumed, unless proven otherwise?
 This sort of inference is already done for function/delegate literals
 and template functions.
 It is not done for other functions, because eg. their code is not
 necessarily available.
 int foo(int x) pure; // how would you infer purity here?
 Also, if normal functions would infer those attributes, they would be
 leaking implementation details all over the place. If a pure
 implementation would have to be changed to a non-pure one, all code that
 relied on the undocumented but inferred purity would break.

I understand your point about functions with no definition, but your point about
normal functions holds true anyway. If I have a pure function foo(), and a
function bar() which relies on the purity of foo(), then changing the purity of
foo() would break bar()'s internals. Either way, purity should still be inferred
at optimization time, where it could really make a difference!


Re: Regarding nothrow and @safe

2011-08-20 Thread Sean Eskapp
== Quote from Timon Gehr (timon.g...@gmx.ch)'s article
 On 08/20/2011 08:18 PM, Sean Eskapp wrote:
  bearophile:
  As far as I know they have decided to make memory overflow errors, so they 
  are
  not exceptions, you can't catch them. Other people will confirm this or not.
 
  In this case, how would you go about handling out-of-memory situations? A 
  systems
  programming language should certainly give the programmer the option to 
  deal with
  this.
 You can catch errors, if you want to deal with them.

Oops, right. In my mind, exceptions are still anything which can be thrown or
caught. I need to remember that it has a more specific meaning in D.


Foreach over tuple of arrays?

2011-08-07 Thread Sean Eskapp
I have a tuple of arrays of different types, but want to call a template
function on each element. How would I do this?

void foo(T)(T elem)
{
...
}

I tried like this:

ArrayTuple!(T) data;
void iterate(alias func, uint n)()
{
static if(n  T.length)
{
foreach(elem; data[n])
func(elem);

iterate!(func, n + 1)();
}
}

Used like this:

iterate!(foo, 0)();

This doesn't work when passing a delegate as func, however. Is there a way to
circumvent this?


Template struct literals should infer template parameters

2011-08-06 Thread Sean Eskapp
If I have something like

struct S(T)
{
T data;
}


I can't make a struct literal with

int mystuff;
someFunc(S(mystuff));

I have to use

int mystuff;
someFunc(S!(int)(mystuff));

Why is this?


Compiling 64-bit code under Windows 7?

2011-05-30 Thread Sean Eskapp
I'm trying to compile a very simple file, main.d:

void main()
{
}

Under Windows 7, 64-bit, with out-of-the-box DMD v2.053 installation. I get
this, however:

C:\Users\Me\devl\testdmd -m64 main.d
Internal error: msc.c 268


64-bit two-step compilation on Ubuntu?

2011-04-25 Thread Sean Eskapp
I'm trying to get a D2 project to build on Ubuntu through Code::Blocks.
Unfortunately, Code::Blocks doesn't allow the simple one-step compilation that
is default with dmd, so it does compiling and linking in two separate steps.
Unfortunately, this is causing some linker errors, the main one being:

/usr/bin/ld: i386 architecture of input file `obj/Debug/main.o' is
incompatible with i386:x86-64 output

I've tried passing -melf_x86_64 to the linker, and that doesn't change
anything. I'm also trying to pass -m64 to the compilation step, and it doesn't
work. Help?


Re: 64-bit two-step compilation on Ubuntu?

2011-04-25 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
  I'm trying to get a D2 project to build on Ubuntu through Code::Blocks.
  Unfortunately, Code::Blocks doesn't allow the simple one-step compilation
  that is default with dmd, so it does compiling and linking in two separate
  steps. Unfortunately, this is causing some linker errors, the main one
  being:
 
  /usr/bin/ld: i386 architecture of input file `obj/Debug/main.o' is
  incompatible with i386:x86-64 output
 
  I've tried passing -melf_x86_64 to the linker, and that doesn't change
  anything. I'm also trying to pass -m64 to the compilation step, and it
  doesn't work. Help?
 First thing I'd try would be to use dmd as the linker.
 dmd compiles in 32-bit by default. Assuming that you're using dmd 2.052, then
 you can use -m64 to tell it to compile for 64-bit, at which point linking with
 gcc should work. Otherwise, you'd need to pass -m32 to gcc when linking
 (unless you're using ld directly (at which point, I don't know what you do),
 and I'm not aware of anyone doing that - dmd doesn't). Regardless, if you're
 linking separately and not using dmd for the linking step, then you need to
 look at dmd.conf and make sure that you include the linker flags that it does,
 or your code may not work.
 In any case, my best suggestion if you can't compile and link in one step
 would be to just use dmd for both.
 - Jonathan M Davis

How do I use dmd as the linker separately from using it as the compiler?

As you can see in my original post, I'm passing -m64 to DMD, but it doesn't 
seem to be picking it up..


Re: 64-bit two-step compilation on Ubuntu?

2011-04-25 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
  == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 
I'm trying to get a D2 project to build on Ubuntu through Code::Blocks.
Unfortunately, Code::Blocks doesn't allow the simple one-step
compilation that is default with dmd, so it does compiling and linking
in two separate steps. Unfortunately, this is causing some linker
errors, the main one being:
   
/usr/bin/ld: i386 architecture of input file `obj/Debug/main.o' is
incompatible with i386:x86-64 output
   
I've tried passing -melf_x86_64 to the linker, and that doesn't change
anything. I'm also trying to pass -m64 to the compilation step, and it
doesn't work. Help?
  
   First thing I'd try would be to use dmd as the linker.
   dmd compiles in 32-bit by default. Assuming that you're using dmd 2.052,
   then you can use -m64 to tell it to compile for 64-bit, at which point
   linking with gcc should work. Otherwise, you'd need to pass -m32 to gcc
   when linking (unless you're using ld directly (at which point, I don't
   know what you do), and I'm not aware of anyone doing that - dmd
   doesn't). Regardless, if you're linking separately and not using dmd for
   the linking step, then you need to look at dmd.conf and make sure that
   you include the linker flags that it does, or your code may not work.
   In any case, my best suggestion if you can't compile and link in one step
   would be to just use dmd for both.
   - Jonathan M Davis
 
  How do I use dmd as the linker separately from using it as the compiler?
 
  As you can see in my original post, I'm passing -m64 to DMD, but it doesn't
  seem to be picking it up..
 If you pass -c to dmd, it won't link, but will just produce .o files.
 Otherwise, it'll link the .o files and produce a binary. If you're doing 2
 step compilation, then you must be passing -c to dmd for the first step. So,
 for the second step, just give it the .o files instead of the .d files and
 don't pass it -c.
 As for -m64, if you have a version of dmd prior to 2.052, then it only does
 32-bit compilation. If you have 2.052, then it should accept -m64 and produce
 64-bit .o files, and produce a 64-bit binary when when not using -c. If that
 doesn't work, then it needs to be reported in bugzilla.
 - Jonathan M Davis

I reinstalled dmd, changed up my compiler flags from global and 
project-specific to just project specific in Code::Blocks, and removed the 
unnecessary -
melf_x86_64 linker flag, and it seems to have started working. Thanks!


Get single keystroke?

2011-03-21 Thread Sean Eskapp
Is there a way to get a single keystroke in D2? Any method I've tried requires
pushing Enter before the stroke is registered.


Re: Get single keystroke?

2011-03-21 Thread Sean Eskapp
== Quote from Andrej Mitrovic (andrej.mitrov...@gmail.com)'s article
 Here's something simpler:
 import std.stdio : writefln;
 extern(C) int kbhit();
 extern(C) int getch();
 void main()
 {
 while(!kbhit())
 {
 // keep polling
 // might use thread.sleep here.
 }
 writefln(Key hit was %s., getch());
 }

What extra linker dependencies does this add?


Re: Get single keystroke?

2011-03-21 Thread Sean Eskapp
== Quote from Andrej Mitrovic (andrej.mitrov...@gmail.com)'s article
 I believe I've found you a solution:
 import std.c.stdio;
 import std.c.linux.termios;
 extern(C) void cfmakeraw(termios *termios_p);
 void main() {
 termios  ostate; /* saved tty state */
 termios  nstate; /* values for editor mode */
 // Open stdin in raw mode
 /* Adjust output channel*/
 tcgetattr(1, ostate);   /* save old state */
 tcgetattr(1, nstate);   /* get base of new
state */
 cfmakeraw(nstate);
 tcsetattr(1, TCSADRAIN, nstate);  /* set mode */
// Read characters in raw mode
 writefln(The key hit is %s, cast(char)fgetc(stdin));
 // Close
 tcsetattr(1, TCSADRAIN, ostate);   // return to original mode
 }
 I've tested this under Ubuntu and DMD 2.052 and it works.

Great, thanks!


Re: DMD2 - compiling and linking in separate steps (64-bit)

2011-03-19 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Friday 18 March 2011 20:49:58 Sean Eskapp wrote:
  incompatible /usr/lib/../lib/librt.so when searching
  for -lrt
  /usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.a when searching
  for -lrt
  /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
  gnu/4.4.5/../../../librt.so when searching for -lrt
  /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
  gnu/4.4.5/../../../librt.a when searching for -lrt
  /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
  gnu/4.4.5/../../../../lib/libc.so
 Look at dmd.conf. It includes several flags which are supposed to be passed to
 the linker - either that or you can use dmd to link rather than using gcc on 
 its
 own. Personally, I wouldn't bother compiling and linking as separate steps, 
 but
 if you do, you need to make sure that you either use the flags in dmd.conf or 
 you
 link with dmd rather than gcc. For the most part, there's no reason to link 
 with
 gcc, even if you want to link separately.
 - Jonathan M Davis

Hmm.. after linking with all the options in dmd.conf (-L/usr/lib32 -L/usr/lib64 
--no-warn-search-mismatch --export-dynamic -lrt), I still get

/usr/bin/ld: skipping incompatible 
/home/me/devl/sfml2/bindings/d/lib/libdsfml-system.a when searching for 
-ldsfml-system
/usr/bin/ld: cannot find -ldsfml-system
/usr/bin/ld: skipping incompatible 
/home/me/devl/sfml2/bindings/d/lib/libdsfml-graphics.a when searching for 
-ldsfml-graphics
/usr/bin/ld: cannot find -ldsfml-graphics
/usr/bin/ld: skipping incompatible 
/home/me/devl/sfml2/bindings/d/lib/libdsfml-audio.a when searching for 
-ldsfml-audio
/usr/bin/ld: cannot find -ldsfml-audio
/usr/bin/ld: skipping incompatible 
/home/me/devl/sfml2/bindings/d/lib/libdsfml-window.a when searching for 
-ldsfml-window
/usr/bin/ld: cannot find -ldsfml-window
collect2: ld returned 1 exit status

Now, I compiled libdsfml-system.a myself, and I know they're 64-bit, so this 
implies ld still isn't recognizing that I want 64-bit executables.


Buliding DSFML2? (64-bit Linux)

2011-03-18 Thread Sean Eskapp
I've been trying for weeks to build the D bindings of SFML2, but with little
success. The main issue is that I get a myriad of linker errors (documented at
http://www.sfml-dev.org/forum/viewtopic.php?p=28345#28345), but I can't figure
out what linking options would solve them.

Can anybody shed some light on this?


Re: Buliding DSFML2? (64-bit Linux) (New info)

2011-03-18 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Friday, March 18, 2011 17:56:44 Sean Eskapp wrote:
  I've been trying for weeks to build the D bindings of SFML2, but
with
  little success. The main issue is that I get a myriad of linker
errors
  (documented at http://www.sfml-dev.org/forum/viewtopic.php?
p=28345#28345),
  but I can't figure out what linking options would solve them.
 
  Can anybody shed some light on this?
 Just glancing at it, it looks like you might be missing pthreads,
though that
 would be pretty weird. You don't normally need to specify -
lpthread. But those
 symbols sure look like they're likely pthread-related.
 - Jonathan M Davis

I've tried -lpthread and -lm, and neither seemed to help. Is it
possible there are platform issues, since D (to my knowledge) is 32-
bit, and I'm 64-bit?


Re: GDC with D2?

2011-03-18 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Friday, March 18, 2011 19:00:40 Sean Eskapp wrote:
  Does GDC support D2?
 Yes. It's also fairly up-to-date now too, I believe (though it is
still a bit
 behind dmd as I understand it - at least as farn as Phobos goes). I
don't use
 anything other than dmd though, so I'm not sure of gdc's exact
state. There _is_
 a fairly up-to-date D2 version though.
 - Jonathan M Davis

Great, thanks!


Re: Building DSFML2? (64-bit Linux)

2011-03-18 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Friday, March 18, 2011 18:58:49 Sean Eskapp wrote:
  == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 
   On Friday, March 18, 2011 17:56:44 Sean Eskapp wrote:
I've been trying for weeks to build the D bindings of SFML2,
but
 
  with
 
little success. The main issue is that I get a myriad of
linker
 
  errors
 
(documented at http://www.sfml-dev.org/forum/viewtopic.php?
 
  p=28345#28345),
 
but I can't figure out what linking options would solve
them.
   
Can anybody shed some light on this?
  
   Just glancing at it, it looks like you might be missing
pthreads,
 
  though that
 
   would be pretty weird. You don't normally need to specify -
 
  lpthread. But those
 
   symbols sure look like they're likely pthread-related.
   - Jonathan M Davis
 
  I've tried -lpthread and -lm, and neither seemed to help. Is it
  possible there are platform issues, since D (to my knowledge) is
32-
  bit, and I'm 64-bit?
 Well, as of dmd 2.052, if you pass -m64 to dmd, it'll compile in
64-bit on
 Linux, but if you don't pass it -m64 (or if you explicitly pass it
-m32), it
 will compile in 32-bit. And if it's compiling in 32-bit, then you
need the 32-
 bit versions of whatever libraries that you're using. pthread is
one of them.
 So, if you don't have a 32-bit version of pthread installed, then
that would
 explain it.
 - Jonathan M Davis

Perfect, thanks!


DMD2 - compiling and linking in separate steps (64-bit)

2011-03-18 Thread Sean Eskapp
I'm trying to use DMD through an IDE, but I'm getting stumped trying to
create 64-bit executables under Linux. I can get everything compiled fine,
using the -m64 compiler flag, but I can't get it to link. Here's the error
list:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libphobos2.a when searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libphobos2.a when
searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libphobos2.a when searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libm.so when searching
for -lm
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libm.a when searching for
-lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libpthread.so when
searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libpthread.a when
searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/libgcc.a when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/librt.so when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/librt.a when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.so when searching
for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.a when searching
for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../librt.so when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../librt.a when searching for -lrt
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../../lib/libc.a when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libc.so when searching
for -lc
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libc.a when searching for
-lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
gnu/4.4.5/../../../libc.a when searching for -lc
collect2: ld returned 1 exit status

How do I use ld to link 64-bit D executables?


Re: DMD on linux? (more problems)

2011-03-03 Thread Sean Eskapp
== Quote from Jesse Phillips (jessekphillip...@gmail.com)'s article
 Sean Eskapp Wrote:
  I'm still having issues with the linux dmd. Here's the relevant
part
  of the output:
 
  ...
  function  func
  function  func
  gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker -
  L/usr/lib32 -Xlinker -L/usr/lib64 -Xlinker --no-warn-search-
mismatch
  -Xlinker --export-dynamic -lrt -lphobos2 -lpthread -lm
  /usr/bin/ld: cannot find -l-Xlinker
  collect2: ld returned 1 exit status
  --- errorlevel 1
  make[1]: *** [all] Error 1
  make[1]: Leaving directory
  ...
 
  Any help is appreciated.
 I think the part LD is tripping up on is -m32 -l -Xlinker
 So it seems you are calling dmd incorrectly or modified dmd.conf
incorrectly as there is no argument after -l so LD thinks you want
to link against lib-Xlinker.

Oops yeah, there was some obsolete in the makefile in my project.
Don't know how it managed to compile on windows, though..

Thanks, though, problem solved.


DMD on linux?

2011-03-02 Thread Sean Eskapp
I'm trying to work with D on Ubuntu, but I keep having this issue:

...
function  func
function  func
gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker 
-L/usr/bin/../lib32 -Xlinker -
L/usr/bin/../lib64 -Xlinker --no-warn-search-mismatch -Xlinker --export-dynamic 
-lrt -
lphobos2 -lpthread -lm
/usr/bin/ld: cannot find -l-Xlinker
/usr/bin/ld: cannot find -lphobos2
collect2: ld returned 1 exit status
--- errorlevel 1
make[1]: *** [all] Error 1
...

I downloaded the DMD v2.052 ZIP from the download page, extracted the linux/bin 
folder into
/usr/bin, the linux/lib64 folder into /usr/lib64, and the src folder into 
/usr/src. Can
somebody please help?


Re: DMD on linux?

2011-03-02 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Wednesday, March 02, 2011 13:52:29 Sean Eskapp wrote:
  I'm trying to work with D on Ubuntu, but I keep having this
issue:
 
  ...
  function  func
  function  func
  gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker
  -L/usr/bin/../lib32 -Xlinker - L/usr/bin/../lib64 -Xlinker
  --no-warn-search-mismatch -Xlinker --export-dynamic -lrt -
lphobos2
  -lpthread -lm
  /usr/bin/ld: cannot find -l-Xlinker
  /usr/bin/ld: cannot find -lphobos2
  collect2: ld returned 1 exit status
  --- errorlevel 1
  make[1]: *** [all] Error 1
  ...
 
  I downloaded the DMD v2.052 ZIP from the download page,
extracted the
  linux/bin folder into /usr/bin, the linux/lib64 folder into
/usr/lib64,
  and the src folder into /usr/src. Can somebody please help?
 1. I never bother installing the zip anywhere. If you just unzip
it and add
 /path/to/unzipped/dmd2/linux/bin to your path, then you should be
fine. I don't
 see any real reason to actual try and install dmd into your system
folders
 (though you obviously can if you want to).
 2. Assuming that you _do_ move files around, you need to adjust
your dmd.conf so
 that it points to the appropriate places.
 3. If you just moved files around, then you might not _have_ a
dmd.conf, and
 you're doubly screwed.
 Take a look at the documentation page for dmd on linux:
 http://www.digitalmars.com/d/2.0/dmd-linux.html
 It's slightly out of date, since with the last release, 64-bit
support was
 added, and the 32-bit version of libphobos.a is in
 /path/to/unzipped/dmd2/linux/lib32 and the 64-bit version is in
 /path/to/unzipped/dmd2/linux/lib64, but the instructions should be
correct
 otherwise.
 You need to make sure that dmd is on your path and that a version
of dmd.conf
 which points to the place where libphobos2.a is is in one of the
places that dmd
 looks for dmd.conf (as described on that page). Also, make sure
that you're
 using a dmd.conf based on the most recent version, or you could be
missing
 necessary linker flags.
 - Jonathan M Davis

Hmm my dmd.conf seems fine, but since the .deb has been updated, I
can just use that. Thanks!


DMD on linux? (more problems)

2011-03-02 Thread Sean Eskapp
I'm still having issues with the linux dmd. Here's the relevant part
of the output:

...
function  func
function  func
gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker -
L/usr/lib32 -Xlinker -L/usr/lib64 -Xlinker --no-warn-search-mismatch
-Xlinker --export-dynamic -lrt -lphobos2 -lpthread -lm
/usr/bin/ld: cannot find -l-Xlinker
collect2: ld returned 1 exit status
--- errorlevel 1
make[1]: *** [all] Error 1
make[1]: Leaving directory
...

Any help is appreciated.


Re: Checking if something is a template specialization?

2011-02-18 Thread Sean Eskapp
== Quote from Lars T. Kyllingstad (public@kyllingen.NOSPAMnet)'s article
 On Fri, 18 Feb 2011 02:02:51 +, Sean Eskapp wrote:
  If I have
 
  class Bar(T)
  {
  }
 
  void foo(Y)()
  {
 ...
  }
 
  Is there a way to check inside foo() that Y is in some way an
  instantiation of Bar? Is there a way to find WHICH instantiation it is?
 void foo(Y)()
 {
 static if (is(Y Z == Bar!Z))
 {
 // Here, Z is now an alias to whichever type Bar is
 // instantiated with.
 }
 else
 {
 // Z is invalid here.
 }
 }

Perfect, thanks!


Finding out if T is a specialization of another template

2011-02-18 Thread Sean Eskapp
I was given this code, to check if Y is a specialization of Bar. How does it 
work?

class Bar(T)
{
}

void foo(Y)()
{
static if (is(Y Z == Bar!Z))
{
// Here, Z is now an alias to whichever type Bar is
// instantiated with.
}
else
{
// Z is invalid here.
}
}


Re: Finding out if T is a specialization of another template

2011-02-18 Thread Sean Eskapp
== Quote from Lars T. Kyllingstad (public@kyllingen.NOSPAMnet)'s article
 On Fri, 18 Feb 2011 17:16:02 +, Sean Eskapp wrote:
  I was given this code, to check if Y is a specialization of Bar. How
  does it work?
 
  class Bar(T)
  {
  }
 
  void foo(Y)()
  {
  static if (is(Y Z == Bar!Z))
  {
  // Here, Z is now an alias to whichever type Bar is //
  instantiated with.
  }
  else
  {
  // Z is invalid here.
  }
  }
 I'm not sure what you mean by how does it work.  If it's the is()
 expression you're wondering about, it's documented here:
 http://www.digitalmars.com/d/2.0/expression.html#IsExpression
 -Lars

Ah, yes. I'd checked the is documentation, but whenever I tried using that is
expression outside of an if statement, it complained about my usage, so I 
assumed
it had something to do with if statements.


Verify tuple is a tuple of class objects?

2011-02-18 Thread Sean Eskapp
Is there a way to run a template at compile time, without using a member?
What I'm trying to do is verify that every element of a tuple is a class type,
and so far, I've been doing this:

template VerifyTuple(Type, Types...)
{
static assert(is(Type : Object), Type.stringof ~  is not a class 
type.);

static if(Types.length == 0)
alias void dummy;
else
alias VerifyTuple!(Types).dummy dummy;
}

and to use it, I have to do this:
class Foo(T...)
{
alias VerifyTuple!(T).dummy dummy;
}

Is there any way to just run the template, without bothering to use the
dummy aliases?


struct opEquals bug

2011-02-17 Thread Sean Eskapp
Has this been reported?

struct A
{
int x;

A foo()
{
return A(x);
}

const bool opEquals(ref const A other)
{
return (x == other.x);
}
}

void main()
{
auto a = A(5);
assert(a == a.foo); // Error
assert(a.foo == a); // OK
}

The first assert fails to compile because a.foo isn't an lvalue, but the
second assert compiles fine. However, the language documentation states that

...the expressions a.opEquals(b) and b.opEquals(a) are tried. If both resolve
to the same opEquals function, then the expression is rewritten to be
a.opEquals(b).
If one is a better match then the other, or one compiles and the other does
not, the one is selected.
Otherwise, an error results.

In this case, a.opEquals(b) doesn't compile, but b.opEquals(a) does, so it
should be selected.


Checking if something is a template specialization?

2011-02-17 Thread Sean Eskapp
If I have

class Bar(T)
{
}

void foo(Y)()
{
   ...
}

Is there a way to check inside foo() that Y is in some way an instantiation of
Bar? Is there a way to find WHICH instantiation it is?


Double-dispatch

2011-02-13 Thread Sean Eskapp
I remember in C++, I had to do double-dispatch using the visitor pattern. This
is cumbersome, just because each subclass has to have the exact same
singly-dispatched code that looks like:

void dispatch(Base other)
{
   other.dispatch(*this);
}

Is there a nicer way to do this in D, or am I stuck with the same thing?


Re: Double-dispatch

2011-02-13 Thread Sean Eskapp
== Quote from bearophile (bearophileh...@lycos.com)'s article
 Sean Eskapp:
  Is there a nicer way to do this in D, or am I stuck with the same thing?
 Andrei has recently said no one needs double dispatch (in D) :-) So Andrei 
 will
be interested in your use case.
 Bye,
 bearophile

The age-old collision handling problem is how I'm using it.


Opt-out polymorphism?

2011-02-13 Thread Sean Eskapp
Is there a way to specify that a function is nonvirtual, but can still be
overriden in base classes? e.g.

class A
{
void foo()
{
writeln(A);
}
}

class B : A
{
void foo()
{
writeln(B);
}
}

void main()
{
(new A).foo();
(new B).foo();
}

Should output:
A
B

Is there a way to do this?


Why no struct default constructors?

2011-02-12 Thread Sean Eskapp
With the removal of scope classes, the only way of which I know to use RAII
objects is to use structs. This is fine, but structs aren't allowed default
constructors! Why is this?


Re: Why no struct default constructors?

2011-02-12 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Saturday 12 February 2011 10:48:04 Sean Eskapp wrote:
  With the removal of scope classes, the only way of which I know to use RAII
  objects is to use structs. This is fine, but structs aren't allowed default
  constructors! Why is this?
 It's because they have to have an init property. _All_ types have an init
 property. It's what they're default initialized to. For bool, it's false. For
 integral types, it's 0. For floating point types, it's NAN. Etc. For classes,
 that's null, so they can have default constructors just fine. However, for
 structs, it must be what the struct's member variables are directly 
 initialized
 to. If you could have an arbitrary default constructor, then you'd have the
 problem of it throwing exceptions as well as it trying to run functions which
 could only be run at runtime. The struct's init value must be known at compile
 time, and it must _always_ be the same. So, it can't involve any functions 
 which
 would have to be run at runtime, and it can't involve anything that would 
 result
 in differing values betwen runs of the default constructor.
 There has been some discussion of allowing structs to have limited default
 constructors, but they would still disallow most of the kinds of things that
 people would want to do with a default constructor. init _must_ be known at
 compile time. So, its value is taken from the value that a struct gets when 
 all
 of its member variables have been directly initialized (or default 
 initialized)
 and no constructor has been called.
 It _can_ be a bit annoying at times, but it's either that or allow undefined
 struct values, which would be a big problem and go against D's philosophy on
 default initialization.
 Since you can't have a default constructor, what you do instead is define a
 static opCall() function for the struct and use that. Then you construct a
 struct (with the name S in this case) like so:
 auto s = S();
 You're still stuck with the init state if you do
 S s;
 or if you're dealing with structs in an array and the like (since they're all
 default constructed to the struct's init property). But you can do RAII just
 fine. Personally, I _always_ use this syntax when declaring struct variables:
 auto S = S();
 So, the situation isn't exactly ideal, but we're kind of stuck, given the
 various constraints that we have to work with.
 - Jonathan M Davis

Alright, thanks for clearing that up!


Invoke garbage collector?

2011-02-09 Thread Sean Eskapp
I'm having an unfortunate DSFML issue, where failing to free objects like
Images or Sprites causes exceptions to eventually be thrown. Calling the
built-in member dispose() causes access violations, so I assume it's not for
programmer use.

However, I need the resources to be freed more quickly than the GC is
apparently doing (I assume the Images and Sprites are eventually cleaned up),
so is there a way to invoke a GC cleanup in some way?


Re: Invoke garbage collector? (Scoped Instances)

2011-02-09 Thread Sean Eskapp
== Quote from Trass3r (u...@known.com)'s article
  However, I need the resources to be freed more quickly than the GC is
  apparently doing
 You could use scoped instances if you need to clean them up soon after
 creation.

To my knowledge, these are being removed from the language, and so, could only 
be
used in the short-term.


Debugging D?

2011-02-06 Thread Sean Eskapp
Are debug symbols compiled with -gc stored in a separate file? Visual Studio
refuses to debug my things, and windbg seems to be remarkably unhelpful.


Re: Debugging D?

2011-02-06 Thread Sean Eskapp
== Quote from Robert Clipsham (rob...@octarineparrot.com)'s article
 On 06/02/11 20:29, Sean Eskapp wrote:
  Are debug symbols compiled with -gc stored in a separate file? Visual Studio
  refuses to debug my things, and windbg seems to be remarkably unhelpful.
 I suggest you take a look at VisualD if you're using visual studio, it
 will handle converting debug info so that visual studio can understand
 it, and give you some intellisense.
 http://www.dsource.org/projects/visuald

I'm using VisualD already, but the project is configured using Makefiles, and I
don't want to go through the hassle of changing project configs in two 
locations.
Is there any way to still get Visual Studio debugging information if it's a
makefile project?


DSFML

2011-01-30 Thread Sean Eskapp
I've been unable to build ANYTHING with DSFML, either by using the version on
the download page, or by using the version in the SVN repository. Has anybody
else had this trouble? Can I just not use DSFML with DMD v2.051?


SFML in D?

2011-01-25 Thread Sean Eskapp
Are there wrappers of some kind for SFML in D?


Opt-out closures

2011-01-23 Thread Sean Eskapp
I get errors when working with nested functions and structs or scoped classes,
because closures can't be used with anything with scoped destruction. This
makes complete sense, but I don't even want the closure functionality of these
nested functions. Personally, I would like to be able to opt-out of the
closure functionality of nested functions: if the enclosing function exits,
and a nested function thereof is called, then a segfault would occur when it
tried to access the stack of its enclosing function; however, access of
scoped-destruction variables from an enclosing-scope function would be fine.

Thoughts? The not-being-able-to-access-scoped-destruction-variables thing is
really getting to me, since one of the main driving features I like about D is
the ability to use anonymous and nested functions.


Re: Opt-out closures

2011-01-23 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Sunday 23 January 2011 06:36:27 Sean Eskapp wrote:
  I get errors when working with nested functions and structs or scoped
  classes, because closures can't be used with anything with scoped
  destruction. This makes complete sense, but I don't even want the closure
  functionality of these nested functions. Personally, I would like to be
  able to opt-out of the closure functionality of nested functions: if the
  enclosing function exits, and a nested function thereof is called, then a
  segfault would occur when it tried to access the stack of its enclosing
  function; however, access of scoped-destruction variables from an
  enclosing-scope function would be fine.
 
  Thoughts? The not-being-able-to-access-scoped-destruction-variables thing
  is really getting to me, since one of the main driving features I like
  about D is the ability to use anonymous and nested functions.
 If a nested function is marked as static, then it results in a function rather
 than a delegate. Of course, that means that you can't access the enclosing
 scope, but if you don't care about that, then just use static.
 - Jonathan M Davis

I want to be able to access the enclosing scope, but NOT after the function has
exited; I should have the option of accessing the enclosing scope, but at the 
cost
of making my delegate not a closure.


Re: Opt-out closures

2011-01-23 Thread Sean Eskapp
== Quote from bearophile (bearophileh...@lycos.com)'s article
 Sean Eskapp:
  I want to be able to access the enclosing scope, but NOT after the function 
  has
  exited; I should have the option of accessing the enclosing scope, but at 
  the cost
  of making my delegate not a closure.
 It seems a worth thing to ask for. A possible syntax (not currently 
 supported):
 void foo() {
 scope void bar() {}
 }
 Bye,
 bearophile

That looks like one of the best options syntax-wise. Nice!


Re: Opt-out closures hack

2011-01-23 Thread Sean Eskapp
== Quote from Torarin (torar...@gmail.com)'s article
 2011/1/23 Sean Eskapp eatingstap...@gmail.com:
  I want to be able to access the enclosing scope, but NOT after the function 
  has
  exited; I should have the option of accessing the enclosing scope, but at 
  the cost
  of making my delegate not a closure.
 
 Until we have a dedicated syntax for it, I think you can use this hack:
 import std.traits;
 auto scopeDelegate(D)(scope D d) if (isDelegate!D)
 {
   return d;
 }
 int main()
 {
StructWithDtor s;
trustedFunction(scopeDelegate({s.a = 5;}); // No heap allocation
 }
 Torarin

Yup, works great with everything I've tried! Thanks.


How to wrap SDL?

2011-01-22 Thread Sean Eskapp
I'm using the Derelict SDL bindings, and I'm wrapping some parts of SDL in my
own objects. Originally, I was using classes, but this caused a number of
errors when the program exited, since Derelict unloaded itself before the
garbage collector took care of destructing my classes.

So I switched to scope classes. This works fine, but I've been told they're
being removed from the language (?) and to use structs instead for RAII.

How should I be wrapping this SDL stuff?


Re: How to wrap SDL?

2011-01-22 Thread Sean Eskapp
== Quote from Andrej Mitrovic (andrej.mitrov...@gmail.com)'s article
 You can use scoped!() from std.typecons:
 import std.stdio;
 import std.typecons;
 class A
 {
 ~this()
 {
 writeln(A destructor);
 }
 }
 void foo()
 {
 auto a1 = scoped!A();
 }
 void main()
 {
 foo();
 writeln(exiting..);
 }
 You must not escape a reference to the object outside of the foo()
 scope. Note that you will get a runtime error if you try to do
 something like this:
 import std.stdio;
 import std.typecons;
 class A
 {
 ~this()
 {
 writeln(A destructor);
 }
 }
 auto foo()
 {
 auto a1 = scoped!A();
 return a1;
 }
 void main()
 {
 auto result = foo();
 writeln(exiting..);
 }
 Illegal call to Scoped this(this)
 A destructor
 core.exception.AssertError@std.typecons(2506): Assertion failure

But these can't be passed to functions either, meaning I can't pass a Screen,
Text, or Font wrapper around, all of which I use in my project!


Structs with pointers?

2011-01-22 Thread Sean Eskapp
Why doesn't this code work?

struct Bar
{
int* x;
}

void foo(Bar a) {}

void main()
{
const a = Bar();
foo(a);
}

But replacing int* with some other type works fine? Even if a write a postblit
function for Bar, it still fails to compile.


Re: Structs with pointers?

2011-01-22 Thread Sean Eskapp
== Quote from Sean Eskapp (eatingstap...@gmail.com)'s article
 Why doesn't this code work?
 struct Bar
 {
   int* x;
 }
 void foo(Bar a) {}
 void main()
 {
   const a = Bar();
   foo(a);
 }
 But replacing int* with some other type works fine? Even if a write a postblit
 function for Bar, it still fails to compile.

Nevermind, I realized it's because constness is transitive in pointers. A const
struct with a pointer member has a const pointer member, and those can't be
implicitly cast to non-const pointer members.


Re: Structs with pointers?

2011-01-22 Thread Sean Eskapp
== Quote from bearophile (bearophileh...@lycos.com)'s article
 Sean Eskapp:
  Nevermind, I realized it's because constness is transitive in pointers. A 
  const
  struct with a pointer member has a const pointer member, and those can't be
  implicitly cast to non-const pointer members.
 Uhm, the struct having a pointer is not important. In theory this too can't 
 compile:
 struct Bar {}
 void foo(Bar b) {}
 void main() {
 const b = Bar();
 foo(b);
 }
 Is this another compiler bug?
 Bye,
 bearophile

No, that compiles fine. Because the struct owns a pointer, the const struct 
owns a
const pointer. When copying a const-struct to a non-const struct, this means you
must cast a const-pointer to a non-const pointer, which shouldn't be allowed.


How to use structs for RAII?

2011-01-22 Thread Sean Eskapp
It was recommended to me to use structs for RAII instead of scope classes,
since scope is being removed (?). However, since default-constructors for
structs can't exist, how does one do this?


Re: How to use structs for RAII?

2011-01-22 Thread Sean Eskapp
== Quote from bearophile (bearophileh...@lycos.com)'s article
 Sean Eskapp:
  It was recommended to me to use structs for RAII instead of scope classes,
  since scope is being removed (?). However, since default-constructors for
  structs can't exist, how does one do this?
 Inside the ~this() you may put code, to deallocate resources you have 
 allocated
in an explicit constructor (or in some creation method). Is this enough?
 Bye,
 bearophile

By explicit constructor, I assume you mean one with parameters? I guess that's
alright.


assert vs enforce?

2011-01-22 Thread Sean Eskapp
What's the difference between assert and enforce in D?


Re: How to use structs for RAII?

2011-01-22 Thread Sean Eskapp
Actually this becomes rather annoying, since I can't use any closures on the
object. Stupidly, I can still use closures with an object which is deleted at 
the
end of the function.


Re: assert vs enforce?

2011-01-22 Thread Sean Eskapp
Ah, that clears it up. Thanks!


Garbage-collected structs vs garbage-collected classes

2011-01-22 Thread Sean Eskapp
When I was using a class to wrap SDL functions and structs, I would have a
problem that Derelict would unload before the garbage-collector cleaned up my
classes, resulting in errors when these classes destructed and tried to call
SDL functions in the process. However, the exact same code using structs to
wrap instead of classes does not produce these errors. For example, rather
than using
scope screen = new Screen(800, 600)
where Screen is a scope class, I'm using
auto screen = new Screen(800, 600)
where Screen is a struct. This also provides me the advantage of being able to
use delegates which use screen. Is there a reason for this?


Is it true scope declarations are being removed?

2011-01-21 Thread Sean Eskapp
Someone mentioned to me that scope declarations, e.g.

scope class A{}
or
scope A myNewObject;

are being removed from the language. Is this true? If so, how will RAII-type
classes be implemented?


Type-qualified functions?

2011-01-21 Thread Sean Eskapp
How does one avoid code duplication in a snippet code like this:

class A{}

void foo(const A, void delegate(const A) fn)
{
// some stuff
// ...
// ...
}

void foo(A, void delegate(A) fn)
{
// exact same stuff, with different qualifiers
// ...
// ...
}


Re: Type-qualified functions?

2011-01-21 Thread Sean Eskapp

 templates:

 void foo(T)(T, void delegate(T) fn)
 {
 }

 This parameterizes foo based on T, which could be A, const A, or int, or
 whatever works to compile the function.

What if the parameters are more general, for instance the first parameter is
always a Foo, the second is a delegate which takes a Foo.Bar, but they're always
qualified the same way?


const-typed class does not have const members

2011-01-21 Thread Sean Eskapp
The following code yields results as commented.

import std.stdio;

class A
{
int b;
}

void main()
{
const A a = new A;
writeln(typeof(a).stringof); // const(A)
writeln(typeof(a.b).stringof); // const(int)

writeln((const A).stringof); // const(A)
writeln(typeof((const A).b).stringof); // int
}

Given this information, how do I work around this in templates? I'd like a
template which can type its params based on members of T, for instance:

void foo(T)(T x, typeof(T.member) y)

but this will yield non-const second parameters even if T is const. Help 
anybody?


Casting between delegates with qualified value type parameters

2011-01-20 Thread Sean Eskapp
Delegates cannot be cast from one type to another, even if the only difference
in type is the qualifiers on value type parameters. However, the same code
works fine with functions instead of delegates, as such:

import std.stdio;

void foo(void function(int) bar)
{
bar(5);
}

void foobar(void delegate(int) bar)
{
bar(5);
}

void main()
{
foo   (function(int i)   { writeln(i); }); // OK
foo   (function(immutable int i) { writeln(i); }); // OK
foobar(delegate(int i)   { writeln(i); }); // OK
foobar(delegate(immutable int i) { writeln(i); }); // error
}


Is there a reason for this, or is it a bug?


Struct constructors

2011-01-20 Thread Sean Eskapp
In code like this:

import std.stdio;

struct foo
{
int val;

static immutable bar = foo(1);

this(int val)
{
this.val = 50;
}
}

void main()
{
writeln(foo.bar.val);
}

The user-defined struct constructor is not called, because it's overridden by
a built-in constructor which treats it like an initializer list. Shouldn't
constructors in structs either generate errors/warnings, or work as they would
appear to?


Re: Struct constructors

2011-01-20 Thread Sean Eskapp
That looks like a similar issue. Thanks!


const vs immutable

2011-01-18 Thread Sean Eskapp
In cases where they are the same, for instance declaring:
const int x = oldX + 5;

vs

immutable int x = oldX + 5;

Or in non-class, non-array function parameters, does it make a difference
which is used?


in vs const

2011-01-17 Thread Sean Eskapp
For function parameters where the scope keyword doesn't matter (e.g.
intrinsic types, many classes, structs, etc.), does in produce different
code from const?


How to use std.bind?

2011-01-17 Thread Sean Eskapp
I used to use boost::bind all the time, but std.bind has me stumped, as I keep
getting static asserts with a cryptic argument has no parameters message. At
this point, the code is just:

class Foo
{
void bar(int i) { writeln(i); }
}

void main()
{
auto foobar = new Foo;
bind(foobar.bar, 5)();
}

I've tried a myriad of different ways, but keep coming up with the same error.
Using bindAlias gives me an error that std.bind.bindAlias(alias FT) is not a
function template.

I'm using DMD v2.051 on a Windows platform. Help anybody?


Re: Using template typetuples?

2011-01-12 Thread Sean Eskapp
That looks like it.. only, it's not working:

void main()
{
TypeTuple!(int, int) foo;
foo[0] = 1;
foo[1] = 2;

double MakeStuff(in int bar)
{
return cast(double)bar;
}

auto foobar = staticMap!(MakeStuff)(foo);
}

This fails compilation with the error Error: function expected before (), not 
()
of type ()


Re: Using template typetuples?

2011-01-12 Thread Sean Eskapp
Nevermind, I see my error.
Thank you!


Casting between tuples

2011-01-12 Thread Sean Eskapp
I have a variable of type TypeTuple!(int, int), and I want to convert all its
elements into a variable of type TypeTuple!(string, string). Is there a way to
do this? Using a loop fails compilation with Error: Integer constant
expression expected instead of i.

I'd also like to be able to convert from arrays of base classes (static size)
to TypeTuples of derived classes. static for doesn't work either. Is there a
way to do this.. without a recursive template function?


Forward declaration error with auto

2011-01-10 Thread Sean Eskapp
Referring to functions declared later inside a module with return type auto
causes an error, but not when the return type is explicitly declared.

The same goes for calling functions in other modules with return type auto. Is
this supposed to happen?


Recommendation: functional keyword

2011-01-09 Thread Sean Eskapp
I recommend that there be a functional keyword, which when applied to
functions, would not allow them to modify existing data, or call impure
functions. This would imply pure.

Thoughts?


Re: Recommendation: functional keyword

2011-01-09 Thread Sean Eskapp
Functional functions could not modify ANY data, including explicitly allocating
variables. Although, come to think of it, this wouldn't imply pure, as they 
should
still be allowed to read global data and call impure functions.


Re: Recommendation: functional keyword

2011-01-09 Thread Sean Eskapp
It's a programmer contract, nothing more. It forces the code to be functional, 
not
procedural. Just like const and @safe are simply programmer contracts, 
functional
would mean no explicit stack allocation, except that allocated in called 
functions.


Is this a bug?

2011-01-09 Thread Sean Eskapp
This code works fine:

int[] arr = [ 1, 2, 3, 4, 5 ];
auto myMax = function int(int a, int b) { return (a  b) ? a : b; };
auto biggest = reduce!(myMax)(arr);

But passing the function literal directly to reduce causes an error. Is this
intentional?


How to convert Map to array?

2011-01-09 Thread Sean Eskapp
I'm trying to use the array() function in std.array to convert a transformed
array using map (std.algorithm) back to a dynamic array, from a Map. I keep
getting a cryptic error object.except...@c:\Program Files
(x86)\D\dmd2\windows\bin\..\..\src\phobos\std\
algorithm.d(426): Cannot reduce an empty range w/o an explicit seed value..
Am I misunderstanding how this is supposed to work?


Re: What's wrong with this code? (OP)

2011-01-08 Thread Sean Eskapp
Tomek got it right. Fixed by copying the objects, rather than using pointers. 
Thanks!


Module is private when calling function

2011-01-07 Thread Sean Eskapp
I have two modules:

foo.d:
public void Foo(int x) {}
private void Foo(string x) {}

private void Bar(string x) {}
public void Bar(int x) {}

main.d:
import foo;

void main()
{
Foo(5); // OK
Foo(Hello); // error: function is private (correct)
Bar(5); // error: module is private (incorrect)
Bar(hello); // error: function is private (correct)
}

With the errors demonstrated. When a public function is denoted below a
private function, the private function seems to intercept the overload. Is
this supposed to happen?


Ref function pointers?

2011-01-06 Thread Sean Eskapp
Is there a way to create a function pointer which returns a reference? In all
the ways I've tried it, my return value becomes not an lvalue.


@safe functions

2011-01-05 Thread Sean Eskapp
This is either a compiler bug, or outdated language documentation, but I'm
having some freedom with @safe functions:

* No casting from a pointer type to any type other than void*.
* No modification of pointer values.
* No taking the address of a local variable or function parameter.

I've attached code which does all three of these things, which compiles and 
runs.

Inline assembler was an error, as well as casting from integer to a pointer
type, but I didn't test anything else.

I'm using dmd2.exe as my compiler.
begin 644 main.d
M:6UP;W)T('-T9YS=1I;SL-@T*0'-a...@=f]i9!F;V\H:6YT('@I#0I[
M#0H):6YT($[#0H):6YT*B!Y(#T@)F$[(\O('1A:VEN9R!A91R97-S(]F
M(QO8V%L('9AFEA8FQE#0H)8VAABH@B`](-AW0H8VAABHI3...@+r\@
M8V%S=EN9R!P;VEN=5R('1O(YO;BUP;VEN=5R('1Y4-@DJB`](#0[
M(\O('=R:71I;F@=7-I;F@;6%L9F]R;65D('!O:6YT97(-@D-@EY(#T@
M)g...@[(\O('1A:VEN9R!A91R97-S(]F('!AF%M971Eb...@04y$(-H86YG
M:6YG('!O:6YT97(@=F%L=64-@DJ2`](#0[(\O(-H86YG:6YG('9A;'5E
M#0H)#0H):6YT((@/2!C87-T*EN=EY.R`O+R!C87-T:6YG(9R;VT@]I
M;G1EB!T7!E('1O('1Y4...@=AA=!IVXG=!V;v...@t*?0t*#0iv;VED
G(UA:6XH*0T*PT*6EN=!X(#...@-3`[#0h)9F]O*'@I.PT*?0T*
`
end


Re: Programming in D for C++ Programmers mistake

2010-12-03 Thread Sean Eskapp
I'm sorry, it must have been some form of nonstandard extension I used! I see 
now
that this fails with gcc.


Programming in D for C++ Programmers mistake

2010-12-02 Thread Sean Eskapp
There's a significant issue in the Programming in D for C++ Programmers
article (http://www.digitalmars.com/d/2.0/cpptod.html)

The Struct Comparison section is quite wrong. In C++, most structs/classes
automatically generate comparison operators. Also, these comparison operators
are member functions of the struct, not external functions.