Re: Looking for a Simple Doubly Linked List Implementation
On Thursday, 29 October 2020 at 22:02:52 UTC, Paul Backus wrote: I'm pretty sure the post you replied to is spam. Yes, when I read the post again it is kind of hollow.
Re: Looking for a Simple Doubly Linked List Implementation
On Thursday, 29 October 2020 at 18:10:28 UTC, IGotD- wrote: Is this what you are looking for? https://dlang.org/phobos/std_container_dlist.html I'm pretty sure the post you replied to is spam.
Re: What is the difference between enum and shared immutable?
On Thursday, 29 October 2020 at 14:39:31 UTC, H. S. Teoh wrote: On Thu, Oct 29, 2020 at 09:50:28AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] D frequently allows no-op attributes. [...] I find that to be a bad smell in terms of language design, actually. Either something should be allowed and have a definite effect, or it should not be allowed. Not this murky grey area where you can write something and it seems to be allowed, but doesn't actually have any effect. Yes, but that is a tough call. Do you want to catch unintended programmer errors or do you want to make it as easy as possible to write generic code? I'm in favour of max strictness, but then you need to keep the feature set down and make sure it is uniform and orthogonal. But I think it is a bit sad that "shared" isn't enforced so that it could lead to actual benefits. Like requiring that globals are typed shared and enable thread local garbage collection. E.g. GC allocation of non-shared should be on a thread local heap and anything shared should be on a global heap.
Re: rt/object.d
On Thursday, 29 October 2020 at 16:09:00 UTC, Adam D. Ruppe wrote: The internal rt namespace is also on my website: http://dpldocs.info/experimental-docs/rt.html but of course that's private so you can't import it from user code. Thanks, that might be useful later :-).
Re: rt/object.d
On Thursday, 29 October 2020 at 16:09:10 UTC, kinke wrote: On Thursday, 29 October 2020 at 16:02:34 UTC, Ola Fosheim Grøstad wrote: I meant the internals like vtable/typeinfo. https://dlang.org/spec/abi.html#classes Thanks!
Re: What is the difference between enum and shared immutable?
On 10/29/20 10:16 AM, H. S. Teoh wrote: > Module-level immutable can be initialized either as part of the > declaration: > >immutable int x = 1; To add, the expression can be a call to a function that need not return immutable, as long as it is pure, which can be inferred by the compiler for templates. Phew! :) pure char[] makeMutableString() { return "hello".dup; } // This works because makeMutableString() is 'pure', i.e. 'i' cannot // share mutable data. immutable i = makeMutableString(); void main() { } So, instead of adding 'pure' to makeMutableString() like above, one can add another set of parethesis to make it a template. (Two characters instead of four! Win! :p) char[] makeMutableString()() { return "hello".dup; } Ali
Re: Looking for a Simple Doubly Linked List Implementation
On Thursday, 29 October 2020 at 18:06:55 UTC, xpaceeight wrote: https://forum.dlang.org/post/bpixuevxzzltiybdr...@forum.dlang.org It contains the data and a pointer to the next and previous linked list node. This is given as follows. struct Node { int data; struct Node *prev; struct Node *next; }; The function insert() inserts the data into the beginning of the doubly linked list. https://jiofilocalhtml.run https://forpc.onl Is this what you are looking for? https://dlang.org/phobos/std_container_dlist.html
Looking for a Simple Doubly Linked List Implementation
https://forum.dlang.org/post/bpixuevxzzltiybdr...@forum.dlang.org It contains the data and a pointer to the next and previous linked list node. This is given as follows. struct Node { int data; struct Node *prev; struct Node *next; }; The function insert() inserts the data into the beginning of the doubly linked list. https://jiofilocalhtml.run https://forpc.onl
Re: What is the difference between enum and shared immutable?
On Thursday, 29 October 2020 at 16:31:41 UTC, Ali Çehreli wrote: On 10/28/20 5:55 PM, matheus wrote: On Wednesday, 28 October 2020 at 22:07:06 UTC, H. S. Teoh wrote: ... (This is why it's a bad idea to use enum with an array literal, because every time it's referenced you get a new copy of the array.) ... Could you please give an example (Snippet) about this? Matheus. An amusing proof: void main() { enum arr = [ 1 ]; assert(arr.ptr != arr.ptr); // Passes :) } Ali Did you just violate the law of identity
Re: What is the difference between enum and shared immutable?
On Thu, Oct 29, 2020 at 04:56:46PM +, IGotD- via Digitalmars-d-learn wrote: > On Thursday, 29 October 2020 at 16:45:51 UTC, Ali Çehreli wrote: > > > > import std; > > > > immutable string p; > > > > shared static this() { > > p = environment["PATH"]; // <-- Run time > > } > > > > Just to clarify, immutable is allowed to be initialized in ctors but > not anything later than that? Moving p = environment["PATH"] to main > would generate an error. 1) Module-level immutable can be initialized either as part of the declaration: immutable int x = 1; 2) Or from inside a shared static this(): immutable int x; shared static this() { x = 2; } Note that initialization from ctor must be done from `shared static this()`, which is global; initialization from `static this` is currently accepted but deprecated, because that's a TLS ctor, and immutables are implicitly shared so you could potentially break immutability by having the TLS ctor set it to a different value per thread. Eventually this will become a hard error. The following are errors: 3) immutable int x = 1; shared static this() { x = 2; // NG: cannot modify immutable } 4) immutable int x; void main() { x = 3; // NG: cannot modify immutable } T -- Lottery: tax on the stupid. -- Slashdotter
Re: What is the difference between enum and shared immutable?
On Thursday, 29 October 2020 at 16:45:51 UTC, Ali Çehreli wrote: import std; immutable string p; shared static this() { p = environment["PATH"]; // <-- Run time } Just to clarify, immutable is allowed to be initialized in ctors but not anything later than that? Moving p = environment["PATH"] to main would generate an error.
Re: What is the difference between enum and shared immutable?
On 10/28/20 3:07 PM, H. S. Teoh wrote: A shared immutable is initialized at compile-time, To prevent a misunderstanding, immutable can be initialized at run time as well. On the other hand, immutable initialized at compile time was surprising to me when I learned it recently: import std; immutable string p; shared static this() { p = environment["PATH"]; // <-- Run time } // Ali learned this relatively recently // (immutable at compile time): immutable lines = import("myfile.txt").splitter('\n').array; pragma(msg, lines); void main() { } Ali
Re: What is the difference between enum and shared immutable?
On 10/28/20 5:55 PM, matheus wrote: On Wednesday, 28 October 2020 at 22:07:06 UTC, H. S. Teoh wrote: ... (This is why it's a bad idea to use enum with an array literal, because every time it's referenced you get a new copy of the array.) ... Could you please give an example (Snippet) about this? Matheus. An amusing proof: void main() { enum arr = [ 1 ]; assert(arr.ptr != arr.ptr); // Passes :) } Ali
Re: rt/object.d
On Thursday, 29 October 2020 at 16:02:34 UTC, Ola Fosheim Grøstad wrote: I meant the internals like vtable/typeinfo. https://dlang.org/spec/abi.html#classes
Re: rt/object.d
On Thursday, 29 October 2020 at 16:02:34 UTC, Ola Fosheim Grøstad: That is the same as the class decl, I meant the internals like vtable/typeinfo. I don't know what you mean. typeinfo isn't a part of Object and the vtable is built from those virtual methods. If you mean the *module* object instead of class Object, I have the docs for that too: http://dpldocs.info/experimental-docs/object.html and like there's TypeInfo in there http://dpldocs.info/experimental-docs/object.TypeInfo.html The internal rt namespace is also on my website: http://dpldocs.info/experimental-docs/rt.html but of course that's private so you can't import it from user code.
Re: rt/object.d
On Thursday, 29 October 2020 at 14:06:08 UTC, Adam D. Ruppe wrote: On Thursday, 29 October 2020 at 14:03:46 UTC, Ola Fosheim Grøstad wrote: The class definition for Object in the runtime object.d is "empty". Where can I find a description of the structure and fields of "class Object"? http://dpldocs.info/experimental-docs/object.Object.html That is the same as the class decl, I meant the internals like vtable/typeinfo.
Re: What is the difference between enum and shared immutable?
On Thu, Oct 29, 2020 at 11:00:42AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 10/29/20 10:39 AM, H. S. Teoh wrote: > > On Thu, Oct 29, 2020 at 09:50:28AM -0400, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > [...] > > > D frequently allows no-op attributes. > > [...] > > > > I find that to be a bad smell in terms of language design, actually. > > Either something should be allowed and have a definite effect, or it > > should not be allowed. Not this murky grey area where you can write > > something and it seems to be allowed, but doesn't actually have any > > effect. > > I think it's to aid in things like: > > @safe: > > // lots of things, but only functions are tagged as @safe [...] But why can't that be treated differently from explicitly writing @safe on a declaration? I mean, yeah, it's easier to implement the compiler that way, but ease of implementation shouldn't count against proper language design! T -- Doubt is a self-fulfilling prophecy.
Re: What is the difference between enum and shared immutable?
On 10/29/20 10:39 AM, H. S. Teoh wrote: On Thu, Oct 29, 2020 at 09:50:28AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] D frequently allows no-op attributes. [...] I find that to be a bad smell in terms of language design, actually. Either something should be allowed and have a definite effect, or it should not be allowed. Not this murky grey area where you can write something and it seems to be allowed, but doesn't actually have any effect. I think it's to aid in things like: @safe: // lots of things, but only functions are tagged as @safe -Steve
Re: What is the difference between enum and shared immutable?
On Thu, Oct 29, 2020 at 09:50:28AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > D frequently allows no-op attributes. [...] I find that to be a bad smell in terms of language design, actually. Either something should be allowed and have a definite effect, or it should not be allowed. Not this murky grey area where you can write something and it seems to be allowed, but doesn't actually have any effect. T -- One reason that few people are aware there are programs running the internet is that they never crash in any significant way: the free software underlying the internet is reliable to the point of invisibility. -- Glyn Moody, from the article "Giving it all away"
Re: rt/object.d
On Thursday, 29 October 2020 at 14:03:46 UTC, Ola Fosheim Grøstad wrote: The class definition for Object in the runtime object.d is "empty". Where can I find a description of the structure and fields of "class Object"? http://dpldocs.info/experimental-docs/object.Object.html
rt/object.d
The class definition for Object in the runtime object.d is "empty". Where can I find a description of the structure and fields of "class Object"?
Re: What is the difference between enum and shared immutable?
On 10/28/20 6:28 PM, IGotD- wrote: On Wednesday, 28 October 2020 at 21:54:19 UTC, Jan Hönig wrote: shared immutable x = 1; Is there a point to add shared to an immutable? Aren't immutable implicitly also shared? You are correct: pragma(msg, typeof(x)); // immutable(int) D frequently allows no-op attributes. -Steve
Re: What is the difference between enum and shared immutable?
On Thu, Oct 29, 2020 at 08:13:42AM +, Jan Hönig via Digitalmars-d-learn wrote: [...] > Is there some rule of thumb when to use what? > > I judge that using enum will slow down the compilation process, but > might increase performance. Nah. The slowdown is practically indiscernible. You should be more concerned about the semantics. > So for a small struct, or array enum is completelty fine. Actually, I'd recommend *never* to use enum with an array literal, because it comes with a GC allocation *every single time it's referenced*: enum E = [ 1 ]; // small array ... auto arr = E; // GC allocation if (arr == E) { // another GC allocation return E; // yet another GC allocation } Array constants should almost always use static immutable. That way, they get allocated once in the executable, and every reference takes a slice of them instead of incurring a GC allocation every single time. > Large arrays should then use immutable, let's say when they are larger > than 1kb? [...] I'd say array constants should *always* use immutable. Use enum for by-value types like PODs and small structs -- because they can be created in situ without incurring a GC allocation. Depending on the architecture and size of the type, it might even compile into instructions that create the value in CPU registers directly, without allocating stack space for it. So that's something desirable for PODs and small structs. T -- Why do conspiracy theories always come from the same people??
Re: Empty functions
On Thu, Oct 29, 2020 at 09:06:21AM +, Jan Hönig via Digitalmars-d-learn wrote: > On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote: > > This would mean, that this one should work as well. > > It does not work as I intended, as `() => {}` has not the return type > of `void`. > > (I don't know how to print: `ReturnType!(() => {})`) What you want is `() {}`, which is equivalent to `void function() {}`. `() => {}` means something different; it's equivalent to: () { return () {}; } i.e., it's a function that returns an empty function. T -- Tell me and I forget. Teach me and I remember. Involve me and I understand. -- Benjamin Franklin
Re: What is the difference between enum and shared immutable?
On Thursday, 29 October 2020 at 12:21:19 UTC, Ola Fosheim Grøstad wrote: You can test this with is(TYPE1==TYPE2) is(shared(immutable(int))==immutable(int)) So I got that to true, which means that shared immutable is exactly the same as immutable. Shared is implicit for immutable which makes sense. That means that the documentation https://dlang.org/articles/migrate-to-shared.html#immutable is correct at least this one time.
Re: What is the difference between enum and shared immutable?
On Thursday, 29 October 2020 at 08:13:42 UTC, Jan Hönig wrote: Regarding the shared keyword, I am not sure if immutables are shared per default. I thought they are not. You can test this with is(TYPE1==TYPE2) is(shared(immutable(int))==immutable(int))
Re: Empty functions
On Thursday, 29 October 2020 at 09:06:21 UTC, Jan Hönig wrote: On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote: This would mean, that this one should work as well. It does not work as I intended, as `() => {}` has not the return type of `void`. (I don't know how to print: `ReturnType!(() => {})`) Arrow lambdas take a single *expression* on the right-hand side, not a function body between curly braces. When you write () => {} the right-hand side is interpreted as an expression, and is expanded by the compiler to () => function void() {} I.e., it is a function that returns another function.
Re: Empty functions
On 29/10/2020 10:06 PM, Jan Hönig wrote: On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote: This would mean, that this one should work as well. It does not work as I intended, as `() => {}` has not the return type of `void`. (I don't know how to print: `ReturnType!(() => {})`) alias RT = void function(); alias Type = RT function(); () => 7; is equivalent to: int func() { return 7; } Or: () { return 7; }
Re: Empty functions
On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote: This would mean, that this one should work as well. It does not work as I intended, as `() => {}` has not the return type of `void`. (I don't know how to print: `ReturnType!(() => {})`)
Re: Empty functions
On Thursday, 29 October 2020 at 08:48:59 UTC, rikki cattermole wrote: () => {} Is actually: () => Expression Rule: ref|opt ParameterWithMemberAttributes => AssignExpression https://dlang.org/spec/expression.html#lambdas This would mean, that this one should work as well. And you can![1] I have changed line 13 from `F();` to `return F();`. Why does this help??? This is a little weird. [1]: https://run.dlang.io/is/eGah5v
Re: synthesising instantiated template parameters and arguments
On Wednesday, 28 October 2020 at 05:51:14 UTC, Nicholas Wilson wrote: but for a templated C this is tricker as I can't use a template sequence parameter (...) unless C uses it in the same position (I'm trying to generate a mangle from it so it needs to be exact). Given class A(T,int,args...) {} alias C = A!(int, 0, float); I need `ScopeClass!C` to be template ScopeClass(C) { class Anon(T,int,args...) // name doesn't matter { // implement members with compile time reflection } alias ScopeClass = Anon!(int, 0, float); } How do I do this? Are you looking for `TemplateArgsOf` [1] ? [1] https://dlang.org/phobos/std_traits.html#TemplateArgsOf -- /Jacob Carlborg
Re: Empty functions
(Params){ FunctionBody; } Rule: ref|opt ParameterWithMemberAttributes FunctionLiteralBody https://dlang.org/spec/expression.html#function_literals void function() Is a type https://dlang.org/spec/type.html#delegates () => {} Is actually: () => Expression Rule: ref|opt ParameterWithMemberAttributes => AssignExpression https://dlang.org/spec/expression.html#lambdas
Empty functions
I have asked this on StackOverflow[1]. I have received a valid answer, which solves my problem, however, I have still not understood, why some versions of it work and some don't. The code is here[2]. I don't understand why `a` compiles just fine, while `b` and `c` don't. I think, that I don't understand what `void function()` does or is. Can someone explain it to me? And I don't see why `(){}` works and `() => {}` does not. [1]: https://stackoverflow.com/questions/64581514/void-lambda-function/64587101#64587101 [2]: https://run.dlang.io/is/GFe9Ht
Re: What is the difference between enum and shared immutable?
On Wednesday, 28 October 2020 at 22:07:06 UTC, H. S. Teoh wrote: [...] An enum only exists at compile-time, and does not occupy any space. Each time it's referenced, a new instance of the value is created. (This is why it's a bad idea to use enum with an array literal, because every time it's referenced you get a new copy of the array.) A shared immutable is initialized at compile-time, and occupies space in the object file / runtime memory. It's also a single instance, and referencing it causes a load of this instance at runtime. It's not copied unless it's a by-value type, so an array literal will get stored as an array in the executable, and every time you reference it you get a slice of it instead of a copy. T (thanks to you and Mike btw :) Is there some rule of thumb when to use what? I judge that using enum will slow down the compilation process, but might increase performance. So for a small struct, or array enum is completelty fine. Large arrays should then use immutable, let's say when they are larger than 1kb? Regarding the shared keyword, I am not sure if immutables are shared per default. I thought they are not.
Re: dub fetching dependencies for wrong configuration(s)
On Wednesday, 28 October 2020 at 21:56:46 UTC, Anonymouse wrote: On Wednesday, 28 October 2020 at 19:34:43 UTC, ikod wrote: To make this transition as painless as possible I'll create new package with major version "2" if you confirm that everything works as expected. ... No vibe-d downloaded! Thanks! I bumped version to 2.0.0 And thanks Andre for idea with packages.