Re: Why not allow elementwise operations on tuples?

2023-01-19 Thread Sergei Nosov via Digitalmars-d-learn
On Wednesday, 18 January 2023 at 16:42:00 UTC, JG wrote: I guess such a method wouldn't be particularly generic since a tuple does not need to consist of types that have the same operations e.g. Tuple!(int,string) etc That's where `areCompatibleTuples` function comes in!

Re: Why not allow elementwise operations on tuples?

2023-01-16 Thread Sergei Nosov via Digitalmars-d-learn
On Friday, 13 January 2023 at 15:27:26 UTC, H. S. Teoh wrote: On Fri, Jan 13, 2023 at 02:22:34PM +, Sergei Nosov via Digitalmars-d-learn wrote: Hey, everyone! I was wondering if there's a strong reason behind not implementing elementwise operations on tuples? Say, I've decided to store

Why not allow elementwise operations on tuples?

2023-01-13 Thread Sergei Nosov via Digitalmars-d-learn
Hey, everyone! I was wondering if there's a strong reason behind not implementing elementwise operations on tuples? Say, I've decided to store 2d points in a `Tuple!(int, int)`. It would be convenient to just write `a + b` to yield another `Tuple!(int, int)`. I can resort to using `int

Re: Can you simplify nested Indexed types?

2022-12-27 Thread Sergei Nosov via Digitalmars-d-learn
On Tuesday, 27 December 2022 at 16:43:49 UTC, Ali Çehreli wrote: On 12/27/22 07:09, Sergei Nosov wrote: If what you are looking for is a way of defining a variable for "any InputRange that produces a specific type (size_t in this case)", then there is inputRangeObject, whic

Re: Can you simplify nested Indexed types?

2022-12-27 Thread Sergei Nosov via Digitalmars-d-learn
On Tuesday, 27 December 2022 at 15:20:24 UTC, Salih Dincer wrote: On Tuesday, 27 December 2022 at 15:09:11 UTC, Sergei Nosov wrote: Consider, I have the following code: ```d auto a = [3, 6, 2, 1, 5, 4, 0]; auto indicies = iota(3); auto ai = indexed(a, indicies); //ai = indexed

Re: Function to print a diamond shape

2014-03-21 Thread Sergei Nosov
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote: This is a somewhat common little exercise: Write a function that takes the size of a diamond and produces a diamond of that size. When printed, here is the output for size 11: * *** * *** *

Re: Function to print a diamond shape

2014-03-21 Thread Sergei Nosov
On Friday, 21 March 2014 at 13:59:27 UTC, Vladimir Panteleev wrote: On Friday, 21 March 2014 at 12:32:58 UTC, Sergei Nosov wrote: On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote: This is a somewhat common little exercise: Write a function that takes the size of a diamond

Just-run-the-unittests

2014-03-16 Thread Sergei Nosov
Hi! Suppose I have a small .d script that has a main. Is there any simple way to just run the unit tests without running main at all? I thought -main switch was intended for this, but apparently it works only if there's no main defined at all, otherwise, it issues a double main definition

Re: Just-run-the-unittests

2014-03-16 Thread Sergei Nosov
On Sunday, 16 March 2014 at 08:22:04 UTC, safety0ff wrote: On Sunday, 16 March 2014 at 07:59:33 UTC, Sergei Nosov wrote: Hi! Suppose I have a small .d script that has a main. Is there any simple way to just run the unit tests without running main at all? Here's the first thing that came

Re: foreach/iota countdown

2014-02-18 Thread Sergei Nosov
On Tuesday, 18 February 2014 at 05:21:24 UTC, Brian Schott wrote: On Monday, 17 February 2014 at 19:22:38 UTC, simendsjo wrote: Should the following two uses be a compile-time error? foreach(i; 10 .. 0) // Never executes foreach(i; iota(10, 0)) // .. neither does this I would like the

Re: Array as an argument, ambiguous behaviour.

2014-01-29 Thread Sergei Nosov
On Wednesday, 29 January 2014 at 13:15:30 UTC, Cooler wrote: On Wednesday, 29 January 2014 at 12:40:00 UTC, Tobias Pankrath wrote: On Wednesday, 29 January 2014 at 11:46:23 UTC, Cooler wrote: Thank you for detailed explanation. But the question is - Is that correct that language allows

Re: Array as an argument, ambiguous behaviour.

2014-01-29 Thread Sergei Nosov
On Wednesday, 29 January 2014 at 15:11:33 UTC, Cooler wrote: Yes, that is how slices work in D. The following article explains the non-determinism that you mention: http://dlang.org/d-array-article.html Ali Thank you for the article. Quotation from the article It is a good idea to note in

Re: enum value vs. immutable

2013-12-01 Thread Sergei Nosov
On Monday, 2 December 2013 at 07:31:56 UTC, Sergei Nosov wrote: On Monday, 2 December 2013 at 05:57:33 UTC, CJS wrote: I was reading the enum page of Ali Çehreli's (excellent) D book (http://ddili.org/ders/d.en/enum.html), and I'm confused by an enum value (not enum type), such as enum

Re: enum value vs. immutable

2013-12-01 Thread Sergei Nosov
On Monday, 2 December 2013 at 05:57:33 UTC, CJS wrote: I was reading the enum page of Ali Çehreli's (excellent) D book (http://ddili.org/ders/d.en/enum.html), and I'm confused by an enum value (not enum type), such as enum secondsPerDay = 60 * 60 * 24; In that situation I would have used an

Re: Function literal bug?

2013-11-28 Thread Sergei Nosov
On Thursday, 28 November 2013 at 08:23:22 UTC, bearophile wrote: Global structs don't need the static attribute. I've thought so, but added it just as a I really mean, that I don't need context. This version of your code gives the output 6 6 on Windows 32 bit: Do you have a 64-bit OS at

Re: Function literal bug?

2013-11-28 Thread Sergei Nosov
On Thursday, 28 November 2013 at 10:23:39 UTC, Kenji Hara wrote: It's a known front-end issue. https://d.puremagic.com/issues/show_bug.cgi?id=11545 Kenji Hara Great! Does this pull resolve both issues? (correct length and x=x syntax)

Function literal bug?

2013-11-27 Thread Sergei Nosov
Hi! This is kind of bug report/question. I'm running Ubuntu 12.04 (x64), DMD v2.064.2 and have the following code: T identity(T)(T e) { return e; } struct S(alias Func) { void call() { import std.stdio; writeln(Func(string).length); } } static struct S1 {

Re: What does it mean void[]?

2013-11-15 Thread Sergei Nosov
On Friday, 15 November 2013 at 09:19:04 UTC, Orfeo wrote: I have found in the module https://github.com/NCrashed/serial-port/blob/master/source/serial/device.d this function: void write(const(void[]) arr) { ... What exactly is void[]? An array of pointers? An array of

alias template parameter

2013-06-21 Thread Sergei Nosov
Hi! I've been thinking about how alias template parameters work and I'm really confused =) It makes perfect sense for literals, names, etc. But what I can't get is how does it work for delegates. If I have a function auto apply(alias fun, T...)(T args) { return fun(args); } And then I

shared vs __gshared

2013-06-10 Thread Sergei Nosov
Hi! I'm puzzled with what's the difference between shared and __gshared. Until now I've (mistakenly) considered that shared variables are free from low-level data races. I.e. the operations with shared data are atomic. And that __gshared is the usual (in C++ sense) shared data. So, in my

Re: shared vs __gshared

2013-06-10 Thread Sergei Nosov
Thank you for answers. Let me check if I got this right. On Monday, June 10, 2013 13:23:26 Steven Schveighoffer wrote: shared was supposed to infer memory barriers, but AFAIK, it doesn't do that. Not sure it ever will. So, my first impression about what shared should do (no low-level races

Failed to sort range

2013-05-28 Thread Sergei Nosov
Hi! I'm trying to implement an array, which uses malloc to allocate memory. Also, I want to implement a random access range interface for it. That went pretty well, until I tried to sort it. Sorting function asserted Failed to sort range of type Array!(int). I've spent quite some time

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 12:57:12 UTC, Sergei Nosov wrote: Hi! I'm trying to implement an array, which uses malloc to allocate memory. Also, I want to implement a random access range interface for it. That went pretty well, until I tried to sort it. Sorting function asserted Failed

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 13:41:19 UTC, bearophile wrote: Sergei Nosov: That went pretty well, until I tried to sort it. Sorting function asserted Failed to sort range of type Array!(int). If you take a look a the implementation of Phobos sort, you see there is a recently added runtime

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
Thx, Ali! 1) First, an observation: This Array design conflates the concepts of container and range. If there are actual elements that are being stored (as opposed to elements being generated), it is better tha a range merely provides access to those elements. popFront should consume the

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 18:38:01 UTC, Ali Çehreli wrote: On 05/28/2013 11:31 AM, Ali Çehreli wrote: @property Array!T opSlice(size_t i, size_t j) { // ... ret.front_ = i; I feel like the initialization of front_ above is not right either. Imagine quick sort where

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 20:43:32 UTC, Ali Çehreli wrote: On 05/28/2013 12:47 PM, Anthony Goins wrote: sort!(ab, SwapStrategy.stable)(arr); This worked for me with the code at your link. I've noticed that too. The reason that works is because in that case it uses Tim Sort. Apparently,

Re: Possible bug

2013-03-26 Thread Sergei Nosov
On Tuesday, 26 March 2013 at 05:40:00 UTC, Steven Schveighoffer wrote: What you have to do is instantiate the template, then call the constructor: S!(int, 4).S!(byte, 5)(3) Note that the way templates work in D, a templated struct is really a shortcut for: template S(T) { struct S { ...

Possible bug

2013-03-25 Thread Sergei Nosov
Hi! This code doesn't compile with dmd v2.062 on Linux_x86_64 pre struct test(T) { T *data_; this(T *data) { data_ = data; } } void main() { int *cptr = null; test!int hello = test(cptr); } /pre Error: dmd test.d test.d(12): Error: struct test.test does not match

Re: Possible bug

2013-03-25 Thread Sergei Nosov
On Monday, 25 March 2013 at 14:12:17 UTC, bearophile wrote: Sergei Nosov: Everything's fine if I specify parameters explicitly: pre test!int hello = test!int(cptr); /pre Some persons have proposed alternative designs, but D is working as currently designed here... Unlike template functions

Re: Possible bug

2013-03-25 Thread Sergei Nosov
Thank you, guys! You made the matters clear to me! It would be an interesting enhancement over C++. Although, Steven, I didn't quite understand what you're suggesting to use in case of templated-struct-templated-constructor Explicitly specifying struct parameters is ok. Deducing