October 08
On Sunday, 21 August 2022 at 05:03:43 UTC, Ali Çehreli wrote:
> On 8/20/22 20:44, Walter Bright wrote:
>
> > I.e. a "payload" can be put in the mantissa bits of a NaN,
> which can be
> > used to provide more information about the NaN.
>
> I think it is called "nan boxing."
>
> > I've never seen anyone
> > use this, though, but someone might
>
> I heard about it either at a meetup or at a DConf. The speaker was explaining that exact technique.

Just learnt from here:

https://github.com/Robert-van-Engelen/tinylisp/issues/12#issuecomment-1752142467

> > Another question I want ask is: the NaN boxing trick is OK, but why it's needed here (for education purpose Lisp implementation, this trick I think actually distracted learners from learning Lisp)? Why cannot we just use bit fields or a small struct as tagged union? Also by using NaN boxing, are we actually wasting 13 bits for each double?
> 
> Lots of modern PL implementations use NaN boxing instead of tagged structs/unions. Nothing gets wasted, because a cell has to be a fixed size anyway, which is the larger size of all possible values it can hold. Adding a tag therefore makes the cell structure larger by a byte, at least, to hold a tag. That also makes addressing less efficient, since cells are no longer guaranteed to be 32 bit aligned (or the tag has to be 32 bits, which wasts more bits).


I think I understand it now, the benefits of using NaN boxing is that: in a 64-bit double

all the doubles are still fully represented
use 48 bit as pointer can still address 262,144 GB memory, that is good enough for any computer today
only integer's range gets shrunk: from 64-bit to 48-bit (49 with sign bit depends on if we choose to use it), that's good for most purpose, and if one really need > 48-bit integer type, then use the fat BigInt (class / struct) then (which will be treated as object pointer type).
(1) and (3) means all the scalar types are stored as scalar, not pointers to some other representations.

That's very compact design indeed.

October 09
On 8/21/22 16:09, Dark Hole wrote:
> 
> My point is making this by default for all primitive types. This will be consistent and simple:
> ```d
> bool x; // Error, use bool? or init it something meaningful
> struct Foo { bool x; } // Error too
> ```
> So we have no problem "programmers make meaningless 0" and have no problem to determine init for most of types.

I think a better way to approach this problem is to have a language where people are not tempted to declare a variable into which they have no sensible value to put in the first place. If you have no value at a given point in the program, you should not need a variable to hold one.
October 09
On Monday, 9 October 2023 at 00:03:24 UTC, Timon Gehr wrote:
> On 8/21/22 16:09, Dark Hole wrote:
>> 
>> My point is making this by default for all primitive types. This will be consistent and simple:
>> ```d
>> bool x; // Error, use bool? or init it something meaningful
>> struct Foo { bool x; } // Error too
>> ```
>> So we have no problem "programmers make meaningless 0" and have no problem to determine init for most of types.
>
> I think a better way to approach this problem is to have a language where people are not tempted to declare a variable into which they have no sensible value to put in the first place. If you have no value at a given point in the program, you should not need a variable to hold one.

~~definitely not bumping this thread to keep it alive~~

Im pretty sure that declaration before use needs to be a thing cause compilers are still bad at knowing where memory sure go and I need my goto and global scope variables.
October 12

On Friday, 26 August 2022 at 16:28:32 UTC, Steven Schveighoffer wrote:

>

On 8/25/22 9:01 PM, Walter Bright wrote:

>

On 8/25/2022 10:38 AM, Steven Schveighoffer wrote:

>

0 is no better here but also no worse.

0 is equal or worse than NaN. It is true that sometimes 0 is equal. But it is never better.

I fully don't ever expect any changes to come from this discussion. But just to continue the point here, yes, it's slightly better in some cases. The question to answer is how many cases, and is the pain caused by having to go correct problems that should never have existed in the first place worth fixing those few cases where it actually helps.

At the end of the day, the answer is: Default initializing floats to NaN is (very) arguably important to the niche high-expertise line of work Walter engaged in, and fairly annoying to the vast sea of untapped market potential and prospective programmers D may or may not sorta-kinda-hope to snag a share of someday, as its figurative hairline gradually recedes trying to determine how best to balance being the greatest wisest language in the world at certain arbitrary vanishingly minor daily debugging issues while still providing users with countless ways to freely shoot themselves in the foot and crash their planes on weekends.

It's all a weighting issue, and the weight has been placed on the importance of the niche work over the some small percentage of grumbling and stubbed toes the different-from-how-everyone-else-does-it change incurs.

October 26

On Thursday, 12 October 2023 at 09:54:33 UTC, cc wrote:

>

On Friday, 26 August 2022 at 16:28:32 UTC, Steven Schveighoffer wrote:

>

On 8/25/22 9:01 PM, Walter Bright wrote:

>

On 8/25/2022 10:38 AM, Steven Schveighoffer wrote:

>

0 is no better here but also no worse.

0 is equal or worse than NaN. It is true that sometimes 0 is equal. But it is never better.

I fully don't ever expect any changes to come from this discussion. But just to continue the point here, yes, it's slightly better in some cases. The question to answer is how many cases, and is the pain caused by having to go correct problems that should never have existed in the first place worth fixing those few cases where it actually helps.

At the end of the day, the answer is: Default initializing floats to NaN is (very) arguably important to the niche high-expertise line of work Walter engaged in, and fairly annoying to the vast sea of untapped market potential and prospective programmers D may or may not sorta-kinda-hope to snag a share of someday, as its figurative hairline gradually recedes trying to determine how best to balance being the greatest wisest language in the world at certain arbitrary vanishingly minor daily debugging issues while still providing users with countless ways to freely shoot themselves in the foot and crash their planes on weekends.

It's all a weighting issue, and the weight has been placed on the importance of the niche work over the some small percentage of grumbling and stubbed toes the different-from-how-everyone-else-does-it change incurs.

Niche maybe. Many other languages default initialize floats to 0 (i.e. Go).

But NaN initialization on floats/double/complex did save me few times in the past, and allowed to actually be able to trace the problem, that I probably did not even knew I had otherwise.

I like NaN initialization. Just like I like null initialization for pointers.

October 25
On 10/8/2023 12:47 PM, mw wrote:
> That's very compact design indeed.


Interestingly, the nan boxing in tinylisp exposed a subtle code gen problem with dmd (fixed now).
October 26

On Thursday, 26 October 2023 at 02:42:37 UTC, Witold wrote:

>

I like NaN initialization. Just like I like null initialization for pointers.

Me too.

Actually, I just tried the follwing in importC, to see how dmd will handle the init:

#include <stdio.h>

int main() {
  int i;
  double d;
  printf("%d %f\n", i, d);
  return 0;
}

$ dmd import_c.c
$ ./import_c
1973916528 0.000000
$ ./import_c
1108345712 0.000000

looks like it still using the C semantics.

From what I read "How ImportC Works": https://dlang.org/spec/importc.html#internals

" ... converts the C syntax into the same AST (Abstract Syntax Tree) that D uses".

So, I'm just wondering can we add a switch: I really want the ImportC will init the variable with D's semantics.

@Walter, How does this sound? :-)

11 12 13 14 15 16 17 18 19 20 21
Next ›   Last »