April 15, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On Mon, 15 Apr 2013 01:52:33 +0200
"Idan Arye" <GenericNPC@gmail.com> wrote:
> but I don't really know where to put it. None of the existing modules seems fit, and I don't want to open a new module(std.monad?) for a single function.
>
> Any suggestions?
I'm not a Phobos dev, but I think std.algorithm would be the right place.
You can always just pick a spot, make a pull request, and if there's a better place then people can just say so in the pull request's discussion and then you can move it.
|
April 15, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Mon, Apr 15, 2013 at 02:01:28PM -0400, Nick Sabalausky wrote: > On Mon, 15 Apr 2013 01:52:33 +0200 > "Idan Arye" <GenericNPC@gmail.com> wrote: > > but I don't really know where to put it. None of the existing modules seems fit, and I don't want to open a new module(std.monad?) for a single function. > > > > Any suggestions? > > I'm not a Phobos dev, but I think std.algorithm would be the right place. [...] Hmm. What about std.functional? It seems to fall into the category of stuff that lets/helps you write functional-style D code. T -- Without geometry, life would be pointless. -- VS |
April 15, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Mon, 15 Apr 2013 11:05:05 -0700
"H. S. Teoh" <hsteoh@quickfur.ath.cx> wrote:
> On Mon, Apr 15, 2013 at 02:01:28PM -0400, Nick Sabalausky wrote:
> > On Mon, 15 Apr 2013 01:52:33 +0200
> > "Idan Arye" <GenericNPC@gmail.com> wrote:
> > > but I don't really know where to put it. None of the existing modules seems fit, and I don't want to open a new module(std.monad?) for a single function.
> > >
> > > Any suggestions?
> >
> > I'm not a Phobos dev, but I think std.algorithm would be the right place.
> [...]
>
> Hmm. What about std.functional? It seems to fall into the category of stuff that lets/helps you write functional-style D code.
>
Yea, but the same is true for a lot of std.algorithm. Besides, despite the name, std.functional appears to mostly just be the place for the tools to use the old string literal style lambdas.
|
April 16, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Monday, 15 April 2013 at 18:02:14 UTC, Nick Sabalausky wrote:
> On Mon, 15 Apr 2013 01:52:33 +0200
> "Idan Arye" <GenericNPC@gmail.com> wrote:
>> but I don't really know where to put it. None of the existing modules seems fit, and I don't want to open a new module(std.monad?) for a single function.
>>
>> Any suggestions?
>
> I'm not a Phobos dev, but I think std.algorithm would be the right
> place.
>
> You can always just pick a spot, make a pull request, and if there's
> a better place then people can just say so in the pull request's
> discussion and then you can move it.
Good idea. It's not really an algorithm - but then again, many of the things in std.algorithm are not really algorithms, and could be easy fit to a separate module, called std.monad.
Ofcourse, I do not suggest to split std.algorithm to std.algorithm and std.monad - that would break too much code...
|
April 16, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Monday, 15 April 2013 at 18:30:26 UTC, Nick Sabalausky wrote:
> On Mon, 15 Apr 2013 11:05:05 -0700
> "H. S. Teoh" <hsteoh@quickfur.ath.cx> wrote:
>
>> On Mon, Apr 15, 2013 at 02:01:28PM -0400, Nick Sabalausky wrote:
>> > On Mon, 15 Apr 2013 01:52:33 +0200
>> > "Idan Arye" <GenericNPC@gmail.com> wrote:
>> > > but I don't really know where to put it. None of the existing modules seems fit, and I don't want to open a new module(std.monad?) for a single function.
>> > >
>> > > Any suggestions?
>> >
>> > I'm not a Phobos dev, but I think std.algorithm would be the right
>> > place.
>> [...]
>>
>> Hmm. What about std.functional? It seems to fall into the category of
>> stuff that lets/helps you write functional-style D code.
>>
>
> Yea, but the same is true for a lot of std.algorithm. Besides, despite
> the name, std.functional appears to mostly just be the place for the
> tools to use the old string literal style lambdas.
Actually, std.functional only has two functions that turn a string to a function. Most of std.functional's members are for creating functions from other functions.
|
April 16, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On 04/16/2013 04:39 AM, Idan Arye wrote: > On Monday, 15 April 2013 at 18:02:14 UTC, Nick Sabalausky wrote: >> ... >> I'm not a Phobos dev, but I think std.algorithm would be the right >> place. >> >> You can always just pick a spot, make a pull request, and if there's >> a better place then people can just say so in the pull request's >> discussion and then you can move it. > > Good idea. It's not really an algorithm - but then again, many of the > things in std.algorithm are not really algorithms, Well, given some obvious constraints on the inputs, they are. > and could be easy fit > to a separate module, called std.monad. > > Ofcourse, I do not suggest to split std.algorithm to std.algorithm and > std.monad - that would break too much code... I do not see how std.monad would be an accurate name in any case. |
April 16, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On 4/15/13 11:05 AM, H. S. Teoh wrote:
> Without geometry, life would be pointless. -- VS
It's this kind of joke where I draw the line :)
|
April 17, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On 15/04/2013 06:00, H. S. Teoh wrote:
> Allowing arbitrary predicates and switch-as-expression allows you to
> write code that shows intent very clearly:
>
> // In pseudo-D syntax
> void fill(T)(T image, int x, int y) {
> image[x,y] = switch {
> case isFillable(image,x,y): fillColor;
> case isBorder(image,x,y): borderColor;
> default: defaultColor;
> };
> }
We could use a conditional operator chain:
image[x,y] = isFillable(image,x,y) ? fillColor :
isBorder(image,x,y) ? borderColor :
defaultColor;
|
April 18, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On Sunday, 14 April 2013 at 23:52:37 UTC, Idan Arye wrote:
>
> Now, I've got it working(the example actually compiles and prints "less then 5"), and I want to make a pull request to put it in Phobos(because it's a useful function) but I don't really know where to put it. None of the existing modules seems fit, and I don't want to open a new module(std.monad?) for a single function.
Nit-picky observation: there's nothing monadic about your predSwitch function, it wouldn't belong in a 'std.monad' module.
Best,
Graham
|
April 18, 2013 Re: Where should I put a `condp` like function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Wednesday, 17 April 2013 at 13:09:45 UTC, Nick Treleaven wrote: > On 15/04/2013 06:00, H. S. Teoh wrote: >> Allowing arbitrary predicates and switch-as-expression allows you to >> write code that shows intent very clearly: >> >> // In pseudo-D syntax >> void fill(T)(T image, int x, int y) { >> image[x,y] = switch { >> case isFillable(image,x,y): fillColor; >> case isBorder(image,x,y): borderColor; >> default: defaultColor; >> }; >> } > > We could use a conditional operator chain: > > image[x,y] = isFillable(image,x,y) ? fillColor : > isBorder(image,x,y) ? borderColor : > defaultColor; Naturally - even as statements, a `switch` statement without a switch expression is no better than a chain of `if`-`else`s. Now, consider this hackish use of `predSwitch`: https://gist.github.com/someboddy/5412843 This is actual D code(you need https://github.com/D-Programming-Language/phobos/pull/1259 to run it), and it prints: ***** *...* *.+.* *...* ***** As expected. This does have an advantage over a chain of `if`-`else`s or ternary operators - you only need to write the argument list once. |
Copyright © 1999-2021 by the D Language Foundation