Re: regarding what seems (to me) unnecessary casts on integer expressions

2021-06-04 Thread someone via Digitalmars-d-learn
On Saturday, 5 June 2021 at 02:07:03 UTC, Adam D. Ruppe wrote: This design was a mistake. Of all the great things I learned and read about it, this behavior was totally unexpected to me. It is really difficult to code strong-typed apps this way -this behavior is really wonderful for

regarding what seems (to me) unnecessary casts on integer expressions

2021-06-04 Thread someone via Digitalmars-d-learn
Consider the following code to keep track of rectangle positions on the screen; eg: (1,2)(3,2) ie: (left,top)(right,bottom), providing get/set properties for one-based positions but only get properties for zero-based positions: ```d public struct gudtPosition { final public void reset() {

Re: regarding what seems (to me) unnecessary casts on integer expressions

2021-06-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 5 June 2021 at 02:38:50 UTC, someone wrote: Furthermore, if, **at least**, there was a way to clearly state what is short (eg 1S a la 1L) things will improve a lot That actually doesn't matter. The compiler actually will automatically type it to the most narrow thing it fits. The

Re: regarding what seems (to me) unnecessary casts on integer expressions

2021-06-04 Thread someone via Digitalmars-d-learn
On Saturday, 5 June 2021 at 01:34:06 UTC, Kyle Ingraham wrote: It looks like you’re being caught by D’s arithmetic conversions: https://dlang.org/spec/type.html#usual-arithmetic-conversions “If the signed type is larger than the unsigned type, the unsigned type is converted to the signed

a=1; b=1; c=1; fine ... now a,b,c=1; ... something like this possible ?

2021-06-04 Thread someone via Digitalmars-d-learn
I think not -just in case.

Re: regarding what seems (to me) unnecessary casts on integer expressions

2021-06-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 5 June 2021 at 01:46:45 UTC, someone wrote: What's the point of declaring, for instance ushort's if then nothing will treat them as ushort's and I have to manually cast() everything to ushort() all the time ? Yeah, it totally sucks. D inherited a silly rule from C - the promote

Re: a=1;b=1;c=1; fine ... now a,b,c=1; ... something like this possible ?

2021-06-04 Thread someone via Digitalmars-d-learn
On Friday, 4 June 2021 at 20:02:28 UTC, drug wrote: a = b = c = 1; fantastic ... спасибо :) !

Re: regarding what seems (to me) unnecessary casts on integer expressions

2021-06-04 Thread Kyle Ingraham via Digitalmars-d-learn
On Saturday, 5 June 2021 at 00:24:01 UTC, someone wrote: On Saturday, 5 June 2021 at 00:24:01 UTC, someone wrote: ? 0 : cast(ushort)(this.pintBottom1 - 1); } It looks like you’re being caught by D’s arithmetic conversions: https://dlang.org/spec/type.html#usual-arithmetic-conversions “If

Re: How to compile Phobos with other D code to create a shared library?

2021-06-04 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 2 June 2021 at 23:23:58 UTC, bachmeier wrote: Are you aware of my embedr project, which handles all that for you, and does a lot of other stuff? https://embedr.netlify.app If you want to do it yourself, you can see the boilerplate you need to add to call a shared library from R

Re: Question about initialization

2021-06-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 4 June 2021 at 11:27:05 UTC, seany wrote: In my untrained eye, this seems haphazard. One requires the use of the new keyword It doesn't. T[] a; just works. it is an array of length 0.

Question about initialization

2021-06-04 Thread seany via Digitalmars-d-learn
Consider initializing a dictionary or associative array : T[U] AA; For example : double [int] AA; This will be dynamic in size. Now consider initializing a dynamic array : T[] A = new T[] (0); or U[][] B = new U [][] (0,0); This will also be dynamic in size. In my

Re: Is it possible to set function attributes conditionally?

2021-06-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 4 June 2021 at 11:33:32 UTC, wjoe wrote: This is a contrived example. In reality I would use this with custom array, hash map and other container implementations so I could use them in @nogc territory by just switching out the allocator. If they are templates, just don't specify

Is it possible to set function attributes conditionally?

2021-06-04 Thread wjoe via Digitalmars-d-learn
Hi, Consider Allocators, e.g.: ```d struct Mallocator { enum usesGC = false; /// implement alloc, free, etc. @nogc } struct GCAllocator { enum usesGC = true; /// implement alloc, free, etc. via the GC } ``` Now I want to have the function attributes set depending on the

Re: Is it possible to set function attributes conditionally?

2021-06-04 Thread wjoe via Digitalmars-d-learn
On Friday, 4 June 2021 at 11:36:09 UTC, Adam D. Ruppe wrote: On Friday, 4 June 2021 at 11:33:32 UTC, wjoe wrote: This is a contrived example. In reality I would use this with custom array, hash map and other container implementations so I could use them in @nogc territory by just switching out

Re: How to compile Phobos with other D code to create a shared library?

2021-06-04 Thread bachmeier via Digitalmars-d-learn
On Friday, 4 June 2021 at 07:26:53 UTC, data pulverizer wrote: Thanks. Looks like I have some more reading to do. I did know about embedr, but I saw it had dependencies and I wanted a standalone and fully transparent D solution. It requires an R package if you want to call D functions from

Re: How to compile Phobos with other D code to create a shared library?

2021-06-04 Thread Alain De Vos via Digitalmars-d-learn
Dub is probably not much of a help :)

Re: How to compile Phobos with other D code to create a shared library?

2021-06-04 Thread bachmeier via Digitalmars-d-learn
On Friday, 4 June 2021 at 15:33:32 UTC, Alain De Vos wrote: Dub is probably not much of a help :) That's right. I typically don't use Dub when I'm calling D functions from R. It's the only way you can use a Dub package like Mir, though, so that's why you might want it to generate a dub.sdl