Re: Passing $ as a function argument

2018-10-16 Thread Simen Kjærås via Digitalmars-d
On Sunday, 14 October 2018 at 15:27:07 UTC, Michael Coulombe wrote: On Sunday, 14 October 2018 at 14:35:36 UTC, lngns wrote: On Sunday, 14 October 2018 at 13:18:37 UTC, lngns wrote: That would require introducing a new type Or just use int with a negative number... That's how it's done in

Re: Passing $ as a function argument

2018-10-14 Thread Michael Coulombe via Digitalmars-d
On Sunday, 14 October 2018 at 14:35:36 UTC, lngns wrote: On Sunday, 14 October 2018 at 13:18:37 UTC, lngns wrote: That would require introducing a new type Or just use int with a negative number... That's how it's done in some dynamic languages. But my point is that it should be compatible

Re: Passing $ as a function argument

2018-10-14 Thread lngns via Digitalmars-d
On Sunday, 14 October 2018 at 13:18:37 UTC, lngns wrote: That would require introducing a new type Or just use int with a negative number... That's how it's done in some dynamic languages. But my point is that it should be compatible with pre-existing code using unsigned indices somehow. I

Re: Passing $ as a function argument

2018-10-14 Thread lngns via Digitalmars-d
On Wednesday, 10 October 2018 at 13:32:15 UTC, Simen Kjærås wrote: struct Sentinel {} Sentinel $; void foo(T)(T loc) { auto bar = double[RandomPInt+1]; static if (is(T == Sentinel)) { return bar[$]; } else { return bar[loc]; } } unittest { foo($); } It

Re: Passing $ as a function argument

2018-10-11 Thread Neia Neutuladh via Digitalmars-d
On 10/11/2018 04:36 AM, Dejan Lekic wrote: On Thursday, 11 October 2018 at 06:58:08 UTC, Simen Kjærås wrote: unittest {     auto x = fun($); // What does it even mean? } After some reading through the whole thread I think his "$ idea" can only be applied to a RandomAccessRange (and similar)

Re: Passing $ as a function argument

2018-10-11 Thread bachmeier via Digitalmars-d
On Thursday, 11 October 2018 at 00:01:27 UTC, James Japherson wrote: I don't understand why you need to be convinced that this is relevant. Do you not realize that there are cases where one wants to select the last element of a list without having to explicitly know it? It's fine if you

Re: Passing $ as a function argument

2018-10-11 Thread Dejan Lekic via Digitalmars-d
On Thursday, 11 October 2018 at 06:58:08 UTC, Simen Kjærås wrote: unittest { auto x = fun($); // What does it even mean? } After some reading through the whole thread I think his "$ idea" can only be applied to a RandomAccessRange (and similar) where the size can be known...

Re: Passing $ as a function argument

2018-10-11 Thread Simen Kjærås via Digitalmars-d
On Wednesday, 10 October 2018 at 23:04:46 UTC, James Japherson wrote: The whole point is not to use $ as an identifier but to specify to the compiler of that it can rewrite it. I know. I'm pointing out that as syntactic sugar, it can't be passed as an int. You seem to think that what the

Re: Passing $ as a function argument

2018-10-11 Thread crimaniak via Digitalmars-d
On Wednesday, 10 October 2018 at 23:04:46 UTC, James Japherson wrote: The whole point is not to use $ as an identifier but to specify to the compiler of that it can rewrite it. It's called 'alias'. // compile time int foo(alias index)(int[] a) { return a[index(a.length)]; } // run

Re: Passing $ as a function argument

2018-10-10 Thread Neia Neutuladh via Digitalmars-d
On 10/10/2018 05:01 PM, James Japherson wrote: All I'm proposing is to to allow one to escape that syntax to function calls. foo(int index) {    return arr[index]; } and D can support foo($-1); which simply gets translated in to arr[arr.length - 1] I think you might have a

Re: Passing $ as a function argument

2018-10-10 Thread Vladimir Panteleev via Digitalmars-d
On Wednesday, 10 October 2018 at 08:46:42 UTC, James Japherson wrote: Would be nice to be able to pass $ as a function argument to be used in automatic path length traversing. You can already do this, by returning a custom type from opDollar: /// Define RealNumbers so that, given `RealNumbers

Re: Passing $ as a function argument

2018-10-10 Thread James Japherson via Digitalmars-d
On Wednesday, 10 October 2018 at 23:26:38 UTC, Dennis wrote: Can you give a real-world, non-foo/bar example where you want to use it? I have trouble understanding what you want to accomplish. I don't understand why you need to be convinced that this is relevant. Do you not realize that

Re: Passing $ as a function argument

2018-10-10 Thread Dennis via Digitalmars-d
Can you give a real-world, non-foo/bar example where you want to use it? I have trouble understanding what you want to accomplish. On Wednesday, 10 October 2018 at 23:04:46 UTC, James Japherson wrote: It also has no context in and of itself. The compiler knows what to do with it... The same

Re: Passing $ as a function argument

2018-10-10 Thread James Japherson via Digitalmars-d
On Wednesday, 10 October 2018 at 13:32:15 UTC, Simen Kjærås wrote: On Wednesday, 10 October 2018 at 08:46:42 UTC, James Japherson wrote: Would be nice to be able to pass $ as a function argument to be used in automatic path length traversing. void foo(int loc) { return bar[loc]; } then

Re: Passing $ as a function argument

2018-10-10 Thread Neia Neutuladh via Digitalmars-d
On 10/10/2018 01:46 AM, James Japherson wrote: Would be nice to be able to pass $ as a function argument to be used in automatic path length traversing. $ only works in indexing operations because that's required to figure out what it refers to. However, you can mostly use it as a readonly

Re: Passing $ as a function argument

2018-10-10 Thread Simen Kjærås via Digitalmars-d
On Wednesday, 10 October 2018 at 08:46:42 UTC, James Japherson wrote: Would be nice to be able to pass $ as a function argument to be used in automatic path length traversing. void foo(int loc) { return bar[loc]; } then foo($) would essentilly become foo(&) becomes ==> return

Re: Passing $ as a function argument

2018-10-10 Thread bachmeier via Digitalmars-d
On Wednesday, 10 October 2018 at 08:46:42 UTC, James Japherson wrote: The usefulness comes from the case when bar is local: void foo(int loc) { auto bar = double[RandomPInt+1]; return bar[loc]; } then foo($) always returns a value and the outside world does not need to know about

Re: Passing $ as a function argument

2018-10-10 Thread bauss via Digitalmars-d
On Wednesday, 10 October 2018 at 08:46:42 UTC, James Japherson wrote: Would be nice to be able to pass $ as a function argument to be used in automatic path length traversing. void foo(int loc) { return bar[loc]; } then foo($) would essentilly become foo(&) becomes ==> return

Passing $ as a function argument

2018-10-10 Thread James Japherson via Digitalmars-d
Would be nice to be able to pass $ as a function argument to be used in automatic path length traversing. void foo(int loc) { return bar[loc]; } then foo($) would essentilly become foo(&) becomes ==> return bar[$]; instead of having do to thinks like foo(bar.length). The