Re: Proposal for custom time string formatting in std.datetime

2011-12-26 Thread zhang
> > As for big module, my solutions are:
> > 1) put related modules into a package (or directory)
> > 2) add a module named all.d into the directory, and this module will import 
> > all the other modules publicly
> > 3) now just import the *all* module when needed
> 
> Here we have yet another example of some one who wants to use "import 
> foo.*;".
Yeah, a module is just a file. So, the file name wildcards seem can be use for 
module names.
--
Zhang 




Re: Proposal for custom time string formatting in std.datetime

2011-12-26 Thread zhang
> >
> > I really like the idea of simply adding "import myPackage;", behaving
> > like your average ".all" module.
> >
> > Doing it this way solves at least three problems: No more clunky
> > maintenance of convenience modules, big modules can later be split up
> > into a package without breaking any client code, and we don't have to
> > worry about a ".all" module for Phobos anymore (which is a suggestion
> > that has been on the table several times).
> 
> I'm not sure if I like that syntax because you wouldn't be able to tell 
> the difference between importing a package and a module. But perhaps 
> that's the point. Otherwise I agree.

The compiler should do this. A package is a directory, and a module just a file.
When importing a package, the compiler will import all the modules in the 
package.
The user doesn't care about this.
--
Zhang 




Re: Proposal for custom time string formatting in std.datetime

2011-12-24 Thread zhang
> On Fri, 23 Dec 2011 02:21:37 -, Walter Bright  
>  wrote:
> 
> > On 12/22/2011 11:25 AM, Piotr Szturmaj wrote:
> >> I wish D could support partial modules - partial as analogy to C#'s  
> >> partial
> >> classes.
> >>
> >> module std.datetime-unit1;
> >> import std.datetime-unit2;
> >> // dash allowed only in submodules with the same module name
> >> ...
> >>
> >> module std.datetime-unit2;
> >> import std.datetime-unit1;
> >> ...
> >>
> >> // then
> >>
> >> module whatever;
> >> import std.datetime; // as usual
> >
> >
> > I have no idea why anyone would want this. (Is it because the file is  
> > too big to fit on a floppy disk? )

As for big module, my solutions are:
1) put related modules into a package (or directory)
2) add a module named all.d into the directory, and this module will import all 
the other modules publicly
3) now just import the *all* module when needed

For example, we have these modules
std\datetime\all.d
std\datetime\unit1.d
std\datetime\unit2.d
std\datetime\unit3.d
in a package called std.datetime (a directory named std\datetime)

To import the datetime package, we use this:
import std.datetime.all;

So, my suggestions are:
1) can we import the *all* module defaultly (maybe it called another module 
name) ?
   Then, we can use "import std.datetime;" instead of "import 
std.datetime.all;".
2) The compiler can recognise the importing module as a package, then import 
all modules in the package automaticly (including sub-package or not ?)
   Then, we just use "import std;" to import all the modules in the standard 
package.

> 
> It's of most benefit (IMO) for the Visual Studio IDE/GUI designer code.   
> The automated code generation goes into one source file, in a partial  
> class.  The user defined code into another source file/partial class.  It  
> makes life easier for both the developer and the GUI designer code itself.

Maybe this is another thing. The "partial class" seems important for 
auto-code-generation or function-extention.

--
Zhang 



Re: ScintillaD 0.0.1

2011-11-11 Thread zhang
> Hey zhang,
> 
> I see you can now run SciteD, but it still crashes of course. Does
> ScintillaD have more bugs to fix, or just SciteD, or even both?
It's so sorry. I hasn't debugged it out why it crashes.
And I'm busy with my company's works. 
It will be a long time before continuing to work with SciteD.
It's really sorry.
--
Zhang 




Re: ScintillaD 0.0.1

2011-09-03 Thread zhang
> Zhang:
> 
> > Project url: https://bitbucket.org/heromyth/scintillad
> > Current status: Not runnable, but compilable and debuggable.
> 
> Have you found something in D/Phobos that has caused you troubles? After your 
> experience do you desire something in D/Phobos to be different?
> 
> Bye,
> bearophile
For Windows, I thinks all the strings for output should be converted to Windows 
Unicode (UTF16).
In D/Phobos, there is a function:
std.string.toStringz()
for conversion from an UTF8 string in D to null-terminated string in C/C++.

Maybe, std.utf.toUTF16z() can't support converting from an normal UTF16 string 
in D to null-terminated string in C/C++ directly.
For example:
wstring ws = "test";
const(wchar)* wsPtr = std.utf.toUTF16z(ws);

Of course, I can do it like this:
const(wchar)* wsPtr = std.utf.toUTF16z(std.utf.toUTF8(ws));
--
Zhang 




Re: ScintillaD 0.0.1

2011-09-03 Thread zhang
> "zhang"  wrote in message 
> news:mailman.2638.1314964940.14074.digitalmar...@puremagic.com...
> > ScintillaD is a D port of Scintilla which is implemented in C++.
> >
> >
> > Project url: https://bitbucket.org/heromyth/scintillad
> > Current status: Not runnable, but compilable and debuggable.
> >
> 
> Fantasic :)
> 
> Once this becomes runnable and useable, do you have any particular plans for 
> it? Any features you're planning to add that aren't in C++ Scintilla? (I'd 
> *love* to be able to have support for elastic tabstops.) Or it is simply to 
> be able to easily use Scintilla from D?
> 

To make the ScintillaD working for D is the first step. The next step is to 
implement a IDE for D like Code::Blocks for C++.
New features should be add to ScintillaD as the requirement needs more. 
--
Zhang 




Re: ScintillaD 0.0.1

2011-09-03 Thread zhang
I use VisualD as the IDE (which has two debug tools) for develop ScintillaD.

Most current bugs are caused by too much null classs objects in D which are 
defined as auto variables not points in C++. 
See this 
http://www.digitalmars.com/d/archives/digitalmars/D/How_to_new_a_class_object_in_a_struct_143658.html.

I'm fixing them. After these done, the program should be runnable.

Some functions also be commented in SciteD, maybe some of them are usable for 
running.

current debug line is:
WindowSetFocus(wEditor); 
in class SciTEWin in platform.win32.SciTEWin.

and go to this line:
EnableAMenuItem(IDM_SAVE, CurrentBuffer().isDirty);
in void CheckMenus() in class SciTEBase in scite.SciTEBase;

--
Zhang 




ScintillaD 0.0.1

2011-09-02 Thread zhang
ScintillaD is a D port of Scintilla which is implemented in C++.

Scintilla is an excellent editing component.

The GUI toolkit which ScintillaD lies on is WindowsApi on Windows.

The ScintillaD's APIs are almost identical with Scintilla's.
The changes to APIs are done mainly in order to use the properties
of D programming language.


Project url: https://bitbucket.org/heromyth/scintillad
Current status: Not runnable, but compilable and debuggable.

--
Zhang 




How to new a class object in a struct

2011-09-01 Thread zhang
Here are some codes:

class AClass
{
int a = 10;
}

struct AStruct
{
AClass aclass;

//this()  // can't do this in a struct
//{
//aclass = new AClass()
//}

this(AClass aclass_)
{
aclass = aclass_;
}
}


int main(string[] args)
{
AStruct astruct;
int a = astruct.aclass.a;
writefln("%d", a);
return 0;
}


In D, this() is prohibited in a struct. So
   AStruct astruct
will leave the aclass object to be null. It's not like the way in C++, the 
aclass object will be created automatically.

It always leads some problems when doing porting from C++ to D.

My solution is to use class instead of struct. Then I can create the aclass 
object in this() when I new an AStruct.

Any suggestion? 
Thanks.

--
Zhang 




Re: DB ORM

2011-08-12 Thread zhang
> Graham Fawcett wrote.
> > On Thu, 11 Aug 2011 20:10:15 +0800, zhang wrote:
> >
> >>> > I think D needs user defined attributes first.
> >>
> >> About attribute, here is an example:
> >>
> >> 
> >>
> >> There is a problem that is D's basic type is not nullable. In C#,
> >> the nullable integer type can be defined as "Int?" or
> >> "Nullable".
> >
> > You don't need attributes for that: you can just define a "struct
> > Nullable(T)" that wraps the value, and provides a way to express a
> > null value.
> >
> > struct Person {
> >   int ID;   // required
> >   Nullable!int age; // optional
> >   ...
> > }
> >
> > void foo(Person p) {
> >   if (p.age.isNull) ...
> >   else writeln(p.age + 100);
> > }
> >
> > Graham
> 
> Alternatively you just use a class to wrap the value:
> 
> template Nullable(T){
> static if(is(T == class)) alias T Nullable;
> else class Nullable{T v; alias v this;}
> }
> 
> 
> The benefit of this approach is that you don't have to invent new ways to 
> test for
> null values.

That's it. So, the nullable basic type is not a problem. Thanks.
--
Zhang 




Re: DB ORM

2011-08-12 Thread zhang
> You mean to indicate the attribute doesn't have a value?
Yes, the field of a table can be null in DB.
------
Zhang 




Re: DB ORM

2011-08-11 Thread zhang
> > I think D needs user defined attributes first.

About attribute, here is an example:

class ClassA
{
private int m_data;
@property int data() { return m_data; }
@property int data(int value) { return m_data = value; }
}


int main(string[] args)
{
ClassA aClass = new ClassA();

aClass.data = 22;
writefln("%d", aClass.data);

return 0;
}


There is a problem that is D's basic type is not nullable. In C#, the nullable 
integer type can be defined as "Int?" or "Nullable".

> I believe it is a lot of work for a single person to create something of  
> the quality of Hibernate. An intermediate step may be appropriate, where  
> all the automatic glue is still done by the programmer.
Have some guys started the first step works?


--
Zhang 




Re: DB ORM

2011-08-10 Thread zhang
About ORM, 
the Python has SQLObject (http://sqlobject.org/), 
the Java has Hibernate (http://www.hibernate.org/), 
and the C# has NHibernate and Entity Framework 
(http://msdn.microsoft.com/en-us/data/aa937723).

The D maybe also need one. Glad to see someone being interesting in this.
--
Zhang 




Re: What should be reterned by std.array.replaceFirst

2011-08-02 Thread zhang
> On Sat, 30 Jul 2011 07:29:54 +0800, zhang wrote:
> 
> > I tested std.array.replaceFirst with the code belown:
> > 
> > string s1 = "abc bcf";
> > 
> > string s2 = s1.replaceFirst("bc", "ee"); writefln("%s\n%s", s1, s2);
> > 
> > and got s2 is "aee". Should it be "aee bcf"?
> > 
> > Is it a bug, or just it is that?
> > 
> > Thanks.
> > --
> > Zhang 
> 
> I'd say, bug file it.
> 
> http://d.puremagic.com/issues/

Has filed a bug and offerd a patch, see here 
http://d.puremagic.com/issues/show_bug.cgi?id=6428

--
Zhang 




What should be reterned by std.array.replaceFirst

2011-07-29 Thread zhang
I tested std.array.replaceFirst with the code belown:

string s1 = "abc bcf";

string s2 = s1.replaceFirst("bc", "ee");
writefln("%s\n%s", s1, s2);

and got s2 is "aee". Should it be "aee bcf"?

Is it a bug, or just it is that?

Thanks.
--
Zhang 




Re: Ask for help about Internal error: e2ir.c 5007

2011-07-14 Thread zhang
> If you trust me, dropping the dmd.exe I emailed you in place of your 
> existing one should give you a line number and file.

Thanks for your dmd.exe. You are so kind. 
I got the error using it.
I have filed a bug at here http://d.puremagic.com/issues/show_bug.cgi?id=6317
--
Zhang 




Re: Ask for help about Internal error: e2ir.c 5007

2011-07-14 Thread zhang
> * SHAMELESS PLUG WARNING *
> 
> Until a compiler developer can look at this, you can use DustMite to help  
> identify the cause of uninformative compiler error messages:
> https://github.com/CyberShadow/DustMite
It seems a interesting tool. Thanks for your information.
--
Zhang 

l


Ask for help about Internal error: e2ir.c 5007

2011-07-13 Thread zhang
I'm porting the Scintilla (C++) to D. The module of scintilla.Editor is a big 
one which has over 10,000 lines. 
I have tried my best to get rid of all the warning and error messages emitted 
by DMD 2.054, except for one:

dmd.exe -version=WindowsXP  -g -debug-IE:\dmd\contrib\import  -c 
scintilla\Editor.d -ofobj\Debug\scintilla\Editor.obj
Internal error: e2ir.c 5007

Of course, there are many bugs hidding in the Editor.d. However, I need more 
hints from the compiler to kill the bugs.
Thanks for any help.

--
Zhang 

t


[help]operator overloading with opEquals in a class

2010-11-03 Thread zhang
This code belown can be compiled with DMD 2.050. However, it throws an error 
message: 
core.exception.HiddenFuncError: Hidden method called for main.AClass

I'm not sure about whether it is a bug. Thanks for any help.
 


import std.stdio;

class AClass
{
int data;

// It's wrong
bool opEquals(AClass a)
{
writefln("running here.");
return data == a.data;
}

// It works
//bool opEquals(Object a)
//{
//writefln("running here.");
//return data == (cast(AClass)a).data;
//}

}


int main(string[] args)
{

AClass class1 = new AClass();
AClass class2 = new AClass();

if(class1 == class2)
writefln("==");
else
writefln("!=");

return 0;
}

--
Zhang 

s