Re: How often I should be using const? Is it useless/overrated?

2022-11-22 Thread XavierAP via Digitalmars-d-learn
On Friday, 18 November 2022 at 11:51:42 UTC, thebluepandabear wrote: A question I have been thinking about whilst using D is how often I should be using const. Many people claim that all variables should be const by default, but whether or not it is really needed is debatable and oftentimes m

Can't assign extern(C) function pointer to D variable?

2022-11-22 Thread XavierAP via Digitalmars-d-learn
I was surprised when it didn't compile, though I immediately found it understandable... Already read through https://dlang.org/spec/interfaceToC.html and https://wiki.dlang.org/Bind_D_to_C Is it really the case (that an extern(C) function pointer cannot be assigned to a D variable)? Or is it a

Re: Can't assign extern(C) function pointer to D variable?

2022-11-22 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 22 November 2022 at 21:32:43 UTC, Hipreme wrote: You need to create an alias containing your callback type. Thanks both!! I have all the pieces of the puzzle. I'm actually staying with the wrapping template solution. (Because the strongly typed one turns out too convoluted, and b

Re: Any easy way to check if an object have inherited an interface?

2019-07-23 Thread XavierAP via Digitalmars-d-learn
On Monday, 22 July 2019 at 21:34:18 UTC, solidstate1991 wrote: It seems that I've to write my own function that searches in the given object's classinfo.interfaces since I couldn't find anything related in Phobos. Do you mean...? interface I {} class C : I {} void main() { C c1;

Re: Is it possible to disallow import for certain functions?

2019-07-27 Thread XavierAP via Digitalmars-d-learn
On Saturday, 27 July 2019 at 11:54:09 UTC, BoQsc wrote: I would like to make sure that function in module that I have won't be imported, is this possible to achieve? In general, make the function private. But indeed, on your case, it is a terrible idea to define a main() function in a module

Re: 1 new

2019-08-06 Thread XavierAP via Digitalmars-d-learn
On Friday, 2 August 2019 at 18:25:28 UTC, jmh530 wrote: When I navigate to https://forum.dlang.org/ I have a message that says "1 new reply" to "your posts." Normally, I click on that "1 new reply" and find the post that's new, go to it, and the message disappears. However, it doesn't seem to g

Re: How do I execute a sql-file inside D code

2019-08-22 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 11:33:33 UTC, Anders S wrote: Use this code to check conn.exec("CREATE DATABASE IF NOT EXISTS boxweb;"); however haven't found a way to run the sql file that create the tables. The file is in the source folder I understand you're using some API to some SQL imple

Re: Is removing elements of AA in foreach loop safe?

2019-08-30 Thread XavierAP via Digitalmars-d-learn
On Thursday, 29 August 2019 at 10:11:58 UTC, berni wrote: Iterating of some structure and removing elements thereby is always errorprone and should be avoided. But: In case of AA, I've got the feeling, that it might be safe: foreach (k,v;ways) if (v.empty) ways.remove(k); Do you

Re: Is removing elements of AA in foreach loop safe?

2019-08-30 Thread XavierAP via Digitalmars-d-learn
On Thursday, 29 August 2019 at 10:11:58 UTC, berni wrote: Do you agree? Or is there a better way to achieve this? An alternative would be to reassign the AAA to the output of std.algorithm.filter()... but assignment between AAs and Ranges isn't so type-direct.

Re: Auto keyword and when to use it

2018-08-21 Thread XavierAP via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:52:17 UTC, QueenSvetlana wrote: So I can't declare class level variables with auto, correct? only local method variables? One difference between D's auto and C#'s var or C++'s auto is that the latter languages allow automatically typed declarations only for l

Re: Auto keyword and when to use it

2018-08-22 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 21:37:00 UTC, QueenSvetlana wrote: I had a misunderstanding about the keyword auto because I wrongfully believed that it made the code like Python Exactly, you are thinking still like D is Python or also dynamically typed. :) You will get when compiling errors t

Templated operator overloading

2018-08-22 Thread XavierAP via Digitalmars-d-learn
I've been trying some things to template operator overloads. The reason is that I want very similar code for different types, but I can't use polymorphism, as they're structs rather than classes. Perhaps this choice is not as advantageous as I think, and I may change this design from structs to

Re: Templated operator overloading

2018-08-22 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 13:20:01 UTC, aliak wrote: "void opOpAssign(string op, T)(ref Tthis, const ref T x)" looks like the wrong signature for opOpAssign. Oh I'll put on my stupid hat now... I realize I had copy-pasted the wrong syntax from the global function attempt, but I swear

Re: Templated operator overloading

2018-08-22 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 12:36:39 UTC, Simen Kjærås wrote: Since both your opOpAssigns match equally, the compiler throws up. The solution is to add some sort of restriction: This doesn't happen apparently: the operator has a left and a right side, even if both types define the operat

Nested template arguments

2018-08-22 Thread XavierAP via Digitalmars-d-learn
Why foo!bar!x is not understood as foo!(bar!x) but instead gives an error "multiple ! arguments are not allowed"? Precisely because multiple "!" can never belong to the same instantiation, why does the parser not understand without needing brackets that the rightmost template

Re: Nested template arguments

2018-08-22 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 14:48:57 UTC, Alex wrote: Because it could be meant as the argument to some templates to the left. Like (foo!bar)!x Sure, it would be a coincidence, if both will work. However, templates are not something where you can simply imply the associative property, I

Re: Doubt about this book: The D Programming Language

2018-12-19 Thread XavierAP via Digitalmars-d-learn
On Sunday, 16 December 2018 at 18:37:15 UTC, Marko wrote: On Amazon The D Programming Language has good reviews but it's 8 years old. So is this book still relevant today? Yes, I would recommend it. It is meant to be comprehensive but introductory, so many language or library changes since are

Return Value Optimization: specification, requirements?

2019-02-02 Thread XavierAP via Digitalmars-d-learn
I've heard here and there that D guarantees RVO, or is even specified to do so... Is it spelled out in the language specification or elsewhere? I haven't found it. Do you know the exact requirements for RVO or NRVO to be possible in theory, and to be guaranteed in practice in D? Does it depe

Re: static arrays at runtime with templates ?

2019-02-04 Thread XavierAP via Digitalmars-d-learn
On Sunday, 3 February 2019 at 16:33:48 UTC, Emil wrote: Is this for real, static arrays at runtime without manually allocating memory ? Is this legitimate or should I expect problems ? Static arrays are always allocated at run-time. It's the size of the array that must be known at compile-t

Re: static arrays at runtime with templates ?

2019-02-04 Thread XavierAP via Digitalmars-d-learn
On Monday, 4 February 2019 at 19:14:38 UTC, Emil wrote: Can std.array.staticArray build static arrays with size known only at run time ? Now that I am not overcome with enthousiasm it looks like it too needs to know the size. A static array's size must be known (or computed) at compile time

Re: Best practices of using const

2019-02-13 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 13 February 2019 at 11:32:46 UTC, envoid wrote: Is there an article that explains best practices of using const in D? Chapter 8 of Andrei Alexandrescu's book The D Programming Language.

Re: Distinguish float and integer types from string

2019-03-11 Thread XavierAP via Digitalmars-d-learn
On Saturday, 9 March 2019 at 18:11:09 UTC, Jacob Shtokolov wrote: One of the task was to take a string from STDIN and detect its type. There were a few options: Float, Integer, string and "something else" (which, I think, doesn't have any sense under the scope of the task). Another std-base

Re: Distinguish float and integer types from string

2019-03-11 Thread XavierAP via Digitalmars-d-learn
On Monday, 11 March 2019 at 15:03:39 UTC, XavierAP wrote: What compiler version are you using? I on the other hand was surprised that I needed the try-catch above, after having already checked isNumeric. The documentation claims that the conversion to int or long would truncate, but my compil

Re: Poor regex performance?

2019-04-04 Thread XavierAP via Digitalmars-d-learn
On Thursday, 4 April 2019 at 09:53:06 UTC, Julian wrote: Relatedly, how can I add custom compiler flags to rdmd, in a D script? For example, -L-lpcre Configuration variable "DFLAGS". On Windows you can specify it in the sc.ini file. On Linux: https://dlang.org/dmd-linux.html

Re: What Does @ Mean?

2019-04-08 Thread XavierAP via Digitalmars-d-learn
On Monday, 8 April 2019 at 11:58:49 UTC, Ron Tarrant wrote: And while I'm asking, does an underscore have special meaning when used either at the beginning or end of a variable name? In D, @ is used as Adam has explained as a prefix indicating attributes (either user-defined ones or, confusi

Re: Are static variables available to other static variables?

2019-04-12 Thread XavierAP via Digitalmars-d-learn
On Friday, 12 April 2019 at 10:56:32 UTC, Jamie wrote: On Friday, 12 April 2019 at 10:49:19 UTC, Jamie wrote: I was trying to declare a static variable dependent on another static variable, but it didn't work. Are static variables not known to other static variables at compile time? void main

Re: Are static variables available to other static variables?

2019-04-12 Thread XavierAP via Digitalmars-d-learn
On Friday, 12 April 2019 at 10:56:32 UTC, Jamie wrote: On Friday, 12 April 2019 at 10:49:19 UTC, Jamie wrote: I was trying to declare a static variable dependent on another static variable, but it didn't work. Are static variables not known to other static variables at compile time? void main

Re: Subtyping of an enum

2019-04-15 Thread XavierAP via Digitalmars-d-learn
On Monday, 15 April 2019 at 08:39:24 UTC, Anton Fediushin wrote: Hello! I am currently trying to add a custom `toString` method Several remarks... First of all, strings can be compared (alphabetically) as well as integers, e.g. assert("foo" > "bar") Perhaps not your use case, but worth notin

Re: Subtyping of an enum

2019-04-15 Thread XavierAP via Digitalmars-d-learn
On Monday, 15 April 2019 at 10:34:42 UTC, Anton Fediushin wrote: On Monday, 15 April 2019 at 10:06:30 UTC, XavierAP wrote: You have defined your sub-typing the opposite way that you wanted it to work: every `Enum` is an `internal`, but the other way around an `internal` may not work as an `En

Re: Subtyping of an enum

2019-04-15 Thread XavierAP via Digitalmars-d-learn
On Monday, 15 April 2019 at 10:34:42 UTC, Anton Fediushin wrote: The problem here is that I want to keep methods that are related to an enum inside of this enum for purely aesthetic and organizational purposes. ... These global functions pollute global namespace. If you have defined `x.toSt

Re: Subtyping of an enum

2019-04-15 Thread XavierAP via Digitalmars-d-learn
On Monday, 15 April 2019 at 12:38:59 UTC, XavierAP wrote: More generally you insist on modules and namespaces to be different concepts, which they are (pointlessly) for C++, but not for D (purposely). Here I should say packages instead of modules... but the general argument stays. Anyway

alias parameters, what for?

2019-05-09 Thread XavierAP via Digitalmars-d-learn
What are the benefits of alias parameters, compared to specifying the template parameters fully? https://dlang.org/spec/template.html#aliasparameters In most examples, at places in Phobos, and in Andrei's and Ali’s books, alias parameters are used for functions (in the general sense). Why this

Re: alias parameters, what for?

2019-05-09 Thread XavierAP via Digitalmars-d-learn
Thanks, I get your points. I do think they make more sense for the standard library, than in every general case (packages for specific uses). Namely, alias parameters provide absolute genericity (instead of overloading every possible use case, or else constraining the API by design), and ultima

Re: Does slicing have an effect?

2019-05-27 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 20:44:49 UTC, rikki cattermole wrote: On 22/05/2019 8:31 AM, Dennis wrote: Does slicing have an effect I'm not aware of, or is this a bug? It could have an effect if a was a struct/class via operator overloads. But in this case it should probably be a bug. It doe

Re: Proper desctructor for an class containing dynamic array of objects

2019-06-14 Thread XavierAP via Digitalmars-d-learn
On Friday, 14 June 2019 at 11:10:58 UTC, rumbu wrote: On Friday, 14 June 2019 at 07:52:24 UTC, Marco de Wild wrote: On Thursday, 13 June 2019 at 16:08:52 UTC, Mike wrote: Opposed to Java, D's member variables are static initialised. Is there any documentation about this? I find it unexpected.

Re: How does this template work?

2019-06-18 Thread XavierAP via Digitalmars-d-learn
On Sunday, 16 June 2019 at 15:11:29 UTC, Robert M. Münch wrote: How does the observerObject Template and function work? I'm struggling because both use the same name and how is the template parameter R deduced/where is it coming from? Looks like it's somehow implicitly deduced. Eponymous temp

DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
I often use a pattern of having const ref struct parameters (as in C++) but this doesn't work in the case of rvalues. The workaround of defining an overload that calls its own name is terrible. I understand there was a DIP 1016 by Manu asking for this case to work. As far as I can tell, this wa

Re: The problem with the conversion.

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 14:58:44 UTC, drug wrote: 19.06.2019 17:52, Den_d_y пишет: void load (const (char *) path) {     SDL_Surface ab = SDL_LoadBMP (path);     a = SDL_CreateTextureFromSurface (ab);     SDL_FreeSurface (ab); } try the following: ``` void load (string path) { imp

Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 12:55:09 UTC, Jonathan M Davis wrote: Even in C++, using const ref is not as good a practice as it once was, because they added move constructors, finally making object moveable. The result is that in many cases, it's actually more efficient to just copy values i

Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
Hmmm I know about move semantics, and C++11 etc. I just don't know how related all that is to my original question. :) On Wednesday, 19 June 2019 at 19:25:59 UTC, Jonathan M Davis wrote: though if I understand correctly with RVO, it may just place the return value outside of the function in th

Re: Is it possible to escape a reserved keyword in Import/module?

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 18:56:57 UTC, BoQsc wrote: I would like to make sure that my modules do not interfere with d lang. Is there any way to escape reserved words? The only reason C# allows this is for interop or code generation for other languages that use the same keyword. For examp

Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 21:06:48 UTC, XavierAP wrote: Now with an rvalue returned from get, interesting, no copy. Still, I wonder what really happened. Again, moving between stacks would still be work. And a different optimization can explain this non copy, for example inlining. My gu

Re: The problem with the conversion.

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 17:28:38 UTC, XavierAP wrote: Also, the return type of SDL_LoadBMP is a pointer, SDL_Surface* not just SDL_Surface. Or just use auto of course if you prefer: void load (string path) { import std.string : toStringz; auto ab = SDL_LoadBMP (path.toStringz);

Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Thursday, 20 June 2019 at 00:30:35 UTC, Jonathan M Davis wrote: Ultimately, if you want a function to accept both rvalues and lvalues as efficiently as posible, just templatize it and use auto ref. I'm aware of auto ref, and I've used it to solve this same problem when I had a template,

Re: Where can find fix length array memory layout document

2019-06-20 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 18 June 2019 at 12:26:14 UTC, lili wrote: Hi guys: Is the Dlang fix-length array alloc on stack? when a test writeln([1]).sizeof //16 writeln([2]).sizeof //16 Why, What is the fix-length array memory layout. You are quite confused... [...] is an array literal, not a

Re: Options for unit testing in D?

2019-06-21 Thread XavierAP via Digitalmars-d-learn
On Friday, 21 June 2019 at 04:08:42 UTC, Mike Brockus wrote: I am wondering as to what options are available for a Meson build user when unit testing? Unit tests are part of the language in D: https://dlang.org/spec/unittest.html These are compiled when you (or whatever build system you use

Re: Options for unit testing in D?

2019-06-23 Thread XavierAP via Digitalmars-d-learn
On Sunday, 23 June 2019 at 01:26:29 UTC, Mike Brockus wrote: I think we made a lot of progress, suddenly it's working and I don't need to include main. Is there a way to indicate based on console output that one executable is the tester and the other is the application? unittest blocks are

Re: assert in unittest has access to private member?

2019-06-30 Thread XavierAP via Digitalmars-d-learn
On Sunday, 30 June 2019 at 17:24:03 UTC, Robert M. Münch wrote: I have a case, with templates, where an assert in a unittest can access a private memember and I don't know how this can happen. Modules are the units of encapsulation in D: https://dlang.org/spec/attribute.html#visibility_attrib

Re: New programming paradigm

2017-09-07 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 6 September 2017 at 23:20:41 UTC, EntangledQuanta wrote: So, no body thinks this is a useful idea or is it that no one understands what I'm talking about? I think it may be a good use, although I haven't invested so much time looking into your particular application. It looks l

multi-dimensional arrays, not arrays of arrays

2017-02-18 Thread XavierAP via Digitalmars-d-learn
Does D provide anything like this? Otherwise, was this ever considered and were reasons found not to have it? I mean at least in C# (not talking about C/C++ at all) you can declare two kind of multi-dimensional arrays: T[][][] or T[,,]. The first is the same as the D ones, array of arrays of..

Re: multi-dimensional arrays, not arrays of arrays

2017-02-18 Thread XavierAP via Digitalmars-d-learn
Nice, thanks! Will check it out

FEM library?

2017-02-21 Thread XavierAP via Digitalmars-d-learn
Is there any D library for FEM (Finite Element Method, see Wikipedia) solving, meshing, etc... already existing somewhere? I'm asking because I'm considering making something in that field as a personal learning project. Depending on what can be found I can jump at some point to use a serious

Re: FEM library?

2017-02-22 Thread XavierAP via Digitalmars-d-learn
@Nicholas yes such a FEM library to be developed would heavily depend on Mir. Ilya Yaroshenko pointed me to it in another thread. I didn't know about DlangScience, thanks. Looks like there is some overlap? @Dukc thanks! Whenever in the future I'm developing for a library project or following

Recommend: IDE and GUI library

2017-02-24 Thread XavierAP via Digitalmars-d-learn
Hi I've looked at wiki.dlang.org/IDEs, and I see that Visual D is linked from dlang.org/download.html. Still I was looking for personal opinions and experiences beyond hard specs, I wonder if one of the IDEs is already dominant at least for each OS for any good reason. My requirements are qui

Re: Recommend: IDE and GUI library

2017-02-25 Thread XavierAP via Digitalmars-d-learn
On Saturday, 25 February 2017 at 20:03:17 UTC, Jacob Carlborg wrote: There's no de factor library for creating GUIs in D. If you want a native look and feel, DWT is a good option. If you want the application to look the same on all platforms, there might be other better suited alternatives. I

Re: How to enforce compile time evaluation (and test if it was done at compile time)

2017-03-01 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 1 March 2017 at 09:19:53 UTC, Christian Köstlin wrote: On 01/03/2017 00:09, Joseph Rushton Wakeling wrote: if (!__ctfe) assert(false); ... might be the best option. That shouldn't be compiled out even in -release builds. thats a nice idea! is this happening because of assert(fal

Re: Recommend: IDE and GUI library

2017-03-01 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 28 February 2017 at 06:16:08 UTC, thedeemon wrote: For me Visual-D served well for years, and for GUI on Windows I've used DFL successfully (quite nice lib, very WinForms-like, with a visual editor) and now mostly use DLangUI (on both Windows and Linux). I'm trying now DlangUI on

Re: rdmd with a file with no extension

2017-03-01 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 1 March 2017 at 16:06:20 UTC, Colin wrote: When running a small D program through rdmd, it seems the file needs a .d extension to work. It looks like the file extension is enforced: https://dlang.org/dmd-windows.html#switches Looks like a feature rather than a bug... At the comma

Re: Recommend: IDE and GUI library

2017-03-01 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 1 March 2017 at 20:00:32 UTC, thedeemon wrote: If you're building your app with VisualD (as opposed to invoking dub externally), make sure you've set up import paths in project settings properly. Thanks. With dub everything works straight forward. I just call it blindly since it

Best memory management D idioms

2017-03-05 Thread XavierAP via Digitalmars-d-learn
I was going to name this thread "SEX!!" but then I thought "best memory management" would get me more reads ;) Anyway now that I have your attention... What I want to learn (not debate) is the currently available types, idioms etc. whenever one wants deterministic memory management. Please do n

Re: Best memory management D idioms

2017-03-06 Thread XavierAP via Digitalmars-d-learn
On Monday, 6 March 2017 at 08:26:53 UTC, Eugene Wissner wrote: The memory management in D is becoming a mess. I am aware this is a hot topic, hence the opening joke. But I just want to learn what toolboxes are currently available, not really discuss how adequate they are, or how often GC is a

Re: How to compile against GitHub fork of Phobos?

2017-03-07 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 01:14:28 UTC, Q. Schroll wrote: I have a fork of the standard-library in the folder "phobos". DMD looking for the built-in phobos is specified in the configuration file (sc.ini on Windows, dmd.conf on Linux), not hardcoded. You may want to remove it from there. Whe

Re: Best memory management D idioms

2017-03-07 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 16:51:23 UTC, Kagamin wrote: There's nothing like that of C++. Don't you think New/Delete from dlib.core.memory fills the bill? for C++ style manual dynamic memory management? It looks quite nice to me, being no more than a simple malloc wrapper with constructor/d

Re: Best memory management D idioms

2017-03-07 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 18:21:43 UTC, Eugene Wissner wrote: To avoid this from the beginning, it may be better to use allocators. You can use "make" and "dispose" from std.experimental.allocator the same way as New/Delete. Thanks! looking into it. Does std.experimental.allocator have a le

DUB specify version identifier on command line?

2017-03-07 Thread XavierAP via Digitalmars-d-learn
I'm talking about the conditional compilation keyword "version", not about version strings. I've looked in DUB's help and reference [1][2] but can't seem to find how to solve my problem. On the command line it seems to be possible to specify debug identifiers, but not version identifiers. [3]

Re: Best memory management D idioms

2017-03-07 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 18:21:43 UTC, Eugene Wissner wrote: To avoid this from the beginning, it may be better to use allocators. You can use "make" and "dispose" from std.experimental.allocator the same way as New/Delete. OK I've been reading on std.experimental.allocator; it looks reall

Re: DUB specify version identifier on command line?

2017-03-08 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 8 March 2017 at 02:15:00 UTC, Nicholas Wilson wrote: Setting version identifiers is done by the `-version=ident` command line flag (this is equivalent to `version = ident` at source level) . This should therefore be settable by the "dflags" dub configuration setting. The way I w

DMD default safety command line switch

2017-03-09 Thread XavierAP via Digitalmars-d-learn
Andrei's 2010 book states that the default safety level can be changed from @system to @safe by means of a -safe command line switch, in the case of the DMD compiler. Now I've tried it and it's not recognized. Was this feature remove on purpose? I could imagine that. The default safety keeps

@safe console input?

2017-03-09 Thread XavierAP via Digitalmars-d-learn
I was surprised by a compiler message saying that std.stdio.readln() (and specifically the overload without arguments) is not safe but @system. Actually I was using it only to pause execution until the user presses Enter. So how else could I do this within a @safe environment? And more gene

can I overload operators as extension methods?

2017-03-09 Thread XavierAP via Digitalmars-d-learn
The same way as T.foo() is lowered to foo(T) if no such member is defined inside the type. It would allow me to extend 3rd party types with operator notation without wrapping them. After trying and reading the specification, looks like nuts, but just wanted to confirm. Thx

Re: @safe console input?

2017-03-09 Thread XavierAP via Digitalmars-d-learn
On Thursday, 9 March 2017 at 23:55:35 UTC, Adam D. Ruppe wrote: Just wrap it in a @trusted function. I knew this answer already of course ;) but I take it as implying that there is no other way. Actually I really wonder why std.stdio.readln() itself is not flagged @trusted. I wouldn't think

Re: DMD default safety command line switch

2017-03-09 Thread XavierAP via Digitalmars-d-learn
On Friday, 10 March 2017 at 00:48:39 UTC, Jack Stouffer wrote: Don't know the history, but as recently as a week ago Andrei has argued against such behavior has balkanizing the community. What behavior? Anyway my question is answered, thanks :)

Re: DMD default safety command line switch

2017-03-09 Thread XavierAP via Digitalmars-d-learn
On Friday, 10 March 2017 at 01:13:26 UTC, XavierAP wrote: What behavior? Anyway my question is answered, thanks :) What behavior is a rhetorical question, meaning that I don't really want it to be answered 0;)

Re: DMD default safety command line switch

2017-03-09 Thread XavierAP via Digitalmars-d-learn
On Friday, 10 March 2017 at 01:17:57 UTC, Jack Stouffer wrote: On Friday, 10 March 2017 at 01:13:26 UTC, XavierAP wrote: On Friday, 10 March 2017 at 00:48:39 UTC, Jack Stouffer wrote: Don't know the history, but as recently as a week ago Andrei has argued against such behavior has balkanizing t

Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
I do not really think it's a bad solution, to check several scalar arguments that must obey the same condition; just wondering if you have better ideas. Try to avoid modifying the function's signature and defining custom types, unless you have a really terrific idea. void calc(double in1, dou

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
Oh... please forget it What a terrible example :p I forgot why I was using pointers at all... I must have had a reason to write this in the past ???

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
On Saturday, 11 March 2017 at 12:35:42 UTC, XavierAP wrote: I do not really think it's a bad solution, to check several scalar arguments that must obey the same condition; just wondering if you have better ideas. Try to avoid modifying the function's signature and defining custom types, unless

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
On Saturday, 11 March 2017 at 13:44:30 UTC, Satoshi wrote: void calc(in double[] array...) { foreach (x; array) { } } To do what I want it should be foreach(ref x; array) -- or const ref. But also I don't want to modify the function signature, certainly in this way. In another situation yes,

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
On Saturday, 11 March 2017 at 19:15:59 UTC, H. S. Teoh wrote: What about just: foreach (const ref p; [in1, in2, in3, in4]) I would think there will be already one copy from the local parameter variables to the in situ array. Then from that one into the for each element it's ref'd al

Re: Best ways to declare associative arrays

2017-03-12 Thread XavierAP via Digitalmars-d-learn
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: string[string] change(ref string[string] arg_array){ //.. arg_array["first"] = strip(readln()); //.. arg_array["second"] = strip(readln()); //.. return def; } Nicholas clarified why your decl

Re: Code style for property

2017-03-12 Thread XavierAP via Digitalmars-d-learn
On Sunday, 12 March 2017 at 11:15:04 UTC, Nicholas Wilson wrote: On Sunday, 12 March 2017 at 10:47:35 UTC, Andrey wrote: And I want make access to read x, y and bar. Probably I should add prefix for private members, that is a question: what prefix should I use? Now I use prefix p_ (from the wor

Phobos function to check if files are identical?

2017-03-13 Thread XavierAP via Digitalmars-d-learn
It's not easy to do by hand of course, but I was wondering if there was one simple function taking two file names and just returning a bool or something like that. I haven't found it in std.file. If such a function doesn't exist in Phobos but there's a good implementation in some other librar

Re: Can you fix this code to avoid using pointers?

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Monday, 13 March 2017 at 14:47:20 UTC, H. S. Teoh wrote: On Sat, Mar 11, 2017 at 08:07:39PM +, XavierAP via Digitalmars-d-learn wrote: [...] But I still like the version with pointers ;) There's nothing wrong with using pointers in D. The fact that D alleviates most cas

Re: Declaring interfaces with a constructor

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Monday, 13 March 2017 at 02:15:21 UTC, David Zhang wrote: What it says on the tin. Is there a way to create interfaces with a constructor or must I use an abstract class. What do you want to do in your constructor? I can't think of anything that wouldn't change some state, either of the cl

Re: code folding

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Monday, 13 March 2017 at 17:29:41 UTC, Inquie wrote: I have been using static if(true) { ... junk } Indeed #region is part of the C# specification, even if it has no effect on the code. (The specification does not say anything about folding/collapsing, just about "marking sections of

Re: Phobos function to check if files are identical?

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Monday, 13 March 2017 at 17:47:09 UTC, H. S. Teoh wrote: Why it is not easy to do by hand? Sorry typo, I had intended to type "I know it is easy"

Re: code folding

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 00:38:12 UTC, Vladimir Panteleev wrote: If you have enough declarations in one file that they call for code folding, it may be better to move them to a separate module. Public imports and aliases allow doing this without breaking any code. [...] Generally speak

Re: Phobos function to check if files are identical?

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Monday, 13 March 2017 at 17:47:09 UTC, H. S. Teoh wrote: Binary comparison is easy. Just read the files by fixed-sized chunks and compare them. Follow up question... What is the best @safe way? Since File.byChunk() is @system. Just out of curiosity, I would rather use it and flag my code

Re: Phobos function to check if files are identical?

2017-03-14 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 08:12:16 UTC, Andrea Fontana wrote: First I would check if the files have different size or if they are the same file (same path, symlink, etc). Good idea. Good reason to have it in std.file. There might also be platform dependent shortcuts?

Re: Phobos function to check if files are identical?

2017-03-14 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 18:26:52 UTC, flamencofantasy wrote: import std.mmfile; auto f1 = new MmFile("file1"); auto f2 = new MmFile("file2"); return f1[] == f2[]; Nice! I don't have experience with memory-mapped files. What are the pros and cons?

Re: Sorting Assosiative Arrays and Finding Largest Common Substring

2017-03-16 Thread XavierAP via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:02:13 UTC, helxi wrote: 1. .length is of type ulong Either use auto or if needed size_t. As Thedeemon says this is an alias of ulong on 64-bit and uint on 32. https://dlang.org/spec/hash-map.html

Re: first try

2017-03-17 Thread XavierAP via Digitalmars-d-learn
On Friday, 17 March 2017 at 00:35:32 UTC, Philip Miess wrote: https://gitlab.com/pmiess/101gamesDlangComputerGames/blob/master/ aceyducy.d You don't need string literals to be verbatim (r"") in order to insert newlines as in the code (without escape sequences). All string literals behave thi

GitHub detects .d source as Makefile?

2017-03-17 Thread XavierAP via Digitalmars-d-learn
So I have put my first code even on GitHub (comments welcome :)) and GitHub seems to detect the wrong language, even if I'm not familiar with this GH feature. https://github.com/XavierAP/etc/tree/master/heatsim The repository itself ("etc") is flagged as been written in Makefile? Right now I

Re: GitHub detects .d source as Makefile?

2017-03-18 Thread XavierAP via Digitalmars-d-learn
On Saturday, 18 March 2017 at 01:33:13 UTC, David Nadlinger wrote: The code GitHub uses to infer source file languages is open-source, and – fittingly – available on GitHub: https://github.com/github/linguist You should check the issues for reports of similar D-related problems, and if ther

Re: GitHub detects .d source as Makefile?

2017-03-18 Thread XavierAP via Digitalmars-d-learn
On Saturday, 18 March 2017 at 10:52:31 UTC, XavierAP wrote: Thanks! It seems I can also override the language detection in .gitattributes, and it is now fixed :) The majority language assigned to the whole repository is fixed, but alas syntax highlighting in heatsim.d is still wrong. Looks

Re: Error: out of memory

2017-03-18 Thread XavierAP via Digitalmars-d-learn
On Saturday, 18 March 2017 at 20:39:20 UTC, StarGrazer wrote: about 2GB before it quites. It also only uses about 12% of cpu. I have 16 GB total memory and about that free. Surely dmd could do a better job? Any way to get it to do such a thing like set the maximum amount of memory it can use?

Re: Error: out of memory

2017-03-19 Thread XavierAP via Digitalmars-d-learn
On Sunday, 19 March 2017 at 20:50:50 UTC, Gand Alf wrote: just use DMD with the -m64 parameter ;) then you should get a x64 DMD No, at least afaik, then you tell DMD to make a x64 exe, but DMD itself (this particular Windows version) is still a 32-bit exe.

Re: GitHub detects .d source as Makefile?

2017-03-20 Thread XavierAP via Digitalmars-d-learn
On Sunday, 19 March 2017 at 21:53:17 UTC, Seb wrote: FWIW this has been fixed by Martin last summer, but the people at GitHub aren't very responsive. The PR is still pending :/ More info: https://trello.com/c/g9PB3ISG/233-improve-d-language-recognition-on-github https://github.com/github/ling

Re: recommend Git GUI client for Linux?

2017-03-25 Thread XavierAP via Digitalmars-d-learn
On Thursday, 2 March 2017 at 06:16:09 UTC, Patrick Schluter wrote: Here [1] is the official git page listing all GUI clients for different plartforms. I use GitExtensions[2] and I like it a lot. It works very well and all the complicated stuff can be done from the GUI interface and also from

really why module declarations?

2017-03-26 Thread XavierAP via Digitalmars-d-learn
I've perused both the spec[1] and Andrei's book, and I the idea I get is that module declarations are optional, recommended only in case of file names not being valid D names. But in the community (and Phobos) I see it's strongly recommended and used throughout. What's the reason? If the decla

  1   2   >