Re: Ncurses deprecated ~master issue

2015-02-11 Thread Paul via Digitalmars-d-learn

On Tuesday, 10 February 2015 at 23:39:56 UTC, Adam D. Ruppe wrote:

On Tuesday, 10 February 2015 at 21:11:14 UTC, Paul wrote:
Yes, I noted the default values, even if I don't understand 
what they do at present(!).


They allow overriding of the input/output files. fdIn normally 
refers to standard input, fdOut refers to standard output, and 
the getSizeOverride lets you provide a custom function instead 
of the default, which is to ask the operating system for the 
size of the terminal with ioctl.



I added those options to support my detachable.d program, which 
is like GNU Screen - it can detach from the terminal and keep 
running. Instead of talking straight to the actual terminal 
files, it talks through a socket to a helper program which lets 
it be reattached on a new terminal.


How do I get/process input? Looking at the source/doc it looks 
like I should be doing something like this for an inifinite loop 
breakable with Esc but it doesn't seem to work (in urxvt or a 
plain xterm):


dchar charIn;
while(charIn != '\U001b')
{
	auto myInput = RealTimeConsoleInput(myTerm, 
ConsoleInputFlags.raw);

charIn = myInput.getch();
}


Comparing function pointers

2015-02-11 Thread Freddy via Digitalmars-d-learn


import std.stdio;

auto test1(){
void testFunc(){
}
return testFunc;
}

auto test2(){
uint a;
void testFunc(){
a=1;
}
return testFunc;
}

void main(){
writeln(test1()==test1());//true
writeln(test2()==test2());//false
}

Is the intended behavior?


Re: Ncurses deprecated ~master issue

2015-02-11 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 11 February 2015 at 18:13:10 UTC, Paul wrote:

How do I get/process input?


Construct the real time input struct outside your loop then use 
getch if you're only interested in the core keyboard ascii stuff 
or nextEvent if you want everything.


The esc key, in particular, is considered a non-character key 
event by terminal.d, so it will not be there on a simple call to 
getch(). (this might have been a mistake but is the way it is)


Search the code for void handleEvent to see an example 
function. There's various event types you can react to and to get 
the info, you do


auto specialized_event = generic_event.get!(InputEvent.Type.TYPE 
HERE);


and look at the members. character event has ev.character. 
noncharacter event has ev.key which is an enum, defined on line 
2057.


PasteEvent doesn't work perfectly so dont' rely on it. 
MouseEvent, if you opt into them, has buttons, x, y, and 
modifierState which might be available.


See the source for each struct to see more.



If you're happy with keys from the middle part of the keyboard, 
getch is the easiest way though, they are sent as simple dchars.


You can also fetch lines at a time with terminal.getline (it is 
on terminal rather than real time input because it is still 
conceptually line buffered (though the implementation turns that 
off to allow editing)).


Re: Comparing function pointers

2015-02-11 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 11 February 2015 at 18:40:05 UTC, Freddy wrote:

Is the intended behavior?


Yes. test2 returns a delegate that closes over a separate copy of 
the local variable, so the data pointer is different each time.


You can get the two pointers with .funcptr and .ptr. You'll find 
.funcptr is the same but .ptr changes.


Re: Comparing function pointers

2015-02-11 Thread ketmar via Digitalmars-d-learn
On Wed, 11 Feb 2015 18:40:03 +, Freddy wrote:

 
 import std.stdio;
 
 auto test1(){
   void testFunc(){
   }
   return testFunc;
 }
 
 auto test2(){
   uint a;
   void testFunc(){
   a=1;
   }
   return testFunc;
 }
 
 void main(){
   writeln(test1()==test1());//true writeln(test2()==test2());//false
 }
 
 Is the intended behavior?

second thing is not a function, it's a closure (fat pointer internally). 
each time you calling `test2()`, you creating new closure. so yes, this 
is intended behavior.

signature.asc
Description: PGP signature


Re: Ncurses deprecated ~master issue

2015-02-11 Thread Paul via Digitalmars-d-learn
On Wednesday, 11 February 2015 at 18:37:49 UTC, Adam D. Ruppe 
wrote:

On Wednesday, 11 February 2015 at 18:13:10 UTC, Paul wrote:

How do I get/process input?


Construct the real time input struct outside your loop then use 
getch if you're only interested in the core keyboard ascii 
stuff or nextEvent if you want everything.


The esc key, in particular, is considered a non-character key 
event by terminal.d, so it will not be there on a simple call 
to getch(). (this might have been a mistake but is the way it 
is)


Search the code for void handleEvent to see an example 
function. There's various event types you can react to and to 
get the info, you do


auto specialized_event = 
generic_event.get!(InputEvent.Type.TYPE HERE);


and look at the members. character event has ev.character. 
noncharacter event has ev.key which is an enum, defined on line 
2057.


PasteEvent doesn't work perfectly so dont' rely on it. 
MouseEvent, if you opt into them, has buttons, x, y, and 
modifierState which might be available.


See the source for each struct to see more.



If you're happy with keys from the middle part of the keyboard, 
getch is the easiest way though, they are sent as simple dchars.


You can also fetch lines at a time with terminal.getline (it is 
on terminal rather than real time input because it is still 
conceptually line buffered (though the implementation turns 
that off to allow editing)).


Perfect, thank you again for a thorough answer.


Re: Why is one d file compiled into two files object file executable.

2015-02-11 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 11 February 2015 at 08:49:40 UTC, Andre Artus wrote:
First to  mind is that in Java .class files are executable (in 
Java runtime), while object files are not.


There was a library, which could load object files with D code, 
resolve symbols and execute it.


Re: Why is one d file compiled into two files object file executable.

2015-02-11 Thread jklp via Digitalmars-d-learn
On Wednesday, 11 February 2015 at 05:08:16 UTC, Venkat Akkineni 
wrote:

Hi

I am coming from Java. What is the purpose of an object file  
why is it generated at compile time in addition to an 
executable. I know C generates an object file too, but I don't 
know what the use is.


Please point me to any detailed documentation u may have 
regarding object files.


Also does D have any facilities for dynamic code generation  
compilation ?


Thankyou
Sincerely
Venkat


It's not D-specific, every compiler for a compiled language 
produces objects:


http://en.wikipedia.org/wiki/Object_file



Re: Why is one d file compiled into two files object file executable.

2015-02-11 Thread Kagamin via Digitalmars-d-learn

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


Question about scope of @nogc

2015-02-11 Thread weaselcat via Digitalmars-d-learn

(Scope might have been a bad word choice...)

Is @nogc intended to only stop from calling functions that 
allocate with the GC, or from interacting with the GC altogether? 
Is there a technical reason that functions such as addrange, etc 
cannot be @nogc if the former since AFAIK such functions do not 
allocate.


Thanks.


Re: GC has a barbaric destroyng model, I think

2015-02-11 Thread Orvid King via Digitalmars-d-learn
On Wednesday, 11 February 2015 at 21:34:00 UTC, Andrey Derzhavin 
wrote:
   If we are using a DMD realization of destroying of 
objects, happens the following: at the calling the «destroy» 
method the calling of dtor takes place always, and then the 
object which is being destroyed is initialized by the default 
state. In other words, after calling «destroy» method, there is 
no way of getting an access to the members of the object that 
is being destroyed (it is meant, that the members are the 
references). GC works the same way.
	This approach in case of manual calling of «destroy» method 
has predictable and understandable consequences (there is no 
reasone to use the object being destroyed). But if GC performes 
the destroying of the objects, a lot of errors appear at the 
accessing to the members which are references, because some of 
them have already been destroyed (access to the members is 
realized in dtors). Such situations can be avoided, by using 
«@nogc» keyword. Howewer «@nogc» keyword doesn't protect us 
from using the references in dtors: we can assign some values 
to the refernces, we can have access to some members by the 
references and assign them some values.That is not correct in 
itself.


If GC starts destroying some group of the objects, it could be 
more correct, if the calls of dtros are occured of all objects 
in a group before phisical memory releasing. Or GC must call 
dtors of the objetcts only, which noone refers to.


The finalization order issue is one that is actually rather 
difficult, if not impossible, to solve without a precise GC. It 
gets even more complicated when you have to deal with cyclic 
references in finalizable allocations.


Re: GC has a barbaric destroyng model, I think

2015-02-11 Thread ketmar via Digitalmars-d-learn
On Wed, 11 Feb 2015 21:33:59 +, Andrey Derzhavin wrote:

 If we are using a DMD realization of destroying of objects, happens the
 following: at the calling the «destroy» method the calling of dtor takes
 place always, and then the object which is being destroyed is
 initialized by the default state. In other words, after calling
 «destroy» method, there is no way of getting an access to the members of
 the object that is being destroyed (it is meant, that the members are
 the references). GC works the same way.
   This approach in case of manual calling of «destroy» method has
 predictable and understandable consequences (there is no reasone to use
 the object being destroyed). But if GC performes the destroying of the
 objects, a lot of errors appear at the accessing to the members which
 are references, because some of them have already been destroyed (access
 to the members is realized in dtors). Such situations can be avoided, by
 using «@nogc» keyword. Howewer «@nogc» keyword doesn't protect us from
 using the references in dtors: we can assign some values to the
 refernces, we can have access to some members by the references and
 assign them some values.That is not correct in itself.
 
 If GC starts destroying some group of the objects, it could be more
 correct, if the calls of dtros are occured of all objects in a group
 before phisical memory releasing. Or GC must call dtors of the objetcts
 only, which noone refers to.

this problem has very easy solition: we should stop calling class dtors 
destructors, and rename them to finalizers.

The field is lost
Everything is lost
The black one has fallen from the sky and the towers in ruins lie

when finalizer is called, the battlefield is devastated, dead bodies lies 
everywhere, and so on. don't expect that those dead ones can still talk.

signature.asc
Description: PGP signature


GC has a barbaric destroyng model, I think

2015-02-11 Thread Andrey Derzhavin via Digitalmars-d-learn
   If we are using a DMD realization of destroying of 
objects, happens the following: at the calling the «destroy» 
method the calling of dtor takes place always, and then the 
object which is being destroyed is initialized by the default 
state. In other words, after calling «destroy» method, there is 
no way of getting an access to the members of the object that is 
being destroyed (it is meant, that the members are the 
references). GC works the same way.
	This approach in case of manual calling of «destroy» method has 
predictable and understandable consequences (there is no reasone 
to use the object being destroyed). But if GC performes the 
destroying of the objects, a lot of errors appear at the 
accessing to the members which are references, because some of 
them have already been destroyed (access to the members is 
realized in dtors). Such situations can be avoided, by using 
«@nogc» keyword. Howewer «@nogc» keyword doesn't protect us from 
using the references in dtors: we can assign some values to the 
refernces, we can have access to some members by the references 
and assign them some values.That is not correct in itself.


If GC starts destroying some group of the objects, it could be 
more correct, if the calls of dtros are occured of all objects in 
a group before phisical memory releasing. Or GC must call dtors 
of the objetcts only, which noone refers to.


Re: Cannot use the same template arguments on function as the ones on struct

2015-02-11 Thread anonymous via Digitalmars-d-learn

On Wednesday, 11 February 2015 at 22:14:44 UTC, MrSmith wrote:

http://dpaste.dzfl.pl/5f1d5d5d9e19

Instead I need to use template constraint which is less compact.
http://dpaste.dzfl.pl/571ae84d783e

Why such behavior happens?


Seems to work when you add an empty template argument list to 
`accepter()`, making it `accepter!()()`: 
http://dpaste.dzfl.pl/2ec186453907


So, compiler bug, I guess? The error message says it tried 
!()(), but explicit !()() actually works. And the empty 
template argument list should be optional anyway.


Re: How to make a Currency class from std.BigInt?

2015-02-11 Thread RuZzz via Digitalmars-d-learn

https://github.com/acmeism/RosettaCodeData/blob/master/Task/Arithmetic-Rational/D/arithmetic-rational.d


Cannot use the same template arguments on function as the ones on struct

2015-02-11 Thread MrSmith via Digitalmars-d-learn
Here I have templated struct that matches type with CborConfig 
tempate specialization


CborConfig will have more parameters in future and all of them 
will be accessed via alias members, so I've used variadic (T...) 
parameter whule matching.


---
template CborConfig(_nonSerializedAttribute)
{
struct CborConfig
{
alias nonSerializedAttribute = _nonSerializedAttribute;
}
}

/// Default non-serialized attribute type
struct NonSerialized{}

/// This CborConfig instantiation will be used by default.
alias defaultCborConfig = CborConfig!(NonSerialized, 
NonSerialized);


struct AccepterT(Config : CborConfig!(T) = defaultCborConfig, 
T...)

{
pragma(msg, T);
}

// template f379.accepter cannot deduce function from argument 
types !()()

void accepter(Config : CborConfig!(T) = defaultCborConfig, T...)()
{
pragma(msg, T);
}
---
^^^
http://dpaste.dzfl.pl/5f1d5d5d9e19

Instead I need to use template constraint which is less compact.
http://dpaste.dzfl.pl/571ae84d783e

Why such behavior happens?


Re: How to make a Currency class from std.BigInt?

2015-02-11 Thread RuZzz via Digitalmars-d-learn

With eris lib some problems, the first error:
.../.dub/packages/eris-0.0.1/eris/integer/digits.d(241): Error: 
cannot implicitly convert expression (digits.length) of type 
ulong to int


What can I import to use rational numbers?
I found it
https://github.com/dsimcha/Rational/blob/master/rational.d
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/rational.d
but I do not understand what the story ended with rational 
numbers in D.


Re: GC has a barbaric destroyng model, I think

2015-02-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 11, 2015 21:40:30 Orvid King via Digitalmars-d-learn 
wrote:
 On Wednesday, 11 February 2015 at 21:34:00 UTC, Andrey Derzhavin
 wrote:
 If we are using a DMD realization of destroying of
  objects, happens the following: at the calling the «destroy»
  method the calling of dtor takes place always, and then the
  object which is being destroyed is initialized by the default
  state. In other words, after calling «destroy» method, there is
  no way of getting an access to the members of the object that
  is being destroyed (it is meant, that the members are the
  references). GC works the same way.
  This approach in case of manual calling of «destroy» method
  has predictable and understandable consequences (there is no
  reasone to use the object being destroyed). But if GC performes
  the destroying of the objects, a lot of errors appear at the
  accessing to the members which are references, because some of
  them have already been destroyed (access to the members is
  realized in dtors). Such situations can be avoided, by using
  «@nogc» keyword. Howewer «@nogc» keyword doesn't protect us
  from using the references in dtors: we can assign some values
  to the refernces, we can have access to some members by the
  references and assign them some values.That is not correct in
  itself.
 
  If GC starts destroying some group of the objects, it could be
  more correct, if the calls of dtros are occured of all objects
  in a group before phisical memory releasing. Or GC must call
  dtors of the objetcts only, which noone refers to.

 The finalization order issue is one that is actually rather
 difficult, if not impossible, to solve without a precise GC. It
 gets even more complicated when you have to deal with cyclic
 references in finalizable allocations.

Yeah. And what it comes down to is that you don't access anything on the GC
heap from a class' finalizer, which seriously limits what you can do with
them. And yes, that can suck, but there isn't an easy solution - especially
when you take cyclical references into account. Basically, don't use class
finalizers unless you have to, and even then, only use them to access stuff
that isn't on the GC heap.

- Jonathan M Davis




Re: Cannot use the same template arguments on function as the ones on struct

2015-02-11 Thread Stefan Koch via Digitalmars-d-learn

DMD cannot overload templated and non-templated functions
an empty template argument is needed


Re: Why is one d file compiled into two files object file executable.

2015-02-11 Thread Andre Artus via Digitalmars-d-learn

On Wednesday, 11 February 2015 at 07:42:31 UTC, Kagamin wrote:
On Wednesday, 11 February 2015 at 05:08:16 UTC, Venkat Akkineni 
wrote:
I am coming from Java. What is the purpose of an object file  
why is it generated at compile time in addition to an 
executable. I know C generates an object file too, but I don't 
know what the use is.


Java uses a similar process: it has to generate .class files 
before they can be packed into a .jar file.


I thought about making that analogy myself, but then decided that 
it is likely to be more confusing than helpful. There are 
similarities, but there are also  numerous distinctions.


First to  mind is that in Java .class files are executable (in 
Java runtime), while object files are not.


A .jar file is just a organized collection of .class files (in a 
compressed container). In that sense a .jar file is perhaps more 
akin to a .lib file.


Re: How to write asia characters on console?

2015-02-11 Thread Kagamin via Digitalmars-d-learn

https://issues.dlang.org/show_bug.cgi?id=2742


Re: How to write asia characters on console?

2015-02-11 Thread Andre Artus via Digitalmars-d-learn

On Sunday, 8 February 2015 at 05:56:22 UTC, Lave Zhang wrote:

Hi,

My first D program is like this:
---
import std.stdio;

void main(string[] args)
{
dstring s1 = hello你好d;
writeln(s1);
}
---
But the output is not correct(and my console codepage is 936):

C:\D\dmd2\samples\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.exe
hello浣犲ソ

thanks.


I just tried this on my Mac(utf8) and it worked as expected. I 
see that you are using Windows, I'm not near a Win* machine right 
now, but can check later.


Re: DUSE_MYLIB12

2015-02-11 Thread Dennis Ritchie via Digitalmars-d-learn

Thanks.


DUSE_MYLIB12

2015-02-11 Thread Dennis Ritchie via Digitalmars-d-learn
Tell me, please, is it possible to set an arbitrary condition 
conditional compilation at the command prompt, type DUSE_MYLIB12 
and in the code as:


version(USE_MYLIB12) {
   .
}

And I didn't like Any DeclarationBlock or Statement that is not 
compiled in still must be syntactically correct:

http://dlang.org/version.html

It may be that using an optional library code is correct, and 
without it not?


Re: DUSE_MYLIB12

2015-02-11 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 11 February 2015 at 11:26:20 UTC, Dennis Ritchie 
wrote:
Tell me, please, is it possible to set an arbitrary condition 
conditional compilation at the command prompt, type 
DUSE_MYLIB12 and in the code as:


version(USE_MYLIB12) {
   .
}


Specify -version=USE_MYLIB12 on the command line.

And I didn't like Any DeclarationBlock or Statement that is not 
compiled in still must be syntactically correct:

http://dlang.org/version.html

It may be that using an optional library code is correct, and 
without it not?


No, that's not possible. Syntactically correct != semantically 
correct. It just means that the syntax rules of the language are 
respected, e.g. parens must be correctly nested (no [} or 
something like that). Since D libraries can't affect the syntax 
of the language, no code can be syntactically correct only in 
that library's presence.


Re: Cannot use the same template arguments on function as the ones on struct

2015-02-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 12, 2015 07:11:12 Stefan Koch via Digitalmars-d-learn 
wrote:
 DMD cannot overload templated and non-templated functions
 an empty template argument is needed

That's not actually true anymore. However, you have to be really careful
when you do it, because it pretty much always favors calling the
non-templated overload when it can, so you need to be very sure that the
right overloads are getting called with the various types. Ultimately, I
think that it's just better to templatize all of the functions and then get
the constraints right, but if the set of types that are supposed to use the
templated overload aren't even vaguely related to the non-templated
overload, then you're probably okay. However, I've found that stuff like
constness and inheritance tends to make it so that the non-templated
overload ends up being called when I want the templated one to be called.
So, in the end, it just pays to test and make sure that the right overload
gets called for the various types that are supposed to be used with them.

- Jonathan M Davis