Re: question as to when a new command gets executed

2020-11-11 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 22:29:00 UTC, SealabJaster wrote: On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry wrote: Thanks. Would you or anyone reading this know if this is unique to D or does C++ also behave like this? Also, where is the memory, that new allocates? Is it i

Re: question as to when a new command gets executed

2020-11-11 Thread SealabJaster via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry wrote: Thanks. Would you or anyone reading this know if this is unique to D or does C++ also behave like this? Also, where is the memory, that new allocates? Is it in the heap (thought heap was available only at runtime) or some othe

Re: question as to when a new command gets executed

2020-11-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry wrote: Also, where is the memory, that new allocates? It is in the executable's static data block, just like if you declared a static array in the global space. I think this is D specific but I'm not sure about that.

Re: question as to when a new command gets executed

2020-11-11 Thread WhatMeWorry via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 06:21:38 UTC, Jacob Carlborg wrote: On 2020-11-11 06:29, WhatMeWorry wrote: Which begs the question, how would the statement, m_State = new BreakState() ever get executed? class DebuggerSession {     private BreakState m_State = new BreakState();     privat

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 13:30:16 UTC, Simen Kjærås wrote: The short answer is 'because that's how we've chosen to define it'. A more involved answer is that changing every reference is prohibitively expensive - it would require the equivalent of a GC collection on every reallocation,

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread zack via Digitalmars-d-learn
Alright, thanks for sharing this thoughts and arguments!

Re: scope front vs [0]

2020-11-11 Thread vitamin via Digitalmars-d-learn
Or similar problem: class Foo{} struct Slice{ Foo[] data; this(return scope Foo[] data)@safe { this.data = data; } Slice opSlice()@safe return scope{ return Slice(data); } Foo opIndex(size_t i)@safe return scope{ return data[i]; } } void main

scope front vs [0]

2020-11-11 Thread vitamin via Digitalmars-d-learn
Hello, Why does expression 'foo = bars[][0].foo' work but 'foo = bars[].front.foo' doesn't? example: class Foo{} struct Bar{ Foo foo; } void main()@safe{ import std; Foo foo; scope Bar[] bars = [Bar.init]; foo = bars[][0].foo;//OK, WHY? foo

Re: Is there a similar library to FreeMarker like in Java

2020-11-11 Thread frame via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 08:13:23 UTC, Namal wrote: Hello, I want to do a small project but I need a text replacement tool/lib like Apache's FreeMarker. Is there something similar for D? Thx Maybe not so powerful but useful: mustache-d

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 10:17:09 UTC, zack wrote: I am new to D. Appending to an array can lead to reallocation, that's clear. But why is the "reference" b not changed accordingly to the new position and still points to "old" memory? Why is b not also changed when reallocating array a

Re: C++ or D?

2020-11-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: I haven't looked into the newest C++. In theory, they might have added something helpful in the past years. I guess you could say that the latest version of C++ allows you to write code that is a little bit less verbose than before. C++

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 10:17:09 UTC, zack wrote: I am new to D. Appending to an array can lead to reallocation, that's clear. But why is the "reference" b not changed accordingly to the new position and still points to "old" memory? Why is b not also changed when reallocating array a

Re: How to get address of a nested function?

2020-11-11 Thread Max Samukha via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 20:13:30 UTC, Daniel Kozak wrote: non static nested function is a delegate, so you can just assign it to delegate like I have posted or you can du this: import std.stdio; void main() { void foo() { writeln("It works as expected"); } enum pf

Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread zack via Digitalmars-d-learn
I am new to D. Appending to an array can lead to reallocation, that's clear. But why is the "reference" b not changed accordingly to the new position and still points to "old" memory? Why is b not also changed when reallocating array a and the old data getting invalid/freed? auto a = [55,10,2

Is there a similar library to FreeMarker like in Java

2020-11-11 Thread Namal via Digitalmars-d-learn
Hello, I want to do a small project but I need a text replacement tool/lib like Apache's FreeMarker. Is there something similar for D? Thx