Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 06:28:14PM +, Paul Backus via Digitalmars-d-learn wrote: > On Tuesday, 21 June 2022 at 17:33:46 UTC, H. S. Teoh wrote: > > > > Does the language allow you to declare a @system delegate inside > > @safe code? > > Yes. This compiles: > > void main() @safe > {

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 01:29:47PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 6/21/22 1:17 PM, H. S. Teoh wrote: [...] > > This is why I've proposed in the past that @safe functions should be > > allowed to call @system delegates that they receive as arguments. The > >

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 04:47:44PM +, Antonio via Digitalmars-d-learn wrote: > On Tuesday, 21 June 2022 at 16:20:32 UTC, Antonio wrote: > > > My code starts to be a @safe/@trusted mess (because external > > libraries). The only solution I have is to "wrap" them or to trust > > all code by

Re: a struct as an multidimensional array index

2022-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 10, 2022 at 08:08:45AM +, Chris Katko via Digitalmars-d-learn wrote: > Is it somehow possible to use a struct as a [multidimensional] array index: > > D > > struct indexedPair > { > size_t x, y; > } > > bool isMapPassable[100][100]; > auto p = indexedPair(50, 50); > >

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-06 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 06, 2022 at 10:18:08PM +, mw via Digitalmars-d-learn wrote: > Hi, > > Suppose I have this code: > > ``` > class GCAllocated { > float[] data; > > this() { > // non-gc-allocated field > this.data = cast(float[])(core.stdc.stdlib.malloc(nBytes)[0 .. nBytes]); > } > }

Re: Unexplainable behaviour with direct struct assignment.

2022-05-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 18, 2022 at 08:05:05PM +, HuskyNator via Digitalmars-d-learn wrote: [...] > ```d > module app; > import std.stdio; > > struct A { > float[1] vec; > this(float[1] n) { > this.vec = n; > } > } > > void main(string[] args) { > A c = A([50.0f]);

Re: class destructors must be @disabled?

2022-05-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 18, 2022 at 02:35:00PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > No. Class destructors are for cleaning up non-GC resources. As long as > you stick to those, you can safely run them. > > Structs that get put into classes have to run their destructors >

Re: class destructors must be @disabled?

2022-05-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 18, 2022 at 11:02:01AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > HORROR: > > Now, a big one that I've just realized. > > - The two guidelines above (the "don't touch class members" one and > the "don't allocate" one) miss an important fact that they apply >

Re: Why are structs and classes so different?

2022-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 16, 2022 at 05:02:57PM +, IGotD- via Digitalmars-d-learn wrote: > On Sunday, 15 May 2022 at 16:08:01 UTC, Mike Parker wrote: > > > > `scope` in a class variable declaration will cause it to the class > > to be allocated on the stack. > > > > Common practice is that a class has

Re: What are (were) the most difficult parts of D?

2022-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 16, 2022 at 04:00:12AM +, cc via Digitalmars-d-learn wrote: > On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: > > What are you stuck at? What was the most difficult features to > > understand? etc. > > > > To make it more meaningful, what is your experience with

Re: Why are structs and classes so different?

2022-05-15 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 15, 2022 at 08:05:05PM +, Kevin Bailey via Digitalmars-d-learn wrote: [...] > But I asked a different question: Why can't I put a class object on > the stack? What's the danger? [...] You can. Use core.lifetime.emplace. Though even there, there's the theoretical problem of stack

Re: What are (were) the most difficult parts of D?

2022-05-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 14, 2022 at 04:39:33AM +, zjh via Digitalmars-d-learn wrote: > On Saturday, 14 May 2022 at 04:31:48 UTC, zjh wrote: > > > Likewise, each post could add something like `votes` , > > Or something like all kinds of `tags` such as > `range/fiber/commandline/auto ref/in/...`. > >

Re: What are (were) the most difficult parts of D?

2022-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 13, 2022 at 06:29:54PM +, Adam D Ruppe via Digitalmars-d-learn wrote: [...] > Yeah, I used to be pro-TLS by default, then got bit by it several > times and moved to the fence, and now I'm anti. > > Data races aren't actually prevented by it (maybe forcing you to > specify shared

Re: What are (were) the most difficult parts of D?

2022-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 12, 2022 at 11:45:47PM +, Guillaume Piolat via Digitalmars-d-learn wrote: > On Thursday, 12 May 2022 at 17:34:30 UTC, H. S. Teoh wrote: > > > > Why is TLS by default a problem? > > > > It's not really for optimization, AIUI, it's more for thread safety: > > module-global state

Re: Back to Basics at DConf?

2022-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 13, 2022 at 03:43:09PM +, Johan via Digitalmars-d-learn wrote: > 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

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 12, 2022 at 09:04:09AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 5/11/22 18:06, Christopher Katko wrote: > > > Cool useful library functions like sumElement that magically don't > > work on static arrays. > > Yeah, that sometimes gets me as well. Although it is trivial

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 12, 2022 at 01:06:02AM +, Christopher Katko via Digitalmars-d-learn wrote: [...] > Cool useful library functions like sumElement that magically don't > work on static arrays. Just slice it with []: int[5] data = [ 1, 2, 3, 4, 5 ]; auto sum = data[].sumElement;

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 11, 2022 at 06:43:39PM +, Guillaume Piolat via Digitalmars-d-learn wrote: > On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: > > What are you stuck at? What was the most difficult features to > > understand? etc. > > - How to do deterministic destruction with

Re: Creating a custom iota()

2022-05-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 12, 2022 at 11:57:54AM +, realhet via Digitalmars-d-learn wrote: [...] > I have my own DateTime struct. > It has opCmp() and opBinary(), I can do arithmetic with this custom > DateTime and the amazing time units of the **quantities** package. > > Now I'm about mo make iterations

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 12, 2022 at 02:42:43PM +, Anonymouse via Digitalmars-d-learn wrote: [...] > The one thing that has caused me most anguish and woe is hands-down > https://issues.dlang.org/show_bug.cgi?id=18026 though. It hasn't bit > me for a while now, but the feeling of uncertainty, that the

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 12, 2022 at 12:13:32PM +, Basile B. via Digitalmars-d-learn wrote: [...] > Problem is more (from https://dlang.org/spec/expression.html#is_expression) > > ``` > is ( Type : TypeSpecialization , TemplateParameterList ) > is ( Type == TypeSpecialization , TemplateParameterList ) >

Re: What are (were) the most difficult parts of D?

2022-05-11 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 11, 2022 at 03:34:12PM +, Paul Backus via Digitalmars-d-learn wrote: > On Wednesday, 11 May 2022 at 15:10:28 UTC, Tejas wrote: > > That'll be true the day when `@safe` becomes the default... Until > > then, I'll atleast do `@safe:` on top of every module :) > > `@safe:` is

Re: What are (were) the most difficult parts of D?

2022-05-11 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 11, 2022 at 01:37:21PM +, matheus via Digitalmars-d-learn wrote: > On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: > > What are you stuck at? What was the most difficult features to > > understand? etc. > > > > To make it more meaningful, what is your experience with

Re: Trait for "can be instantiated"?

2022-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 10, 2022 at 04:10:26PM +, Ben Jones via Digitalmars-d-learn wrote: > On Tuesday, 10 May 2022 at 16:05:15 UTC, H. S. Teoh wrote: > > Using wrapper structs, etc., for this is IMO total overkill. Just > > use an enum for your token types. Something like this would > > suffice: > >

Re: Trait for "can be instantiated"?

2022-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 10, 2022 at 03:26:28PM +, Ben Jones via Digitalmars-d-learn wrote: [...] > I'm writing a lexer and I'm using sumtype to store any of the token types. > Some have values associated with them (like brackets and parens which are > defined as `enum lparen = '('` or whatever) and some

Re: Using regular expressions when reading a file

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 06:50:17PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > On Thursday, 5 May 2022 at 18:15:28 UTC, H. S. Teoh wrote: > > auto m = matchFirst(line, p_property); > > Yes, it looks more attractive. Thanks! I just don't quite understand how > `matchFirst` works.

Re: Using regular expressions when reading a file

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 05:53:57PM +, Alexander Zhirov via Digitalmars-d-learn 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

Re: Including C sources in a DUB project

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 06:05:55AM +, Alexander Zhirov via Digitalmars-d-learn wrote: > I'm sure there is such a topic on the forum, but after scrolling > through the search, I didn't find anything. The bottom line is that I > want to enable compilation of C sources in DUB and then build the

Re: How to use destroy and free.

2022-05-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 04, 2022 at 10:04:53PM +, forkit via Digitalmars-d-learn wrote: > 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: [...] [...] > > > To deny a programmer the option to release the

Re: How to use destroy and free.

2022-05-04 Thread H. S. Teoh via Digitalmars-d-learn
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 not be needed). > > To deny a programmer the option to

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 05:25:06PM +, cc via Digitalmars-d-learn wrote: > On Tuesday, 3 May 2022 at 17:05:09 UTC, H. S. Teoh wrote: > > Oops, sorry, I made a mistake. The definition of Serializable should be: > > > > class Serializable(Base, Derived = Object) : Base {} > > There we go,

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 04:59:42PM +, cc via Digitalmars-d-learn wrote: > On Tuesday, 3 May 2022 at 16:51:33 UTC, H. S. Teoh wrote: [...] > > > On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: > > > > class Base : Serializable!(Base) { ... } > > > > class Derived :

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 04:38:23PM +, cc via Digitalmars-d-learn wrote: > On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: > > class Base : Serializable!(Base) { ... } > > class Derived : Serializable!(Base, Derived) { ... } > > This is really interesting syntax, I'm

Re: How to use destroy and free.

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 02:57:46PM +, Alain De Vos via Digitalmars-d-learn 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 > variable is going out of scope. >

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 04:38:53PM +0200, Arafel via Digitalmars-d-learn wrote: > On 3/5/22 15:57, Adam D Ruppe wrote: > > So doing things yourself gives you some control. > > Yes, it is indeed possible (I acknowledged it), but I think it's much > more cumbersome than it should, and puts the load

Re: How to remove an element from a dynamic array with given index ?

2022-05-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 02, 2022 at 08:33:55PM +, Vinod K Chandran via Digitalmars-d-learn wrote: > Hi all, > I have dynamic array and I want to remove an element from it. All I > have the index of the element to remove. And I want to the array > should be in the same order. How to do it ? int[]

Re: A template construct like using()

2022-04-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 26, 2022 at 09:33:43PM +, Chris Katko via Digitalmars-d-learn wrote: [...] > I'm looking for a construct that mimics using(var)/with(var) > > D > bitmap* b; > > draw_with(b) > { > draw_pixel(red, 16, 16); //draw red pixel to bitmap b (b is implied above) > } > >

Re: Library for image editing and text insertion

2022-04-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 26, 2022 at 05:22:54PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > It is necessary to write a utility that will insert (x,y) text on the > image. It is desirable that the utility does not depend on large > libraries, since a minimum utility size is required. I'm looking

Re: How to use destroy and free.

2022-04-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 25, 2022 at 01:28:01PM +, Alain De Vos via Digitalmars-d-learn wrote: > Could thc or hboehm provide solutions ? In general, GC (of any kind) does not (and cannot) guarantee the order objects will be collected in. So in the dtor, you cannot assume that any objects you depend on

Re: How to get an IP address from network interfaces

2022-04-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 22, 2022 at 03:46:01PM +, IGotD- via Digitalmars-d-learn wrote: > On Friday, 22 April 2022 at 12:58:24 UTC, H. S. Teoh wrote: > > > > Why would you not want to use OS APIs? > > > > 1. Portability Usually when portability matters, you already have specific OSes that you're

Re: How to get an IP address from network interfaces

2022-04-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 22, 2022 at 09:26:13AM +, IGotD- via Digitalmars-d-learn wrote: > On Thursday, 21 April 2022 at 07:20:30 UTC, dangbinghoo wrote: > > > > [... Berkley sockets network code ...] > > > > It really makes me sad when I see this. D has some native networking > API but unfortunately

Re: Understanding alias template parameters

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 09:02:47PM +, JG via Digitalmars-d-learn wrote: > Hi, > > Could someone possibly help me to understand why the commented line > doesn't compile? > > > ```d > import std; > > struct MapResult(R,F) > { > R r; > const F f; > auto empty() { return r.empty; }

Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 02:11:03AM +, Alain De Vos via Digitalmars-d-learn wrote: > Following java program creates an infinite fibonacci sequence (stream) > an takes the first 42 values of it. [...] > How would this program look converted to dlang ? > Maybe there are multiple solutions ?

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 11:25:29AM +, Alain De Vos via Digitalmars-d-learn wrote: > On Thursday, 21 April 2022 at 06:57:41 UTC, drug wrote: > > On 21.04.2022 08:49, Alain De Vos wrote: > > > Following program: > > > ``` > > > import std.stdio; > > > > > > void main() @trusted > > > { [...] >

Re: Beginner memory question.

2022-04-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 19, 2022 at 05:01:15PM +, Era Scarecrow via Digitalmars-d-learn wrote: [...] > In linux using zram i've allocated and made a compressed drive of 8Gb > which took only 200k of space [...] All unallocated pages are assumed > null/zero filled, and if you zeroize a block it will

Re: Beginner memory question.

2022-04-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 19, 2022 at 12:54:06PM +, bauss via Digitalmars-d-learn wrote: > On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: > > On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: > > > Is virtual memory entering into the equation? > > > > Probably. Memory allocated

Re: Why do immutable variables need reference counting?

2022-04-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 18, 2022 at 12:55:26PM +, wjoe via Digitalmars-d-learn wrote: > On Sunday, 17 April 2022 at 14:14:37 UTC, H. S. Teoh wrote: > > Not entirely true. See paragraph 3 in: > > > > https://dlang.org/spec/unittest.html > > > > and 10.24.11.3 in: > > > >

Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 18, 2022 at 08:22:26AM +, cc via Digitalmars-d-learn wrote: > On Monday, 18 April 2022 at 03:21:30 UTC, H. S. Teoh wrote: > > Structs in D ought to be treated like "glorified ints", as Andrei > > puts it. If you need complex ctors and complex methods, that's a > > sign you should

Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-17 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Apr 17, 2022 at 05:35:13PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/17/22 08:13, HuskyNator wrote: [...] > > - 2: Why does adding a constructor to a struct disable the use of > > the static initialization syntax? > > I am not sure how to answer this question because I am

Re: Why do immutable variables need reference counting?

2022-04-17 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Apr 17, 2022 at 04:09:12PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] > Failing asserts are a messy part of the language. They are supposed to > be: > > 1) not catchable, because they indicate a bug in the program; > 2) catchable in order to be testable; > 3) assumed impossible

Re: Why do immutable variables need reference counting?

2022-04-17 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Apr 17, 2022 at 01:06:36PM +, wjoe via Digitalmars-d-learn wrote: [...] > On the matter of undefined behavior. Technically a program is in > undefined behavior land after throwing an error, thus every unittest > that continues after assertThrown is therefore nonsense code, is it > not

Re: Why do immutable variables need reference counting?

2022-04-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 13, 2022 at 08:39:17AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/12/22 21:34, Salih Dincer wrote: > > > I tried the following and I didn't understand one thing: Why is > > there no need to use dup when slicing? [...] Because of two things: (1) there is a GC, and (2)

Re: Importing version identifiers from another file?

2022-04-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 12, 2022 at 10:07:15AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/11/22 01:57, KytoDragon wrote: > > > Is there any way to import version specifiers from a separate file? > > Have you tried mixing in the versions? Have one file with the versions > in it: > > //

Re: Const Variables

2022-04-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 04, 2022 at 11:20:31AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/3/22 17:42, H. S. Teoh wrote: > > > In some sense, this is like an extension of ctors initializing > > immutable values. The compiler tracks whether the variable has been > > initialized yet, and inside

Re: Const Variables

2022-04-03 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Apr 03, 2022 at 03:42:15PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > In any case, there is no logical constness in D. (However, one can > play tricks like using casts. (Which may be undefined behavior, etc. > etc.)) [...] A thought occurred to me. What is logical const,

Re: Does the GC consider slice lengths?

2022-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 01, 2022 at 01:15:01PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/1/22 10:46, Steven Schveighoffer wrote: > > >> But if it considers slices and their lengths specially, then it > >> would see that the mid section is not referenced any more. > > > > It's not a

Re: How do you properly use immutable on class members?

2022-03-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 29, 2022 at 05:58:11PM +, Fruitful Approach via Digitalmars-d-learn wrote: > I have immutable members: > > `immutable immutable(Prop)[] axioms` which I can't initialize with > Prop[], so I call this "immutable-poisoning" of the rest of my code. > Can you provide a 10 line example

Re: Why exe size change if import entire std or just writeln?

2022-03-23 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 24, 2022 at 01:49:30AM +, Marcone via Digitalmars-d-learn wrote: > import std.stdio : writeln; > > void main(){ > writeln("Bom dia"); > } > > > Size exe file: 258 KB > > -- > > import std; > > void main(){ >

Re: Basic question about size_t and ulong

2022-03-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 22, 2022 at 09:11:00PM +, Era Scarecrow via Digitalmars-d-learn wrote: [...] > I'd almost wish D had a more lenient mode and would do automatic > down-casting, then complain if it *would* have failed to downcast data > at runtime. [...] We already have this: import

Re: I like dlang but i don't like dub

2022-03-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 22, 2022 at 05:36:13PM +, IGotD- via Digitalmars-d-learn wrote: > On Friday, 18 March 2022 at 18:16:51 UTC, Ali Çehreli wrote: > > > > The first time I learned about pulling in dependencies terrified me. [...] > >

Re: Determining function template from runtime type: better ideas?

2022-03-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 22, 2022 at 07:09:07AM +, cc via Digitalmars-d-learn wrote: > Sorry for the fairly lengthy post. I'm wondering if there are any > suggested good practices in place for calling templated functions > using the runtime type of an object, e.g. what `typeid(object)` > returns. [[...]

Re: I like dlang but i don't like dub

2022-03-21 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Mar 20, 2022 at 07:51:38AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 3/20/22 05:27, Adam D Ruppe wrote: > > > So if it just coincidentally happens to be the same code, I'd > > actually rather copy/paste it than import it. > > This is very interesting because it is so much

Re: I like dlang but i don't like dub

2022-03-18 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 18, 2022 at 11:16:51AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > tldr; I am talking on a soap box with a big question mind hovering > over on my head: Why can't I accept pulling in dependencies > automatically? Because it's a bad idea for your code to depend on some

Re: I like dlang but i don't like dub

2022-03-18 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 18, 2022 at 04:13:36AM +, Alain De Vos via Digitalmars-d-learn wrote: > Dlang includes some good ideas. > But dub pulls in so much stuff. Too much for me. > I like things which are clean,lean,little,small. > But when i use dub it links with so many libraries. > Are they really

Re: Write UTF-8 bytes directly to stack buffer

2022-03-10 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 10, 2022 at 05:39:34PM +, Chris Piker via Digitalmars-d-learn wrote: > Hi D > > There are quite a few string, array and range functions in phobos so > I'm getting confused as to the right way to encode string data as > UTF-8 directly into a stack buffer while keeping track of the

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 04, 2022 at 08:38:11PM +, ag0aep6g via Digitalmars-d-learn wrote: [...] > The second version involves auto-decoding, which isn't actually > needed. You can work around it with `str.byCodeUnit.filter!...`. On my > machine, times become the same then. [...] And this here is living

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 04, 2022 at 07:51:44PM +, matheus via Digitalmars-d-learn wrote: [...] > for(j=0;j<1_000_000;++j){ > s=""; > s = str.filter!(ch => ch.isDigit).to!string; This line allocates a new string for every single loop iteration. This is generally not something you want

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 03, 2022 at 06:36:35PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 3/3/22 13:03, H. S. Teoh wrote: > > > string s = "blahblah123blehbleh456bluhbluh"; > > > assert(result == 123456); > > I assumed it would generate separate integers 123 and 456. I started > to

Re: How to remove all characters from a string, except the integers?

2022-03-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 03, 2022 at 10:54:39PM +, matheus via Digitalmars-d-learn wrote: > On Thursday, 3 March 2022 at 21:03:40 UTC, H. S. Teoh wrote: [...] > > -- > > void main() { > > string s = "blahblah123blehbleh456bluhbluh"; > > auto result = s.filter!(ch => ch.isDigit).to!int; > >

Re: How to remove all characters from a string, except the integers?

2022-03-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 03, 2022 at 08:23:14PM +, forkit via Digitalmars-d-learn wrote: > On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote: > > > > I'm a simple man who uses D with the old C mentality: > > > > import std.stdio; > > > > void main(){ > > string s, str = "4A0B1de!2C9~6"; > >

Re: Setting SQLite compile time parameters from etc.c.sqlite3

2022-03-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 01, 2022 at 08:59:46PM +, data pulverizer via Digitalmars-d-learn wrote: > Hello all, > > I'm not sure how to set the compile time parameters in D's SQLite > module particular the items that take multiple parameters, for example > in the C API manual `SQLITE_CONFIG_MMAP_SIZE`

Re: Odd behaviour of std.range

2022-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 22, 2022 at 05:25:18PM +, frame via Digitalmars-d-learn wrote: > On Tuesday, 22 February 2022 at 13:25:16 UTC, bauss wrote: > > > Welcome to the world of auto decoding, D's million dollar mistake. > > Well, I think it's ok for strings but it shouldn't do it for simple > arrays

Re: keyword as struct field

2022-02-20 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 20, 2022 at 04:52:30PM +, partypooper via Digitalmars-d-learn wrote: > On Sunday, 20 February 2022 at 15:33:17 UTC, Andrey Zherikov wrote: > > On Sunday, 20 February 2022 at 11:08:55 UTC, partypooper wrote: > > > keyword as struct field > > > > I believe this is the case for the

Re: Does anyone build for Android? Tons of link errors..

2022-02-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 16, 2022 at 08:40:02PM +, Fry via Digitalmars-d-learn wrote: > I'm getting a ton of linker errors when building with LDC with the > aarch64 release from here: [...] > Is anyone able to build for android? I adapted the instructions from:

Re: split Error - no overload matches

2022-02-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 15, 2022 at 06:37:44PM +, meta via Digitalmars-d-learn wrote: > A trick i use often: > > ```D > import std; > > void main() > { > import uni = std.uni; > writeln("Learning D is fun".split!(uni.isWhite)); > } > > ``` > > Under-rated way of importing things, you don't

Re: how to handle very large array?

2022-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 12, 2022 at 06:41:14PM +, Era Scarecrow via Digitalmars-d-learn wrote: > On Thursday, 10 February 2022 at 01:43:54 UTC, H. S. Teoh wrote: > > On Thu, Feb 10, 2022 at 01:32:00AM +, MichaelBi via > > Digitalmars-d-learn wrote: > > > thanks, very helpful! i am using a assocArray

Re: Declaring a reusable formula and using it in other scopes.

2022-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 12, 2022 at 05:52:01PM +, Basile B. via Digitalmars-d-learn wrote: [...] > The problem with that solution is that it's not clean. > The problem of the initial problem is to have automatic capture of `i` > and `args` in any scope... > > Lost cause ? Lost cause, IMO. Automatic

Re: Is there an equivavlent to C# boxing in D?

2022-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 12, 2022 at 09:37:56AM +, IGotD- via Digitalmars-d-learn wrote: > On Saturday, 12 February 2022 at 00:41:22 UTC, H. S. Teoh wrote: [...] > > > > final class Boxed(T) { > > T payload; > > alias payload this; // caveat: probably not a good idea in general > >

Re: Is there an equivavlent to C# boxing in D?

2022-02-11 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 12, 2022 at 12:27:34AM +, IGotD- via Digitalmars-d-learn wrote: > If you want to store a value type on the heap in D you just use "new" > and a pointer to the type. The same thing in C# would be to wrap the > value type into an object. However when you do that automatic >

Re: Cross Compile to Linux from Windows using LDC?

2022-02-10 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 10, 2022 at 04:43:12PM +, Fry via Digitalmars-d-learn wrote: > Is it possible to compile for Linux from Windows using the LDC > compiler? It seems like it is possible to compile for different > architectures Linux x86 -> Linux Arm but what about for Windows x86 -> > Linux x86? I'm

Re: how to handle very large array?

2022-02-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 10, 2022 at 01:32:00AM +, MichaelBi via Digitalmars-d-learn wrote: > On Wednesday, 9 February 2022 at 19:48:49 UTC, H. S. Teoh wrote: > > [...] > > thanks, very helpful! i am using a assocArray now... Are you sure that's what you need? T -- Computers are like a jungle: they

Re: How to use sets in D?

2022-02-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 10, 2022 at 12:53:08AM +, Siarhei Siamashka via Digitalmars-d-learn wrote: > On Wednesday, 9 February 2022 at 21:05:47 UTC, Siarhei Siamashka wrote: > > Is the current implementation of associative arrays in D language > > resistant to Denial of Service hash collision attacks? >

Re: how to handle very large array?

2022-02-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 09, 2022 at 11:05:23AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 2/9/22 10:38, MoonlightSentinel wrote: > > > There's a way to use a much smaller array to manage the lanternfish > > population... > > As soon as I read your comment, I was reminded of a certain ingenious

Re: How to use sets in D?

2022-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 08, 2022 at 10:02:30PM +, Paul Backus via Digitalmars-d-learn wrote: [...] > It also works if you use parentheses: > > mySet[...] = (void[0]).init; OT1H, nice that works! ... but OTOH, ugh, it looks so ugly. :-P I think I'll just stick with the alias. T -- Who told you

Re: How to use sets in D?

2022-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 08, 2022 at 09:47:13PM +, Paul Backus via Digitalmars-d-learn wrote: [...] > The `alias` and the `enum` just make the code a little nicer to read > by letting you write `Unit` instead of `void[0]` and `unit` instead of > `void[0].init`. You could get rid of them and the code would

Re: How to use sets in D?

2022-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 08, 2022 at 09:08:47PM +, tastyminerals via Digitalmars-d-learn wrote: [...] > > bool[E] works just fine. > > > > The bool does take up 1 byte, though, so if you're *really* want to > > optimize that away, you could do this: > > > > alias Unit = void[0]; > > enum unit =

Re: Approach to Integration Testing in D

2022-02-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 04, 2022 at 12:38:08PM +, Vijay Nayar via Digitalmars-d-learn wrote: [...] > What is your approach to integration testing in D? Do you use > `unittest` blocks? Do you write stand-alone programs that interact > with a running version of your program? Is there a library that makes >

Re: ldc executable crashes with this code

2022-02-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 04, 2022 at 03:58:19PM +, Stanislav Blinov via Digitalmars-d-learn wrote: [...] > As others have already stated, casting immutability away is something > that has to be supported, e.g. to interface with const-agnostic APIs. > `@safe` requires such casts to be more verbose, with

Re: ldc executable crashes with this code

2022-02-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 03, 2022 at 02:01:34AM +, forkit via Digitalmars-d-learn wrote: [...] > would be nice if the compiler told me something though :-( > > i.e. "hey, dude, you really wanna to that?" Mark your function @safe, and the compiler will stop you from unsafe casts of this nature. That's

Re: ldc executable crashes with this code

2022-02-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 03, 2022 at 01:39:33AM +, forkit via Digitalmars-d-learn wrote: > On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote: > > On Wed, Feb 02, 2022 at 11:21:52PM +, forkit via Digitalmars-d-learn > > wrote: [...] > > > char[] palindrome = cast(char[])"able was I ere

Re: ldc executable crashes with this code

2022-02-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 02, 2022 at 11:21:52PM +, forkit via Digitalmars-d-learn wrote: [...] > char[] palindrome = cast(char[])"able was I ere I saw elba"; String literals are immutable by default. Casting immutable to mutable is UB (Undefined Behaviour). [...] > writeln(palindrome.reverse);

Re: Can anyone provide an example of how D templates are overridable by global symbols?

2022-01-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 29, 2022 at 12:17:49AM +, Siarhei Siamashka via Digitalmars-d-learn wrote: > On Friday, 28 January 2022 at 23:43:00 UTC, H. S. Teoh wrote: > > You don't have to rely on any opinions. Try it out yourself and find > > out for sure. > > I guess, my problem and the source of all

Re: Can anyone provide an example of how D templates are overridable by global symbols?

2022-01-28 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 28, 2022 at 11:01:41PM +, Siarhei Siamashka via Digitalmars-d-learn wrote: [...] > Internet seems to disagree about what happens when multiple weak > symbols are encountered and various interpretations can be found: > "Given multiple weak symbols, choose any of the weak symbols",

Re: Embarrassed to ask this question because it seems so trivial but genuinely curious...

2022-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 27, 2022 at 05:42:09PM +, WhatMeWorry via Digitalmars-d-learn wrote: > While studying Ali's book at chapter "Constructor and Other Special > Functions" and the below code snippet: [...] > // Original > //this(int i) const { writeln("a const object"); } >

Re: gdc or ldc for faster programs?

2022-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 27, 2022 at 08:46:59AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...] > I see that template instantiations are linked through weak symbols: > > $ nm deneme | grep foo > [...] > 00021380 W _D6deneme__T3fooTiZQhFNaNbNiNfZv > > What I know is that weak symbols can be

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 11:01:57PM +, forkit via Digitalmars-d-learn wrote: > On Tuesday, 25 January 2022 at 20:01:18 UTC, Johan wrote: > > > > Tough to say. Of course DMD is not a serious contender, but I > > believe the difference between GDC and LDC is very small and really > > in the

Re: passing a variadic parameter to randomSample

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 10:48:26PM +, forkit via Digitalmars-d-learn wrote: [...] > ... but my main focus here, was learning about variadic template > functions. D has several flavors of variadics: 1) C-style variadics (not type-safe, not recommended): int func(int firstArgc, ...)

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 10:41:35PM +, Elronnd via Digitalmars-d-learn wrote: > On Tuesday, 25 January 2022 at 22:33:37 UTC, H. S. Teoh wrote: > > interesting because idivl is known to be one of the slower > > instructions, but gdc nevertheless considered it not worthwhile to > > replace it,

Re: passing a variadic parameter to randomSample

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 02:07:43PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...] > auto RandomChoice(R)(R[] r...) > > > { > > auto rnd = MinstdRand0(unpredictableSeed); > > return only(r).randomSample(1, rnd).front; > > Which makes that simpler as well because being a slice,

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 01:30:59PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...] > I posted the program to have more eyes on the assembly. ;) [...] I tested the code locally, and observed, just like Ali did, that the LDC version is unambiguously slower than the gdc version by a small

  1   2   3   4   5   6   7   8   9   10   >