Re: Where I download Digital Mars C Preprocessor sppn.exe?

2022-04-03 Thread Tejas via Digitalmars-d-learn

On Sunday, 3 April 2022 at 08:37:45 UTC, user1234 wrote:

On Saturday, 2 April 2022 at 21:57:02 UTC, Marcone wrote:
Where I download Digital Mars C Preprocessor sppn.exe? I need 
it to use ImportC


it's part of the [DMC] toolchain.

[DMC]: 
http://ftp.digitalmars.com/Digital_Mars_C++/Patch/dm857c.zip


Guys I think Ali is right... The post was meant as an April 
fool's joke... It was pretty badly mistimed though, at the time 
of his posting, it was 3rd April in my place, and undoubtedly 2nd 
everywhere else


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, and how can we make it
useful?  Useful meaning, it's not just a convention (like in C++) with
no hard guarantees and no verifiability.

Currently, D has physical const, so `const` cannot be used for things
like caching, lazily-initialized objects, and other things that are
logically const but not physically const because mutation is involved.
But what really is physical const?  It's essentially a contract,
guaranteed by the language and statically verified by the compiler, that
the physical data has not changed.  IOW, it's a contract stating that
the data physically stored before operation X is identical to the data
physically stored after operation X, and that it has not changed in the
meantime.

Now can we extend this concept to logical const?  Perhaps in this way:
instead of guaranteeing the physical data is unchanged, what about a
contract that guarantees that *externally-observable behaviour* of the
object is unchanged?  Meaning, the object may actually have changed
internally, but as long as this cannot be observed externally (and this
includes *future* behaviour of the object -- so we're not just slipping
internal state changes under the carpet that may later alter the
object's behaviour), to the outside world it behaves as though it were
actually const.

In the case of lazy initialization, for example, it ought to be provable
that the value of the object, as observed by the outside world, cannot
change. The initial state where the value is uninitialized is not
observed by the outside world; the only observable value only appears
after initialization, and does not change henceforth.

Similarly for a cached value: it ought to be provable that the first
computation of value is the *only* value that can be externally
observed; after the initial computation, the value will never change
again.

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 the ctor you can assign to immutable because the
uninitialized value is not observable from outside before that. Once
assigned, the compiler enforces no subsequent changes.

It's also like D's extension of purity, where impure operations are
allowed as long as the outside world cannot tell the difference.

There should be some way of implementing logical const along these lines
that still provides guarantees whilst relaxing the physical immutability
rule.


T

-- 
It only takes one twig to burn down a forest.


Re: Const Variables

2022-04-03 Thread Ali Çehreli via Digitalmars-d-learn

On 4/3/22 11:24, Salih Dincer wrote:
> On Sunday, 3 April 2022 at 14:29:22 UTC, Paul Backus wrote:
>> On Sunday, 3 April 2022 at 13:50:28 UTC, Salih Dincer wrote:
>>> Hi all,
>>>
>>> Do you have a good example of how const variables actually work?

You are right that const is not absolutely necessary. However, it is 
such a useful concept that some programming languages don't allow 
mutation at all.


Immutability is seen to be so valuable that some people argue that the 
default in D should be immutable. (Rust is just one example where the 
default is const. In that language, you have to use 'mut' (presumably 
short for "mutable") for variables that can be mutated.)


>> This is covered in the const FAQ:
>>
>> https://dlang.org/articles/const-faq.html
>
> The programs I write are not multithreaded. Also, I don't work as a
> team.

So you agree with that article. :) The rest of us who work with 
multi-threaded programs or with other developers agree with it as well. ;)


> Thanks for the link but there is only the following example:
>
> ```d
> struct Foo
> {
>  mutable int len;

Wow! That article must be from the early days of D. There is no 
'mutable' in D (any more?).


>  mutable bool len_done;
>  const char* str;
>  int length()
>  {
>  if (!len_done)
>  {
>  len = strlen(str);
>  len_done = true;

That example is the concept of logical constness, where the object 
computes some value as neeeded and caches the result for later use. The 
member 'len' (and len_done) is modified even if the 'f' object below is 
const. However, the example doesn't fit today's D because the function 
should have been marked as 'const' as well:


int length() const {
  // ...
}

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.))


>  }
>  return len;
>  }
>  this(char* str) { this.str = str; }
> }
> const Foo f = Foo("hello");
> bar(f.length);

So, there is the 'const' object f and calling its length() member 
function, which mutates two members of the object. As those mutations do 
not change the value of the object, the object is considered still the 
same. In other words, caching something about the object is considered 
to not change that object. That's what is meant with logical const: 
There has been changes but they did not change the state of the object.


Ali



Re: Const Variables

2022-04-03 Thread Salih Dincer via Digitalmars-d-learn

On Sunday, 3 April 2022 at 14:29:22 UTC, Paul Backus wrote:

On Sunday, 3 April 2022 at 13:50:28 UTC, Salih Dincer wrote:

Hi all,

Do you have a good example of how const variables actually 
work?


So I'm not talking about system resources and programming 
errors.  I want to say it's good.  Because if everything works 
without it, why does it exist?


This is covered in the const FAQ:

https://dlang.org/articles/const-faq.html


The programs I write are not multithreaded.  Also, I don't work 
as a team.  Thanks for the link but there is only the following 
example:


```d
struct Foo
{
mutable int len;
mutable bool len_done;
const char* str;
int length()
{
if (!len_done)
{
len = strlen(str);
len_done = true;
}
return len;
}
this(char* str) { this.str = str; }
}
const Foo f = Foo("hello");
bar(f.length);
```

Moreover, I did not understand anything from the example in the 
article :)


SDB@79


Re: arsd.minigui

2022-04-03 Thread JG via Digitalmars-d-learn

On Sunday, 3 April 2022 at 17:10:48 UTC, Adam Ruppe wrote:

On Sunday, 3 April 2022 at 16:58:03 UTC, JG wrote:

[...]


Which resizeImage did you use, from the imageresize module? 
What pain you have with it? Some of its settings take some 
tweaking.


[...]


Thank you very much for your quick reply. I see now I was doing 
something silly.


Re: arsd.minigui

2022-04-03 Thread Adam Ruppe via Digitalmars-d-learn

On Sunday, 3 April 2022 at 16:58:03 UTC, JG wrote:

Hi,

I have an png image that I generate (via pdf via pdflatex) that 
I want to scale and display in a widget. Is this possible via 
something in arsd? I tried resizeImage but that doesn't seem to 
do what I expect. Any suggestions?


Which resizeImage did you use, from the imageresize module? What 
pain you have with it? Some of its settings take some tweaking.


Though in a widget, you can also stretch automatically on 
Windows... actually XRender can do it too i believe but I never 
implemented that. Maybe I should.


But imageresize should work with some experimentation. This is 
how I did it in my image viewer application:



   auto i = loadImageFromFile(arg);

auto size = 
calculateSizeKeepingAspectRatio(i.width, i.height, maxWidth, 
maxHeight);
if(size.width != i.width || 
size.height != i.height) {
i = imageResize(i, 
size.width, size.height, null, 1.0, 0.6);

}


then pass that i to one of the minigui/simplediplay functions to 
display.


arsd.minigui

2022-04-03 Thread JG via Digitalmars-d-learn

Hi,

I have an png image that I generate (via pdf via pdflatex) that I 
want to scale and display in a widget. Is this possible via 
something in arsd? I tried resizeImage but that doesn't seem to 
do what I expect. Any suggestions?









Re: Unit tests via DUB

2022-04-03 Thread Andre Pany via Digitalmars-d-learn

On Saturday, 2 April 2022 at 11:53:12 UTC, alexanderzhirov wrote:
I don't quite understand why compiling unit tests using DUB 
doesn't work.


[...]


Have a look here
https://andre2007.github.io/d-tips/dub/application_template/

Kind regards
Andre





Re: Const Variables

2022-04-03 Thread Paul Backus via Digitalmars-d-learn

On Sunday, 3 April 2022 at 13:50:28 UTC, Salih Dincer wrote:

Hi all,

Do you have a good example of how const variables actually work?

So I'm not talking about system resources and programming 
errors.  I want to say it's good.  Because if everything works 
without it, why does it exist?


This is covered in the const FAQ:

https://dlang.org/articles/const-faq.html


Const Variables

2022-04-03 Thread Salih Dincer via Digitalmars-d-learn

Hi all,

Do you have a good example of how const variables actually work?

So I'm not talking about system resources and programming errors. 
 I want to say it's good.  Because if everything works without 
it, why does it exist?


Thanks, SDB@79


Re: Where I download Digital Mars C Preprocessor sppn.exe?

2022-04-03 Thread user1234 via Digitalmars-d-learn

On Saturday, 2 April 2022 at 21:57:02 UTC, Marcone wrote:
Where I download Digital Mars C Preprocessor sppn.exe? I need 
it to use ImportC


it's part of the [DMC] toolchain.

[DMC]: 
http://ftp.digitalmars.com/Digital_Mars_C++/Patch/dm857c.zip


Re: Where I download Digital Mars C Preprocessor sppn.exe?

2022-04-03 Thread forkit via Digitalmars-d-learn

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 to 
realize that it wasted time.


https://dlang.org/spec/importc.html


ImportC is an interesting, and possibly useful feature..to a 
select few, but ALL will have to carry it.


IMO...ImportC will be D's biggest mistake.



Re: Where I download Digital Mars C Preprocessor sppn.exe?

2022-04-03 Thread Ali Çehreli via Digitalmars-d-learn

On 4/2/22 16:40, Marcone wrote:
> ImportC is deprecated as everything in D is deprecated and abandoned.

You're off a little: April Fool's was yesterday. :o)

Ali