Re: What is the difference between enum and shared immutable?

2020-10-28 Thread matheus via Digitalmars-d-learn
On Thursday, 29 October 2020 at 01:26:38 UTC, Mike Parker wrote: enum int[] arr = [1,2,3]; someFunc(arr); This is identical to someFunc([1,2,3]); Manifest constants have no address. They are effectively aliases for their values. Hi Mike, I really didn't know about this. Thanks for the

Re: What is the difference between enum and shared immutable?

2020-10-28 Thread matheus via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 22:07:06 UTC, H. S. Teoh wrote: ... (This is why it's a bad idea to use enum with an array literal, because every time it's referenced you get a new copy of the array.) ... Could you please give an example (Snippet) about this? Matheus.

Re: Is there something I'm not getting here?

2020-10-26 Thread matheus via Digitalmars-d-learn
On Tuesday, 27 October 2020 at 02:21:39 UTC, matheus wrote: On Tuesday, 27 October 2020 at 01:26:56 UTC, James Blachly wrote: On 10/26/20 9:19 PM, Ruby The Roobster wrote: Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides

Re: Is there something I'm not getting here?

2020-10-26 Thread matheus via Digitalmars-d-learn
On Tuesday, 27 October 2020 at 01:26:56 UTC, James Blachly wrote: On 10/26/20 9:19 PM, Ruby The Roobster wrote: Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides that I don't know about? ... The error I keep getting no

Re: Question about: ("1.1").to!int;

2020-10-24 Thread matheus via Digitalmars-d-learn
On Saturday, 24 October 2020 at 04:04:18 UTC, Виталий Фадеев wrote: On Friday, 23 October 2020 at 16:59:06 UTC, matheus wrote: On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Well since the caller is

Re: Question about: ("1.1").to!int;

2020-10-23 Thread matheus via Digitalmars-d-learn
On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Since (1.1).to!int = 1, shouldn't the string value ("1.1").to!int at least try to convert to float/double and then to int? The thing is, that's a great way

Re: Question about: ("1.1").to!int;

2020-10-23 Thread matheus via Digitalmars-d-learn
On Friday, 23 October 2020 at 08:09:13 UTC, Виталий Фадеев wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c =

Question about: ("1.1").to!int;

2020-10-21 Thread matheus via Digitalmars-d-learn
Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c = (1.1).to!int; // this works and c = 1 auto d = ("1.1").to!int; // Doesn't work } The forth line gives me:

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread matheus via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 12:06:00 UTC, drug wrote: There are two other way: ... // using foreach foreach (i; 0..a.length) write(a[i], ", "); ... Yes you can use foreach, but in this case will not act the way the OP wanted. In his for loop example the "i" is incremented

Re: Compiler is calling `_memset64` in betterC

2020-10-19 Thread matheus via Digitalmars-d-learn
On Sunday, 18 October 2020 at 19:24:28 UTC, Ferhat Kurtulmuş wrote: I plan to start a project in reasonable size, I wonder if I should really use betterC... if I encounter a bug like this, will I be stuck at it? The bug report says, it is a dmd specific problem, and LDC, my favorite d

Re: Working with pointers/adresses

2020-07-09 Thread matheus via Digitalmars-d-learn
On Thursday, 9 July 2020 at 17:24:33 UTC, matheus wrote: On Wednesday, 8 July 2020 at 20:33:39 UTC, Paul Backus wrote: import std.stdio; void main() { int i; readf("%d\n", i); // read a number ubyte* p = cast(ubyte*) i; // convert it to a pointer writeln(*p); // write the data

Re: Working with pointers/adresses

2020-07-09 Thread matheus via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 20:33:39 UTC, Paul Backus wrote: import std.stdio; void main() { int i; readf("%d\n", i); // read a number ubyte* p = cast(ubyte*) i; // convert it to a pointer writeln(*p); // write the data at that address to the console } Note that this program

Re: Privatize a few members to allow messing with them #11353

2020-06-30 Thread matheus via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 20:01:43 UTC, Stanislav Blinov wrote: On Tuesday, 30 June 2020 at 19:58:05 UTC, matheus wrote: +loc.linnum = loc.linnum + incrementLoc; This works because it was declared: void linnum(uint rhs) { _linnum = rhs; } Right? Almost. Given these

Re: Privatize a few members to allow messing with them #11353

2020-06-30 Thread matheus via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 19:55:56 UTC, matheus wrote: On Tuesday, 30 June 2020 at 19:46:35 UTC, Stanislav Blinov ... @safe @nogc pure @property { const uint linnum() { return _linnum; } const uint charnum() { return _charnum; } void linnum(uint rhs) { _linnum

Re: Privatize a few members to allow messing with them #11353

2020-06-30 Thread matheus via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 19:46:35 UTC, Stanislav Blinov wrote: On Tuesday, 30 June 2020 at 19:42:57 UTC, matheus wrote: in this case this was more a style thing than anything else right? Or is there something I'm not able to see? Before the change, linnum and charnum are public variables,

Privatize a few members to allow messing with them #11353

2020-06-30 Thread matheus via Digitalmars-d-learn
Hi, I was looking the PR in DMD and I found this one: https://github.com/dlang/dmd/pull/11353/ One of the changes was: -loc.linnum += incrementLoc; +loc.linnum = loc.linnum + incrementLoc; I usually do the former and I particularly hate the later, so my question is,

Re: What would be the advantage of using D to port some games?

2020-06-24 Thread matheus via Digitalmars-d-learn
On Wednesday, 24 June 2020 at 19:46:55 UTC, IGotD- wrote: A previous game implementation in D would be interesting and if you do it you are welcome to write your about experiences here. It's hard to say what features you would take advantage in D as I haven't seen the code in C/C++. However,

Re: What would be the advantage of using D to port some games?

2020-06-24 Thread matheus via Digitalmars-d-learn
On Wednesday, 24 June 2020 at 19:14:48 UTC, IGotD- wrote: On Wednesday, 24 June 2020 at 18:53:34 UTC, matheus wrote: What I'd like to know from the experts is: What would be the advantage of using D to port such games? Can you elaborate your question a little bit more. Why would you

What would be the advantage of using D to port some games?

2020-06-24 Thread matheus via Digitalmars-d-learn
Hi, I currently use D for small CLI/Batch apps, before that I used to program in C. Despite of using D I usually program like C but with the advantage of: GC, AA, CTFE and a few classes here and there. As we can see there are a lot of old classic games source available like: DOOM, Duke

Re: How to use this forum ?

2020-05-20 Thread matheus via Digitalmars-d-learn
On Wednesday, 20 May 2020 at 20:49:52 UTC, Vinod K Chandran wrote: Hi all, I have some questions about this forum. 1. How to edit a post ? 2. How to edit a reply ? 3. How to add some code(mostly D code) in posts & replies. 4. How to add an image in posts & replies. 5. Is there a feature to mark

Re: DConf 2017 Videos

2020-04-25 Thread matheus via Digitalmars-d-learn
On Saturday, 25 April 2020 at 11:11:07 UTC, Jacob Carlborg wrote: I have previously downloaded the DConf videos. I sent them to Mike for him to upload. Thank you very much for this.

Re: DConf 2017 Videos

2020-04-24 Thread matheus via Digitalmars-d-learn
On Friday, 24 April 2020 at 21:11:48 UTC, Steven Schveighoffer wrote: ... and whomever controlled the sociomantic youtube account took down all the videos... First of all thanks for replying and... Ouch! After that I hope D Foundation learned the lesson and keep the videos themselves instead

DConf 2017 Videos

2020-04-24 Thread matheus via Digitalmars-d-learn
Hi, please could someone tell me where can I find videos from DConf 2017? I pretty sure I watched them on Youtube sometime ago, but I can't find anymore. By the way, I'm looking from one video where someone shows some "C flaws" and how to D as Better C could solve that. I think it was the

Re: Swedish letters fuck up parsing into SQL querry

2020-03-24 Thread matheus via Digitalmars-d-learn
On Monday, 23 March 2020 at 15:41:50 UTC, Adam D. Ruppe wrote: On Monday, 23 March 2020 at 15:15:12 UTC, Anders S wrote: I'm creating a connection to the db and conn.exec(sql) It depends on the library but it is almost always easier to do it right than to do it the way you are. like with

Re: How to get child class Type and members from parent class?

2019-11-20 Thread Matheus via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 13:46:07 UTC, Jacob Carlborg wrote: On Wednesday, 20 November 2019 at 10:05:11 UTC, zoujiaqing wrote: import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); } } class B :

Re: Help making a game with transparency

2019-09-28 Thread matheus via Digitalmars-d-learn
Ok, I took a look over my old projects and I found exactly what you want, by the way it's from 2012. It uses Derelict 2.0 bindings and will draw a PNG image where you can move around with cursor keys. If you want I can send you the whole project (Makefile, DLL's) and everything else to

Re: Help making a game with transparency

2019-09-27 Thread matheus via Digitalmars-d-learn
On Friday, 27 September 2019 at 21:16:07 UTC, Murilo wrote: ... Here it is, how do I make the ship have a transparent background? First: Your PNG file has transparency data information right? Second: I was Looking into the drawImage function (Line 854):

Re: Help making a game with transparency

2019-09-27 Thread matheus--- via Digitalmars-d-learn
On Friday, 27 September 2019 at 16:36:14 UTC, Murilo wrote: ...Do you know the arsd library? Yes but I use mostly terminal.d and others. On the other hand I use to code games too using SDL and OpenGL. I know for example in OpenGL you can do: glEnable(GL_ALPHA_TEST); to enable alpha channel

Re: Help making a game with transparency

2019-09-27 Thread matheus via Digitalmars-d-learn
On Friday, 27 September 2019 at 02:54:27 UTC, Murilo wrote: Hi guys, I am making a game but for some reason the sprites do not show with the transparent background that they were supposed to. I'm using the arsd library. Can anyone help me? Sorry this is a bit vague. I suppose you're using

Re: Private variables accessible from outside class

2019-08-08 Thread matheus via Digitalmars-d-learn
On Thursday, 8 August 2019 at 15:51:45 UTC, Drobet wrote: ... My question is if this is intended behavior, and if yes, why? This is true if the class is inside the same module: "Private means that only members of the enclosing class can access the member, or members and functions in the same

Re: Question about ubyte x overflow, any safe way?

2019-08-05 Thread matheus via Digitalmars-d-learn
On Monday, 5 August 2019 at 01:41:06 UTC, Ali Çehreli wrote: ... Two examples with foreach and ranges. The 'ubyte.max + 1' expression is int. The compiler casts to ubyte (because we typed ubyte) in the foreach and we cast to ubyte in the range: ... Maybe it was a bad example of my part

Re: Question about ubyte x overflow, any safe way?

2019-08-04 Thread matheus via Digitalmars-d-learn
On Sunday, 4 August 2019 at 18:38:34 UTC, Paul Backus wrote: ... Use std.experimental.checkedint: import std.stdio; import std.experimental.checkedint; void main() { for(Checked!(ubyte, Throw) u = ubyte(250); u < 256; ++u) { writeln(u.get); } } An exception will be thrown when

Re: Question about ubyte x overflow, any safe way?

2019-08-04 Thread matheus via Digitalmars-d-learn
On Sunday, 4 August 2019 at 18:15:30 UTC, Max Haughton wrote: What do you want to do? If you just want to count to 255 then use a foreach This was just an example, what I'd like in this code is either: Get an error (exception) when overflow or even an warning (Only if "some" flag was

Question about ubyte x overflow, any safe way?

2019-08-04 Thread matheus via Digitalmars-d-learn
Hi, The snippet below will produce an "infinite loop" because obviously "ubyte u" will overflow after 255: import std.stdio; void main(){ ubyte u = 250; for(;u<256;++u){ writeln(u); } } Question: Is there a way (Flag) to prevent this? Matheus.

Re: Speed of Random Numbers

2019-08-03 Thread matheus via Digitalmars-d-learn
On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: For me the "goodness of random" is NOT important. If that's the case, you could roll your own RNG: //DMD64 D Compiler 2.072.2 import std.stdio; import std.datetime; import std.array, std.random; void main(){ ubyte x;

Re: Help me decide D or C

2019-08-01 Thread matheus via Digitalmars-d-learn
On Thursday, 1 August 2019 at 09:43:20 UTC, Kagamin wrote: On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote: 1) Improve as a programmer 2) Have fun doing programs Thats it basically. I am planning to study all "free" time I have. I am doing basically this since last year. Try

Re: Help me decide D or C

2019-07-31 Thread matheus via Digitalmars-d-learn
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: ... Should I go for C and then when I become a better programmer change to D? Should I start with D right now? ... I think it depend your intent, but right now for a beginner between C and D I would go with C, because as you noted

Re: Blog Post #0050: MVC III - ComboBoxText, Add & Remove

2019-07-05 Thread matheus via Digitalmars-d-learn
On Friday, 5 July 2019 at 09:34:08 UTC, Ron Tarrant wrote: Today is a bit of a milestone for the blog as the 50th regular post goes up. Also, the facelift is coming along nicely, the next phase of which should be ready to push by July 9th. And today's topic continues with the MVC series by

Re: create and initialise array

2019-06-19 Thread matheus via Digitalmars-d-learn
On Thursday, 20 June 2019 at 01:06:09 UTC, Alex wrote: Is there a way of creating and initialising a dynamic array ? for example I am doing this: auto arr = new float[]; arr[] = 0.0f; Profiling indicates that the compiler (gdc) is spending significant time memsetting the whole array to

Re: Reuse/reset dynamic rectangular array?

2019-05-25 Thread matheus via Digitalmars-d-learn
On Saturday, 25 May 2019 at 14:28:24 UTC, Robert M. Münch wrote: How can I reset a rectangualr array without having to loop through it? int[][] myRectData = new int[][](10,10); myRectData.length = 0; myRectData[].length = 0; myRectData[][].length = 0; They all give:

Re: Performance of tables slower than built in?

2019-05-21 Thread matheus via Digitalmars-d-learn
On Wednesday, 22 May 2019 at 00:55:37 UTC, Adam D. Ruppe wrote: On Wednesday, 22 May 2019 at 00:22:09 UTC, JS wrote: I am trying to create some fast sin, sinc, and exponential routines to speed up some code by using tables... but it seems it's slower than the function itself?!? There's

Re: Struct destructor

2019-03-02 Thread Matheus via Digitalmars-d-learn
On Saturday, 2 March 2019 at 11:32:53 UTC, JN wrote: ... Is this proper behavior? I'd imagine that when doing foos.remove("bar"), Foo goes out of scope and should be immediately cleaned up rather than at the end of the scope? Or am I misunderstanding how should RAII work?

Re: How to cast arrays?

2019-03-01 Thread Matheus via Digitalmars-d-learn
On Saturday, 2 March 2019 at 02:14:01 UTC, Murilo wrote: How do I cast a ubyte[] into uint[]? It keeps raising an error, I have read the documentation saying there are restrictions for that concerning the length of the arrays. By the way here is how: void foo(){ ubyte[] x = [1,2]; auto

Re: How to cast arrays?

2019-03-01 Thread Matheus via Digitalmars-d-learn
On Saturday, 2 March 2019 at 02:14:01 UTC, Murilo wrote: How do I cast a ubyte[] into uint[]? It keeps raising an error, I have read the documentation saying there are restrictions for that concerning the length of the arrays. https://dlang.org/spec/expression.html#cast_expressions "Casting

Re: Modulo that 'wraps' the number?

2019-01-21 Thread Matheus via Digitalmars-d-learn
On Monday, 21 January 2019 at 18:39:27 UTC, Steven Schveighoffer wrote: Not a Python user, just hoping to help answer questions :) Yes I know in fact I'm not the OP but from what I understood from his post, he want to replicate, but I may be wrong. If it's the case, this code may help him:

Re: Modulo that 'wraps' the number?

2019-01-21 Thread Matheus via Digitalmars-d-learn
On Monday, 21 January 2019 at 15:01:27 UTC, Steven Schveighoffer wrote: Probably, this optimizes into better code, but maybe the optimizer already does this with the expression above: auto tmp = n % 3; if(tmp < 0) tmp += 3; It's just not a nice single expression. -Steve I don't think

Re: Is there a nice syntax to achieve optional named parameters?

2019-01-17 Thread Matheus via Digitalmars-d-learn
On Thursday, 17 January 2019 at 16:55:33 UTC, SrMordred wrote: Yes, but there is a mistake there: alias is part of the template: foo(alias x)(){} //note extra parens than u call like an template: foo!"a"; //equivalent = foo!("a")(); foo!1; I see now and thanks. Matheus.

Re: Is there a nice syntax to achieve optional named parameters?

2019-01-17 Thread Matheus via Digitalmars-d-learn
On Thursday, 17 January 2019 at 01:43:42 UTC, SrMordred wrote: Let me throw this idea here: ... I usually do this too, I like to use struct and then in another language I use reflection do optimize binding. Anyway I understood all your code, except for this "alias code" auto NewWindow(