On Saturday, 2 April 2022 at 23:40:39 UTC, Marcone wrote:
ImportC is deprecated as everything in D is deprecated and
abandoned. No link works, every download link is broken as no
one cares. All D code is always full of bugs and needs to be
corrected by the user before trying to run it, in order
On Wednesday, 4 May 2022 at 02:42:44 UTC, Mike Parker wrote:
On Tuesday, 3 May 2022 at 14:57:46 UTC, Alain De Vos wrote:
Note, It's not i'm against GC. But my preference is to use
builtin types and libraries if possible,
But at the same time be able to be sure memory is given free
when a variab
On Wednesday, 4 May 2022 at 05:13:04 UTC, Mike Parker wrote:
On Wednesday, 4 May 2022 at 04:52:05 UTC, forkit wrote:
It is certainly *not* about you not having to care anymore
(about memory management).
That's not at all what I said. You don't have to care about
*when* memory is dealloca
On Wednesday, 4 May 2022 at 08:23:33 UTC, Mike Parker wrote:
On Wednesday, 4 May 2022 at 05:37:49 UTC, forkit wrote:
That's not at all what I said. You don't have to care about
*when* memory is deallocated, meaning you don't have to
manage it yourself.
In any case, I disagree that caring abo
On Wednesday, 4 May 2022 at 12:57:26 UTC, Ali Çehreli wrote:
On 5/3/22 22:37, forkit wrote:
> In any case, I disagree that caring about when memory gets
deallocted
> means you shouldn't be using GC. (or did I get that one wrong
too??)
At least I don't agree with you there. :) Yes, one should no
On Wednesday, 4 May 2022 at 15:04:13 UTC, cc wrote:
The MemUtils package offers a `ScopedPool` utility that seems
interesting. It isn't well documented however so I have no
idea if it actually works like I expect. I presume this would
work something akin to a VM memory snapshot/rollback for t
On Wednesday, 4 May 2022 at 21:55:18 UTC, H. S. Teoh wrote:
On Wed, May 04, 2022 at 09:46:50PM +, forkit via
Digitalmars-d-learn wrote: [...]
That languages with GC typically give the programmer some
control over the GC, is evidence that programmers do care
(otherwise such features would
On Thursday, 5 May 2022 at 17:53:57 UTC, Alexander Zhirov wrote:
I want to use a configuration file with external settings. I'm
trying to use regular expressions to read the `Property =
Value` settings. I would like to do it all more beautifully. Is
there any way to get rid of the line break ch
On Friday, 6 May 2022 at 07:51:01 UTC, Alexander Zhirov wrote:
On Friday, 6 May 2022 at 05:40:52 UTC, forkit wrote:
auto myTuple = line.split(" = ");
Well, only if as a strict form :)
well.. a settings file should be following a strict format.
..otherwise...anything goes... and good luck wi
On Tuesday, 10 May 2022 at 03:22:04 UTC, MichaelBi wrote:
s is the string, and print result as following:
s.array.sort!("athen how to transfer into
[['A',231],['C',247],['G',240],['T',209]]? tried map!, but can
only sortout key or value... tried array(), but result is not
sorted then...thanks
On Thursday, 12 May 2022 at 21:58:33 UTC, Ali Çehreli wrote:
I am considering proposing a presentation for DConf 2022.
Would a "Back to Basics" style presentation be interesting? If,
so what exact topic would you like to see?
For ideas, here is what CppCon 2021 had on their track:
https://
On Friday, 13 May 2022 at 03:31:53 UTC, Ali Çehreli wrote:
On 5/12/22 18:56, forkit wrote:
> So...you want to do a talk that challenges D's complexity, by
getting
> back to basics?
I wasn't thinking about challenging complexity but it gives me
ideas.
I am looking for concrete topics like tem
On Friday, 13 May 2022 at 15:56:31 UTC, H. S. Teoh wrote:
My mental image of this is Ali presenting some simple common
task, then at 3/4 of the presentation there's an amazing trick
that lets you write it in D in 5 times less code than in other
languages, and my mind is blown and I remember
On Sunday, 15 May 2022 at 15:59:17 UTC, Alain De Vos wrote:
Can i summarize ,
structs are value-objects which live on the stack.
class instances are reference objects which live on the heap.
the real difference, is that structs, being value types, are
passed by value, and classes, being refere
On Sunday, 15 May 2022 at 15:26:40 UTC, Kevin Bailey wrote:
I've done some scripting in D over the years but I never dug
into D until recently. I'm going through Learning D and I was
reminded that structs and classes are so different.
- struct methods are non-virtual while class methods are vi
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote:
In you OOP example, I am curious why you chose Shape to be an
interface, rather than a base class.
On Sunday, 15 May 2022 at 21:33:24 UTC, Ali Çehreli wrote:
I still think my answer is the real one. My implied question
remains: Why does C++ have struct and class disticnction? I
know they have different default access specifications but does
that warrant two kinds?
Here is a ver
On Wednesday, 8 June 2022 at 01:11:45 UTC, Mike Parker wrote:
...The author withdrew the DIP
..
That's a shame.
Seems like a useful language feature. I'd be using it already if
it existed.
I'd have gone for:
int[..] arr = [1,2,3];
On Wednesday, 8 June 2022 at 01:32:42 UTC, Steven Schveighoffer
wrote:
I like `$`. It's got a well-defined meaning, and already is
somewhat magic.
-Steve
I agree it's magic.
warray[5..$] - this is one of the best uses of syntax magic in D!
I think it's what first attracted me to the lang
Is it possible to create a package.d, consisting of (for
example), two modules, where each module can access private
declarations within each other.
In essence, declaring 'a module level friendship', or a kind of
'extended module' if you want.
I might still want to add another module to the
On Sunday, 12 June 2022 at 05:05:46 UTC, forkit wrote:
e.g. If I could something like this:
// foo_1.d
module foo_1
private int a; // a is private to module foo_1
// foo_2.d
module foo_2
private int b; // b is private to module foo_2
// foo.d
module foo[dependencies:foo_1, foo_2];
import st
On Sunday, 12 June 2022 at 05:46:17 UTC, Mike Parker wrote:
I don't get it.
How does this enable one module to access the private parts of
another module?
Isn't 'private' *always* private to the module?
The idea I had, was to be able to spread a 'module' over more
than one file - for the
On Tuesday, 28 June 2022 at 18:42:11 UTC, Marcone wrote:
Beloved,
I love programming in D. D is my favorite programming language.
I'm not a professional programmer, but I love to program. I
would like to learn D deeply. Most programming languages have a
PDF/CHM/MOBI/ePub version of the stand
On Tuesday, 28 June 2022 at 21:14:42 UTC, Marcone wrote:
Is there any way to do this automatically like Python?
https://docs.python.org/3/download.html
Of course there is. But someone has to volunteer their time and
effort to do it ;-)
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote:
Next code originally was a classic C code I've written, it's
pure vertical thinking, now, I converted it successfully to D
code, but I think I made no much changes to make it has more
horizontal thinking style that it seems D program
On Monday, 8 November 2021 at 12:04:26 UTC, forkit wrote:
case 'o' :
result = result.filter!(a => (a % 2 == 1)).array;
oops.
case 'o' :
result = result.filter!(a => (a % 2 != 0)).array;
On Monday, 8 November 2021 at 12:04:26 UTC, forkit wrote:
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote:
Next code originally was a classic C code I've written, it's
pure vertical thinking, now, I converted it successfully to D
code, but I think I made no much changes to make it
On Wednesday, 10 November 2021 at 04:54:58 UTC, Stanislav Blinov
wrote:
On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote:
They both produce exactly the same output.
But do vastly different things.
But I tell ya.. the cognitive load .. well.. it increased
dramatically ;-)
Of cours
On Wednesday, 10 November 2021 at 04:54:58 UTC, Stanislav Blinov
wrote:
On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote:
They both produce exactly the same output.
But do vastly different things.
But I tell ya.. the cognitive load .. well.. it increased
dramatically ;-)
Of cours
On Wednesday, 10 November 2021 at 22:17:48 UTC, russhy wrote:
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache.
So I really don't give a damn about allocations .. not one
little bit ;-)
Having the right mindset helps n
On Wednesday, 10 November 2021 at 23:05:06 UTC, H. S. Teoh wrote:
On Wed, Nov 10, 2021 at 10:17:48PM +, russhy via
Digitalmars-d-learn wrote:
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
> btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache.
> So I really don't give
On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote:
On Wed, Nov 10, 2021 at 11:39:40PM +, forkit via
Digitalmars-d-learn wrote: [...]
I still remember compiling code on my 286x86 ... talk about
low memory..whoaaah.
...
But if you're in a time-constrained inner loop, y
// --
module test;
import std.stdio;
void main()
{
writeln("Hello World!");
}
// ---
dmd test.d -cov
..but no .lst file anywhere to be found. Huh! I don't get it.
On Thursday, 11 November 2021 at 21:13:03 UTC, Stanislav Blinov
wrote:
On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote:
It depends on what you're doing. In the OP's example, yeah
worrying about allocations is totally blowing things out of
proportions.
But that's the thing. Ho
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote:
Next code originally was a classic C code I've written, it's
pure vertical thinking, now, I converted it successfully to D
code, but I think I made no much changes to make it has more
horizontal thinking style that it seems D program
On Thursday, 11 November 2021 at 21:40:33 UTC, Ali Çehreli wrote:
On 11/11/21 1:37 PM, forkit wrote:
dmd test.d -cov
...but no .lst file anywhere to be found. Huh! I don't get it.
Please run the program! :)
Ali
oh! that kinda makes sense, now that I think of it ;-)
On Friday, 12 November 2021 at 01:05:15 UTC, Stanislav Blinov
wrote:
On Thursday, 11 November 2021 at 22:10:04 UTC, forkit wrote:
It's called 'staged learning'.
Staged learning is the only way for humans to learn, due to
the limitations of the human cognitive system. Specifically,
the way sh
On Thursday, 11 November 2021 at 19:34:42 UTC, Stanislav Blinov
wrote:
Original C code from the first post can only fail on I/O, which
is arguably out of your control. And the meat of it amounts to
10 conditional stores. Your implementations, in both C and D,
are a very, very far distance awa
On Friday, 12 November 2021 at 19:32:31 UTC, Dr Machine Code
wrote:
On Thursday, 11 November 2021 at 23:51:42 UTC, foxit wrote:
On Thursday, 11 November 2021 at 22:35:21 UTC, forkit wrote:
[...]
Actually, the reason I got soo confused is clear to me now.
I have my own GUI IDE, which I wr
Code below is self explanatory.
Any assistance on how to get the line number is welcome ;-)
// ++
module test;
import std;
class myClass{ void foo(){}}
void myFunction1(){}
void main()
{
// list the first user defined member of this module (other
than main)
On Saturday, 13 November 2021 at 06:05:37 UTC, Stanislav Blinov
wrote:
On Saturday, 13 November 2021 at 05:31:51 UTC, forkit wrote:
Code below is self explanatory.
Any assistance on how to get the line number is welcome ;-)
https://dlang.org/spec/traits.html#getLocation
That?
Thanks. That
On Saturday, 13 November 2021 at 07:20:14 UTC, Ali Çehreli wrote:
It works because we mix-in the value of the string 'm', which
becomes a symbol.
('foreach' instead of 'static foreach' works as well.)
Ali
Thanks. Really appreciate the help provided in this thread :-)
Final working code be
On Saturday, 13 November 2021 at 17:22:16 UTC, Stanislav Blinov
wrote:
On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote:
int i;
foreach(m; __traits(allMembers, mixin(__MODULE__)))
// ...
__traits(getLocation, mixin(m))[1]);
What you really should be doing is this:
On Saturday, 13 November 2021 at 23:02:15 UTC, pascal111 wrote:
I touch that D is big language, it's not small like standard C.
This will cost me much studying, so I think I need slow down
and learn it step by step.
Yes. C is so much smaller, and thus simpler (till you wanna do
something co
On Sunday, 14 November 2021 at 04:24:09 UTC, Stanislav Blinov
wrote:
On Sunday, 14 November 2021 at 04:05:45 UTC, forkit wrote:
However, there is no isClass method. Why not?
How do I determine if a member is a class.. I wonder...
```
static if (is(something == class)) { /* ... */ }
```
or,
On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote:
Let's say I want to write a simple program that asks for an
input of a single character.
After pressing a single key on a keyboard, the character is
printed out and the program should stop.
module test;
void main()
{
import core.s
On Monday, 29 November 2021 at 14:58:07 UTC, Willem wrote:
Thanks again for all the responses. For now -- I am simply
adding the DLL to the EXE and writing it out to the working
directory. Not elegant - but it does work.
"Programmers are not to be measured by their ingenuity and their
l
On Sunday, 5 December 2021 at 16:24:34 UTC, Chris Katko wrote:
I know there "is" a solution, it's just so odd to have this
much difficulty using a string.
Paying attention to the online docs would help you too ;-)
https://dlang.org/library/std/socket/internet_address.this.html
But, in the e
On Wednesday, 8 December 2021 at 14:27:22 UTC, BoQsc wrote:
On Wednesday, 8 December 2021 at 14:16:16 UTC, bauss wrote:
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.st
On Wednesday, 8 December 2021 at 22:35:35 UTC, Stanislav Blinov
wrote:
You're passing a literal. Try passing a runtime value (e.g. a
command line argument). Also, -O2 -release :) Uless, of course,
your goal is to look at debug code.
but this will change nothing.
the compilation cost of usin
On Wednesday, 8 December 2021 at 22:55:02 UTC, forkit wrote:
On Wednesday, 8 December 2021 at 22:35:35 UTC, Stanislav Blinov
wrote:
You're passing a literal. Try passing a runtime value (e.g. a
command line argument). Also, -O2 -release :) Uless, of
course, your goal is to look at debug code.
On Thursday, 9 December 2021 at 18:00:42 UTC, kdevel wrote:
PRO:
- saves two lines of boilerplate code
CONS:
- raw loop
- postinc ++ is only permitted in ++C
- inconsistent spacing around "="
- mixing tabs and spaces for indentation
- arrow code
more PROs:
- You become less dependent on s
On Friday, 10 December 2021 at 12:15:18 UTC, Rumbu wrote:
I thought it's a beauty contest.
Well, if it's a beauty contest, then i got a beauty..
char[("abc;def;ab".length - count("abc;def;ab", ";"))] b =
"abc;def;ab".replace(";", "");
On Friday, 10 December 2021 at 22:35:58 UTC, Arjan wrote:
"abc;def;ghi".tr(";", "", "d" );
I don't think we have enough ways of doing the same thing yet...
so here's one more..
"abc;def;ghi".substitute(";", "");
On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim
Grøstad wrote:
Using libraries can trigger hidden allocations.
ok. fine. no unnecessary, hidden allocations then.
// --
module test;
import core.stdc.stdio : putchar;
nothrow @nogc void main()
{
string str = "ab
On Saturday, 11 December 2021 at 21:42:49 UTC, ManKey wrote:
What implementations of the C standard library does importC
support?
umm... the site has search function you know ;-)
https://dlang.org/spec/importc.html
On Saturday, 11 December 2021 at 09:25:37 UTC, Ola Fosheim
Grøstad wrote:
```putchar(…)``` is too slow!
On planet Mars maybe, but here on earth, my computer can do about
4 billion ticks per second, and my entire program (using putchar)
takes only 3084 ticks.
ok. one line in this code is causing a problem (as noted in
comments)
an explanation as to the cause, is welcome ;-)
//
module test;
import std : writeln, writefln;
import std.conv : to;
void main()
{
string str = "abc;def;ab";
char* w = cast(char*)str;
w
On Monday, 13 December 2021 at 09:49:05 UTC, forkit wrote:
oh...
Windows
- dmd version is 2.098.0-dirty
- ldc2 version is 1.28 (based on dmd v2.098.0)
Linux
- dmd version is 2.098
- ldc2 version is 1.20.1 (based on dmd v2.090.1)
On Monday, 13 December 2021 at 09:49:05 UTC, forkit wrote:
char* w = cast(char*)str.toStringz; // this seems to be the
solution
class has ended ;-)
On Monday, 13 December 2021 at 12:06:53 UTC, WebFreak001 wrote:
You should really use `.dup` if you want to mutate your string.
(You would need to duplicate anyway if you don't want an unsafe
cast)
(this produces an unpredictable result??)
char* w = cast(char*)str.dup;
(but this seems to wo
On Monday, 13 December 2021 at 20:28:26 UTC, H. S. Teoh wrote:
On Mon, Dec 13, 2021 at 08:04:24PM +, forkit via
Digitalmars-d-learn wrote:
On Monday, 13 December 2021 at 12:06:53 UTC, WebFreak001 wrote:
>
> You should really use `.dup` if you want to mutate your
> string. (You w
On Monday, 13 December 2021 at 20:28:26 UTC, H. S. Teoh wrote:
On Mon, Dec 13, 2021 at 08:04:24PM +, forkit via
Digitalmars-d-learn wrote:
On Monday, 13 December 2021 at 12:06:53 UTC, WebFreak001 wrote:
>
> You should really use `.dup` if you want to mutate your
> string. (You w
On Sunday, 12 December 2021 at 08:25:09 UTC, Dave P. wrote:
ImportC is not ready for general use yet.
I think you nailed it ;-)
https://dlang.org/changelog/2.098.1.html
On Monday, 13 December 2021 at 21:13:25 UTC, H. S. Teoh wrote:
What you should be doing is:
return to!string(str[0 .. len]);
Or just:
return str[0 .. len].idup;
T
oh.. so many different ways...(to both produce the same bug, and
also to produce the correct output).
... i
On Tuesday, 14 December 2021 at 08:07:43 UTC, WebFreak001 wrote:
The best way would be not doing this at all - when you
manipulate strings/arrays in D you can do so by just assigning
the elements like this:
```d
immutable(char)[] replaceChar(char[] str, char ch1, char ch2)
{
for (ulong i
strange things happen when I compile (on windows) the code below
with:
dmd -m64
(compilation just crashes - no error message at all)
or
ldc2 -m64
(compilation works, but memory usage during compilation goes
completely wild! upto 22GB, then down to 7GB, then finally
completes.)
//
mo
On Tuesday, 4 January 2022 at 23:37:57 UTC, H. S. Teoh wrote:
... .. .
Which seems to confirm my suspicions.
T
yes, this sounds like it might be it.
I tried using = void;
.. results:
dmd -m64 -> just results in an 'out of memory' message (but at
least i get a message this time)
ldc2 -
On Tuesday, 4 January 2022 at 23:37:57 UTC, H. S. Teoh wrote:
Or the compiler would run out of memory before it gets to
optimizing away those assignments, so it would just outright
crash. I ran your code on my computer and got this:
uncaught exception
core.exception.AssertError@src/
Do not understand why one line is not considered @safe, but the
other is.
//
module test;
import std;
@safe void main()
{
immutable string[] strings = ["one", "one", "two"];
immutable(string)*[] pointers = null;
foreach(size_t i, ref str; strings)
{
if(str == "on
On Sunday, 9 January 2022 at 21:56:05 UTC, Salih Dincer wrote:
Try the @trusted and in/out:
...
..
.
thanks for introducing me to the in/out feature of D :-)
I'll certainly look into that feature more.
But my question still remains:
//pointers ~= &str; // why is this *not* allowed in @safe
On Monday, 10 January 2022 at 03:21:46 UTC, Paul Backus wrote:
Taking the address of a local variable is forbidden in @safe
code. Even though str is a ref variable that points to a
heap-allocated string, it is still considered a local variable
because it is declared inside the body of a funct
On Tuesday, 11 January 2022 at 14:54:51 UTC, Paul Backus wrote:
..
If you compile with -preview=dip1000, the compiler will
actually keep track of which pointers point to stack memory,
and will allow your original code. But -preview=dip1000 is
still somewhat experimental, and the documentation
On Tuesday, 11 January 2022 at 21:50:00 UTC, Paul Backus wrote:
..
If you know a particular bit of code is memory safe, but the
compiler can't prove it, you can mark that code as @trusted.
For example:
() @trusted { pointers ~= &str; )();
This example uses an immediately-invoked function
I am familiar with the concept of a slice in D.
However, a slice is a consecutive slice, is in not? (e.g) [4..$-1]
I would like a slice (or a view, or whatever name you wanna call
it), of particular elements within an array that may not be
consecutive. e.g. [4-7,8,10,13-16]
Consider below:
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote:
Yes std.algorithm : filter.
```d
import std.stdio : writeln;
import std.algorithm : filter;
void main()@safe{
auto a = ["one", "one", "two", "one", "two", "one",
"one", "two"];
writeln(a);
writeln(a.filter
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote:
Yes std.algorithm : filter.
```d
import std.stdio : writeln;
import std.algorithm : filter;
void main()@safe{
auto a = ["one", "one", "two", "one", "two", "one",
"one", "two"];
writeln(a);
writeln(a.filter
On Thursday, 13 January 2022 at 20:32:40 UTC, Stanislav Blinov
wrote:
On Thursday, 13 January 2022 at 19:52:27 UTC, forkit wrote:
Any idea on how I can get a ptr (without hardcoding C style)
e.g. something like this:
immutable(string)*[] pointers = strings.filter!(x => x ==
"one").to!pointer
I want int[][] like this -> [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10],
[11, 12, 13, 14, 15]]
Any help will be appreciated.
note: to2Darray is not a valid statement ;-)
// ---
module test;
import std;
void main()
{
int[][] arrayOfarrays = iota(1, 16).chunks(5).to2Darray; //
how to convert this
I want to do the equivalent of this:
int[][] arrayOfarrays = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11,
12, 13, 14, 15]];
But getting the initialiser values using iota and chunks instead.
Any help will be appreciated.
note: to2Darray is not a valid statement ;-)
// ---
module test;
import
On Saturday, 15 January 2022 at 02:41:08 UTC, Paul Backus wrote:
import std.algorithm: map;
import std.array: array;
int[][] arrayOfArrays = iota(1, 16).chunks(5).map!array.array;
oh. thanks!
also it seems I reposted the same question (didn't realise this
one got posted)
On Saturday, 15 January 2022 at 03:18:21 UTC, forkit wrote:
oops. ignore this - was a repost of another post that I thought
never got posted ;-)
On Saturday, 15 January 2022 at 03:48:41 UTC, Steven
Schveighoffer wrote:
Alternatively (with only one allocation for the int[] data):
```d
int[][] arrayOfArrays = iota(1, 16).array.chunks(5).array;
```
-Steve
All answers were helpful ;-)
But I like this one the best, because I find it both
so at this link: https://dlang.org/spec/arrays.html
it indicates an array of type[] is of type 'Dynamic array'.
with that in mind, I ask, is this below a 'Dynamic array'.
If not, why not?
int[][] mArr2 = array(iota(1, 9).chunks(2).map!array.array);
On Sunday, 16 January 2022 at 04:58:21 UTC, Ali Çehreli wrote:
I have a problem with calling type[] a dynamic array because it
is a slice, which may be providing access to the elements of a
dynamic array.
Yes. A more useful way of describing [] would be to say:
"[] represents a dynamic ar
On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote:
...my DConf Online 2020 presentation here:
https://dconf.org/2020/online/#ali1
Ali
Hey, that is a really great presentation!
Many more people should watch it, and learn ;-)
On Sunday, 16 January 2022 at 11:43:40 UTC, Ali Çehreli wrote:
So, in all three examples it is the same D feature, a slice,
that references data but the data is managed in different ways.
Ali
Well, it's fair to say, that 'range-based programming' is kinda
new to me.
With this statement:
On Sunday, 16 January 2022 at 23:03:49 UTC, Ali Çehreli wrote:
That's not correct. There are many range algorithms that are
lazy to defer memory allocation but array() is not one of
those. array() does eagerly allocate memory, which is it's
whole purpose:
https://dlang.org/phobos/std_arra
On Sunday, 16 January 2022 at 23:34:41 UTC, Ali Çehreli wrote:
Definitely a -profile=gc bug. Here are the existing ones:
https://issues.dlang.org/buglist.cgi?quicksearch=profile%20gc
Ali
yeah, a bug makes more sense ... otherwise I really would have
had a slice to data that doesn't exist
On Monday, 17 January 2022 at 00:54:19 UTC, forkit wrote:
..
module test;
import std;
@safe void main()
{
// mArr1 is a dynamic array allocated on the gc heap.
int[][] mArr1 = [[1, 2], [3, 4], [5, 6], [7, 8]];
static assert(is(typeof(mArr1.array(;
alias R1 = typeof(mArr1)
On Monday, 17 January 2022 at 03:11:50 UTC, Steven Schveighoffer
wrote:
The profile=gc appears to only show GC allocations that the
*compiler* initiates (i.e. via `new`, array operations (like
appending) or closure allocations). It does not detect that the
functions that actually allocate mem
so I'm wondering why the code below prints:
1 2 3 4
and not
1 2 3 4 5
as I would expect.
foreach (value; 1..5) writef("%s ", value);
also, why is this not possible:
int[] arr = 1..5.array;
On Monday, 17 January 2022 at 11:58:18 UTC, Paul Backus wrote:
This kind of half-open interval, which includes the lower bound
but excludes the upper bound, is used in programming because it
lets you write
foreach (i; 0 .. array.length) writef("%s ", array[i]);
...without going past the
On Monday, 17 January 2022 at 22:06:47 UTC, H. S. Teoh wrote:
Basically,
foreach (i; a .. b)
is equivalent to:
for (auto i = a; i < b; i++)
Just think of that way and it will make sense.
I think it's fair to say, that I'm familiar with 0-based indexing
;-)
my concern wa
On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote:
If I ever needed to foreach over 1-based indices, I'd write it
this way in order to avoid all confusion:
foreach (i; 1 .. 5 + 1)
{
}
This will immediately make whoever reads the code (i.e., myself
after 2
On Tuesday, 18 January 2022 at 16:02:42 UTC, Tejas wrote:
Newer languages nowadays use `start..intent, think it's something we should follow?
I've decided to avoid using number ranges 'directly', and instead
use a wrapper function...
auto range(T:T)(T a, T b)
{
import std.range : iota;
so I use this compile command (on Windows, using ldc)
-link-defaultlib-shared=true
Then (in simple example) the size of my compiled .exe:
From 806KB down to 18KB
Oh. That's so much nicer on my SSD ;-)
(yes, I understand the implictions here of dynamic sharing, but I
test/compile/debug so muc
On Tuesday, 18 January 2022 at 20:50:06 UTC, Ali Çehreli wrote:
Needs a little more work to be correct. The following produces
and empty range. ;)
range(uint.min, uint.max)
Also, is it important for the result to be the same as T? For
example, even if T is ubyte, because b+1 is 'int', the
On Tuesday, 18 January 2022 at 22:09:18 UTC, Adam D Ruppe wrote:
On Tuesday, 18 January 2022 at 22:04:15 UTC, forkit wrote:
so I use this compile command (on Windows, using ldc)
On Linux dmd can do `-defaultlib=libphobos2.so` for the same
thing.
On Windows, dmd cannot handle a shared drunti
On Tuesday, 18 January 2022 at 22:35:08 UTC, H. S. Teoh wrote:
On Tue, Jan 18, 2022 at 10:04:15PM +, forkit via
Digitalmars-d-learn wrote:
so I use this compile command (on Windows, using ldc)
-link-defaultlib-shared=true
Then (in simple example) the size of my compiled .exe:
From 806KB
1 - 100 of 167 matches
Mail list logo