Directly compiling a D program with other libraries

2023-03-12 Thread Jeremy via Digitalmars-d-learn
Hello, I am new to this forum and to D. I am trying to compile a basic D program with libraries (`requests` which requires `cachetools` and `automem`) without using dub. I have never used dub before, only a compiler. The folders containing the libraries are in the same folder as main.d, the

Re: Best way to read/write Chinese (GBK/GB18030) files?

2023-03-12 Thread zjh via Digitalmars-d-learn
On Sunday, 12 March 2023 at 20:03:23 UTC, 0xEAB wrote: ... Thank you for your reply, but is there any way to output `gbk` code to the console?

Re: const in functions

2023-03-12 Thread FozzieBear via Digitalmars-d-learn
On Sunday, 12 March 2023 at 15:09:45 UTC, Salih Dincer wrote: ... So I don't agree with part of this comment (made elsewhere in this thread): "You can live without 'const' until your code interacts with other people's code." Code interacts with other code. Code should always be clear as

Re: Best way to read/write Chinese (GBK/GB18030) files?

2023-03-12 Thread 0xEAB via Digitalmars-d-learn
On Sunday, 12 March 2023 at 00:54:53 UTC, zjh wrote: On Saturday, 11 March 2023 at 19:56:09 UTC, 0xEAB wrote: If you desire to use other encodings, how about using ubyte + ubyte[]? There is no example. To read binary data from a file and dump it into another, you do: ```d import std.file

Re: 'auto' keyword

2023-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 3/12/23 06:07, DLearner wrote: > 1. As a shorthand to make the type of the variable being declared the > same as the type on the right hand side of an initial assignment. As Adam explained, D already has type inference without a special keyword. However, some places where 'auto' (or

Re: const in functions

2023-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 3/12/23 08:09, Salih Dincer wrote: > As someone who has used const very little in my life You can live without 'const' until your code interacts with other people's code. For example, the following program works just fine: struct S { int * p; void foo() {} } void bar(S s) {}

Re: 'auto' keyword

2023-03-12 Thread kdevel via Digitalmars-d-learn
On Sunday, 12 March 2023 at 13:27:05 UTC, Adam D Ruppe wrote: [...] *any* storage class will work for type inference. [...] After heaving read [1] I immediately thought of this: void main () { deprecated i = 3; i = 4; } $ dmd test.d test.d(4): Deprecation: variable

Re: const in functions

2023-03-12 Thread Hipreme via Digitalmars-d-learn
On Sunday, 12 March 2023 at 15:09:45 UTC, Salih Dincer wrote: Hi, As someone who has used const very little in my life, I want to learn and ask: What are consts used in function parameters for; isn't there a copy already? Const is used for you not be able to change your values inside

Re: 'auto' keyword

2023-03-12 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 12 March 2023 at 15:31:07 UTC, Salih Dincer wrote: Moreover, `auto ref` or `ref auto` is needed in functions. That's because `ref` isn't part of the argument or return value's type, so it isn't covered by **type** inference. Instead, D has a totally separate feature for "`ref`

Re: 'auto' keyword

2023-03-12 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 12 March 2023 at 13:07:58 UTC, DLearner wrote: Is it correct that this _single_ keyword is used to indicate _two_ quite different things: 1. As a shorthand to make the type of the variable being declared the same as the type on the right hand side of an initial assignment. The

const in functions

2023-03-12 Thread Salih Dincer via Digitalmars-d-learn
Hi, As someone who has used const very little in my life, I want to learn and ask: What are consts used in function parameters for; isn't there a copy already? ```d /* * Here's we have a class (Foo is partially simple): */ class Foo(T) { T x; // <--- Because gonna just an int

Re: 'auto' keyword

2023-03-12 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 12 March 2023 at 13:07:58 UTC, DLearner wrote: Is it correct that this _single_ keyword is used to indicate _two_ quite different things: No, it only actually does #2 in your thing. The type is optional meaning *any* storage class will work for type inference. `auto` is not

'auto' keyword

2023-03-12 Thread DLearner via Digitalmars-d-learn
Is it correct that this _single_ keyword is used to indicate _two_ quite different things: 1. As a shorthand to make the type of the variable being declared the same as the type on the right hand side of an initial assignment. Example: ```auto A = 5;``` makes A an int. 2. To indicate