Re: Reading file contents when file has changed

2012-07-13 Thread Kevin Cox
On Jul 13, 2012 4:40 PM, OlaOst ola...@gmail.com wrote:

 I'm working on a program (using dmd 2.059 under windows) that
automatically reloads the contents of a file if it has changed, by checking
the last modified timestamp on the file every 0.2 seconds, then using the
readText function in std.file to read in the file contents.

 It works pretty well, but every once in a while I get a The process
cannot access the file because it is in use by another process error
message. I guess this happens when my D program tries to read the file
before the text editor manages to close its handle on the file.

 This would be fair enough if I was writing to the file in my D program,
but I only want to read from it. Is this a bug or is there a better way to
get file contents in D?

While the text editor is writing the file reading it is a silly thing to do
(no one knows what's there).  I'm not familiar with windows but locking
under Linux works as so.  Any number or processes can have a read lock but
if there is a write lock only the single process can access that file.

Also isn't there something like inotify on windows?  Polling sounds like
the wrong solution.


Re: What was the reason for not including std.net.curl in the Windows phobos library?

2012-07-07 Thread Kevin Cox
On Jul 7, 2012 8:45 AM, Gary Willoughby d...@kalekold.net wrote:

 What was the reason for not including 'std.net.curl' in the Windows
phobos library?

IIRC it is licencing issues, they can't include curl in the distribution
without certain requirements that were deemed to awkward to implement.


Re: floats default to NaN... why?

2012-06-07 Thread Kevin Cox
On Jun 7, 2012 9:53 PM, Minas minas_mina1...@hotmail.co.uk wrote:

 I agree that the default value for floats/doubles should be zero. It
feels much more natural.

 I think the problem here is that people are thinking about some stuff too
much. D is a rather new language that wants to be practical. Floats
defaulting to NaN is NOT practical FOR MOST PEOPLE when at the same time I
write:

 int sum;

 for(...)
  sum += blah blah blah

 And it works.

 Having floats deaulting to a value that's un-natural for most people is,
in my opinion, craziness. Even if that's more correct in a mathematical
sense.

 Please excuse my English.

The idea isn't being practical exactly.  The idea was to use invalid
values as defaults. Unfortunately things like ints don't have invalid
values, so they chose zero.  The idea is to make people initialize their
variables.  It would have been better to pick 19472937 as the int default
because not many people will use that value.

The code you showed would be considered **bad** because you did not
initialize your variables, however ints defaulting to zero is well defined
so it isn't really a big deal.

With floats there is this wonderful value that ensures that nothing
reasonable comes out of a bad calculation, NaN.  Therefore this is used as
a default because if you forget to initialize your vars it will jump out at
you.

This is the thought that was used and many people don't agree.  It is
**very** unlikely to be changed now but __maybe__ D3 however far off that
is.  I hope not though, I hope ints default to 8472927 instead, but
everyone has different opinions.


Re: Static function conflicts with Non-Static?!

2012-06-02 Thread Kevin Cox
On Jun 2, 2012 6:38 AM, bearophile bearophileh...@lycos.com wrote:

 Jonathan M Davis:


 Personally, I wish that it weren't legal to call a static function with
an
 object and that you had to explicitly use the class,


 I agree.

 Bye,
 bearophile

Same here, D 3.0?


Re: D under Linux Mint

2012-05-23 Thread Kevin Cox
On May 23, 2012 5:48 PM, snow marcel.patzw...@googlemail.com wrote:

 Hello, Ive tried to install D under Linux and followed the steps
 described on . this page http://dlang.org/dmd-linux.html . I
 checked all folders after every step and everything is where it
 should be. In the secound step I did both, adding dmd to the PATH
 and copied the executables into the lib folder. If I type dmd
 into the console, I get back all infos about D, so this is
 already working. But if I try to run a simple Hello world program
 like this:

 import std.stdio;

 void main() {
writeln(Hallo Welt);
}

 I get the following error:
 object.d: Error: module object is in file 'object.d' which cannot
 be read
 import path[0] = /usr/local/bin/../../src/phobos
 import path[1] = /usr/local/bin/../../src/druntime/import


 My DMD folder is in the home directory and the dmd.config
 contains this:
 [Environment]

 DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
 -L-L%@P%/../lib64 -L-L%@P%/../lib32 -L--no-warn-search-mismatch
 -L--export-dynamic

 I already tried to compile the program with geany and the
 console. In the console i trid to compile it as: dmd hello.d and
 dmd -c hello.d. But everywhere I get the same errors



It appears that dmd can't find the library files.  IIRC object.d is part of
the runtime.  Check the paths in the error message and try to ensure
necessary files are found.


Re: How to make a directory?

2012-05-01 Thread Kevin Cox
On May 1, 2012 7:49 PM, Alex Rønne Petersen xtzgzo...@gmail.com wrote:

 Also, is there a way to require the root password of the user when going
 create the directory in a restricted folder (like /usr) AFTER the
 application has started?


 No idea, sorry.


 Thank you.


 --
 - Alex

You could execute a system command and change your apps privileges but this
is a bad/risky way to do it.  I would use sudo or gksudo and launch the
command externally so that you don't grant your app root permissions and
then do something stupid.  If those actions are common I would only allow
root to use your app.


Re: Aquivalent References as in C++?

2012-04-16 Thread Kevin Cox
On Apr 16, 2012 5:29 PM, Namespace rswhi...@googlemail.com wrote:

 That case I would like to prevent, but at the same time allow
 Ivalues. How does that work in D classes?
 As far as I know this operates with structs, but shouldn't it be
 possible with classes and objects too?

I would recommend a precondition.  It is a language enforced method of
restricting what values may be passed into a function.  If the code is
compiled for release the checks are not included and do not cost anything.


Re: D 50% slower than C++. What I'm doing wrong?

2012-04-15 Thread Kevin Cox
On Apr 15, 2012 4:30 AM, Joseph Rushton Wakeling 
joseph.wakel...@webdrake.net wrote:
 ... the compiler accepts it.  Whether that's because it's acceptably
pure, or because the compiler just doesn't detect this case of impurity, is
another matter.  The int k is certainly mutable from outside the scope of
the function, so AFAICS it _should_ be disallowed.

As far as I understand pure includes the hidden this parameter  so it is
pure if when you call it on the same structure with the same arguments you
always get the same results.  Although that seams pretty useless in the
optimization standpoint because the function can modify it's own object
between calls.


Re: Creating a file in ~/.config (ubuntu)

2012-04-13 Thread Kevin Cox
Try using the $HOME environment variable.


Re: How to set up QTD?.

2012-04-09 Thread Kevin Cox
On Apr 8, 2012 10:59 PM, vmars316 vmars...@live.com wrote:

 Greetings,
 I would also like to try out QTD.

 So far, I have set things up this:
 C:\D\dmd2\QT

 I made a .batch file for both drcc.exe and duic.exe .
 duic.exe gave no feedback.

 drcc.exe gave the following feedback:

 C:\D\dmd2\QT\binECHO ON

 C:\D\dmd2\QT\bindrcc.exe
 Qt resource compiler
 Usage: drcc.exe  [options] inputs

 Options:
  -o filewrite output to file rather than stdout
  -name name create an external initialization function with
name
  -threshold level   threshold to consider compressing files
  -compress levelcompress input files by level
  -root path prefix resource access path with root path
  -no-compress   disable all compression
  -no-static-initialize  disable automatic initialization of resources
with prog
 ram start
  -binaryoutput a binary file for use as a dynamic resource
  -namespace turn off namespace macros
  -project   Output a resource file containing all
 files from the current directory
  -version   display version
  -help  display this information

 C:\D\dmd2\QT\binREM C:\D\dmd2\windows\bin\dmd.exe

 C:\D\dmd2\QT\binpause
 Press any key to continue . . .

 Pls, do I need to re-do file/Folder placement?
 Also, do I need to create .bat files for every .d I want to compile?
 Can someone show me how to get qtd running?

 Thanks...Vernon



I think rcc is the Qt resource compiler.  I'm not at my computer at the
moment to check, but if so it will translate xml resource files into D
source.


Re: How to set up QTD?.

2012-04-09 Thread Kevin Cox
On Apr 9, 2012 12:09 PM, vmars316 vmars...@live.com wrote:

 On Monday, 9 April 2012 at 12:52:47 UTC, Kevin Cox wrote:

 I think rcc is the Qt resource compiler.  I'm not at my computer at the
 moment to check, but if so it will translate xml resource files into D
 source.


 I think rcc is the Qt resource compiler.
 I don't know what the above means.
 What are its implications?
 Is my setup ok?: C:\D\dmd2\QT
 Or do I need to dump 'QT Folder' into 'drcc.exe Folder'?

 Also, do I need to create '*.bat' files for every '*.d' I want to
edit/compile?
 Pls, what would that .bat file look like?
 Could someone show me a working cmd-line for the .bat file?
 Do I need to specify 'environmental-variables'?

 Thanks a lot for your helps...Vernon

Qt as quite extensive documentation.  Look into the documents about
compiling projects.  It is not a 1 to 1 translation but the workflow is the
same.


Re: Latest versions of Entice Designer and DFL?

2012-04-08 Thread Kevin Cox
On Apr 8, 2012 4:49 PM, vmars316 vmars...@live.com wrote:

 Win7:
 Greetings,
 Ok, I got the command line for dmd2 running (Hello World). :)

 Now I would like to install a Visual GUI Builder.
 Not knowing any better, think I'll try Entice Designer and DFL.
 The most current versions I can find are for 2008.
 Are there more current versions? Url please.
 Is there a combined *.zip install for them?
 Also, is Entice Designer and DFL a reasonable choice?
 I am always oopen for a better option.

 Thanks...Vernon

If you want to use QtD you can use QtDesigner and I think QtD has a moc for
D.  Worst case you can dynamically load the forum from the xml file
QtDesigner spits out.


Re: GUI library

2012-03-25 Thread Kevin Cox
On Sun, Mar 25, 2012 at 11:13 AM, Jacob Carlborg d...@me.com wrote:

 On 2012-03-25 15:04, Tyro[17] wrote:

 Is there one available for use with D2 on MAC OS X?

 Thanks,
 Andrew


 * QtD - Bindings to Qt. Use the native drawing operations of the operating
 system (I think). Available on all platforms. Not sure if this is developed
 any more.


I would reccomend Qt as well.  You will get native cross-platform widgets
with great performance.  I am not sure how far QtD is but I know it once
had a lot of development on it.


Re: Capturing caller's file/line number in variadic template functions

2012-03-16 Thread Kevin Cox
On Mar 16, 2012 2:29 PM, Adam D. Ruppe destructiona...@gmail.com wrote:

 Put the string file = blaha in the template argument list,
 before the variadic.

 voic checkConsistency(string file = __FILE__, int line = __LINE__,
T...)(T t) {


But then you have to write it each time.


Re: Dumb question about git

2012-03-01 Thread Kevin Cox
When people say git encourages rewriting history.  Don't listen.  Once you
have pushed your changes to the world they are immutable.  This is because
git uses cryptography internally and changing the history messes everything
up.  If you haven't pushed you can change all of your history and it will
all be fine.  But if someone else (github) has the old hisory bad things
happen.  If you are sure nobody has pulled from github you can use --force
when pushing (I think).  It will work no matter what but you will piss off
people if they have pulled from you.  Please note that this kind of history
modifying is considered bad practice.
On Mar 1, 2012 10:10 AM, H. S. Teoh hst...@quickfur.ath.cx wrote:

 OK, so I'm new to git, and I ran into this problem:

 - I forked druntime on github and made some changes in a branch
 - Pushed the changes to the fork
 - Pulled upstream commits to master
 - Merged master with branch
 - Ran git rebase master, so that my changes appear on top of the latest
  upstream master.
 - Tried to push branch to my fork, but now it complains that I have
  non-fast-forward changes and rejects the push.

 What's the right thing to do here? Looks like I screwed up my branch
 history. How do I fix it?

 Thanks!


 T

 --
 Real Programmers use cat  a.out.



Re: Dumb question about git

2012-03-01 Thread Kevin Cox
On Mar 1, 2012 12:15 PM, H. S. Teoh hst...@quickfur.ath.cx wrote:

 On Thu, Mar 01, 2012 at 10:22:33AM -0500, Kevin Cox wrote:
  When people say git encourages rewriting history.  Don't listen.  Once
  you have pushed your changes to the world they are immutable.  This is
  because git uses cryptography internally and changing the history
  messes everything up.  If you haven't pushed you can change all of
  your history and it will all be fine.  But if someone else (github)
  has the old hisory bad things happen.  If you are sure nobody has
  pulled from github you can use --force when pushing (I think).  It
  will work no matter what but you will piss off people if they have
  pulled from you.  Please note that this kind of history modifying is
  considered bad practice.
 [...]

 OK, so what's the right way to do it then? I have some changes in a
 branch, but master has been updated since, so I want to merge in the
 latest updates so that the branch changes are compatible with the latest
 code. If I just pull from master, then my changes get buried underneath
 the newest changes.

 I guess I still don't quite understand how things are supposed to work
 in situations like this.


 T

 --
 Music critic: That's an imitation fugue!

This time I would just --force.  In the future the idea is to only push
changes once you are happy with them.

What I would do next time is:
- work
- commit
- work
- commit
- pull
- rebase (make what you have done look pretty)
- push


Re: Trouble with -lib in linux undefined reference to `_Dmain'

2012-02-29 Thread Kevin Cox
I think you need the -lib in the linker command (too?).
On Feb 29, 2012 12:25 PM, André an...@s-e-a-p.de wrote:

 Hi,
 I use Mono-D and have a hello world example which compiles fine.
 I set the compiler option -lib and receives an error undefined
 reference to `_Dmain'.

 Following commands are generated for the build process:
 dmd -c main.d 
 -of/home/user/Dokumente/**MonoDevelop/HelloWorld/**HelloWorld/obj/Debug/main.o
 -I/usr/include/d/dmd/phobos -I/usr/include/d/dmd/**druntime/import
 -gc -debug -lib

 dmd -gc -debug -of/home/user/Dokumente/**MonoDevelop/HelloWorld/**
 HelloWorld/bin/Debug/**HelloWorld obj/Debug/main.o

 Do I miss an additional linux option or is the order of the commands wrong?

 Kind regards
 André



Re: UnitTest and visual D

2012-02-23 Thread Kevin Cox
I am having the same problem with visual d plugin for monodevelop.  When I
compile from the command line the tests run.

A possibly related problem is that some files do not get recompiled when
changed unless I do a rebuild.
On Feb 23, 2012 8:38 PM, Jonathan M Davis jmdavisp...@gmx.com wrote:

 On Friday, February 24, 2012 02:11:50 Chris Pons wrote:
  I am following the book The D Programming Language and am at
  the portion about functions and unittest. For some reason I
  cannot get unittest to do anything noticeable.

 If the unit tests pass, they don't print anything unless you add
 statements to
 them which do. You only get stuff being printed out on failure. This works
 particularly well for the command line (it's normal in Unix-land for stuff
 to
 print nothing on success unless them printing stuff out is their job - this
 makes it easier to pipe programs and the like). Some people complain about
 it
 from time to time, but that's the way it is. If you really want them to
 print
 something though, you can always add your own print statements.

 If you compiled with -unittest, the unit tests run before main does, so if
 all
 of your tests pass, then your program will run normally after the unit
 tests
 have been run.

 It's not uncommon for people to do something like this so that they can
 have
 the unit tests run without running their actual program:

 version(unittest) void main() {}
 else void main()
 {
  //Your normal main...
 }

 - Jonathan M Davis



Re: UnitTest and visual D

2012-02-23 Thread Kevin Cox
On Feb 23, 2012 9:41 PM, Jonathan M Davis jmdavisp...@gmx.com wrote
 There may very well be further problems due to what the IDE is doing
(such as
 not doing a full recompile when you enable -unittest), but the unit tests
 won't print anything out on success regardless unless you use print
statements
 in them

It still doesn't run them when I do a full rebuild.  In the build output I
see -unittest in the command line.  It is really weird.  I haven't looked
at it too closly.  For now I am just compiling from the command line.


Re: D runtime Garbage Collector details

2012-02-23 Thread Kevin Cox
On Feb 23, 2012 6:50 PM, Vadim vadim.goryu...@gmail.com wrote:

 I am looking for the details on D Garbage Collection implementation. I
will much appreciate if someone suggests the answers or give some links to
existing documentation clarifying the following points:

 1. Is it Mark-n-Sweep or copy or generational collector or simple
reference counting? Or anything else? Any documentation on this would be
very helpful

 2. Sun/Oracle JVM publishes a number of counters in shared memory so that
user may easily monitor the memory usage and the GC statistics real-time
without affecting the application (and without modifying the application).
Is there anything similar for D GC?

 3. Is there any performance tests of D GC efficiency? Is it possible to
write GC-predictable code (without manual allocate/free) or at least do
something like System.gc

There is quite a lot of info in the mailing list.  Off of the top of my
head I know it is a mark and sweep.  There is someone who did their Phd on
GC in D and he did a fairly good analysis of the current situation.

And as the fellow before me said, there is a garbage collector control.


Re: Weird opEquals Problem

2012-02-22 Thread Kevin Cox
Oh, ok.

First of all the docs appear somewhat misleading.  I thought that function
was an example on how to overload it.  That could be clarified a little.

Second of all, isn't that inefficient?  And  if you wanted to be able to
compare to another type you don't control?  I think it would make more
sense to have it pick the best match much like other overloads.
On Feb 22, 2012 9:05 PM, H. S. Teoh hst...@quickfur.ath.cx wrote:

 On Wed, Feb 22, 2012 at 08:51:50PM -0500, Kevin wrote:
  I have the following code which gives the same result on ldc2 and
  dmd.  If I compare two objects of different classes I always get
  false even though the comparator is called.
 [...]
  The key thing to notice is that opEquals() gets called both times.
  Any ideas about what is happening?

 It's because when A and B are different types, the compiler translates
 A==B to:

A.opEquals(B)  B.opEquals(A)

 Both parties need to agree before they are considered equal.


 T

 --
 Shin: (n.) A device for finding furniture in the dark.



Re: Let this() figure out T implicitly?

2012-02-17 Thread Kevin Cox
The error message is saying that you are trying to use Foo as a type but
Foo is not a type, it is a template for a type.
On Feb 17, 2012 7:20 AM, kraybourne st...@kraybourne.com wrote:

 Hi!

 This doesn't work:

import std.stdio;
class Foo(T)
{
T t;
this(T val)
{
t = val;
}
}

void main()
{
auto o = new Foo(5);
}
_

$ dmd foo
foo.d(13): Error: class foo.Foo(T) is used as a type
$ _

 So I must

auto o = new Foo!(int)(5);

 Then it compiles. Is it possible to have this() figure out the type some
 way? (In this particular example it's perhaps not such a big deal. But
 imagine a lot more args.)

 (Side note: What _does_ that error message mean? I don't get it.)

 thanks
 /krbrn



Re: Let this() figure out T implicitly?

2012-02-17 Thread Kevin Cox
Yes.  At least as the compiler would say.  It's a little odd but I believe
that is how the D Nam mangling works.  I personally just think of
Foo!(Class) as the type.
On Feb 17, 2012 8:05 AM, kraybourne st...@kraybourne.com wrote:

 On 2/17/12 1:51 PM, Kevin Cox wrote:

 The error message is saying that you are trying to use Foo as a type but
 Foo is not a type, it is a template for a type.


 Ah, so module.Foo is really not a class, but a template? I think I get it!
 Thanks!

 (Is then module.Foo(int).Foo the actual class type? I think I've seen
 errors like that pop up...)


  On Feb 17, 2012 7:20 AM, kraybourne st...@kraybourne.com
 mailto:st...@kraybourne.com wrote:

Hi!

This doesn't work:

import std.stdio;
class Foo(T)
{
T t;
this(T val)
{
t = val;
}
}

void main()
{
auto o = new Foo(5);
}
_

$ dmd foo
foo.d(13): Error: class foo.Foo(T) is used as a type
$ _

So I must

auto o = new Foo!(int)(5);

Then it compiles. Is it possible to have this() figure out the type
some way? (In this particular example it's perhaps not such a big
deal. But imagine a lot more args.)

(Side note: What _does_ that error message mean? I don't get it.)

thanks
/krbrn





Re: Default Implementation For an Interface

2012-02-17 Thread Kevin Cox
I wasn't looking to implement meathods in the interface, I was looking to
have a default class that implements the interface that would be created if
you called `new Interface();`  I don't think this is possible. and now that
I think about it I think that it is for a good reason.

On Fri, Feb 17, 2012 at 12:21 PM, Jacob Carlborg d...@me.com wrote:

 On 2012-02-17 18:04, Steven Schveighoffer wrote:

 On Wed, 15 Feb 2012 22:01:51 -0500, Kevin kevincox...@gmail.com wrote:

  I was implementing a framework and I found that I wanted two things.
 - A strong set of interfaces so that I can get what I want from a
 variety of sources.
 - Some basic implementations of these interfaces.

 For example, say I was writing a database class. I could either name
 the interface Database and call the class DatabaseImplementation or
 something but that is ugly. If I call the interface IDatabase, the
 Database class looks nice but I need to convince users to write
 functions that take IDatabases not Databases.

 I was wondering if there was any way to implement a default
 implementation. This way, I could create my Database interface and
 classes could implement that but if you called `new Database()` you
 would still get a basic database.


 Aside from what has been said already, if you wish to have methods that
 are not static defined in the interface, final methods currently work:

 interface I
 {
 void foo();
 final void callFoo() {writeln(about to call foo); foo(); writeln(ok,
 I called foo);}
 }

 This isn't exactly a default implementation, since you can't override
 it.


 But you could have one final method, the implementation and one virtual,
 the one you would override. It's an idea, I don't know if it's a good one.


 --
 /Jacob Carlborg