June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
On Wed, Jun 05, 2013 at 12:47:44PM -0700, Brad Roberts wrote: > On 6/5/13 12:34 PM, Andrei Alexandrescu wrote: > >On 6/5/13 2:26 PM, Brad Anderson wrote: > >>On Wednesday, 5 June 2013 at 17:36:05 UTC, Andrei Alexandrescu wrote: > >>>Right now we have joiner(), which given several ranges of T, offers a > >>>range of T. Developing along that idea, we should have two opposite > >>>functions: itemize() and collect(). > >> > >>collect() is sometimes used as the name for map() in some languages > >>(e.g., Ruby, Smalltalk). I don't think it's a problem but maybe a note > >>in the documentation would be warranted to point people to map. > >>Alternatively it could be called something like bundle or parcel. > > > >Love bundle/parcel! Probably bundle more because it's more obvious it's a verb. > > > >Andrei > > Well, both bundle and parcel can be both nouns and verbs. "Verbing weirds language." -- Calvin & Hobbes. :-P T -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth |
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Wednesday, 5 June 2013 at 19:49:05 UTC, H. S. Teoh wrote:
> Oh? I thought the compiler would be smart enough to look for
> "std/algorithm.d" when you say "import std.algorithm", and to look for std/algorithm/*.d when there's trailing stuff following "std.algorithm".
import testmod.test;
import testmod;
test2.d(2): Error: can only import from a module, not from package testmod
Error: module testmod from file testmod.d conflicts with package name testmod
or if you reverse the order
test2.d(2): Error: can only import from a module, not from a member of module testmod. Did you mean `import testmod : test`?
The filenames are easy to sort out (and don't necessarily matter anyway, since contrary to popular belief, they don't aren't required to match the module name), but the compiler assigns them a name (the same name) and then considers it a kind of type mismatch between package and module.
|
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | On 6/5/13 3:47 PM, Brad Roberts wrote:
> Well, both bundle and parcel can be both nouns and verbs.
Hrm, yah. Not even sure what the relative frequencies are.
Andrei
|
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | On Wednesday, 5 June 2013 at 19:47:57 UTC, Brad Roberts wrote: > On 6/5/13 12:34 PM, Andrei Alexandrescu wrote: >> On 6/5/13 2:26 PM, Brad Anderson wrote: >>> On Wednesday, 5 June 2013 at 17:36:05 UTC, Andrei Alexandrescu wrote: >>>> Right now we have joiner(), which given several ranges of T, offers a >>>> range of T. Developing along that idea, we should have two opposite >>>> functions: itemize() and collect(). >>> >>> collect() is sometimes used as the name for map() in some languages >>> (e.g., Ruby, Smalltalk). I don't think it's a problem but maybe a note >>> in the documentation would be warranted to point people to map. >>> Alternatively it could be called something like bundle or parcel. >> >> Love bundle/parcel! Probably bundle more because it's more obvious it's a verb. >> >> Andrei > > Well, both bundle and parcel can be both nouns and verbs. We already have that function and it's called `chunks`: http://dlang.org/phobos/std_range.html#chunks |
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Attachments:
| isn't that what DIP37 is supposed to address?
On Wed, Jun 5, 2013 at 12:47 PM, H. S. Teoh <hsteoh@quickfur.ath.cx> wrote:
> On Wed, Jun 05, 2013 at 03:44:30PM -0400, Andrei Alexandrescu wrote:
> > On 6/5/13 3:38 PM, Andrei Alexandrescu wrote:
> > >On 6/5/13 2:42 PM, H. S. Teoh wrote:
> > >>Is that even necessary? We could just do this:
> > >>
> > >>----std/algorithm.d----
> > >>module std.algorithm;
> > >>public import std.algorithm.search;
> > >>public import std.algorithm.compare;
> > >>public import std.algorithm.iteration;
> > >>public import std.algorithm.sort;
> > >>public import std.algorithm.set;
> > >>public import std.algorithm.mutation;
> > >>----snip----
> > >
> > >For perfect 100% undetectable backwards compatibility:
> > >
> > >module std.algorithm;
> > >private import std.algorithm.search;
> > >alias balancedParens = std.algorithm.search.balancedParens;
> > >alias boyerMooreFinder = std.algorithm.search.boyerMooreFinder;
> > >...
> > >
> > >
> > >Andrei
> >
> > Wait, that all doesn't work - there's confusion between the file std/algorithm.d file and the std/algorithm/ directory.
> [...]
>
> Oh? I thought the compiler would be smart enough to look for "std/algorithm.d" when you say "import std.algorithm", and to look for std/algorithm/*.d when there's trailing stuff following "std.algorithm".
>
> Or is this why somebody was suggesting some time ago about importing a directory being implicitly translated to importing "_.d" in the directory?
>
>
> T
>
> --
> Do not reason with the unreasonable; you lose by definition.
>
|
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wed, 05 Jun 2013 15:38:56 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote: > On 6/5/13 2:42 PM, H. S. Teoh wrote: >> Is that even necessary? We could just do this: >> >> ----std/algorithm.d---- >> module std.algorithm; >> public import std.algorithm.search; >> public import std.algorithm.compare; >> public import std.algorithm.iteration; >> public import std.algorithm.sort; >> public import std.algorithm.set; >> public import std.algorithm.mutation; >> ----snip---- > > For perfect 100% undetectable backwards compatibility: > > module std.algorithm; > private import std.algorithm.search; > alias balancedParens = std.algorithm.search.balancedParens; > alias boyerMooreFinder = std.algorithm.search.boyerMooreFinder; > ... All this does over public import is avoid adding the full names into the namespace (which would arguably be OK, since those didn't exist before). public import already automatically aliases all the symbols for you. One thing you have to be careful of is if blah is a function in std.algorithm, and you have a module named std.algorithm.blah, you would have troubles. So I would name the modules things like 'std.algorithm.searching' instead of 'std.algorithm.search', since search is a really good name for a function. -Steve |
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On 6/5/2013 11:36 AM, David Nadlinger wrote: > It also doesn't utilize template constraints, reinvents isRandomAccessRange && > hasSlicing under a poor name, Didn't want to include all of Phobos, which happens if you import std.range. > uses C printf (!) in the examples, Again, trying to make it lightweight. > has random 2-3 letter variable names (dis, dip, di, si) all over the place, … si - source index di - destination index Not random. Would you prefer i and j? :-) |
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On 6/5/2013 12:45 PM, H. S. Teoh wrote: > This is a maintenance nightmare, though. A minor bit of tedium, yes. A nightmare, that's way overblowing things. Neglecting it or making a typo results in a compile time lookup error, not launching nuclear missiles. > I'd vote against it unless doing otherwise causes major breakage of existing code. Doing it other ways requires more kitchen sink complicated language features. Not every keystroke is worth saving. |
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On 6/5/13 4:29 PM, Idan Arye wrote:
> On Wednesday, 5 June 2013 at 19:47:57 UTC, Brad Roberts wrote:
>> On 6/5/13 12:34 PM, Andrei Alexandrescu wrote:
>>> On 6/5/13 2:26 PM, Brad Anderson wrote:
>>>> On Wednesday, 5 June 2013 at 17:36:05 UTC, Andrei Alexandrescu wrote:
>>>>> Right now we have joiner(), which given several ranges of T, offers a
>>>>> range of T. Developing along that idea, we should have two opposite
>>>>> functions: itemize() and collect().
>>>>
>>>> collect() is sometimes used as the name for map() in some languages
>>>> (e.g., Ruby, Smalltalk). I don't think it's a problem but maybe a note
>>>> in the documentation would be warranted to point people to map.
>>>> Alternatively it could be called something like bundle or parcel.
>>>
>>> Love bundle/parcel! Probably bundle more because it's more obvious
>>> it's a verb.
>>>
>>> Andrei
>>
>> Well, both bundle and parcel can be both nouns and verbs.
>
> We already have that function and it's called `chunks`:
> http://dlang.org/phobos/std_range.html#chunks
That's different because it chunks in-place, whereas bundle() would use its own buffer.
Andrei
|
June 05, 2013 Re: std.compress | ||||
---|---|---|---|---|
| ||||
Posted in reply to SomeDude | On Wednesday, June 05, 2013 20:56:12 SomeDude wrote:
> On Wednesday, 5 June 2013 at 18:36:34 UTC, David Nadlinger wrote:
> > It also doesn't utilize template constraints, reinvents isRandomAccessRange && hasSlicing under a poor name, uses C printf (!) in the examples, has random 2-3 letter variable names (dis, dip, di, si) all over the place, …
> >
> > David
>
> Walter explained that calling printf allowed him not to import half of std. I think it's a good practice to limit dependencies to a reasonable minimum. Of course, it's hard to come up with a general rule as to what "reasonable" means here.
Given that pretty much every program is going to use std.stdio in one form or another, I see little point in avoiding using it. And since it's an example, it makes even less sense. I would even argue that using printf is bad practice. writeln and writefln are properly typesafe, whereas printf is not. If you really actually _need_ to restrict how much you're importing, then using printf makes sense, but in general, it really doesn't.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation