Re: dlang.org/Learn "hello_world".sort.chain ...
On Tuesday, 26 December 2023 at 11:19:29 UTC, Sergey wrote: Use typeid, instead of typeof Thanks! Got quite a type but I will worry about that later: std.range.SortedRange!(Result, "a < b").SortedRange
TDPL book and __traits(compiles...) snippet
In section 6.2 of The D Programming Language it talks about how the compiler will try and tell if you are going to use a null reference. It gives this code snippet below to demonstrate that. But with DMD v2.096.1-dirty I am getting that the compiler thinks the code is OK. With a "!" the assert fails. class A { int x; } A a; assert(!__traits(compiles, a.x = 5));
Re: Error: Outside Unicode code space
On Friday, 9 July 2021 at 03:32:31 UTC, Adam D Ruppe wrote: On Friday, 9 July 2021 at 03:09:52 UTC, Tony wrote: The editor I am using (Code::Blocks) displays the characters just fine. So it seems that the error message should be "Error: Outside the ASCII code space". D supports stuff outside the ASCII code space just fine. Are you sure the file is saved as utf 8? if it is something like Windows 1252 it can still often be displayed but dmd won't know what to make of it. When I checked "Settings->Editor...->Encoding Settings" it was set to WINDOWS-1252. Changing it to UTF-8 fixed the issue. Thanks!
Error: Outside Unicode code space
I copied some text from a web page into a comment and I get the error "Error: Outside Unicode code space". This appears to be an incorrect error message. It is upset about double quotes that lean forward or backwards, and apostrophes that lean backwards. And dashes that aren't the keyboard dash character. The editor I am using (Code::Blocks) displays the characters just fine. So it seems that the error message should be "Error: Outside the ASCII code space".
Re: ChromeOS and DLang
On Thursday, 27 May 2021 at 19:39:15 UTC, Ozan Sueel wrote: Hi I think about writing apps vor ChromeOS, but before running in a death end, I ask by myself, is D a good choice for this approach? Any experience with this new upcoming operating system? New and upcoming? ChromeOS was first released 10 years ago. Are they adding something different to it?
Re: ugly and/or useless features in the language.
On Saturday, 15 May 2021 at 21:15:01 UTC, Ola Fosheim Grostad wrote: On Saturday, 15 May 2021 at 14:31:08 UTC, Alain De Vos wrote: In general it is better to have fewer features and instead improve metaprogramming so that missing features can be done in a library. Why is metaprogramming added features better than the same features added in the language? One is standard between entities, the other is not.
Re: DConf talk : Exceptions will disappear in the future?
On Tuesday, 5 January 2021 at 18:42:42 UTC, Marvin wrote: On Monday, 4 January 2021 at 15:39:50 UTC, ludo456 wrote: Listening to the first visioconf of the Dconf 2020, titled Destroy All Memory Corruption, (https://www.youtube.com/watch?v=XQHAIglE9CU) Walter talks about not using exceptions any more in the future. He says something like "this is where languages are going" [towards no using exceptions any more]. Can someone point me to an article or more explanations about that? if Exceptions disappear in the future in Dlang, I will download the last version that support exceptions and never update. I have a similar feeling. Exceptions were a great addition to programming languages in my opinion.
Re: Pro programmer
On Sunday, 25 August 2019 at 21:30:10 UTC, GreatSam4sure wrote: I am wondering as to what is the starting point of being a pro programmer. If I want to be a pro programmer what language must I start with? Most pro programmer I have heard of are all C and C++ Guru. Most of the best guys on this D forum falls into that category. I really want to know programming to the core not just tied to a language or just at the level of drag and drop or use a framework or library. I will appreciate your help in this matter. I am ready to put in hard work. I ready know a little of java, actionscrip 3.0, kotlin, D but at the surface level but can use them to write app. But I am concern with matter like how can I write a GUI toolkit from the ground up. When you say "pro programmer" are you referring to someone who programs for a living for a company, or a "top notch/very good programmer" ?
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote: My goals: 1) Improve as a programmer 2) Have fun doing programs That's it basically. I am planning to study all "free" time I have. I am doing basically this since last year. Are you only considering D and C or just mentioning them in this forum? The interpreted dynamically-typed languages like Python are considered easier to use and have the largest amount of functionality in their libraries. If it is just down to D or C, then definitely D. C would be at or near the bottom in terms of a language to have fun doing general programming and learning.
Re: Singleton in Action?
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: So, my big question is, do I instantiate like this: DSingleton singleton = new DSingleton; Or like this: DSingleton singleton = singleton.get(); And subsequent calls would be...? The same? Using get() only? This seems to be a case where D's definition of "private" can cause confusion versus examples from other languages with private as "access only inside the class". In other languages DSingleton singleton = new DSingleton; would never compile (the desired behavior), since the constructor is private. But D allows it in some cases due to "private to class OR module". If DSingleton is in the same module, as for example in a small test program with DSingleton and main() in the same file, then it compiles. So I think your code is fine, it's just that it can be circumvented - the private constructor can be called - if DSingledton and the instantiating code are in the same module.
Re: Why does nobody seem to think that `null` is a serious problem in D?
On Saturday, 1 December 2018 at 19:02:54 UTC, H. S. Teoh wrote: But that's precisely the problem. It's not always possible to tell whether a variable has been initialized. E.g.: To me, the possibility of a "false positive" doesn't preclude the use of a warning unless that possibility is large. Besides using a compiler option or pragma to get rid of it, the warning also goes away if you assign NULL or (X *) 0. Surprisingly, clang (gcc 6.3 does not give the warning) is not smart enough to then issue a "possibly dereferencing null pointer" warning. Therefore, leaving it up to the compiler to detect uninitialized variables is unreliable, and therefore any code that depends on this cannot be trusted. Code like the above could be exploited by a sufficiently sophisticated hack to make the uninitialized value of p coincide with something that will open a security hole, and the compiler would not be able to reliably warn the programmer of this problem. I don't know that "leaving it up to the compiler" is a correct characterization. I don't see the programmer doing anything different with the warning capability in the compiler than if it wasn't there. In either case, the programmer will attempt to supply values to all the variables they have declared and are intending to use, and in the correct order.
Re: Why does nobody seem to think that `null` is a serious problem in D?
On Saturday, 1 December 2018 at 11:16:49 UTC, Dukc wrote: This is great when it works, but the problem is that it would be gargantuan effort -and compile time sink- to make it work perfectly. When it's just about if-else if chains, switches or boolean logic as in the example, the analysis won't be too complicated. But swap those booleans out for a string, and make the conditions to test whether it's a phone number, and whether it satisfies some predicate implemented in a foreign language, and you'll see where the problem is. I think he is just talking about the compiler or static analyzer seeing if a variable has been given a value before it is used, not if it was given a valid value.
Re: Why does nobody seem to think that `null` is a serious problem in D?
isocpp.org just had a link to a blog post where someone makes a case for uninitialized variables in C++ being an advantage in that you can potentially get a warning regarding use of an uninitialized variable that points out an error in your code. https://akrzemi1.wordpress.com/2018/11/22/treating-symptoms-instead-of-the-cause/
Re: D is supposed to compile fast.
On Sunday, 25 November 2018 at 22:00:21 UTC, Chris Katko wrote: On Saturday, 24 November 2018 at 20:44:57 UTC, welkam wrote: On Friday, 23 November 2018 at 08:57:57 UTC, Chris Katko wrote: D is supposed to compile fast. You didnt read the fine print. It compiles simple code fast. Also compilation is separate step from linking and your program might spend half of "compilation" time in link phase. Wait wait wait wait wait. So 1) I have to compile manually, then link. Except that also runs the files every time even if they're up-to-date. Is that normal behavior for C/C++? "runs the files every time"? If that means "compiles the files every time", then no. D works exactly like C/C++ - you only need to compile-to-object-code source files in the project that have changed since the last time they were compiled.
D Language 2.1
From std.compiler.D_major and std.compiler.D_minor I see that my D language version is at 2.0 . But the version of gdc front-end I am using (via Debian default gdc package as of a few months ago) from std.compiler.version_major and std.compiler.version_minor is at 2.68 . That is a lot of bug fixes, with 0 changes to the language. Actually, I realize that changes to the language are being reflected in compiler versions, not language versions. Just wondering why it was decided not to version the language (2.1, 2.2, etc.)
version(StdDoc)
In std.compiler there is this code: /// Which vendor produced this compiler. version(StdDdoc) Vendor vendor; else version(DigitalMars) Vendor vendor = Vendor.digitalMars; else version(GNU) Vendor vendor = Vendor.gnu; else version(LDC) Vendor vendor = Vendor.llvm; else version(D_NET) Vendor vendor = Vendor.dotNET; else version(SDC) Vendor vendor = Vendor.sdc; else Vendor vendor = Vendor.unknown; What is the situation in which the identifier StdDoc is set?
Re: Who can stop it ? Help me,thank you.
On Wednesday, 17 October 2018 at 14:06:49 UTC, FrankLike wrote: Where can get the new dmd or ldc2 that's no 'Trojan horse virus' ? https://dlang.org/download.html
Re: Why is it hard to make Qt bindings?
On Thursday, 5 July 2018 at 12:52:49 UTC, Steven Schveighoffer wrote: On 7/5/18 4:42 AM, drug wrote: There were several attempts to make Qt binding for dlang, but either they has failed or has been stalled. It would be nice to collect that experience. Considering 2.081 supports C++ special member (not all but majority) isn't it time to make another attempt or the problem is more complex? Could you publish your experience in making Qt bindings here? I'm not a Qt user, but doesn't Qt require a special pre-compiler, or even use the preprocessor in a way that is difficult to duplicate in D? Qt does have it's own pre-processor, but CopperSpice, a fork of Qt does not require that. http://www.copperspice.com/
Re: Passing directory as compiler argument not finding file
On Friday, 13 April 2018 at 12:46:32 UTC, Cym13 wrote: On Friday, 13 April 2018 at 01:27:06 UTC, Tony wrote: I think that the typical model (at least in other languages) is to only compile one D source file at a time. Compile the b.d file with the -c option to create an object file. Then put the object file in a library file (either static (easier) or dynamic). Then you can use the -L compiler option to specify the directory of the library and the -l compiler option to specify the library (library name is shortened - libb.a referenced as -lb). Regardless of whether that would work or not this is the opposite of what's recommended in D. D compilers expect you to compile everything at once, or at least by module. That's where it works best when it comes to optimizations etc. What does "or at least by module" mean? Is it possible to have a module that is made up of more than one source file? What information does a D compiler get when you stick a.d and b.d on the command line that it doesn't get if you compile a.d and import b.d ?
Re: Passing directory as compiler argument not finding file
On Thursday, 12 April 2018 at 07:48:28 UTC, Jamie wrote: Really, it's more like: A/ a.d module A.a; import std.stdio; import B.b; void main() { writeln(f(4)); } B/ b.d module B.b; size_t f(size_t input) { return input * 2; } And in A/ I'm compiling dmd -ofoutput a.d ../B/b.d and instead I was thinking I could compile with dmd -ofoutput a.d -I../B b.d and would get the same result. The former works, the latter does not. Is there something like this that I can use or do I have to pass all the files with the direct path to them? Thanks I think that the typical model (at least in other languages) is to only compile one D source file at a time. Compile the b.d file with the -c option to create an object file. Then put the object file in a library file (either static (easier) or dynamic). Then you can use the -L compiler option to specify the directory of the library and the -l compiler option to specify the library (library name is shortened - libb.a referenced as -lb).
Re: Passing directory as compiler argument not finding file
On Thursday, 12 April 2018 at 05:39:21 UTC, Jamie wrote: Am I using the -I compiler option incorrectly? I believe so. I think it is for finding import files, not the files you are compiling. - -I=directory Look for imports also in directory
Re: Packages and module import
On Monday, 19 March 2018 at 17:29:10 UTC, Russel Winder wrote: I had assumed that a directory of modules was a package. So for example: [...] On Monday, 19 March 2018 at 17:29:10 UTC, Russel Winder wrote: To my amateur eyes, first command-line build looks like a linking of object files into a .so. The second command-line build looks like compilation is taking place. Seems like the command-line used to compile the library is missing.
Re: how to make private class member private
On Sunday, 18 March 2018 at 18:04:13 UTC, Tony wrote: On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote: D is not C++, C#, or Java. C++ uses friend to get around the issue. Java has no solution. I don't know about C#. Java has four protection levels. If you don't explicitly specify [private, protected, public] the protection level is implicitly "package-private". That means that any class in the same package can access that attribute. I believe that Java packages are identical to D packages. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/accessibility-levels C# has 6 accessibility levels: public - Access is not restricted. protected - Access is limited to the containing class or types derived from the containing class. private - Access is limited to the containing type. internal - Access is limited to the current assembly. protected internal - Access is limited to the current assembly or types derived from the containing class. private protected - Access is limited to the containing class or types derived from the containing class within the current assembly. Available since C# 7.2. What is a C# Assembly? Someone says on a forum: "An assembly is a "unit of deployment" for .NET, almost always a .exe or .dll. In C# terms, it's basically a single C# project." And also refers to https://social.msdn.microsoft.com/Forums/en-US/088ce8ed-ef9b-4dea-88b3-ca016885e26d/what-is-an-assembly-in-terms-of-c?forum=csharplanguage which says: "Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly."
Re: how to make private class member private
On Sunday, 18 March 2018 at 18:32:42 UTC, Jonathan M Davis wrote: They're similar, but there are differences. For instance, you can do package(a) in D in order to do something like put the stuff in a.b.c in package a rather than a.b. Is there a known situation where it makes sense to put module c in directory/package b - rather than directory/package a, and then tell the D compiler to treat it like it was in directory/package a?
Re: how to make private class member private
On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote: D is not C++, C#, or Java. C++ uses friend to get around the issue. Java has no solution. I don't know about C#. Java has four protection levels. If you don't explicitly specify [private, protected, public] the protection level is implicitly "package-private". That means that any class in the same package can access that attribute. I believe that Java packages are identical to D packages.
Re: How to simplify nested ifs
On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: if (source?pool?repository?directory?users) // do something That type of chain is sometimes referred to as a "train wreck" (see Law of Demeter). If this is a common lookup it could be: if (source && source.GotSomeUsers() )
Re: Do forum posts use any markup language?
On Saturday, 10 March 2018 at 18:02:48 UTC, Bogdan wrote: I'd like to distinguish between regular text and code, maybe have quotes, etc. A poster has come up with a standard way to delineate code and also show if multiple files are involved (along with an "extraction to files" program): https://forum.dlang.org/thread/ndgdqraxjkuvfsjhe...@forum.dlang.org This method now works at https://run.dlang.io
Re: std.traits.isBoolean
On Monday, 19 February 2018 at 17:22:04 UTC, Nathan S. wrote: On Monday, 19 February 2018 at 15:12:15 UTC, Tony wrote: But, assuming there is a use case for it, what if you want to restrict to a type that is either boolean, or a struct/class that can substitute for boolean - how do you do that without using the "private" BooleanTypeOf thing? In that case you can just write `is(T : bool)`. Thanks. Assuming it would substitute, that should probably be used on this page in place of BooleanTypeOf since BooleanTypeOf is not supposed to be public: https://dlang.org/library/std/traits/is_boolean.html "enum isBoolean(T) = is(BooleanTypeOf!T) && !isAggregateType!T;"
Re: std.traits.isBoolean
On Monday, 19 February 2018 at 13:47:15 UTC, Basile B. wrote: Indeed but Phobos maintainers don't want the ...TypeOf family to be documented. (https://github.com/dlang/phobos/pull/5747) Ok, thanks. But, assuming there is a use case for it, what if you want to restrict to a type that is either boolean, or a struct/class that can substitute for boolean - how do you do that without using the "private" TypeOfBoolean thing?
Re: std.traits.isBoolean
On Sunday, 18 February 2018 at 15:12:50 UTC, Mike Parker wrote: Generally, no. But with alias this, it can be: = import std.traits : BooleanTypeOf; import std.stdio : writeln; struct NoBool { int x; } struct AliasThisBool { bool b; alias b this; } void main() { static if(is(BooleanTypeOf!NoBool)) writeln("NoBool"); static if(is(BooleanTypeOf!AliasThisBool)) writeln("AliasThisBool"); } Thanks! It doesn't appear that BooleanTypeof is documented on dlang.org (outside of it's placement on the isBooleanType page). At least it isn't coming up in a "BooleanTypeOf site:dlang.org" search and not on the traits page: https://dlang.org/library/std/traits.html
std.traits.isBoolean
At https://dlang.org/library/std/traits/is_boolean.html it has: enum isBoolean(T) = is(BooleanTypeOf!T) && !isAggregateType!T; per: https://dlang.org/library/std/traits/is_aggregate_type.html isAggregateType is true for [struct, union, class, interface]. So BooleanTypeOf!T is true for structs, unions, classes and interfaces? And if yes, why is that so?
Re: std.zip size limit of 2 GB?
On Thursday, 15 February 2018 at 18:49:55 UTC, Steven Schveighoffer wrote: I think it's inherent in the zlib API. I haven't used all of the library, but the portion I did use (using zstream) uses uint for buffer sizes. Wouldn't using a uint for buffer size give a size limit of greater than 4GB? Seems like an int is in the mix somewhere.
Wiki spam
Don't know if there is a better place to report this, but the wiki attracted a spammer: https://wiki.dlang.org/The_Search_Of_Charter_Yacht_Designer https://wiki.dlang.org/User:MichelMeudell
Re: String Type Usage. String vs DString vs WString
On Monday, 15 January 2018 at 02:09:25 UTC, rikki cattermole wrote: Unicode has three main variants, UTF-8, UTF-16 and UTF-32. The size of a code point is 1, 2 or 4 bytes. I think to be technically correct, 1 (UTF-8), 2 (UTF-16) or 4 (UTF-32) bytes are referred to as "code units" and the size of a code point varies in UTF-8 and UTF-16.
Re: Rvalue references
On Sunday, 14 January 2018 at 00:55:27 UTC, Jonathan M Davis wrote: [...] It the simplest case, it means that the compiler does a bitwise copy rather than a deep copy, but in other cases, it means that the compiler is able to use the object in-place rather than creating a deep copy that it places elsewhere. If you want to know more on the topic, you can always look into C++ move constructors. They were added so that C++ could avoid a lot of unnecessary copies. D took the approach of requiring that structs be moveable (e.g. it's undefined behavior to have a struct contain a pointer to itself), which simplifies things considerably. [...] Thanks!
Re: Rvalue references
On Monday, 8 January 2018 at 23:31:27 UTC, Jonathan M Davis wrote: auto foo(T)(auto ref T t) { return t; } foo(42); will result in foo being instantiated as int foo(int t) { return t; } whereas int i; foo(i); will result in foo being instantiated as int foo(ref int t) { return t; } So, by using auto ref, a function can accept both lvalues and rvalues. And in D, rvalues get moved, not copied. What does it mean to "move" a variable/value instead of copying it? Was "auto ref" created for anything besides structs?
DUB and lib curl (-lcurl)
I am on Ubuntu 16.04. I was looking at Getting Started with DUB: http://code.dlang.org/getting_started I did the "dub init myproject" and it worked fine. Then I added dependency: ' dependency "dub" version="~>1.3.0" ' as shown in the next step. This got an error: - dub build Fetching dub 1.3.0 (getting selected version)... Performing "debug" build using dmd for x86_64. dub 1.3.0: building configuration "library"... ../../../.dub/packages/dub-1.3.0/dub/source/dub/internal/sdlang/token.d(26,2): Deprecation: struct core.time.FracSec is deprecated - FracSec has been deprecated in favor of just using Duration for the sake of simplicity ../../../.dub/packages/dub-1.3.0/dub/source/dub/internal/sdlang/token.d(26,2): Deprecation: struct core.time.FracSec is deprecated - FracSec has been deprecated in favor of just using Duration for the sake of simplicity myproject ~master: building configuration "application"... Linking... /usr/bin/ld: cannot find -lcurl collect2: error: ld returned 1 exit status Error: linker exited with status 1 dmd failed with exit code 1. - I am wondering if the tutorial should caution that "you need to have lib curl already on your system", or if I have a bad DUB install (lib curl should have been installed with DUB).
Re: Error trying to build dlang.org
On Thursday, 4 January 2018 at 02:20:32 UTC, Seb wrote: On Thursday, 4 January 2018 at 01:50:47 UTC, Tony wrote: Following the instructions here on Ubuntu 16.04: https://github.com/dlang/dlang.org/blob/master/CONTRIBUTING.md I did the command make -f posix.mak html but it failed to successfully complete: --- make[1]: Leaving directory '/home/user/dlang/dmd/src' ../dmd/generated//release//dmd -c -o- -Df/home/user/dlang/dlang.org/web/spec/spec.html macros.ddoc html.ddoc dlang.org.ddoc doc.ddoc .generated/2.078.0.ddoc .generated/dblog_latest.ddoc .generated/twid_latest.ddoc spec/spec.ddoc spec/spec.dd make: ../dmd/generated//release//dmd: Command not found posix.mak:466: recipe for target '/home/user/dlang/dlang.org/web/spec/spec.html' failed make: *** [/home/user/dlang/dlang.org/web/spec/spec.html] Error 127 1) Did you clone the `dmd` repository yourself? yes 2) Is ../dmd existent? Try nuking ../dmd and doing a fresh clone of ../dmd I forgot to check, but I deleted the dlang.org directory and tried again starting from git clone and this time it appears to have worked. Guess I should have tried that first before posting.
Error trying to build dlang.org
Following the instructions here on Ubuntu 16.04: https://github.com/dlang/dlang.org/blob/master/CONTRIBUTING.md I did the command make -f posix.mak html but it failed to successfully complete: --- make[1]: Leaving directory '/home/user/dlang/dmd/src' ../dmd/generated//release//dmd -c -o- -Df/home/user/dlang/dlang.org/web/spec/spec.html macros.ddoc html.ddoc dlang.org.ddoc doc.ddoc .generated/2.078.0.ddoc .generated/dblog_latest.ddoc .generated/twid_latest.ddoc spec/spec.ddoc spec/spec.dd make: ../dmd/generated//release//dmd: Command not found posix.mak:466: recipe for target '/home/user/dlang/dlang.org/web/spec/spec.html' failed make: *** [/home/user/dlang/dlang.org/web/spec/spec.html] Error 127
Re: How to use the -I command line switch?
On Wednesday, 3 January 2018 at 12:21:28 UTC, tipdbmp wrote: // C:\libs\my_module.d module my_module; void foo() {} // main.d module main; import my_module; void main() { foo(); } Running dmd with: dmd -IC:\libs main.d my_module.d I get: Error: module my_module is in file 'my_module.d' which cannot be read import path[0] = C:\libs import path[1] = path\to\dmd\D\dmd2\windows\bin\..\..\src\phobos import path[2] = path\to\dmd\D\dmd2\windows\bin\..\..\src\druntime\import As has already been mentioned, the -I is not used for command-line files. Just compiling (-c option) shows that the -I is enough for DMD to find the import file: dmd -c main.d -Ic:\libs successfully compiles main.d into main.obj To do a full compile and link of main without compiling my_module.d each time: C:\libs>dmd -lib -ofmy_module.lib my_module.d creates "my_module.lib". Then use it to link with in main.d compile/link: C:\code\d\forum>dmd main.d -Ic:\libs -Llib c:\libs\my_module OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 9: Unknown Option : NOILIB main.exe is created even though there is a mysterious warning.
Re: How to use the -I command line switch?
On Wednesday, 3 January 2018 at 18:35:21 UTC, Ali Çehreli wrote: On 01/03/2018 09:10 AM, tipdbmp wrote: dmd main.d C:\libs\my_module.d That does not use the -I switch. It compiles if I specify the full path to my_module.d: dmd -IC:\libs main.d C:\libs\my_module.d I don't understand the error message though. -I is for import directives only. imports are needed to compile the importing module. All other modules still need to be compiled themselves and added to the program either as individual .o files or as libraries (e.g. .a, .lib, etc.). The method you've shown is a shorthand for "compile each to .o and add each to the program." Working as expected... :) What about the error message? If -I is only for DMD finding "import ..." files, and not files on the command line, why does DMD list what was in the -I "where to look for import directives" when saying that it can't find a command-line file? It says that it can't locate my_module.d and then lists the directory that my_module.d is in.
Re: Slices and Dynamic Arrays
On Monday, 1 January 2018 at 02:10:14 UTC, Jonathan M Davis wrote: The DLang Tour should probably be fixed to use the term dynamic array though. Or embrace both terms but take care that it is clear that they are synonyms and one may be preferred depending on context. As a beginner, I had some confusion seeing both terms used. There is dual terminology in use outside of dlang.org. The book Programming In D says: Slice: Another name for dynamic array. When I write slice I will specifically mean a slice; and when I write array, I will mean either a slice or a fixed-length array, with no distinction. Slices Slices are the same feature as dynamic arrays. They are called dynamic arrays for being used like arrays, and are called slices for providing access to portions of other arrays. They allow using those portions as if they are separate arrays. ---
Re: How do you safely deal with range.front?
On Sunday, 31 December 2017 at 13:14:10 UTC, aliak wrote: On Sunday, 31 December 2017 at 01:03:17 UTC, Tony wrote: For me, front() should throw a pre-defined exception when called on an empty range in order to eliminate undefined behavior. It does take some time to make a check, but D does array bounds checking by default. Ideally the front() check could be turned off somehow ("-boundschecks=off") by the user for those who want maximum speed, but I guess there is no way to do that when using pre-compiled functions in a library. That sounds like a good idea. Wouldn't the same apply to array bounds checking for precompiled functions though? Yeah, seems like the standard library must be doing one or the other (bounds checking array indexes or not bounds checking them) all the time, depending on how it was compiled. Also, is going out of array bounds well-defined behavior in D even with bounds check off? I'm no expert, but I can't think of how it could be. And any links to docs on UB in D? This thread was the first time I have heard it used with regard to D.
Re: Slices and Dynamic Arrays
On Sunday, 31 December 2017 at 14:24:40 UTC, Jonathan M Davis wrote: The D Slices article does an excellent job of explaining all of this. It's just that it calls the GC-allocated memory buffer the dynamic array instead of calling T[] the dynamic array like the language and spec do. Regardless, all non-null dynamic arrays are slices of memory. The DLang Tour also uses the term slice to refer to T[]. "The type of arr is int[], which is also called a slice." "A slice consists of two members - a pointer to the starting element and the length of the slice:"
Re: Slices and Dynamic Arrays
On Sunday, 31 December 2017 at 04:20:28 UTC, codephantom wrote: On Sunday, 31 December 2017 at 03:57:17 UTC, Tony wrote: On Sunday, 31 December 2017 at 03:08:05 UTC, Ivan Trombley wrote: double[] D = [3.14159]; Can you guess what D is? :D It took me a while but I finally came up with "a slice of pi" a slice of pi is irrational. Even on special occasions?
Re: Slices and Dynamic Arrays
On Sunday, 31 December 2017 at 03:08:05 UTC, Ivan Trombley wrote: double[] D = [3.14159]; Can you guess what D is? :D It took me a while but I finally came up with "a slice of pi"
Re: Slices and Dynamic Arrays
On Friday, 29 December 2017 at 23:13:20 UTC, Jonathan M Davis wrote: The term "slice" is a bit overused in D, meaning a variety of things. It doesn't help that some folks dislike the official terminology. In general, a slice is a contiguous group of elements. A slice of memory would be a contiguous block of memory. A dynamic array therefore refers to a slice of memory and could be called a slice, but it's also the case that using the slice operater on a container is called slicing - e.g. rbt[] would give you a range over the container rbt, and that range is a slice of the container, but it's not an array at all. For me, it is confusing to use "slice" and "dynamic array" as synonyms. My initial impression was that they must have different code underlying them, and different behavior. I would pick one or the other. It should be: D Arrays - Static - Dynamic or D Arrays - Static - Slice The DLang Tour has a section on Slices that says in bold "Slices and dynamic arrays are the same". I think that sentence deserves an explanation as to why there are two terms being utilized for the same thing. I would prefer that "slice" as a noun was used only for the time when a dynamic array was initialized from a slice of another array. Or better yet - slice was never used as a noun - only a verb or adjective: took a slice of array A to form a slice dynamic array B (or slice-intialized dynamic array B). D Arrays - Static - Dynamic - Slice-Initialized Dynamic
Re: How do you safely deal with range.front?
For me, front() should throw a pre-defined exception when called on an empty range in order to eliminate undefined behavior. It does take some time to make a check, but D does array bounds checking by default. Ideally the front() check could be turned off somehow ("-boundschecks=off") by the user for those who want maximum speed, but I guess there is no way to do that when using pre-compiled functions in a library.
Slices and Dynamic Arrays
In DLang Tour:Arrays https://tour.dlang.org/tour/en/basics/arrays there is: --- int size = 8; // run-time variable int[] arr = new int[size]; The type of arr is int[], which is a slice. --- In "D Slices" https://dlang.org/d-array-article.html there is: --- int[] a; // a is a slice Based on those two web pages it appears that the name for a dynamic arrayin D is "slice". That is, anytime you have a dynamic array (even a null reference version) it is called a slice. Is that correct?
DLang Tour : Functions as arguments
On this page: https://tour.dlang.org/tour/en/basics/delegates there is: void doSomething(int function(int, int) doer) { // call passed function doer(5,5); } doSomething(add); // use global function `add` here // add must have 2 int parameters I can't get it to compile unless it is: doSomething();
Ddoc - No Documentation
Wondering what the rationale is for this: https://dlang.org/spec/ddoc.html#no_documentation No Documentation No documentation is generated for the following constructs, even if they have a documentation comment: Invariants Postblits Destructors Static constructors and static destructors Class info, type info, and module info
Re: std.range.interfaces : InputRange moveFront
On Thursday, 30 November 2017 at 09:50:37 UTC, Tony wrote: On Thursday, 30 November 2017 at 09:47:14 UTC, Tony wrote: Thanks for the reply. Probably just missing it, but in poking around dlang.org (Language Reference and Library Reference) I am having trouble finding out about the move(), front() and moveFront() functions, as is used here on a dynamic array. That should just be front() and moveFront() used here. I ran across move() in looking at the standard library for the definitions of the other two. Found a move() here: https://dlang.org/library/std/algorithm/mutation/move.html Function std.algorithm.mutation.move
Re: std.range.interfaces : InputRange moveFront
On Thursday, 30 November 2017 at 09:47:14 UTC, Tony wrote: Thanks for the reply. Probably just missing it, but in poking around dlang.org (Language Reference and Library Reference) I am having trouble finding out about the move(), front() and moveFront() functions, as is used here on a dynamic array. That should just be front() and moveFront() used here. I ran across move() in looking at the standard library for the definitions of the other two.
Re: std.range.interfaces : InputRange moveFront
On Thursday, 30 November 2017 at 06:36:12 UTC, Ali Çehreli wrote: move is an operation that transfers the state of the source to the destination. The front element becomes its .init value and its previous values is returned by moveFront(). The important bit is that, the element is *not* copied: import std.range; struct S { int i; bool is_a_copy = false; this(this) { is_a_copy = true; } } void main() { auto r = [S(1)]; auto a = r.front; assert(a.is_a_copy); // yes, a is a copy assert(a.i == 1); // as expected, 1 assert(r.front.i == 1);// front is still 1 auto b = r.moveFront(); assert(!b.is_a_copy); // no, b is not a copy assert(b.i == 1); // state is transferred assert(r.front.i == 0);// front is int.init } Thanks for the reply. Probably just missing it, but in poking around dlang.org (Language Reference and Library Reference) I am having trouble finding out about the move(), front() and moveFront() functions, as is used here on a dynamic array.
std.range.interfaces : InputRange moveFront
What does the moveFront() method do in the InputRange interface? std.range.interfaces : InputRange.moveFront()
Re: User defined type and foreach
On Saturday, 18 November 2017 at 05:24:30 UTC, Tony wrote: Forgot to handle pre-mature foreach exit: import std.stdio : writeln; class RefRange { int foreach_index; int[] items; this(int[] src) { items = src; } bool empty() { if (foreach_index == items.length) { foreach_index = 0; // reset for another foreach return true; } return false; } int front() { return items[foreach_index]; } void popFront() { foreach_index++; } void resetIteration() { foreach_index = 0; } } void main() { int[] ints = [1, 2, 3]; auto refRange = new RefRange(ints); writeln("Ref 1st Run:"); foreach(i; refRange) { writeln(i); if ( i == 2 ) { refRange.resetIteration(); break; } } assert( ! refRange.empty); writeln("Ref 2nd Run:"); foreach(i; refRange) writeln(i); // works } --- Ref 1st Run: 1 2 Ref 2nd Run: 1 2 3
Re: User defined type and foreach
On Friday, 17 November 2017 at 17:55:30 UTC, Jonathan M Davis wrote: When you have foreach(e; range) it gets lowered to something like for(auto r = range; !r.empty; r.popFront()) { auto e = r.front; } So, the range is copied when you use it in a foreach. In the case of a class, it's just the reference that's copied. So, both "r" and "range" refer to the same object, but with a struct, you get two separate copies. So, when foreach iterates over "r", "range" isn't mutated. Ah, I get it now ("r=range; process r"), thanks! So, in the general case, if you want to use a range in foreach without consuming the range, it needs to be a forward range, and you need to call save. e.g. foreach(e; range.save) Seems like you can make class-based ranges to work on multiple foreach calls without having to do save, although maybe it falls apart in other usage. It also doesn't appear that the compiler requires an @property annotation as specified in the interface : import std.stdio : writeln; class RefRange { int foreach_index; int[] items; this(int[] src) { items = src; } bool empty() { if (foreach_index == items.length) { foreach_index = 0; // reset for another foreach return true; } return false; } int front() { return items[foreach_index]; } void popFront() { foreach_index++; } } void main() { import std.stdio; int[] ints = [1, 2, 3]; auto refRange = new RefRange(ints); writeln("Ref 1st Run:"); foreach(i; refRange) writeln(i); assert( ! refRange.empty); writeln("Ref 2nd Run:"); foreach(i; refRange) writeln(i); // works } -- Ref 1st Run: 1 2 3 Ref 2nd Run: 1 2 3
Re: User defined type and foreach
On Friday, 17 November 2017 at 07:40:35 UTC, Mike Parker wrote: You might also find use in this article (poorly adapted from Chapter 6 of Learning D by the publisher, but still readable): https://www.packtpub.com/books/content/understanding-ranges makes a distinction about "range consumption" with regard to a "reference type" or a "value type" and it isn't clear to me why there would be a difference. With a value type, you're consuming a copy of the original range, so you can reuse it after. With a reference type, you're consuming the original range and therefore can't reuse it. struct ValRange { int[] items; bool empty() @property { return items.length == 0; } int front() @property { return items[0]; } void popFront() { items = items[1 .. $]; } } class RefRange { int[] items; this(int[] src) { items = src; } bool empty() @property { return items.length == 0; } int front() @property { return items[0]; } void popFront() { items = items[1 .. $]; } } void main() { import std.stdio; int[] ints = [1, 2, 3]; auto valRange = ValRange(ints); writeln("Val 1st Run:"); foreach(i; valRange) writeln(i); assert(!valRange.empty); writeln("Val 2nd Run:"); foreach(i; valRange) writeln(i); assert(!valRange.empty); auto refRange = new RefRange(ints); writeln("Ref 1st Run:"); foreach(i; refRange) writeln(i); assert(refRange.empty); writeln("Ref 2nd Run:"); foreach(i; refRange) writeln(i); // prints nothing } Thanks for the reference and the code. I will have to iterate over the packpub text a while consulting the docs. I see that the code runs as you say, but I don't understand what's going on. You say with regard to a "value type" : "you're consuming a copy of the original range" but I don't see anything different between the processing in the struct versus in the class. They both have a dynamic array variable that they re-assign a "slice" to (or maybe that is - that they modify to be the sliced version). Anyway, I can't see why the one in the struct shrinks and then goes back to what it was originally. It's like calls were made by the compiler that aren't shown.
Re: User defined type and foreach
On Friday, 17 November 2017 at 01:16:38 UTC, H. S. Teoh wrote: It should be .empty, .popFront, and .front, not .pop. Also, these methods are *range* primitives, and over time, we have come to a consensus that generally speaking, it's a bad idea to conflate containers with ranges over containers. The main thing is that iterating over a range is supposed to consume it, which is usually not what you want with a container. The usual idiom is to separate the two concepts, and have the container provide a mechanism for returning a range over its contents, usually via .opIndex with no arguments, or .opSlice. Then you would just write: foreach (e; myContainer[]) { // [] calls .opIndex/.opSlice ... } Unfortunately, built-in arrays, which are also ranges, are one exception to this rule that, due to their ubiquity in D, also serve to mislead newcomers to D about when/where range primitives should be implemented. Generally speaking, built-in arrays should not be considered exemplary in this respect, but rather should be understood as exceptions. The general convention is to separate your containers from ranges over its contents, and to provide .opIndex / .opSlice that constructs a range over the container when needed. The other consideration is that if you don't really need range functionality, i.e., the only thing you want to do with your container is to put it in a foreach loop, then you can sidestep this whole mess and just implement .opApply for your container and call it a day. Of course, then you won't be able to use generic algorithms like those in std.algorithm with your container, but if you didn't intend to anyway, it's not a big deal. T Thanks T! Good information, especially "iterating over a range is supposed to consume it". I have been reading dlang.org->Documentation->Language Reference, but should have also read dlang.org->Dlang-Tour->Ranges. Although that page makes a distinction about "range consumption" with regard to a "reference type" or a "value type" and it isn't clear to me why there would be a difference.
Re: User defined type and foreach
On Thursday, 16 November 2017 at 18:34:54 UTC, Steven Schveighoffer wrote: On 11/16/17 8:10 AM, ag0aep6g wrote: On 11/16/2017 09:03 AM, Tony wrote: However, when I use the class with foreach, the opindex gets called to create a dynamic array, rather than use the empty(),front(),popFront() routines. I would prefer it use the three methods, rather than create a dynamic array. https://issues.dlang.org/show_bug.cgi?id=14619 I took a shot at fixing. Way more complex than I realized. I was initially miffed that I had added empty(), popFront() and pop() and they weren't being used, but I don't have a problem with using [] instead of them. Maybe call it a feature and document it. But I do have a complaint about the methods empty(), popFront() and pop(). I think they should have a special syntax or name to reflect that they are not general purpose methods. __empty() or preferably __forEachDone(). empty() is typically used to say if a container has no data, not if you are at the end of external foreach loop processing. pop() and popFront() also would typically have different meanings with certain containers and their names don't reflect that they have a special "external foreach loop" purpose.
Re: User defined type and foreach
On Thursday, 16 November 2017 at 13:35:13 UTC, Tony wrote: On Thursday, 16 November 2017 at 13:10:11 UTC, ag0aep6g wrote: On 11/16/2017 09:03 AM, Tony wrote: However, when I use the class with foreach, the opindex gets called to create a dynamic array, rather than use the empty(),front(),popFront() routines. I would prefer it use the three methods, rather than create a dynamic array. https://issues.dlang.org/show_bug.cgi?id=14619 And also this one which was marked as a duplicate of yours https://issues.dlang.org/show_bug.cgi?id=16374 "When lowering a foreach, the compiler gives priority to opSlice over front/popFront/empty, which is counter-intuitive (and also undocumented)." "opSlice" -> "opSlice or opIndex". That should be "opSlice or opIndex-with-no-parameters"
Re: User defined type and foreach
On Thursday, 16 November 2017 at 13:10:11 UTC, ag0aep6g wrote: On 11/16/2017 09:03 AM, Tony wrote: However, when I use the class with foreach, the opindex gets called to create a dynamic array, rather than use the empty(),front(),popFront() routines. I would prefer it use the three methods, rather than create a dynamic array. https://issues.dlang.org/show_bug.cgi?id=14619 And also this one which was marked as a duplicate of yours https://issues.dlang.org/show_bug.cgi?id=16374 "When lowering a foreach, the compiler gives priority to opSlice over front/popFront/empty, which is counter-intuitive (and also undocumented)." "opSlice" -> "opSlice or opIndex".
Re: User defined type and foreach
On Thursday, 16 November 2017 at 12:56:18 UTC, Steven Schveighoffer wrote: On 11/16/17 3:03 AM, Tony wrote: I made a stack data type and created an opIndex() so it could be turned into a dynamic array, and created empty() (unfortunate name), front() and popFront() methods, which I read allow it to be used with foreach. However, when I use the class with foreach, the opindex gets called to create a dynamic array, rather than use the empty(),front(),popFront() routines. I would prefer it use the three methods, rather than create a dynamic array. Remove the opIndex, and see if it works. If it does, then this is a bug. The compiler should try to use the type as a range before seeing if opIndex gives it something. Yes, if I remove opIndex() from the class, doing a foreach loop causes popFront(),empty(), and front() to be called and the foreach loop works.
Re: User defined type and foreach
On Thursday, 16 November 2017 at 08:26:25 UTC, Andrea Fontana wrote: On Thursday, 16 November 2017 at 08:03:48 UTC, Tony wrote: I made a stack data type and created an opIndex() so it could be turned into a dynamic array, and created empty() (unfortunate name), front() and popFront() methods, which I read allow it to be used with foreach. However, when I use the class with foreach, the opindex gets called to create a dynamic array, rather than use the empty(),front(),popFront() routines. I would prefer it use the three methods, rather than create a dynamic array. You can try to implement opApply(). Check: http://ddili.org/ders/d.en/foreach_opapply.html Thanks. Interesting that that page does not mention the behavior I am seeing, which is that foreach over a user-defined datatype can be implemented with only a 'T[] opIndex()' method.
User defined type and foreach
I made a stack data type and created an opIndex() so it could be turned into a dynamic array, and created empty() (unfortunate name), front() and popFront() methods, which I read allow it to be used with foreach. However, when I use the class with foreach, the opindex gets called to create a dynamic array, rather than use the empty(),front(),popFront() routines. I would prefer it use the three methods, rather than create a dynamic array.
Re: Missing return value error not present with template
On Wednesday, 15 November 2017 at 11:20:24 UTC, Biotronic wrote: Thanks Biotronic! I found this on the html documentation for templates: "The body of the TemplateDeclaration must be syntactically correct even if never instantiated. Semantic analysis is not done until instantiated", and that is a great explanation of why it is not semantically analyzed.
Missing return value error not present with template
This code: class MyClass { public: int SomeMethod () { } } void main() { } gets a compile error: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int but if I make it a template class: class MyClass(T) { there is no compile error. I don't know why the error isn't given for the template code as well.
Re: string version of array
On Tuesday, 14 November 2017 at 07:56:06 UTC, rikki cattermole wrote: On 14/11/2017 7:54 AM, Tony wrote: Is there an easy way to get the string representation of an array, as would be printed by writeln(), but captured in a string? struct Foo { int x; } void main() { Foo[] data = [Foo(1), Foo(2), Foo(3)]; import std.conv : text; import std.stdio; writeln(data.text); } --- [Foo(1), Foo(2), Foo(3)] Thanks. That flipped function calling syntax definitely takes some getting used to.
string version of array
Is there an easy way to get the string representation of an array, as would be printed by writeln(), but captured in a string?
Re: core file
On Monday, 13 November 2017 at 07:38:14 UTC, Ali Çehreli wrote: It is. If you search for "where is core file ubuntu" you will hit the output of 'man core', as well as answers like the following, which explains that the file may be under /var/cache/abrt: https://stackoverflow.com/questions/2065912/core-dumped-but-core-file-is-not-in-current-directory Thanks for the "man core" tip and the link.
Re: core file
On Monday, 13 November 2017 at 07:38:14 UTC, Ali Çehreli wrote: On 11/12/2017 10:25 PM, Tony wrote: >>> "Segmentation fault (core dumped)" I've been assuming that if it says "dumped", the core is dumped. > I am on Ubuntu 16.04. Thanks, I didn't know that "producing a core file" > was configurable, and it appears that it isn't. It is. If you search for "where is core file ubuntu" you will hit the output of 'man core', as well as answers like the following, which explains that the file may be under /var/cache/abrt: https://stackoverflow.com/questions/2065912/core-dumped-but-core-file-is-not-in-current-directory Ali My mistake. When I said "and it isn't", I was trying to say "and it isn't set on my system as shown by 'ulimit -a'".
Re: core file
On Monday, 13 November 2017 at 05:37:12 UTC, codephantom wrote: On Monday, 13 November 2017 at 05:01:18 UTC, Tony wrote: I am getting the message from my program execution: "Segmentation fault (core dumped)" But I don't see a core file in the current directory or in my home directory. Is there one somewhere? Would I be able to do anything meaningful with it if it exists? More info than that is needed. What platform are you on? Do you have core dumps enabled/disabled? If you have it enabled...where does it put them? And yes, core dumps are potentially useful for debugging. However, given you're asking that question, and getting core dumps, then it might be easier for you to use the -g option when you compile, and then run your executable (or a.out) through a debugger: https://www.youtube.com/watch?v=vcVmWbYEIsk I am on Ubuntu 16.04. Thanks, I didn't know that "producing a core file" was configurable, and it appears that it isn't.
core file
I am getting the message from my program execution: "Segmentation fault (core dumped)" But I don't see a core file in the current directory or in my home directory. Is there one somewhere? Would I be able to do anything meaningful with it if it exists?
Re: Conditional compilation of array of structs initializer
Thanks Mike!
Conditional compilation of array of structs initializer
Doing a port of some C code that has an #ifdef in the middle of an initialization for an array of structs. I am getting a compile error trying to get equivalent behavior with "static if" or "version". Is there a way to achieve this other than making two separate array initialization sections? struct a { int y; int z; } immutable string situation = "abc"; int main() { a[] theArray = [ { 10, 20 }, // version(abc) static if (situation == "abc") { { 30, 40 }, } { 50, 60 } ]; return 0; }
Re: Any book recommendation for writing a compiler?
Author Allen Holub has made his out-of-print book, Compiler Design in C, available as a free pdf download: http://holub.com/compiler/ And Torben Mogensen is doing the same with his more recent Basics of Compiler Design: http://www.diku.dk/~torbenm/Basics/
Cyclic dependency error
My program compiled, but when I ran it I got this error message: object.Error@src/rt/minfo.d(371): Cyclic dependency between module variable and main variable* -> misc -> main* -> variable* I take it that the -> represents a dependency from the module on that line, to the module on the line below. My question is what do the asterisks represent?
fputs, stdout
There is a fputs/stdout in core.stdc.stdio. std.stdio "public imports" that: "public import core.stdc.stdio;" Wondering why: import core.stdc.stdio : fputs; import core.stdc.stdio : stdout; void main() { fputs( cast(const char *)"hello world\n",stdout); } compiles and runs, but if I change the imports to: import std.stdio : fputs; import std.stdio : stdout; I get this compile error: fputs_test.d(11): Error: function core.stdc.stdio.fputs (scope const(char*) s, shared(_IO_FILE)* stream) is not callable using argument types (const(char*), File)
Re: Associative arrays with keys containing mutable indirections
I prefer the built-in associative array over using some template library. It has the clean look and ease-of-use that you get with a similar data structure in dynamic languages like Python. I consider it a top feature of D.
Re: Garbage Collector profiling and the dynamic array reserve() function
On Tuesday, 17 October 2017 at 13:27:24 UTC, Steven Schveighoffer wrote: I don't know what "allocations" represents, but reserve actually calls gc_malloc, and the others do not (the space is available to expand into the block). There should be only one allocation IMO. -Steve So there should be a bug report written for this?
Garbage Collector profiling and the dynamic array reserve() function
Found this unanswered question on StackOverflow. This program: import std.stdio; void add(ref int[] data) { data ~= 1; data ~= 2; } void main() { int[] a; writeln("capacity:",a.capacity); auto cap = a.reserve(1000); // allocated may be more than requested assert(cap >= 1000); assert(cap == a.capacity); writeln("capacity:",a.capacity); a.add(); writeln(a); } compiled with "dmd -profile=gc" has this output in profilegc.log bytes allocated, allocations, type, function, file:line 4 1 int[] profiling.add profiling.d:8 4 1 int[] profiling.add profiling.d:7 The question is: why doesn't using reserve() cause an allocation to be shown?
Re: @property with 2 arguments
On Sunday, 1 October 2017 at 07:11:14 UTC, bitwise wrote: On Sunday, 1 October 2017 at 05:57:53 UTC, Tony wrote: "@property functions can only have zero, one or two parameters" I am looking for an example of an @property function defined with two parameters and the syntax for how it is accessed without (). And also this, which probably shouldn't actually work: struct S { @property void prop(int a, int b){} } int main(string[] argv) { S s; s.prop = AliasSeq!(1, 2); return 0; } Thanks! I was thinking it was something that looked like that, although the limitation to two items was puzzling.
Re: @property with 2 arguments
On Sunday, 1 October 2017 at 06:34:56 UTC, Jonathan M Davis wrote: On Sunday, October 01, 2017 05:57:53 Tony via Digitalmars-d-learn wrote: "@property functions can only have zero, one or two parameters" I am looking for an example of an @property function defined with two parameters and the syntax for how it is accessed without (). If it has two parameters, then it's a free function that can be used as a setter. e.g. @property void foo(ref T t, int i) { ... } myT.foo = 42; - Jonathan M Davis Thanks!
@property with 2 arguments
"@property functions can only have zero, one or two parameters" I am looking for an example of an @property function defined with two parameters and the syntax for how it is accessed without ().
Re: Creating a dynamic library
On Saturday, 30 September 2017 at 10:09:43 UTC, Mike Wey wrote: On 30-09-17 03:27, Tony wrote: One thing I picked up from SCons is creating dynamic object files with a .os extension and static object files with the standard .o extension. That way they can be compiled in the same directory in the same build step. But dmd rejects the files that are named *.os. Is there an extension besides .o that dmd would accept for the dynamic object files? I've been using .pic.o so it still ends with .o for dmd. Thanks for the suggestion! I was thinking that this might be a linker function only and tried to use g++ and gcc for the .so creation but, while they both create the same size file as each other, it is different than what dmd does when called with -shared.
Re: core.stdc.time
On Saturday, 30 September 2017 at 07:45:27 UTC, Jacob Carlborg wrote: On 2017-09-30 08:56, Tony wrote: The documentation says: -- This module contains bindings to selected types and functions from the standard C header . Note that this is not automatically generated, and may omit some types/functions from the original C header. --- It says "this is not automatically generated". I am seeing it on my Ubuntu Linux system. What would cause it to not be generated and what would be the solution? It means that it's manually translated from C to D and not translated automatically using some tool. Thanks!
core.stdc.time
The documentation says: -- This module contains bindings to selected types and functions from the standard C header . Note that this is not automatically generated, and may omit some types/functions from the original C header. --- It says "this is not automatically generated". I am seeing it on my Ubuntu Linux system. What would cause it to not be generated and what would be the solution?
Re: Creating a dynamic library
On Saturday, 30 September 2017 at 01:02:08 UTC, Elronnd wrote: dmd bla.d bla2.d -shared -fPIC -oflibbla.so Thanks. I don't normally compile right into a .so, but I think this is OK: dmd my_file.o my_other_file.o -shared -of=libutest.so One thing I picked up from SCons is creating dynamic object files with a .os extension and static object files with the standard .o extension. That way they can be compiled in the same directory in the same build step. But dmd rejects the files that are named *.os. Is there an extension besides .o that dmd would accept for the dynamic object files?
Creating a dynamic library
I would like to know that command line (I am on Linux) I would use to compile a D file and create an object file that is suitable for a Linux dynamic library (.so). I believe it is probably dmd -c -fPIC my_file.d Also, what is the command line to create a dynamic library from one or more object files that have been compiled for dynamic invocation? dmd ??? -shared ???
Re: Coverage (-cov)
On Sunday, 24 September 2017 at 05:48:32 UTC, Tony wrote: I am compiling a module (utils) with one function in it with the -cov compiler option on Ubuntu 14.04 with DMD v2.073.2. I then compile a "main module" with -cov that imports the "utils module" and calls the one function. The *.lst output file shows lines that executed in the "main module". I would like it to also show lines that executed in the module that was imported. Is this possible? Oops. Never mind. I just noticed the utils.lst output file.
Coverage (-cov)
I am compiling a module (utils) with one function in it with the -cov compiler option on Ubuntu 14.04 with DMD v2.073.2. I then compile a "main module" with -cov that imports the "utils module" and calls the one function. The *.lst output file shows lines that executed in the "main module". I would like it to also show lines that executed in the module that was imported. Is this possible?
How to set connect timeout on a blocking socket?
Help me! How to set connect timeout on a blocking socket?
Re: Trying to compile weather program
I happened to notice that among my libcurl*s libcurl-gnutls.so.3 libcurl-gnutls.so.4 libcurl-gnutls.so.4.3.0 libcurl.so.3 libcurl.so.4 libcurl.so.4.3.0 none were just libcurl.so. So I made a link for libcurl.so to the latest version and now I am getting the same link errors I got after downloading the -dev version. So apparently my can't find -lcurl was because I didn't have a non-versioned libcurl.so available as it went away when I created one (and there was probably one created by the -dev download).
Re: Trying to compile weather program
On Monday, 24 August 2015 at 06:28:34 UTC, Yazan D wrote: On Sun, 23 Aug 2015 16:00:16 +, Tony wrote: Thanks for the replies. It compiles OK with just. However, it isn't linking: /usr/bin/ld: cannot find -lcurl I do have some versions of libcurl on my system: /usr/lib/x86_64-linux-gnu/libcurl.so.3 /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 /usr/lib/x86_64-linux-gnu/libcurl.so.4 I see there is a -L option to pass things to the linker -Llinkerflag pass linkerflag to link but I am not sure how to use it. I've had the same problem recently. What I did was that I ran `dmd main.d -L-L/usr/lib/x86_64-linux-gnu/ -L-lcurl -v`. It would still fail to link, but I can find the linking command from the verbose output. It was something like this: `gcc main.o -o main -m64 -L/usr/lib/x86_64-linux- gnu/ -lcurl -L/usr/lib/x86_64-linux-gnu -Xlinker --export-dynamic - l:libphobos2.a -lpthread -lm -lrt`. As you can see, -lcurl is there, but it still needs to be added again after -l:libphobos2.a. So just add it again so the command becomes: `gcc main.o -o main -m64 -L/usr/lib/x86_64-linux-gnu/ -lcurl -L/usr/lib/ x86_64-linux-gnu -Xlinker --export-dynamic -l:libphobos2.a -lpthread -lm - lrt -lcurl`. And it links and runs. I had an additional -lcurl in already in my output, but added another at the end: gcc weather_report.o -o weather_report -m64 -L/usr/lib/x86_64-linux-gnu/ -lcurl -L/usr/lib/x86_64-linux-gnu -Xlinker --export-dynamic -lcurl -l:libphobos2.a -lpthread -lm -lrt -lcurl but it still complains that it cannot find -lcurl. It even does it if I add -lcurl everywhere: gcc weather_report.o -o weather_report -m64 -L/usr/lib/x86_64-linux-gnu/ -lcurl -L/usr/lib/x86_64-linux-gnu -Xlinker --export-dynamic -lcurl -l:libphobos2.a -lcurl -lpthread -lcurl -lm -lrt -lcurl As an aside, I remember having to add additional mentions of a library in a link line years ago on Unix. I am surprised they haven't changed the way it works so that you only have to mention it once.
Re: Trying to compile weather program
On Sunday, 23 August 2015 at 16:20:04 UTC, Gerald Jansen wrote: On Sunday, 23 August 2015 at 16:00:19 UTC, Tony wrote: /usr/bin/ld: cannot find -lcurl Just the other day I had a similar problem (compiling vibenews, ld complained of missing -levent and -lssl), which I managed to solve simply by installing the development versions of the libraries (i.e. libevent-dev and libssl-dev). Maybe if you install libcurl-dev you will have the same luck I had. (But hopefully someone will give a more enlightened reply.) Synaptic gave me a choice of 3 libcurl* libcurl4-nss-dev (NSS flavour) libcurl4-gnutls-dev (GnuTLS flavour) libcurl4-openssl-dev (OpenSSL flavour) Confusing that there are 3 choices. I downloaded the OpenSSL one and the can't find lcurl has gone away. But I am now getting linking errors with regard to curl certain curl functions not being found.
Re: Trying to compile weather program
On Sunday, 23 August 2015 at 16:00:19 UTC, Tony wrote: Thanks for the replies. It compiles OK with just. However, it isn't linking: /usr/bin/ld: cannot find -lcurl I do have some versions of libcurl on my system: /usr/lib/x86_64-linux-gnu/libcurl.so.3 /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 /usr/lib/x86_64-linux-gnu/libcurl.so.4 I see there is a -L option to pass things to the linker -Llinkerflag pass linkerflag to link but I am not sure how to use it. I tried ld weather_report.o -lcurl -L/usr/lib/x86_64-linux-gnu and ld weather_report.o -lcurl -L /usr/lib/x86_64-linux-gnu but it also says it can't find libcurl: ld: cannot find -lcurl
Re: Trying to compile weather program
Thanks for the replies. It compiles OK with just. However, it isn't linking: /usr/bin/ld: cannot find -lcurl I do have some versions of libcurl on my system: /usr/lib/x86_64-linux-gnu/libcurl.so.3 /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 /usr/lib/x86_64-linux-gnu/libcurl.so.4 I see there is a -L option to pass things to the linker -Llinkerflag pass linkerflag to link but I am not sure how to use it.
Trying to compile weather program
I found this weather program on the main page (it seems to rotate what it here): // Get your local weather report pragma(lib, curl); import std.functional, std.json, std.net.curl, std.stdio, std.string; alias getJSON = pipe!(get, parseJSON); auto K2C = (float f) = f - 273.15; auto K2F = (float f) = f / 5 * 9 - 459.67; void main() { auto loc = getJSON(ipinfo.io/)[loc] .str.split(,); auto resp = getJSON( api.openweathermap.org/data/2.5/weather ~ ?lat= ~ loc[0] ~ lon= ~ loc[1]); auto city = resp[name].str; auto country = resp[sys][country].str; auto desc = resp[weather][0][description].str; auto temp = resp[main][temp].floating; writefln(` +-+ |%s| +-+ | weather | %-23s| +-+ | temperature | %.2f°C (%.2f°F) | +-+ `.outdent, centerJustifier(city ~ , ~ country, 41), desc, temp.K2C, temp.K2F); } I am compiling on Ubuntu 14.02 with DMD v2.066.1 I get this compile error: weather_report.d(32): Error: undefined identifier centerJustifier
main() return code.
Why is it acceptable to specify main as returning void (in addition to returning int)?
website update
It looks like this page: http://dlang.org/hash-map.html Should have the override keyword added the the member functions in Foo: class Foo { int a, b; size_t toHash() { return a + b; } bool opEquals(Object o) { Foo foo = cast(Foo) o; return foo a == foo.a b == foo.b; } }