Re: Challenge Tuples

2024-04-26 Thread matheus via Digitalmars-d-learn
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote: ... Very nice, for your first example I need to think a bit because I'm bit rusty in C#, but I think it will not be as easier as D version. For the bonus part: private static void Main(string[] args){ var a = (1,2,3,(1,3),5)

Re: TIL: statically initializing an Associative Array

2024-05-06 Thread matheus via Digitalmars-d-learn
On Tuesday, 7 May 2024 at 00:10:27 UTC, Andy Valencia wrote: I had a set of default error messages to go with error code numbers, and did something along the lines of: string[uint] error_text = [ 400: "A message", 401: "A different message" ]; and got "expression is not a constant

Re: TIL: statically initializing an Associative Array

2024-05-06 Thread matheus via Digitalmars-d-learn
On Tuesday, 7 May 2024 at 01:02:04 UTC, matheus wrote: On Tuesday, 7 May 2024 at 00:10:27 UTC, Andy Valencia wrote: ... Based on what I understood and that issue, I think it was fixed: ... By the way it works as immutable too. Matheus.

Re: How to use D without the GC ?

2024-06-11 Thread matheus via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 13:00:50 UTC, Vinod K Chandran wrote: ... Similar posts that may help: https://forum.dlang.org/thread/hryadrwplyezihwag...@forum.dlang.org https://forum.dlang.org/thread/dblfikgnzqfmmglwd...@forum.dlang.org Matheus.

Re: Unexpected range assignment behaviour

2024-07-19 Thread matheus via Digitalmars-d-learn
On Friday, 19 July 2024 at 15:33:34 UTC, Dennis wrote: On Friday, 19 July 2024 at 09:34:13 UTC, Lewis wrote: But the value of $ here is 3. Why do I get a RangeError at runtime even though the slice is the correct size (and the same size as the hardcoded one that works)? The range `0 .. 3` has

Re: Segmentation fault while reading a file

2024-07-31 Thread matheus via Digitalmars-d-learn
On Wednesday, 31 July 2024 at 23:06:30 UTC, Ruby The Roobster wrote: ... or is `readln` bugging out because the file (backpack.obj contained in the linked .zip file) is too large? ... I don't have I compiler in hand to try your code at moment, but about your concern over the size of the file,

Re: Library for image editing and text insertion

2022-04-27 Thread matheus via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote: ... I know about Adam Ruppe's work, I already used his terminal.d, but I think that unfortunately most people don't and I think it should be announced more in these parts. For me arsd is for D what stb is for C. I think in the

Re: What are (were) the most difficult parts of D?

2022-05-11 Thread matheus via Digitalmars-d-learn
On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: What are you stuck at? What was the most difficult features to understand? etc. To make it more meaningful, what is your experience with other languages? Ali I don't know if this will be helpful but here it goes, my user case i

Re: Question on shapes

2022-05-16 Thread matheus via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote: ... 2) If you want to have a shape hierarchy, then you can start by defining its interface and implement that interface by concrete shape types. Drawing is ordinarily handled by member functions: ... Hi Ali, I'm not the author but I

Installing DMD on linux via snap

2022-05-18 Thread matheus via Digitalmars-d-learn
Hi, Even my problem is already solved, I'm passing this information because I don't know if you are aware. Yesterday I needed to install DMD on a fresh installed version of Linux, so since I was using Xubuntu I decided to use snap. sudo snap install dmd Then a warning appeared saying that

Re: Installing DMD on linux via snap

2022-05-18 Thread matheus via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 15:27:57 UTC, rikki cattermole wrote: Snap package source: https://github.com/dlang-snaps/dmd.snap/ Hasn't been updated in 3 years. I see... and even that I found my answer elsewhere, this problem was already discussed there: https://github.com/dlang-snaps/dmd.sn

Re: Compiler switch for integer comparison/promotion to catch a simple error

2022-05-29 Thread matheus via Digitalmars-d-learn
On Sunday, 29 May 2022 at 01:35:23 UTC, frame wrote: Is there a compiler switch to catch this kind of error? ```d ulong v = 1; writeln(v > -1); ``` IMHO the compiler should bail a warning if it sees a logic comparison between signed and unsigned / different integer sizes. There is 50% chance

Re: Compiler switch for integer comparison/promotion to catch a simple error

2022-05-30 Thread matheus via Digitalmars-d-learn
On Monday, 30 May 2022 at 13:15:12 UTC, bauss wrote: Good luck convincing Walter that this is a mistake :) I don't think this is a matter of convincing or changing the behavior, I think that a flag for this case (If not exist) should be added as a warning. A language where some people use t

Re: Comparing Exceptions and Errors

2022-06-05 Thread matheus via Digitalmars-d-learn
On Sunday, 5 June 2022 at 15:07:13 UTC, kdevel wrote: ... I would refactor the code: I really liked this one. The way it solves and at same time restrict the "external access" with that struct of (a,b) makes the code easier to maintain too. Glad I keep lurking around this forum. Matheus.

Re: Why allow initializers of non-static members that allocate?

2022-06-10 Thread matheus via Digitalmars-d-learn
On Friday, 10 June 2022 at 07:49:43 UTC, Mike Parker wrote: ... And it *is* documented: Struct fields are by default initialized to whatever the Initializer for the field is, and if none is supplied, to the default initializer for the field's type. The default initializers are evaluated at co

Re: Why allow initializers of non-static members that allocate?

2022-06-10 Thread matheus via Digitalmars-d-learn
On Saturday, 11 June 2022 at 01:52:58 UTC, Mike Parker wrote: ... That's because static arrays are allocated as part of the instance: ... Yes I understood the problem, but the naive me was thinking that in this example: struct S{ int[] arr = new int[](5); } For some reason this would

Doubt about char.min/max == typeid(char)

2022-10-06 Thread matheus via Digitalmars-d-learn
Hi, Could anyone please tell me why the properties of min/max of a char returns a "char type" and not a value as an int? I just got this while playing around: void main(){ import std.stdio; writeln(char.max); // "nothing" writeln(typeid(char.max)); // "char" writeln(cast(int)c

Re: Doubt about char.min/max == typeid(char)

2022-10-06 Thread matheus via Digitalmars-d-learn
On Friday, 7 October 2022 at 01:02:57 UTC, torhu wrote: On Friday, 7 October 2022 at 00:13:59 UTC, matheus wrote: Hi, Could anyone please tell me why the properties of min/max of a char returns a "char type" and not a value as an int? Well, why whould the highest and lowest values of a type

Re: How do I correctly install packages for use with Visual Studio?

2022-10-16 Thread matheus via Digitalmars-d-learn
On Sunday, 16 October 2022 at 11:09:31 UTC, Decabytes wrote: I'm trying to set up Visual Studio 2022 with Visual D, and I'm running into issues trying to get my project to build correctly. It's a double whammy because I've never used Visual Studio before (Just an Emacs Guy), but I need to debug

Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
Hi, I have a design question and I'd like to hear some advice. Let's say that I want to create a method to sort an array: arr.sort(asc); I think usually this would usually return a new set of that array but now sorted. But If I want to do this in the original, I think I would do this:

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
Hi H. S. Teoh, I think you misunderstood my question, since English is not my first language maybe this was a problem from my part, but anyway, I'm not talking about "sort" from main library. This example was if I had designed my "own version". Matheus.

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
On Sunday, 23 October 2022 at 16:16:55 UTC, Sergey wrote: On Sunday, 23 October 2022 at 15:47:27 UTC, matheus wrote: Hi H. S. Teoh, I think you misunderstood my question, since English is not my first language maybe this was a problem from my part, but anyway, I'm not talking about "sort" fro

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
On Sunday, 23 October 2022 at 17:36:25 UTC, Paul Backus wrote: On Sunday, 23 October 2022 at 13:32:44 UTC, matheus wrote: ... You say your idea is "like passing some argument", so why not actually pass an argument? For example: ... Hi, thanks for the example, and yes I'd like to do that,

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread matheus via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 20:12:25 UTC, Paul Backus wrote: On Tuesday, 25 October 2022 at 17:54:16 UTC, Salih Dincer wrote: On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote: It's not a bug. They're pointing to the exact same instance of `A` in memory: I don't understand? S

Re: What's the correct way of creating an instance of class in D?

2022-11-02 Thread matheus via Digitalmars-d-learn
On Thursday, 3 November 2022 at 04:41:14 UTC, Siarhei Siamashka wrote: ... https://dlang.org/spec/class.html Matheus.

Re: Comparison of two 'dynamic arrays'.

2022-11-13 Thread matheus. via Digitalmars-d-learn
On Sunday, 13 November 2022 at 15:45:40 UTC, DLearner wrote: On Sunday, 13 November 2022 at 14:39:26 UTC, Siarhei Siamashka wrote: On Sunday, 13 November 2022 at 14:28:45 UTC, DLearner wrote: Creating a step 1.5: ``` int[] B = A; ``` ```D auto B = A.dup; ``` This will create a copy of A rath

Re: Comparison of two 'dynamic arrays'.

2022-11-13 Thread matheus. via Digitalmars-d-learn
On Sunday, 13 November 2022 at 17:10:23 UTC, DLearner wrote: ... The slight generalisation shown at bottom also worked. However, is there a way of avoiding the for-loop? ... I don't have too much knowledge in D, but I think so. (My main language is C). Well, one way to make things "better"

Why am I getting different array size depending where I calling?

2022-11-14 Thread matheus via Digitalmars-d-learn
Hi all, Well my doubt is pretty much the title for the snippet below: import std.stdio; void[] getFoo(){ void[] _ = new void[int.sizeof*2]; (cast(int[])_)[0] = 2; return _; } void main() { void[] bar = new void[int.sizeof*2]; (cast(int[])bar)[0] = 1; writeln(cast(int[])bar

Re: Why am I getting different array size depending where I calling?

2022-11-14 Thread matheus via Digitalmars-d-learn
On Monday, 14 November 2022 at 21:07:42 UTC, Adam D Ruppe wrote: On Monday, 14 November 2022 at 21:00:38 UTC, matheus wrote: void[] getFoo(){ writeln(cast(int[])bar); auto foo = getFoo(); writeln(foo); Prints: [1, 0] [2, 0, 0, 0, 0, 0, 0, 0] Looking through godbolt.org the ASM gen

Re: Is defining get/set methods for every field overkill?

2022-11-17 Thread matheus via Digitalmars-d-learn
On Thursday, 17 November 2022 at 04:39:35 UTC, thebluepandabear wrote: ... It's not a lot of code that has been added but if you have a class with say 10 different fields, adding getter methods would definitely increase the code size by a lot, so what are you guys thoughts on this? Food for

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread matheus via Digitalmars-d-learn
On Friday, 18 November 2022 at 09:42:21 UTC, []() {}() wrote: ... I think you missed the point of that video very badly. By the way just a few points from that video: Around: 2:32 -> "Never ever put in an 'accessor' until it actually does something...". Around: 3:10 -> "If there is an 'acc

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread matheus via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 23:25:46 UTC, DLearner wrote: On Tuesday, 29 November 2022 at 19:06:20 UTC, rikki cattermole wrote: [...] Please see the following example: ... I think this was discussed before a few weeks ago here (But I don't remember the thread), and this is a design choic

Re: How Can i see associative array implement , is where has pseudocode write in Dlang?

2022-12-29 Thread matheus via Digitalmars-d-learn
On Thursday, 29 December 2022 at 11:24:38 UTC, lil wrote: How Can i see associative array implement , is where has pseudocode write in Dlang? Maybe this will help: https://github.com/dlang/phobos/blob/master/std/array.d Matheus.

Re: dChar Error

2022-12-30 Thread matheus via Digitalmars-d-learn
On Friday, 30 December 2022 at 10:03:20 UTC, Salih Dincer wrote: On Friday, 30 December 2022 at 09:29:16 UTC, novice2 wrote: On Friday, 30 December 2022 at 04:43:48 UTC, Salih Dincer wrote:  ...  // example one:  char[] str1 = "cur:€_".dup;  ...  // example two: dchar[] str2 = cast(dchar

Re: dChar Error

2022-12-30 Thread matheus via Digitalmars-d-learn
On Friday, 30 December 2022 at 15:28:05 UTC, Salih Dincer wrote: ... In this case, std.conv.to can be used for mutable dchars, right? For example, is this solution the right approach? ```d auto toDchar(S)(inout S str) { import std.conv : to; return str.to!(dchar[]); } void main() { auto

Re: dChar Error

2022-12-30 Thread matheus via Digitalmars-d-learn
On Friday, 30 December 2022 at 22:02:41 UTC, Ali Çehreli wrote: On 12/30/22 13:54, matheus wrote: > But yes I think it will generate a copy (mutable) based on this test: In this case it does copy but in the case of dchar[] to dchar[], there will be no copy. Similarly, there is no copy from im

Re: Address of a class object

2023-01-01 Thread matheus via Digitalmars-d-learn
On Sunday, 1 January 2023 at 09:01:24 UTC, Paul wrote: ... If the size of MyClass is 9 bytes why do MyClassO1 & O2 addresses only differ by 4 bytes? Because those addresses(4FFB20 4FFB24) are the addresses of the class **variables**, not the addresses of the **objects** themselves? Becaus

Re: Why does this code only work with `std.conv.to` whilst not with `cast`?

2023-01-08 Thread matheus via Digitalmars-d-learn
On Sunday, 8 January 2023 at 11:29:10 UTC, thebluepandabear wrote: ... There is an explanation here: https://forum.dlang.org/post/tqukutfzeaxedunuv...@forum.dlang.org But in any case I'd like to point it out that I think you could do that foreach without casting or std.conv by just omitting

Re: Why does this code only work with `std.conv.to` whilst not with `cast`?

2023-01-08 Thread matheus via Digitalmars-d-learn
On Sunday, 8 January 2023 at 12:39:37 UTC, thebluepandabear wrote: ... The `foreach` worked for that case since `bark` is a method of `IDog`. `update` is not so a conversion to `Button[]` is needed. In that case, you could do a casting like this: import std.stdio, std.conv; interface IDog

Re: Coding Challenges - Dlang or Generic

2023-01-09 Thread matheus via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 01:22:33 UTC, H. S. Teoh wrote: ... Here's a challenge. Given an input year, for example, "2023", write a program that outputs (for the corresponding year): ... The layout isn't like yours, I wrote this using a D Online compiler and I'm very sleepy right now:

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread matheus via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 05:21:15 UTC, H. S. Teoh wrote: Printing it in this format is trivial, and not very interesting. The interest in the challenge is to lay it out like I posted, side-by-side,... Like I said I did it over D online compiler which unfortunately I couldn't validate

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread matheus via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 07:38:31 UTC, Salih Dincer wrote: On Tuesday, 10 January 2023 at 03:18:54 UTC, matheus wrote: ...` You don't need validDate. Because there is daysInMonth: ... That's really better. thanks for the info. Matheus.

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread matheus via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 11:23:15 UTC, drug007 wrote: 10.01.2023 13:57, matheus пишет: ... [To clarify the situation](https://wiki.dlang.org/Component_programming_with_ranges) (H S Teoh is the author of this article) Hmm very interesting (I'm at work and I just gave it a glimpse). But

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread matheus via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 22:10:57 UTC, Paul wrote: ... I think you must have done a blog post or tutorial or something, Teoh, because I've seen this before. Don't let this go to your head :), but I was blown away by the presentation and solution! BTW where is it posted? ITT: https://

Re: Coding Challenges - Dlang or Generic

2023-01-13 Thread matheus via Digitalmars-d-learn
On Thursday, 12 January 2023 at 19:06:49 UTC, Salih Dincer wrote: ... Now, I wrote a nested class using range and copying from Matheus' code. Of course not as comprehensive as [your dcal](https://github.com/quickfur/dcal/blob/master/dcal.d). I like this one and even thought of a new challenge

Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread matheus via Digitalmars-d-learn
On Sunday, 15 January 2023 at 12:44:51 UTC, thebluepandabear wrote: ... How will the variable `outer` become the reference to the current `X` object (if that makes sense?). Does the compiler do it automatically? I think you'll need to do this: class X { private int num; struct Y {

Re: Coding Challenges - Dlang or Generic

2023-01-17 Thread matheus via Digitalmars-d-learn
On Friday, 13 January 2023 at 21:12:17 UTC, Salih Dincer wrote: On Friday, 13 January 2023 at 18:59:01 UTC, matheus wrote: Unfortunately it's not working for me Yeah, it was an old development version. I also implemented another version the same day: * [Nested Class](https://forum.dlang.or

Re: Coding Challenges - Dlang or Generic

2023-01-17 Thread matheus via Digitalmars-d-learn
On Tuesday, 17 January 2023 at 23:08:19 UTC, Siarhei Siamashka wrote: On Tuesday, 17 January 2023 at 21:50:06 UTC, matheus wrote: Question: Have you compared the timings between this way (With ranges) and a normal way (Without ranges)? If you are intensively using ranges, UFCS or the other co

Re: Coding Challenges - Dlang or Generic

2023-01-18 Thread matheus via Digitalmars-d-learn
On Wednesday, 18 January 2023 at 01:05:58 UTC, Siarhei Siamashka wrote: On Tuesday, 17 January 2023 at 23:27:03 UTC, matheus wrote: I ran in two sites: https://onecompiler.com/d and then https://godbolt.org/, with the latter I set LDC with -O2. My version (Source in the end) ran about 2x faste

Re: Coding Challenges - Dlang or Generic

2023-01-18 Thread matheus via Digitalmars-d-learn
On Wednesday, 18 January 2023 at 04:51:11 UTC, Salih Dincer wrote: On Tuesday, 17 January 2023 at 21:50:06 UTC, matheus wrote: Have you compared the timings between this way (With ranges) and a normal way (Without ranges)? Of course it is possible to speed it up. However, even as it is, it i

Re: Need some technical help an object oriented wrapper I am creating for bindbc.sfml

2023-01-26 Thread matheus via Digitalmars-d-learn
On Tuesday, 24 January 2023 at 03:42:34 UTC, thebluepandabear wrote: ... if not please tell me and I will remove this... How you would do that? Matheus.

Re: Any working REPL program on windows? DREPL doesn't compile

2023-03-23 Thread matheus via Digitalmars-d-learn
On Thursday, 23 March 2023 at 09:39:40 UTC, John Xu wrote: Anybody know any working REPL program? I failed to find a working one. https://github.com/dlang-community/drepl can't compile on my Windows 10, dub reports: ... According to their Readme: Supported OS Works on any OS with full sha

Re: Indenting standards religions K&R, whitesmiths etc

2023-05-31 Thread matheus via Digitalmars-d-learn
On Wednesday, 31 May 2023 at 16:24:38 UTC, Cecil Ward wrote: ... So my question: would I get lynched for the following? (below) ... I don't know nothing about all this but looking your example code, I write and I'd prefer to read something like this (Editing your own code): pure nothrow et

Re: Want to try out string interpolation in D?

2023-10-23 Thread matheus via Digitalmars-d-learn
On Friday, 20 October 2023 at 16:41:40 UTC, Imperatorn wrote: Here's a script to get you started ... Now try string interpolation: ```d import std.stdio; void main() { string name = "Johan"; int age = 37; int iq = 8001; int coffees = 1000; writeln(i"Your

Re: Weird bug in std.logger? Possible memory corruption

2023-11-01 Thread matheus via Digitalmars-d-learn
On Tuesday, 31 October 2023 at 21:19:34 UTC, Arafel wrote: ... Assigning the value to a variable works as expected: ```d import std.logger : info; void main() { auto s = foo(); info(s); } auto foo() { info("In foo"); return "Hello, world."; } ``` ... Unless you do: stri

Re: Weird bug in std.logger? Possible memory corruption

2023-11-01 Thread matheus via Digitalmars-d-learn
On Wednesday, 1 November 2023 at 17:26:42 UTC, Christian Köstlin wrote: ... It's really weird: https://run.dlang.io/is/fIBR2n Interesting because I wrote a similar test as you did. And that increment (Or lack of) called my attention, If I can I'll try and take a look at that (std.logger) info

Re: Advent of Code 2023

2023-12-03 Thread matheus via Digitalmars-d-learn
On Saturday, 2 December 2023 at 13:33:33 UTC, Johannes Miesenhardt wrote: On Friday, 1 December 2023 at 01:01:31 UTC, Siarhei Siamashka wrote: Advent of Code 2023 starts in a few hours from now. I suggest to discuss D language solutions here. But to avoid spoilers, it's best to do this with a 24

Doubt about Struct and members

2024-01-08 Thread matheus via Digitalmars-d-learn
Hi, I was doing some tests and this code: import std; struct S{ string[] s = ["ABC"]; int i = 123; } void foo(bool b, string str){ S t1; writeln("t1.s: ", t1.s, ", t1.s.ptr: ", t1.s.ptr, " t1.i: ", t1.i); if(b){ t1.s[0] = str; }else{ t1.s = [str];

Re: Doubt about Struct and members

2024-01-08 Thread matheus via Digitalmars-d-learn
On Monday, 8 January 2024 at 17:56:19 UTC, H. S. Teoh wrote: ... It's not recommended to use initializers to initialize mutable array-valued members, because it probably does not do what you think it does. What the above code does is to store the array ["ABC"] somewhere in the program's pre-i

Would you recommend TDPL today?

2024-01-15 Thread matheus via Digitalmars-d-learn
Hi, I'm mostly a lurker in these Forums but sometimes I post here and there, my first language was C and I still use today together with my own library (A Helper) which is like a poor version of STB (https://github.com/nothings/stb). I usually use D language sometimes as C on steroids, using A

Re: Would you recommend TDPL today?

2024-01-16 Thread matheus via Digitalmars-d-learn
On Tuesday, 16 January 2024 at 02:25:32 UTC, matheus wrote: ... I'll reply to myself but I just would like to say thanks to Jonathan M Davis and Mike Shah. I started with TDPL but I'll fill my knowledge with the other suggestions you gave me. Thanks again, Matheus.

Re: The difference between the dates in years

2024-02-10 Thread matheus via Digitalmars-d-learn
On Saturday, 10 February 2024 at 19:16:35 UTC, Alexander Zhirov wrote: ... Maybe this will help: I think if you will divide it can't be 365, but 365.242199. About your code: I having tested fully, but I found a few problems and I wrote (Again without further tests) as below: import std;

Re: The difference between the dates in years

2024-02-10 Thread matheus via Digitalmars-d-learn
On Saturday, 10 February 2024 at 22:11:48 UTC, Brad Roberts wrote: Back when I was doing lots of software developer interviews, one of my frequent questions involved date math. This wasn't because it's difficult from a coding standpoint, but that it's NOT a coding problem. The key part of the

Re: Alguien me dice como podria conectarme a una base de datos en SQL server?

2024-03-14 Thread Matheus via Digitalmars-d-learn
On Thursday, 14 March 2024 at 17:08:17 UTC, dany wrote: ... queria conectarme a SQLserver :'( You will need an ODBC driver (Bindings): https://code.dlang.org/packages/arsd-official%3Amssql Matheus.

Re: Why is this code slow?

2024-03-24 Thread matheus via Digitalmars-d-learn
On Sunday, 24 March 2024 at 19:31:19 UTC, Csaba wrote: ... Here are the results: C: 0.04s Python: 0.33s D: 0.73s ... I think a few things can be going on, but one way to go is trying using optimization flags like "-O2", and run again. But anyway, looking through Assembly generated: C: ht

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread matheus via Digitalmars-d-learn
On Friday, 29 March 2024 at 22:50:53 UTC, curiousprogramma08 wrote: ... If I'm not mistaken, like in classes "private" is module based: https://wiki.dlang.org/Access_specifiers_and_visibility Matheus.

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread matheus via Digitalmars-d-learn
On Saturday, 30 March 2024 at 02:11:25 UTC, zjh wrote: On Friday, 29 March 2024 at 22:50:53 UTC, curiousprogramma08 wrote: you can use openD. Wait a minute, they already added this modification into their language? Interesting! Matheus.

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: 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 Basi

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;

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: 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 active).

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-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 (Usin

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: 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 engi

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 a

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): https://github.com/adamdruppe/arsd/blo

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 build

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: 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 my

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: 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

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: 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 m

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 Nukem

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 want

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, on

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, in

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,

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 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 definition

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: 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 a

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 compile

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

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: std.conv.ConvException@/

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 = (1.1).to

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-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 handli

  1   2   >