Re: GREETINGS FROM iSTANBUL

2021-08-01 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 1 August 2021 at 18:22:05 UTC, Paul Backus wrote: On Sunday, 1 August 2021 at 17:56:00 UTC, rikki cattermole wrote: It appears you are using the wrong lowercase character. I think so too, here's the proof: ```d import std.string, std.stdio; void main() { auto istanbul =

Re: GREETINGS FROM iSTANBUL

2021-08-01 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 1 August 2021 at 18:22:05 UTC, Paul Backus wrote: A common solution to this in other languages is to have a version of toUpper that takes a locale as an argument. Some examples: - Javascript:

GREETINGS FROM iSTANBUL

2021-08-01 Thread Salih Dincer via Digitalmars-d-learn
Greetings from istanbul... In our language, the capital letter 'i' is used, similar to the lower case. But in this example: ```d // D 2.0.83 import std.stdio, std.uni; void main() { auto message = "Greetings from istanbul"d; message.asUpperCase.writeln; // GREETINGS FROM ISTANBUL /*

Re: abstract classes and interfaces

2021-09-27 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 27 September 2021 at 16:11:31 UTC, kyle wrote: DMD compiles this providing no notice... What is the version of your DMD?

Re: Protected Members in Class

2021-12-24 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 24 December 2021 at 10:26:37 UTC, apz28 wrote: https://dlang.org/spec/attribute.html#visibility_attributes #5 Okay, what about the 2nd question (super or this). ```d import app, std.stdio; void main() { auto any = new Any("int"); //any.get().writeln; /* assert(any.data ==

Re: Protected Members in Class

2021-12-24 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 24 December 2021 at 11:29:31 UTC, Salih Dincer wrote: ```d module app; class Any { protected/* private//*/ string Data; this(string data) { Data = data; } @property getData() { return Data; } } string getData(Any test) { return test.Data; } ``` What is the

Re: Protected Members in Class

2021-12-24 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 24 December 2021 at 14:29:29 UTC, Paul Backus wrote: `protected` in D means "this symbol can only be accessed from (a) the module where it's defined, and (b) classes that inherit from the class where it's defined." Please, can you show me this?

Protected Members in Class

2021-12-24 Thread Salih Dincer via Digitalmars-d-learn
What do I need to do to see that the protected is active, need a separate module? ```d // Source: https://tour.dlang.org/tour/en/basics/classes class Any { // protected is just seen by inheriting // classes protected string type; this(string type) { this.type = type;

Re: Protected Members in Class

2021-12-24 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 24 December 2021 at 08:35:38 UTC, Salih Dincer wrote: What do I need to do to see that the protected is active, need a separate module? ```d // Source: https://tour.dlang.org/tour/en/basics/classes Addition made for one of the inherited class: ```d override string

Re: How to loop through characters of a string in D language?

2021-12-22 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 13 December 2021 at 09:36:57 UTC, Ola Fosheim Grøstad wrote: ```d @safe: string prematureoptimizations(string s, char stripchar) @trusted { import core.memory; immutable uint flags = GC.BlkAttr.NO_SCAN|GC.BlkAttr.APPENDABLE; char* begin =

Re: How to loop through characters of a string in D language?

2021-12-23 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 23 December 2021 at 16:13:49 UTC, Stanislav Blinov wrote: You're comparing apples and oranges. When benchmarking, at least look at the generated assembly first. I looked now and you're right. Insomuch that it should be eggplant not apple, banana not orange...:) Because it's an

Re: Wrong result with enum

2021-11-11 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 11 November 2021 at 14:52:45 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: Unless explicitly set, default type is int. 110 is greater than int.max. 11 ```d enum w = 100_000; size_t b = w * w; // size_t b =

bool empty() const for ranges

2021-11-26 Thread Salih Dincer via Digitalmars-d-learn
Hi All; I have two questions that make each other redundant. Please answer one of them. I'm implementing ```bool empty() const``` for ranges as below: ```d bool empty() // const { bool result; if(!head) { result = true; fastRewind(); } return result; //

Re: I need some help for my DCV update

2021-11-27 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 27 November 2021 at 11:19:18 UTC, Ferhat Kurtulmuş wrote: On Friday, 26 November 2021 at 09:16:56 UTC, Ferhat Kurtulmuş wrote: I am working on the DCV to make it compilable with the recent versions of LDC, mir libraries, and stuff. I have not yet simply forked it to work on it. I

Wrong result with enum

2021-11-10 Thread Salih Dincer via Digitalmars-d-learn
is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result void main() { size_t subTest1 = tLimit; assert(subTest1 == tLimit);/* no error */ size_t subTest2 = wLimit; assert(subTest2 == wLimit);/* no

Re: Wrong result with enum

2021-11-11 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 11 November 2021 at 06:34:16 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result ```

Re: abs and minimum values

2021-10-29 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 October 2021 at 21:23:15 UTC, kyle wrote: ``` void main() { import std.math : abs, sgn; alias n_type = short; //or int, long, byte, whatever assert(n_type.min == abs(n_type.min)); assert(sgn(abs(n_type.min)) == -1); } ``` I stumbled into this fun today. I

Re: Completing C code with D style

2021-11-03 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 20:36:08 UTC, russhy wrote: I don't understand why you guys offer OP such complicate/bloated examples, it'll only make things confusing and slow down compilation time with templates and imports, this is not needed at all I don't like complicated things

The type inference everywhere

2021-10-31 Thread Salih Dincer via Digitalmars-d-learn
```d auto foo(int value, auto s = Section(2, 60)) { int max; /* ^--- ? ...*/ return Section (0, max) } ``` Is possible something like above pointed. OK, I know it isn't because I tried! Well, wouldn't it be nice if it did? Why shouldn't the inference be

Re: The type inference everywhere

2021-10-31 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 31 October 2021 at 17:35:35 UTC, Ali Çehreli wrote: On 10/31/21 7:07 AM, Salih Dincer wrote: > ```d > auto foo(int value, auto s = Section(2, 60)) { > int max; /* ^--- ? > ...*/ > return Section (0, max) > } > ``` > Is possible something like above

T... args!

2021-12-08 Thread Salih Dincer via Digitalmars-d-learn
Hi all, Is this not a contradiction? : and 3.1415 aren't string: ```d void foo(string...)(string args) { foreach(ref str; args) { str.writeln('\t', typeof(str).stringof); } } foo("Pi", "number", ':', 3.1415); /* Pi string number string : char 3,1415 double

Re: T... args!

2021-12-08 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 23:47:07 UTC, Adam Ruppe wrote: On Wednesday, 8 December 2021 at 23:43:48 UTC, Salih Dincer wrote: I think you meant to say void foo(string[] args...) {} Not exactly... ```d alias str = immutable(char)[]; void foo(str...)(str args) { foreach(ref a; args)

Re: How to loop through characters of a string in D language?

2021-12-08 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote: Let's say I want to skip characters and build a new string. The string example to loop/iterate: ``` import std.stdio; void main() { string a="abc;def;ab"; } ``` The character I want to skip: `;` Expected result: ``` abcdefab

Re: @safe question

2022-01-09 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 9 January 2022 at 20:58:05 UTC, forkit wrote: Do not understand why one line is not considered @safe, but the other is. // module test; import std; @safe void main() { immutable string[] strings = ["one", "one", "two"]; immutable(string)*[] pointers = null;

Re: number ranges

2022-01-17 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 17 January 2022 at 11:58:18 UTC, Paul Backus wrote: On Monday, 17 January 2022 at 10:24:06 UTC, forkit wrote: Edsger W. Dijkstra, a well-known academic computer scientist, has written in more detail about the advantages of this kind of interval:

Re: Dynamic array ot not

2022-01-16 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 16 January 2022 at 11:43:40 UTC, Ali Çehreli wrote: void main() { enum count = 7; // Allocate some memory void* rawData = malloc(int.sizeof * count); If count is not equal to 8 I get weird results! The reason of course, is the free(): // [93947717336544, 1, 2, 3, 4, 5, 6]

Re: Make shared static this() encoding table compilable

2022-03-16 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 16 March 2022 at 18:40:35 UTC, zhad3 wrote: On Tuesday, 15 March 2022 at 03:01:05 UTC, Salih Dincer wrote: OMG, I gasp at my computer screen and waited for minutes. :) When you edit the code at the back-end level, you can use system resources in the best way. I think you should

Re: Make shared static this() encoding table compilable

2022-03-14 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 14 March 2022 at 09:40:00 UTC, zhad3 wrote: [...] I usually compile my projects using LDC where this works fine, but I don't want to force others to use LDC because of this one problem. Hence I'd like to ask on how to change the code so that it compiles on DMD in release mode

Nested Classes with inheritance

2022-03-18 Thread Salih Dincer via Digitalmars-d-learn
Greetings to all... There are nested classes as below. But beware, there's also inheritance, extra! If you construct ```Bar b``` from main(), it's okay. But if declare the constructor in Foo(), the program crashes with a segmentation error. Is this not legal? Like two mirrors are facing

Re: Help needed to learn templates

2022-03-19 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 19 March 2022 at 05:54:26 UTC, Vinod K Chandran wrote: Question 1 - `U` is appearing in the first static if statement. But we had to write `U` on the template line, right? Like - `template rank(T, U)` Question 2 - The statif if test is - `T t == U[ ]` What does that mean ?

Re: Nested Classes with inheritance

2022-03-19 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 19 March 2022 at 00:16:48 UTC, user1234 wrote: ```d if (typeid(this) !is typeid(Bar)) this.b = new Bar(this.i); ``` A very clever and ingenious solution. Thanks... SDB@79

Re: error forward references if scope

2022-03-12 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 12 March 2022 at 13:12:25 UTC, vit wrote: ```d enum touch_T = __traits(hasMember, T, "touch"); ``` I think you meant build instead of touch? ```d struct Query { public const SharedPtr!Builder builder; } interface Builder { void build(ref Query query); } struct SharedPtr(T)

Re: initializing struct containing user defined type

2022-02-18 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 18 February 2022 at 16:45:24 UTC, Ali Çehreli wrote: On 2/18/22 07:01, kdevel wrote: > Error: struct `B` has constructors, cannot use `{ initializers }`, > use `B( initializers )` instead > > What is the rationale behind that? I mean: If the compiler exactly > sees what the

Re: Function Parameters without Names?

2022-02-19 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 19 February 2022 at 23:37:01 UTC, Vijay Nayar wrote: What is the main motivator to allow parameters with no names? Do they get an automatic implied name like `_` or something? The problem was about [here](https://dlang.org/spec/class.html#constructors), it should not be type

Re: Colors in Raylib

2022-02-28 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 28 February 2022 at 12:18:37 UTC, Mike Parker wrote: ```d enum expandEnum(EnumType, string fqnEnumType = EnumType.stringof) = (){ string expandEnum; foreach(m;__traits(allMembers, EnumType)) { expandEnum ~= "alias " ~ m ~ " = " ~ fqnEnumType ~ "." ~ m ~ ";"; }

Colors in Raylib

2022-02-28 Thread Salih Dincer via Digitalmars-d-learn
Hi All, Is there a namespace I should implement in Raylib? For example, I cannot compile without writing Colors at the beginning of the colors: ```Colors.GRAY``` SDB@79

Re: Colors in Raylib

2022-03-01 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 28 February 2022 at 12:18:37 UTC, Mike Parker wrote: Then you can mixin aliases for any named enum members you'd like: ```d mixin(expandEnum!Colors); ``` Meanwhile it's very skillful :) It is possible to change all the color palette with a second parameter: ```d import

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

2022-03-03 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 3 March 2022 at 13:25:32 UTC, Stanislav Blinov wrote: auto filtered = () { auto r = args[1].find!isNumber; // check if a string contains integers ``` **When using ```find!isNumber```:** ``` 0123456789 @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_

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

2022-03-03 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 4 March 2022 at 02:36:35 UTC, Ali Çehreli 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 implement a range with findSkip, findSplit,

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

2022-03-03 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 3 March 2022 at 20:23:14 UTC, forkit 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: [...] ```d string s, str = "4A0B1de!2C9~6"; foreach(i;str){ if(i < '0' || i > '9'){ continue; } s ~=

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

2022-03-03 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 4 March 2022 at 02:36:35 UTC, Ali Çehreli wrote: I assumed it would generate separate integers 123 and 456. I started to implement a range with findSkip, findSplit, and friends but failed. :/ I worked on it a little. I guess it's better that way. But I didn't think about

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

2022-03-04 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 4 March 2022 at 10:34:29 UTC, Ali Çehreli wrote: [...] isMatched() and chunkOf() are not necessary at all. I wanted to use readable names to fields of the elements of chunkBy instead of the cryptic t[0] and t[1]: It's delicious, only four lines: ```d "1,2,3".chunkBy!(n => '0' <= n

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

2022-03-04 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 4 March 2022 at 07:55:18 UTC, forkit wrote: If you get this question at an interview, please remember to first ask whether it's ascii or unicode  ```d auto UTFsample = ` 1 İş 100€, 1.568,38 Türk Lirası çarşıda eğri 1 çöp 4lınmaz!`; UTFsample.splitNumbers.writeln; // [1, 100, 1,

Re: Simple way to handle rvalues and templates.

2022-02-27 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 27 February 2022 at 06:11:28 UTC, Ali Çehreli wrote: I don't like the name readFrom() yet but that works. :) It seems very delicious, can stay as read(): ```d auto read(T, Endian E = Endian.bigEndian, R) (R range) { import bop = std.bitmanip; return bop.read!(T,

Re: Nested Classes with inheritance

2022-03-19 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 20 March 2022 at 01:28:44 UTC, Era Scarecrow wrote: Inheritance and Polymorphism is one of the hardest things to grasp mostly because examples they give in other books of 'objects' is so far unrelated to software that it doesn't really compare. `"An object is like a book which you

Re: How to exclude function from being imported in D language?

2022-03-20 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 8 March 2022 at 18:38:47 UTC, Paul Backus wrote: On Tuesday, 8 March 2022 at 17:47:47 UTC, BoQsc wrote: For example, you could use a [`version` condition][1]: ```d module otherprogram; version (Otherprogram_NoMain) { // no main function } else { void main(string[] args)

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

2022-03-29 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 29 March 2022 at 19:26:51 UTC, Ali Çehreli wrote: Better yet, and as I know you know :), and as it comes up occasionally but I usually forget in my own code; 'in' is much better than 'const' on function parameters because it has super powers when compiled with -preview=in:

Re: Does the GC consider slice lengths?

2022-04-01 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 1 April 2022 at 16:24:33 UTC, Ali Çehreli wrote: void main() { auto a = new int[1_000_000]; auto b = a[0..1]; // Hold on to the first element a = a[$-1..$]; // Drop all but the last element // Are the middle elements gone, or is b keeping // them alive just because

Re: Can std.variant be used with std.container.rbtree?

2022-04-02 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 1 April 2022 at 22:22:21 UTC, Vijay Nayar wrote: A `RedBlackTree` constructs and runs perfectly fine using "int" as the data type, but it seems to blow up as soon as I use `std.variant : Variant`. ``` Compilation output (1: )

Re: Unit tests via DUB

2022-04-02 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 2 April 2022 at 13:31:47 UTC, Alexander Zhirov wrote: On Saturday, 2 April 2022 at 13:12:04 UTC, Salih Dincer wrote: 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. Source code? A

Re: Unit tests via DUB

2022-04-02 Thread Salih Dincer 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. Source code?

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

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 4 April 2022 at 07:32:00 UTC, rempas wrote: Does anyone knows what's going on here? Source code?

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 4 April 2022 at 07:48:40 UTC, rempas wrote: Maybe, I didn't explained it properly. The example works. However, I wonder if it randomly works or if it is safe to do something like that as if the bytes have been initialized to '\0'. ```d import core.memory : pureMalloc; import

Re: Removing elements from dynamic arrays?

2022-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 4 April 2022 at 23:15:30 UTC, Enjoys Math wrote: ```d // remove an item from an array template drop(T) { T drop( inout T[] arr, T which ) { int i; T result; for (i=0; i < arr.length; i++) {

Re: Printing a quoted string

2022-03-20 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 20 March 2022 at 09:42:44 UTC, Caten wrote: On Sunday, 2 January 2022 at 21:16:55 UTC, Amit wrote: On Sunday, 2 January 2022 at 19:26:50 UTC, WebFreak001 wrote: [...] On Sunday, 2 January 2022 at 19:37:38 UTC, JG wrote: [...] Yes! That's what I needed. I wrapped it in a

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

2022-03-24 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 24 March 2022 at 01:49:30 UTC, Marcone wrote: If dependencies are resolved at compile time, why does the compiler include extra stuff? You are right! Test results on linux: ```d //import std.stdio : writefln;/* version = 1; import core.stdc.stdio : printf;//*/ void main() {

Re: gdc or ldc for faster programs?

2022-01-29 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 26 January 2022 at 18:00:41 UTC, Ali Çehreli wrote: For completeness (and noise :/) here is the final version of the program: Could you also try the following code with the same configurations? ```d struct LongScale { struct ShortStack { short[] stack; size_t

Re: gdc or ldc for faster programs?

2022-01-30 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 29 January 2022 at 18:28:06 UTC, Ali Çehreli wrote: On 1/29/22 10:04, Salih Dincer wrote: > Could you also try the following > code with the same configurations? The program you posted with 2 million random values: ldc 1.9 seconds gdc 2.3 seconds dmd 2.8 seconds I understand

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 15 January 2022 at 06:43:05 UTC, forkit wrote: On Saturday, 15 January 2022 at 03:48:41 UTC, Steven Schveighoffer wrote: int[][] arrayOfArrays = iota(1,16). array.chunks(5).array; -Steve All answers were helpful ;-) But I like this one the best, because I find it both easier

Re: Improve a simple event handler

2022-01-17 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 15 January 2022 at 23:15:16 UTC, JN wrote: I am writing a simple event handler object for observer pattern. https://gist.github.com/run-dlang/d58d084752a1f65148b33c796535a4e2 (note: the final implementation will use an array of listeners, Did you especially make an effort not to

Re: number ranges

2022-01-21 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 21 January 2022 at 17:25:20 UTC, Ali Çehreli wrote: Ouch! I tried the following code, my laptop got very hot, it's been centuries, and it's still running! :p :) ```d size_t length() inout { auto len = 1 + (last - first) / step; return cast(size_t)len; } ``` Does

Re: number ranges

2022-01-21 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 20 January 2022 at 16:33:20 UTC, Ali Çehreli wrote: So if we add the 1.0 value after 0.900357627869 to be *inclusive*, then that last step would not be 0.3 anymore. (Thinking about it, step would mess up things for integral types as well; so, it must be checked during

Re: number ranges

2022-01-19 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 23:13:14 UTC, Ali Çehreli wrote: But I like the following one better because it is fast and I think it works correctly. Is it okay to swap places instead of throwing an error? Let's also implement BidirectionalRange, if okay. This great struct will now run 4x4

Re: number ranges

2022-01-19 Thread Salih Dincer via Digitalmars-d-learn
Hi, It looks so delicious.  Thank you. On Wednesday, 19 January 2022 at 18:59:10 UTC, Ali Çehreli wrote: And adding length() was easy as well. Finally, I have provided property functions instead of allowing direct access to members. It doesn't matter as we can't use a 3rd parameter. But

Re: How to alias

2022-01-20 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 14 January 2022 at 17:48:41 UTC, kyle wrote: ```d void main() { import std.stdio; Broke foo = Broke(10); Broke bar = Broke(20); writeln(foo + 15); //prints 25 as expected writeln(foo + bar); //prints 20 } ``` I guess what you want to do is something like this:

Re: Dynamic array ot not

2022-01-16 Thread Salih Dincer via Digitalmars-d-learn
```d import std; // If we summarize in code... void main() { // It's a dynamic array and its copy below: size_t[] arr = [1, 2, 3, 4, 5, 6]; auto arrCopy = arr.dup; // This is its lazy range: auto range = arr.chunks(2); typeid(range).writeln(": ", range); // But this is its copy

Re: Dynamic array ot not

2022-01-16 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 17 January 2022 at 01:06:05 UTC, Salih Dincer wrote: ```d // Taaata, magic... // Your eyes don't surprise you! typeid(range).writeln(": ", range); typeid(slices).writeln(": ", slices); ``` In fact, although range and slice seem to be equal to each other, they are not!

Lambdas Scope

2022-04-11 Thread Salih Dincer via Digitalmars-d-learn
How is this possible? Why is it compiled? Don't the same names in the same scope conflict? ```d int function(int) square; void main() { square = (int a) => a * a; int square = 5.square; assert(square == 25); } ``` Thanks, SDB@79

Re: Why do immutable variables need reference counting?

2022-04-12 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 11 April 2022 at 21:48:56 UTC, Ali Çehreli wrote: On 4/11/22 08:02, Paul Backus wrote: > any pointers or references To add, Salih and I were in an earlier discussion where that concept appeared as "indirections." Ali I tried the following and I didn't understand one thing: Why

Re: Why do immutable variables need reference counting?

2022-04-11 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 11 April 2022 at 03:24:11 UTC, Ali Çehreli wrote: The output: 0 is (about to be) alive! 0 is (already) dead. 1 is (about to be) alive! 1 is (already) dead. 2 is (about to be) alive! 2 is (already) dead. It worked for me in a different way. 1 is (about to be) alive! 2 is

Re: Removing elements from dynamic arrays?

2022-04-05 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 5 April 2022 at 14:10:44 UTC, Steven Schveighoffer wrote: [...] I'd implement it probably like this (for D2): ```d auto drop(T)(ref T[] arr, T which) { import std.algorithm, std.range; auto f = arr.find(which); debug if(f.empty) throw ...; auto result = arr.front; arr

Re: How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 08:55:43 UTC, BoQsc wrote: I have a feeling that some parts of my code contains unterminated strings and they do overflow into other string [...] If you suspect overflow, you can try string wrapping.

Re: Removing elements from dynamic arrays?

2022-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 16:54:26 UTC, Steven Schveighoffer wrote: This is almost equivalent, but it requires a lambda and an allocation. So I'm not sure what thing you are trying to do here. I tried to get these results but it didn't work: abc efg h [0, 3] [4, 7] [8, 9] abcefgh

Re: Nested function requires forward declaration?

2022-04-14 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 14 April 2022 at 08:55:25 UTC, Chris Katko wrote: [...] It appears the nested function's variable capture depends on forward declaration (the right term?). Whereas, I was under the impression most/all of D worked on a multiple pass compilation so the order of declarations

Re: Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote: Here is an example of what I would hope for to work but it surely does not work: If I were you I would use enum, look at my code: ```d enum Options { silenceErrors = false } void someFunction (Options option =

Re: Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 11 September 2023 at 20:17:09 UTC, H. S. Teoh wrote: Someone should seriously come up with a way of eliminating the repeated type name in default parameters. Why not allow it to be flexible enough by using a template parameter? ```d enum Options : bool { silenceErrorsOff,

Re: Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 11 September 2023 at 22:13:25 UTC, H. S. Teoh wrote: Because sometimes I want a specific type. it's possible... ```d alias ST = Options; void specificType(ST option = ST()) { if(option) { assert(false); } else assert(true); } void main() { specificType(); // No

Re: Dinamyc arrays

2023-09-17 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 17 September 2023 at 17:15:34 UTC, Timofey wrote: I`ve just started learning d and have a question. What should I write to set dinamyc rectangular array length in both dimentions? For example, I have declareted an array: ``` int[][] matrix;``` and want set it as n*n matrix. Thanks

Re: Setting struct as default parameter of a function using struct literal?

2023-09-12 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 11 September 2023 at 23:47:33 UTC, H. S. Teoh wrote: Since the type of the parameter is already known, the compiler does not need me to repeat the type name. It already knows enough to figure it out on its own. "Don't Repeat Yourself" (DRY). I think there are 3 possibilities,

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-17 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 15 October 2023 at 07:22:53 UTC, Imperatorn wrote: You already got a lot of good answers, I thought I'd just share this for anyone searching for nogc string formatting compatible with betterC: https://code.dlang.org/packages/bc-string Doesn't it make more sense to use

Function Overloading

2023-10-31 Thread Salih Dincer via Digitalmars-d-learn
```d struct Calculate {   int memory; string result;    auto toString() => result;    this(string str)    {        add(str);    }    this(int num) {        add(num); } import std.string : format;    void add(string str)    {        result ~= str.format!"%s + ";  

Re: Function Overloading

2023-11-02 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 1 November 2023 at 20:04:52 UTC, Basile B. wrote: Yes. D constructors are not named but the current implementation adds a name that is `__ctor`, so add ```d alias add = __ctor; ``` to you struct. Yeah, it works! Thanks...:) SDB@79

Re: bigEndian in std.bitmanip

2023-11-02 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 31 October 2023 at 14:43:43 UTC, Imperatorn wrote: It might make sense to change since little endian is the most common when it comes to hardware. But big endian is most common when it comes to networking. So I guess it depends on your view of what is most common. Interacting with

bigEndian in std.bitmanip

2023-10-31 Thread Salih Dincer via Digitalmars-d-learn
Hello, Why isn't Endian.littleEndian the default setting for read() in std.bitmanip? Okay, we can easily change this if we want (I could use enum LE in the example) and I can also be reversed with data.retro.array(). ```d void main() { import std.conv : hexString; string helloD =

Re: bigEndian in std.bitmanip

2023-10-31 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 31 October 2023 at 10:24:56 UTC, Jonathan M Davis wrote: On Tuesday, October 31, 2023 4:09:53 AM MDT Salih Dincer via Digitalmars-d- learn wrote: Hello, Why isn't Endian.littleEndian the default setting for read() in std.bitmanip? Why would you expect little endian

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-02 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 October 2023 at 16:05:39 UTC, Paul Backus wrote: `T[] opSlice()` is the D1 version and exists only for backwards compatibility. You should use `T[] opIndex()` in new code. Forgive me for asking again, I think opSliceAssign(T value) has also been improved, right? ```d //

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 1 October 2023 at 17:41:08 UTC, Salih Dincer wrote: Also, is it correct to use [] when returning? Thanks... [Here](https://dlang.org/spec/operatoroverloading.html#slice), the opIndex() is proposed and an example of parameterized the opSlice() is given for multidimensional

The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Salih Dincer via Digitalmars-d-learn
Hi, What is the difference between T[] opIndex() and T[] opSlice(), which haven't parameters? ```d struct S(T) {    T[] arr;        T[] opIndex() => arr[];/*    T[] opSlice() => arr;//*/ } alias Type = int; void main() {    auto s = S!Type([1,2,3]);    auto arr = s[]; // calls

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-02 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 October 2023 at 20:42:14 UTC, Paul Backus wrote: I don't know what's wrong in your example but this works for me: I found the reason for the error: https://forum.dlang.org/thread/vckvftkdzcrnikudu...@forum.dlang.org SDB@79

opIndexAssign

2023-10-02 Thread Salih Dincer via Digitalmars-d-learn
Hi, opIndexAssign, which is void, cannot compromise with opIndex, which is a ref! Solution: Using opSliceAssign. Could this be a bug? Because there is no problem in older versions (e.g. v2.0.83). ```d struct S {  int[] i;  ref opIndex(size_t index) => i[index];  auto opSliceAssign/*

Re: Key and value with ranges

2023-10-02 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 October 2023 at 20:20:44 UTC, Joel wrote: I want the output sorted by value. Look: https://forum.dlang.org/post/qjlmiohaoeolmoavw...@forum.dlang.org ```d struct SIRALA(T) { } ``` You can use SIRALA(T). Okay, his language is Turkish but our common language is D. His feature

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-02 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:01:34 UTC, Jonathan M Davis wrote: For most code, you'd just write an opIndex with a single parameter for indexing an element, opSlice with two parameters for slicing the range or container, and then either opIndex or opSlice with no parameters to return a

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 18:09:55 UTC, Imperatorn wrote: At the very least, the spec should do a better job of documenting when the compiler will try a fallback and when it won't. Who will be the hero and add the documentation?  More importantly, is there a priority order? Because

Re: how to assign multiple variables at once by unpacking array?

2023-10-08 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 9 October 2023 at 01:15:21 UTC, Salih Dincer wrote: the staticMapN() template implemented by Ali Çehreli, which is not in the standard library, is needed: It would be great if the unlimited version was added to std.meta. This template seeded/sprouted in here:

Re: how to assign multiple variables at once by unpacking array?

2023-10-08 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 7 October 2023 at 16:12:47 UTC, mw wrote: Interesting: in terms of easy of coding, clarity and future maintenance, which one is superior? The one liner in Python, or your "solution" with dozen lines of code? BTW, is that a solution at all? Did it achieved what the original goal

Re: opIndexAssign

2023-10-05 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 5 October 2023 at 12:00:22 UTC, Timon Gehr wrote: void opIndexAssign(int value, int index){ i[index] = value; } In this case I need to define many operator overloads. For example (+=), this won't work without returns ref: ```d s[1] += 3;  assert(s.i == [2, 45]); // Error:

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-05 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 5 October 2023 at 16:40:49 UTC, Gaurav Negi wrote: Well, in the D programming language, both opIndex and opSlice are two different operators used to access elements of a custom type. Yeah, D is on its way to becoming a near-perfect programming language... ```d enum

Re: how to assign multiple variables at once by unpacking array?

2023-10-07 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 7 October 2023 at 07:31:45 UTC, mw wrote: https://stackoverflow.com/questions/47046850/is-there-any-way-to-assign-multiple-variable-at-once-with-dlang How to do this Python code in D: ``` s = "1 2 3" A,B,C = map(int, s.split(" ")) A,B,C (1, 2, 3) ``` Is there a better way

  1   2   3   4   >