Re: renamepalooza time

2011-01-22 Thread Don

Jonathan M Davis wrote:

On Friday, January 21, 2011 06:04:53 spir wrote:

On 01/21/2011 09:44 AM, Jonathan M Davis wrote:

Well, entab, I'd argue_does_  follow the naming convention, because entab
would be a verb, albeit a made up one. Certainly, en is a prefix, not
another word, so I think that entab is fine. If that doesn't fly, then
go with enTab, I guess, but I'd argue that entab is a single word and
fine as it is.

I fully agree with you on the linguistic side: entab is a single-word
term, just like eg input (no-one would suggest inPut ;-). But
practically, the decomposition enTab helps understanding this
identifier by nicely highlighting tab, don't you think?
This is even more relevant for foreigners, who have here to guess: (1)
that entab is not a 'normal' english single-word term they would just
not know (2) as you say, that en- is a verb-forming prefix in english
one can more or less freely use. Non-trivial.


I'm afraid that I don't agree at all. enTab is hideous and arguably confusing 
precisely because en is _not_ a word. I'd start trying to figure out what en was 
short for if I saw an enTab function. entab is _far_ clearer. Would you make a 
function named enClose? I should hope not. Granted, enclose is actually a word 
that you'll find in a dictionary, but en is a normal prefix in English, and trying 
to treat it as a word or abbrevation in function names would just be confusing.


- Jonathan M Davis


Even worse -- 'en' _is_ a word! (From typography, with 'en' and 'em'). 
It could mean a narrow tab, in contrast to an emTab, which would be a 
wide tab...


It's unfortunate that the dominant language for programming is the one 
with by far the worst spelling.


Re: DVCS

2011-01-22 Thread Walter Bright

Andrei Alexandrescu wrote:

On 1/22/11 12:35 AM, Walter Bright wrote:

Phobos1 on 10.10 is dying in its unit tests because Ubuntu changed how
gcc's strtof() works. Erratic floating point is typical of C runtime
library implementations (the transcendentals are often sloppily done),
which is why more and more Phobos uses its own implementations that Don
has put together.


I think we must change to our own routines anyway. One strategic 
advantage of native implementations of strtof (and the converse sprintf 
etc.) is that we can CTFE them, which opens the door to interesting 
applications.


We can also make our own conversion routines consistent, pure, thread safe and 
locale-independent.


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Walter Bright

Gour wrote:

I'm very seriously considering to put PC-BSD on my desktop and of
several others in order to reduce my admin-time required to maint. all
those machines.


OSX is the only OS (besides DOS) I've had that had painless upgrades. Windows 
upgrades never ever work in place (at least not for me). You have to wipe the 
disk, install from scratch, then reinstall all your apps and reconfigure them.


You're hosed if you lose an install disk or the serial # for it.

Ubuntu isn't much better, but at least you don't have to worry about install 
disks and serial numbers. I just keep a list of sudo apt-get commands! That 
works pretty good until the Ubuntu gods just decide to drop kick your apps (like 
sunbird) out of the repository.


Re: DVCS

2011-01-22 Thread Vladimir Panteleev
On Sat, 22 Jan 2011 08:35:55 +0200, Walter Bright  
newshou...@digitalmars.com wrote:


The only real problem I've run into (so far) is the sunbird calendar has  
been unceremoniously dumped from Ubuntu. The data file for it is in some  
crappy binary format, so poof, there goes all my calendar data.


Hi Walter, have you seen this yet? It's an article on how to import your  
calendar data in Lightning, the official Thunderbird calendar extension. I  
hope it'll help you:


http://brizoma.wordpress.com/2010/05/04/sunbird-and-lightning-removed-from-ubuntu-10-04-lucid-lynx/

--
Best regards,
 Vladimirmailto:vladi...@thecybershadow.net


Re: DVCS

2011-01-22 Thread spir

On 01/22/2011 07:35 AM, Walter Bright wrote:

I finally did do it, but as a clean install. I found an old 160G drive,
wiped it, and installed 10.10 on it. (Amusingly, the About Ubuntu box
says it's version 11.04, and /etc/issue says it's 10.10.)


Same for me ;-)
_
vita es estrany
spir.wikidot.com



Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread spir

On 01/22/2011 09:58 AM, Walter Bright wrote:

Gour wrote:

I'm very seriously considering to put PC-BSD on my desktop and of
several others in order to reduce my admin-time required to maint. all
those machines.


OSX is the only OS (besides DOS) I've had that had painless upgrades.
Windows upgrades never ever work in place (at least not for me). You
have to wipe the disk, install from scratch, then reinstall all your
apps and reconfigure them.


Same in my experience. I had to recently re-install from scratch my 
ubuntu box recently (recently why I have the same amusing info as Walter 
telling my machine runs ubuntu 11.04?) because 10.04 -- 10.10 upgrade 
miserably crashed (at the end of the procedure, indeed).


And no, this is not due to me naughtily the system; instead while 
userland is highly personalised I do not touch the rest (mainly my brain 
cannot cope with the standard unix filesystem hierarchy).


(I use linux only for philosophical reasons, else would happily switch 
to mac.)


Denis
_
vita es estrany
spir.wikidot.com



Re: DVCS

2011-01-22 Thread spir

On 01/22/2011 10:34 AM, Vladimir Panteleev wrote:

On Sat, 22 Jan 2011 08:35:55 +0200, Walter Bright
newshou...@digitalmars.com wrote:


The only real problem I've run into (so far) is the sunbird calendar
has been unceremoniously dumped from Ubuntu. The data file for it is
in some crappy binary format, so poof, there goes all my calendar data.


Hi Walter, have you seen this yet? It's an article on how to import your
calendar data in Lightning, the official Thunderbird calendar extension.
I hope it'll help you:

http://brizoma.wordpress.com/2010/05/04/sunbird-and-lightning-removed-from-ubuntu-10-04-lucid-lynx/


Yes, lightning seems to have been the successor mozilla project to 
sunbird (wikipedia would probably tell you more).


Denis
_
vita es estrany
spir.wikidot.com



Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread retard
Sat, 22 Jan 2011 00:58:59 -0800, Walter Bright wrote:

 Gour wrote:
 I'm very seriously considering to put PC-BSD on my desktop and of
 several others in order to reduce my admin-time required to maint. all
 those machines.
 
 OSX is the only OS (besides DOS) I've had that had painless upgrades.
 Windows upgrades never ever work in place (at least not for me). You
 have to wipe the disk, install from scratch, then reinstall all your
 apps and reconfigure them.
 
 You're hosed if you lose an install disk or the serial # for it.
 
 Ubuntu isn't much better, but at least you don't have to worry about
 install disks and serial numbers. I just keep a list of sudo apt-get
 commands! That works pretty good until the Ubuntu gods just decide to
 drop kick your apps (like sunbird) out of the repository.

Don't blame Ubuntu, http://en.wikipedia.org/wiki/Mozilla_Sunbird

It was developed as a standalone version of the Lightning calendar and 
scheduling extension for Mozilla Thunderbird. Development of Sunbird was 
ended with release 1.0 beta 1 to focus on development of Mozilla 
Lightning.[6][7]

Ubuntu doesn't drop support for widely used software. I'd use Google's 
Calendar instead.


Re: Ad hoc ranges

2011-01-22 Thread Tomek Sowiński
Andrei Alexandrescu napisał:

 On 1/21/11 7:35 PM, Tomek Sowiński wrote:
  Andrei Alexandrescu napisał:
 
  Like I said, anything that doesn't bother to expose range-interfaced 
  iterators and is not performance critical is
  considered a target for ad hoc ranges. Working with non-D libraries, or 
  libraries ported to D but preserving
  mother-language idioms. Tasks like traversing a tree of GUI widgets, or 
  business specific objects where defining
  proper ranges rarely happens and is use-case driven in practice. I expect 
  they could be of some use in unittesting
  as mock input. Vaguely related: educational -- ad hoc ranges read almost 
  like a for loop so the learning curve for
  ranges in general is eased off.
 
  Adding them to Phobos is an interesting idea. We need to evaluate their 
  worth, though.
 
  Everybody: if you could write up a one-liner like range(empty, popFront, 
  front), what would you use it for?
 
  How about a singleton range - a range with exactly one element. It could
  be done with repeat(x, 1) but let's try it with your function as a
  warm-up exercise.
 
  If x is nullable, range(x, x=null, x); it destroys x, though. Otherwise the 
  state must be held separately on the
  stack.
 
  bool empty;
  auto r = range(empty, empty=true, x);
 
  So repeat(x, 1) wins this one. I think such nuggets can better be expressed 
  as a degenerate case of existing
  facilities. I envision ad hoc ranges at places where no iteration is 
  defined and a one-off range struct doesn't
  pay. Like database-backed entities which don't conform to any clear-cut 
  data structure, but if you squint you see
  it's sort of a tree, and you may just be able to e.g. walk through children 
  recursively fetching only active ones
  from DB, traverse columns of interest, and dump their content to a grid 
  component which takes an arbitrary range of
  values. And all this can be wrapped in std.parallelism to overlap DB round 
  trips.
 
 I think the challenge here is to figure out where to store the state. 
 The idiom makes it difficult for the delegates to communicate state to 
 one another.

On the stack, for loops do it for years.

-- 
Tomek



Re: back down on Earth [was: Re: Constructors...]

2011-01-22 Thread Pelle

On 01/21/2011 02:02 PM, spir wrote:

On 01/21/2011 04:02 AM, Andrei Alexandrescu wrote:

That being said, it's not difficult to define a generic function that
copies fields over from one class object to another. Here's a start:

import std.stdio;

void copyMembers(A)(A src, A tgt) if (is(A == class)) {
foreach (e; __traits(allMembers, A)) {
static if (!is(typeof(__traits(getMember, src, e)) == function)
 e != Monitor)
{
__traits(getMember, tgt, e) = __traits(getMember, src, e);
}
}
}


side-note
How many programmers in the world consider this kind of code not
difficult? These few lines mix 3 features I personly find, say,
'special': generics using 'is' constraints, static if, __traits.
personal From those 3, static if is not ugly. /personal

Is code like this supposed to be considered normal? Where is D2 speak
going to? Merge into this a handful of range/algos, a pinch of happy
qualifiers here  there, a specimen of... string-mixin ;-)

How to welcome newcomers?
/side-note

Denis
_
vita es estrany
spir.wikidot.com



What you're saying doesn't make sense. :-)

You welcome them by saying they can copy a class object by using 
copyMembers. Newcomers may not write that code, but using it is dead simple.


I suspect most D users couldn't implement floating point formatting 
either, or a bunch of other hard stuff.


Re: renamepalooza time

2011-01-22 Thread so
Ever since I worked with STL, I fell in love with  
names_with_underscores. I can't explain it, but my feeling is that code  
using that convention is calm and levelheaded. Camel case forces me to  
think of one-word names because at the second word some beauty is  
already lost; never felt the same with the underscores. If I could go  
back in time I'd propose that convention throughout.

Agree on every bit!
Silly me, i was thinking you are one of those (or the one) that enforce  
camelCase!


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Christopher Nicholson-Sauls
On 01/22/11 03:57, spir wrote:
 On 01/22/2011 09:58 AM, Walter Bright wrote:
 Gour wrote:
 I'm very seriously considering to put PC-BSD on my desktop and of
 several others in order to reduce my admin-time required to maint. all
 those machines.

 OSX is the only OS (besides DOS) I've had that had painless upgrades.
 Windows upgrades never ever work in place (at least not for me). You
 have to wipe the disk, install from scratch, then reinstall all your
 apps and reconfigure them.
 
 Same in my experience. I had to recently re-install from scratch my
 ubuntu box recently (recently why I have the same amusing info as Walter
 telling my machine runs ubuntu 11.04?) because 10.04 -- 10.10 upgrade
 miserably crashed (at the end of the procedure, indeed).
 
 And no, this is not due to me naughtily the system; instead while
 userland is highly personalised I do not touch the rest (mainly my brain
 cannot cope with the standard unix filesystem hierarchy).
 
 (I use linux only for philosophical reasons, else would happily switch
 to mac.)
 
 Denis
 _
 vita es estrany
 spir.wikidot.com
 

Likewise I had occasional issues with Ubuntu/Kubuntu upgrades when I was
using it.  Moving to a rolling release style distribution (Gentoo)
changed everything for me.  I haven't had a single major issue since.
(I put major in there because there have been issues, but of the
glance at the screen, notice the blocker, type out the one very short
command that will fix it, continue updating variety.)

Heck, updating has proven so straight-forward that I check for updates
almost daily.  I originally went to Linux for philosophical reasons,
as well, but now that I've had a taste of a real distro I really don't
have any interest in toying around with anything else.

I do have a Windows install for development/testing purposes though...
running in a VM.  ;)  Amazingly enough, Windows seems to be perfectly
happy running as a guest O/S.  If it was possible to do the same with OS
X, I would.  (Anyone know a little trick for that, using VirtualBox?)

-- Chris N-S


Re: Why is the in storage class missing from the ParameterStorageClass enum?

2011-01-22 Thread Christopher Nicholson-Sauls
On 01/20/11 21:57, Andrej Mitrovic wrote:
 On 1/21/11, Jonathan M Davis jmdavisp...@gmx.com wrote:
 Umm. in is never the default. in is essentially an alias for const scope.
 The
 default is non-shared and mutable.

 - Jonathan M Davis

 
 That's what I thought. But I did saw it mentioned in this NG a couple
 of times, I can't remember by who though.
 
 In any case, in seems to be missing from that enum definition. So
 unless there's a specific reason for its absence, I'd file an
 enhancement request.

It's possible someone was talking about D1 where 'in' meant something
very different, and was in fact the default.

-- Chris N-S


Re: renamepalooza time

2011-01-22 Thread torhu

On 22.01.2011 01:36, Sean Kelly wrote:

Andrei Alexandrescu Wrote:


 Ever since I worked with STL, I fell in love with
 names_with_underscores. I can't explain it, but my feeling is that code
 using that convention is calm and levelheaded. Camel case forces me to
 think of one-word names because at the second word some beauty is
 already lost; never felt the same with the underscores.


I like the look of the STL convention, but overall prefer that Camel case distinguishes 
between types and values.  It completely eliminates the need for a _type 
suffix in STL-style typedefs, for one.


No problem:

Some_type
some_variable

I haven't actually used this style personally.  I've just noticed that 
it's the style used throughout Stroustrup's latest book (Programming). 
Seems like the obvious next step for the underscore style of naming.


Function/method signatures in D

2011-01-22 Thread Justin Johansson

To inquire precisely, my question is
what *exactly* constitutes a function/method signature in D?

Aside from functions/methods having an aspect of arity, what can be said 
in detail about the types of their formal arguments and return type?


Cheers,
Justin Johansson


Re: renamepalooza time

2011-01-22 Thread Justin Johansson

On 22/01/11 10:55, bearophile wrote:

I think variable names in camelcase are less noisy.


Sorry, I meant:

I think variable names in camelcase are more noisy.


Bye,
bearophile



I think youAre probablyRight (that camelCase is moreNoisy) but 
unfortunately yourArgument foundered beCause of a typoMistake.


:-) Justin


Re: renamepalooza time

2011-01-22 Thread piotrek
On Fri, 21 Jan 2011 18:16:20 -0600, Andrei Alexandrescu wrote:
 
 Ever since I worked with STL, I fell in love with
 names_with_underscores. I can't explain it, but my feeling is that code
 using that convention is calm and levelheaded. Camel case forces me to
 think of one-word names because at the second word some beauty is
 already lost; never felt the same with the underscores. If I could go
 back in time I'd propose that convention throughout.
 
 Andrei

Hehe. This the one only case I'm happy we can't turn back the time ;) For me 
camelCase is *much* more beautiful  than underscores. When reading STL 
code my eyes coupled with brain  have  difficulties with instant distinction 
where the name exactly  starts and ends (thanks to intention of simulating 
spaces). 

PS. One worders are the best, of course.

Cheers
Piotrek


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Daniel Gibson

Am 22.01.2011 13:21, schrieb retard:

Sat, 22 Jan 2011 00:58:59 -0800, Walter Bright wrote:


Gour wrote:

I'm very seriously considering to put PC-BSD on my desktop and of
several others in order to reduce my admin-time required to maint. all
those machines.


OSX is the only OS (besides DOS) I've had that had painless upgrades.
Windows upgrades never ever work in place (at least not for me). You
have to wipe the disk, install from scratch, then reinstall all your
apps and reconfigure them.

You're hosed if you lose an install disk or the serial # for it.

Ubuntu isn't much better, but at least you don't have to worry about
install disks and serial numbers. I just keep a list of sudo apt-get
commands! That works pretty good until the Ubuntu gods just decide to
drop kick your apps (like sunbird) out of the repository.


Don't blame Ubuntu, http://en.wikipedia.org/wiki/Mozilla_Sunbird

It was developed as a standalone version of the Lightning calendar and
scheduling extension for Mozilla Thunderbird. Development of Sunbird was
ended with release 1.0 beta 1 to focus on development of Mozilla
Lightning.[6][7]

Ubuntu doesn't drop support for widely used software. I'd use Google's
Calendar instead.


Ubuntu doesn't include Lightning, either.

Walter: You could add the lightning plugin to your thunderbird from the 
mozilla page: http://www.mozilla.org/projects/calendar/lightning/index.html
Hopefully it automatically imports your sunbird data or is at least able 
to import it manually.




more naming

2011-01-22 Thread Andrei Alexandrescu
OK, so we have replace(haystack, needle, nail) which replaces _all_ 
occurrences of needle in haystack with nail. How would you call a 
function that replaces only the _first_ occurrence of needle with nail?


Must be a distinct function, not a runtime parameter to the existing 
function. This is because the function that replaces only one occurrence 
only requires nail to be an input range.



Andrei


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Andrej Mitrovic
On 1/22/11, Christopher Nicholson-Sauls ibisbase...@gmail.com wrote:
  If it was possible to do the same with OS
 X, I would.  (Anyone know a little trick for that, using VirtualBox?)


No, that is illegal!

But you might want to do a google search for *cough* iDeneb *cough*
and download vmware player. :p


Re: more naming

2011-01-22 Thread Andrej Mitrovic
What if you want to replace a _count_ number of occurrences of needle
in haystack with nail? That's what Python's replace does, although I
think that only works for strings in Python.


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Daniel Gibson

Am 22.01.2011 17:36, schrieb Andrej Mitrovic:

On 1/22/11, Christopher Nicholson-Saulsibisbase...@gmail.com  wrote:

  If it was possible to do the same with OS
X, I would.  (Anyone know a little trick for that, using VirtualBox?)



No, that is illegal!

But you might want to do a google search for *cough* iDeneb *cough*
and download vmware player. :p


A google search for virtualbox osx takwing may be interesting as well.


Re: more naming

2011-01-22 Thread Justin Johansson

On 23/01/11 03:27, Andrei Alexandrescu wrote:

OK, so we have replace(haystack, needle, nail) which replaces _all_
occurrences of needle in haystack with nail. How would you call a
function that replaces only the _first_ occurrence of needle with nail?

Must be a distinct function, not a runtime parameter to the existing
function. This is because the function that replaces only one occurrence
only requires nail to be an input range.


Andrei


If you articulate this question to yourself over and over until you 
understand the *salient* problem (i.e. the real problem that sticks out) 
you will answer your own question and then have no need to resort to 
newsgroup answers.


If you are feeling lost, a good tactic to solve your problem is to think 
about function signatures in all their D glory not forgetting, of 
course, about D's innovative transitive xxx (const/immutable) constructs 
to include in the specification of your function(s).


Justin


Re: more naming

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 10:47 AM, Andrej Mitrovic wrote:

What if you want to replace a _count_ number of occurrences of needle
in haystack with nail? That's what Python's replace does, although I
think that only works for strings in Python.


A specific count is rare but can be added as a defaulted parameter. The 
only problem is that one is special because it accepts a weaker range as 
replacement.


Andrei


Re: more naming

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 11:03 AM, Justin Johansson wrote:

On 23/01/11 03:27, Andrei Alexandrescu wrote:

OK, so we have replace(haystack, needle, nail) which replaces _all_
occurrences of needle in haystack with nail. How would you call a
function that replaces only the _first_ occurrence of needle with nail?

Must be a distinct function, not a runtime parameter to the existing
function. This is because the function that replaces only one occurrence
only requires nail to be an input range.


Andrei


If you articulate this question to yourself over and over until you
understand the *salient* problem (i.e. the real problem that sticks out)
you will answer your own question and then have no need to resort to
newsgroup answers.

If you are feeling lost, a good tactic to solve your problem is to think
about function signatures in all their D glory not forgetting, of
course, about D's innovative transitive xxx (const/immutable) constructs
to include in the specification of your function(s).

Justin


Now I am feeling lost indeed :o).

Andrei


Re: more naming

2011-01-22 Thread Torarin
2011/1/22 Andrei Alexandrescu seewebsiteforem...@erdani.org:
 OK, so we have replace(haystack, needle, nail) which replaces _all_
 occurrences of needle in haystack with nail. How would you call a function
 that replaces only the _first_ occurrence of needle with nail?

 Must be a distinct function, not a runtime parameter to the existing
 function. This is because the function that replaces only one occurrence
 only requires nail to be an input range.


 Andrei


It sounds like the current replace should be named replaceAll.

Torarin


Re: more naming

2011-01-22 Thread so

It sounds like the current replace should be named replaceAll.

Torarin


replaceAll
replaceN
replaceFirst
replaceLast


Python's partition

2011-01-22 Thread Andrei Alexandrescu
Looking through Python's string functions 
(http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed 
partition():


partition(sep)
Split the string at the first occurrence of sep, and return a 
3-tuple containing the part before the separator, the separator itself, 
and the part after the separator. If the separator is not found, return 
a 3-tuple containing the string itself, followed by two empty strings. 
New in version 2.5.


Right now we find find and findSkip; partition would be a great 
complement, and can be implemented for all forward ranges.


One question is naming - partition() is not good for us because 
std.algorithm.partition implements Hoare's in-place partition algorithm. 
How should we call the function?



Andrei


Re: more naming

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 11:38 AM, Torarin wrote:

2011/1/22 Andrei Alexandrescuseewebsiteforem...@erdani.org:

OK, so we have replace(haystack, needle, nail) which replaces _all_
occurrences of needle in haystack with nail. How would you call a function
that replaces only the _first_ occurrence of needle with nail?

Must be a distinct function, not a runtime parameter to the existing
function. This is because the function that replaces only one occurrence
only requires nail to be an input range.


Andrei



It sounds like the current replace should be named replaceAll.

Torarin


That's what I'm fearing - changing current replace to replaceAll and 
adding replace with the meaning of replaceFirst would silently change 
the semantics of existing code.


Andrei


Re: more naming

2011-01-22 Thread Daniel Gibson

Am 22.01.2011 18:46, schrieb Andrei Alexandrescu:

On 1/22/11 11:38 AM, Torarin wrote:

2011/1/22 Andrei Alexandrescuseewebsiteforem...@erdani.org:

OK, so we have replace(haystack, needle, nail) which replaces _all_
occurrences of needle in haystack with nail. How would you call a
function
that replaces only the _first_ occurrence of needle with nail?

Must be a distinct function, not a runtime parameter to the existing
function. This is because the function that replaces only one occurrence
only requires nail to be an input range.


Andrei



It sounds like the current replace should be named replaceAll.

Torarin


That's what I'm fearing - changing current replace to replaceAll and
adding replace with the meaning of replaceFirst would silently change
the semantics of existing code.

Andrei


IMHO replace (without eny suffix) sounds like it replaces every occurence.
So just add replaceFirst for a function that replaces only the first 
occurence :)


Cheers,
- Daniel


Re: more naming

2011-01-22 Thread Adam D. Ruppe
Torarin wrote:
 It sounds like the current replace should be named replaceAll.

That would break lots of existing code, and it doesn't seem to
fit.

If replacing only the first element means it can take a special
range, whereas all other n is is the same, it seems obvious
that replaceFirst be the special function (that's what I'd call
it too) and normal replace be either:

a) Kept exactly as it is

b) Add a runtime parameter:

string replace(string item, string replaceWhat, string replaceWith, int howMany 
=
int.max);

So it stays the same as it is now by default, but can cover
any number of items in the same way.



If n == infinity was a special case for algorithm or input,
it'd make sense to give it a special name (though still big
points against it because of inertia). But it isn't. n==1 is
special, but n != 1 is always the same.

So I'd say go replaceFirst.


Re: Python's partition

2011-01-22 Thread so
On Sat, 22 Jan 2011 19:44:30 +0200, Andrei Alexandrescu  
seewebsiteforem...@erdani.org wrote:


Looking through Python's string functions  
(http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed  
partition():


partition(sep)
 Split the string at the first occurrence of sep, and return a  
3-tuple containing the part before the separator, the separator itself,  
and the part after the separator. If the separator is not found, return  
a 3-tuple containing the string itself, followed by two empty strings.  
New in version 2.5.


Right now we find find and findSkip; partition would be a great  
complement, and can be implemented for all forward ranges.


One question is naming - partition() is not good for us because  
std.algorithm.partition implements Hoare's in-place partition algorithm.  
How should we call the function?



Andrei


splitAt? I think splitanything is much better then partition.


Re: Python's partition

2011-01-22 Thread Torarin
Divide? As in dividing a pie chart.

Torarin


Re: more naming

2011-01-22 Thread Torarin
2011/1/22 Andrei Alexandrescu seewebsiteforem...@erdani.org:

 That's what I'm fearing - changing current replace to replaceAll and adding
 replace with the meaning of replaceFirst would silently change the semantics
 of existing code.

 Andrei


Yeah, I see that problem. I'm just so used to replace first being
the default in text editors, and then you have a replace all button
if you want to replace everything. That also seems to be Walter's
reasoning in std.typetuple.


Re: more naming

2011-01-22 Thread bearophile
Daniel Gibson:

 IMHO replace (without eny suffix) sounds like it replaces every occurence.
 So just add replaceFirst for a function that replaces only the first 
 occurence :)

OK.

Bye,
bearophile


Re: Python's partition

2011-01-22 Thread spir

On 01/22/2011 06:44 PM, Andrei Alexandrescu wrote:

Looking through Python's string functions
(http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
partition():

partition(sep)
Split the string at the first occurrence of sep, and return a 3-tuple
containing the part before the separator, the separator itself, and the
part after the separator. If the separator is not found, return a
3-tuple containing the string itself, followed by two empty strings. New
in version 2.5.

Right now we find find and findSkip; partition would be a great
complement, and can be implemented for all forward ranges.

One question is naming - partition() is not good for us because
std.algorithm.partition implements Hoare's in-place partition algorithm.
How should we call the function?


separate(d)

Denis
_
vita es estrany
spir.wikidot.com



Re: renamepalooza time

2011-01-22 Thread Max Samukha

On 01/22/2011 02:16 AM, Andrei Alexandrescu wrote:

On 1/21/11 4:49 PM, Jonathan M Davis wrote:

On Friday, January 21, 2011 13:30:11 Ali Çehreli wrote:

Andrei Alexandrescu wrote:
 iswhite

I like separating is with an underscore, like most coding styles do:

is_whitespace

Warm and fuzzy... :)


Most? I've never dealt with a coding style that had underscores. It's
generally
camelcase, though I get the impression that using underscores in C
code is more
common (I've mostly used C++ and Java). Regardless however, Phobos'
coding style
uses camelcase, not underscores. And this whole thread was started to
try and
find better names for functions which need new names, because they don't
currently follow Phobos' naming conventions.


Ever since I worked with STL, I fell in love with
names_with_underscores. I can't explain it, but my feeling is that code
using that convention is calm and levelheaded. Camel case forces me to
think of one-word names because at the second word some beauty is
already lost; never felt the same with the underscores. If I could go
back in time I'd propose that convention throughout.

Andrei



My problem with underscore-delimited identifiers is that they can get 
really hard on eyes:


int my_temp_var = some_object_instance.some_field.some_other_field;

The dots are completely lost. Also, when identifiers are getting long 
(and in large libraries they tend to) the underscores become to look 
pretty annoying. I have worked with many conventions and camelCase 
remains my favorite for now.


string splitting funcs

2011-01-22 Thread spir

While we're at tweaking std.string:

When writing string libs or types (like Text recently), I implement 3 
string splitting methods. This may --or not-- be useful for D's string 
module.


The core point is: what to do with empty parts? They may be generated when:
* the separator is present at either end of the source string
* successive separators occur in the source string
Thus,
split(--abc-def, --)
basically returns
[,abc,,def,,]

This may be or not what we expect. But why? I ended up considering there 
are 2 distinct use cases where we need to split a string:

1. it is like a record (fields)
2. it is like a list (elements)

In the first case, we want to keep empty fields so that each field has a 
constant index, and sometimes empty fields are meaningful. For instance, 
in name--phone--email, when phone is absent, we still want email as 
third field.
In the case of a list instead, most commonly empty elements are 
irrelevant, actually often due to flexibility of the grammar (not always 
formal). For instance, lists of words / numbers / tokens; or more simply 
lines: we will rarely keep blank ones for further process.


This leads to 2 different string splitting funcs, eg
string[] listElements (string sep)
string[] recordFields (string sep)
(names discussable ;-)
The first func is symmetric to join. The second one may simply filter 
the first one's results, or instead drop empty elements on the fly.


Finally, there is a third, different, use case, which may well be the 
most common one, and requires yet another func:

string[] split (string whitespace= \t\n)
which indeed splits on any whitespace. Usually, the expected behaviour 
is any combination or repetition of ws chars is considered a single 
separator; but ws at start/end well generates an empty part.


Makes sense?

Denis
_
vita es estrany
spir.wikidot.com



Re: Potential patent issues

2011-01-22 Thread Nick Sabalausky
Don nos...@nospam.com wrote in message 
news:ihcrve$1t5l$1...@digitalmars.com...
 spir wrote:
 On 01/21/2011 03:51 PM, Don wrote:
 Don wrote:
 BlazingWhitester wrote:
 I spotted some patents that can theaten current DMD implementation.
 Wanted to clarify things.

 http://www.freepatentsonline.com/6185728.pdf - this patent describes
 method pointers implementation (delegates)

 This was obviously a patent aimed at protecting Delphi from VB. It's
 all about the RAD designer: visual connections between GUI elements
 and events has a 1:1 correspondence with code; delegates are used to
 achieve this.

 D delegates can store a data pointer to a nested function, or to an
 object. This is rather more general (not an object-oriented feature),
 and doesn't provide a 1:1 correspondence to visuals.
 I presume they were only able to satisfy the requirements for novelty
 and non-obviousness, because of the RAD usage. In fact, there doesn't
 seem to be any suggestion that delegates would be used for anything 
 else.
 The more general idea of storing a data pointer and a function pointer
 together is simple and obvious, and surely has prior art.

 D's delegate scheme is essentially the same as described by Richard
 Hickey, C++ report (Feb 1995).

 See also a discussion on comp.std.c++, Feb 1996, titled Generic Object
 Callbacks. Ian Willmott states:
 I suggest that a new data type needs to be added to the language. We
 could call it pointer-to-bound-member-function.
 ...
 Conceptually, it is a two-element structure consisting of
 pointer into data space, identifying an object, and a pointer into
 code space, identifying a member function on that object. The static
 type of such a variable is the signature (return type and arguments)
 of the member functions it is compatible with, just as the type of a
 regular function pointer is the signature of the functions it can
 reference. The only operations defined for this type are assignment,
 equality, and callthrough. Static typechecking is done at the point
 where a value of this type is created, and where a call is made
 through it. 

 Borland's patent dates from Feb 6, 2001. They were SIX YEARS too late.
 g

 IIUC, the structure you describe is /exactly/ the same, both concretely 
 and semantically as Oberon-2 type-bound procedures (read: virtual 
 methods). Oberon-2 was created in 1991, IIRC. This makes 10 years ;-)
 Unlike you, I don't consider D's delegate to follow the same scheme. 
 Sure, it's a pair of pointers, one of which point to a routine (to use a 
 neutral word). But in the case of D the second one does not point to to a 
 type/object, but to the definition scope (environment). This is very 
 different, isn't it?
 Thus I would consider D to not even be concerned by the patent. If you 
 use a 3-integer struct to store a color, do you have to pay royalties to 
 the owner of a patent about a 3-integer struct used to store a position? 
 Indeed, lawyers...

 Yeah. I think we can be certain that that patent has zero risk for D.
 On the positive side -- I think that the rise of public source 
 repositories (with complete histories) means that public disclosure has 
 become much more common (factor of 1000 or more) than the days when these 
 junk patents were issued.

 Imagine you're a patent examiner, who has to work out if a particular code 
 idea has been previously published. How can you be confident that it 
 doesn't already exist in the billions of lines of open source code on the 
 web? And how much would you charge someone who asked you to check them 
 all?


I've been under the impression that, as a rule, the USPTO doesn't check for 
prior art and deliberately leaves invalid due to prior art up to the 
courts.




Re: more naming

2011-01-22 Thread spir

On 01/22/2011 05:27 PM, Andrei Alexandrescu wrote:

OK, so we have replace(haystack, needle, nail) which replaces _all_
occurrences of needle in haystack with nail. How would you call a
function that replaces only the _first_ occurrence of needle with nail?

Must be a distinct function, not a runtime parameter to the existing
function. This is because the function that replaces only one occurrence
only requires nail to be an input range.


Apart voting for replaceFirst:

Python doc:
string.replace(str, old, new[, maxreplace])¶
Return a copy of string str with all occurrences of substring old 
replaced by new. If the optional argument maxreplace is given, the first 
maxreplace occurrences are replaced.


In years and years of string processing, I have used maxreplace once, I 
guess, and the value was not 1. Does something like replace first belong 
to stdlib? Even more if it needs be so special. When needed, isnt'it 
easy to write in two lines using find's result? Also, what is the 
correct behaviour when not found (what is the one true way)?



Denis
_
vita es estrany
spir.wikidot.com



Re: more naming

2011-01-22 Thread Andrej Mitrovic
On 1/22/11, spir denis.s...@gmail.com wrote:
 In years and years of string processing, I have used maxreplace once, I
 guess, and the value was not 1.

Isn't Andrei talking about std.algorithm.replace, which should work
with any range and not just strings?


Re: Potential patent issues

2011-01-22 Thread Jean Crystof
Nick Sabalausky Wrote:

 I've been under the impression that, as a rule, the USPTO doesn't check for 
 prior art and deliberately leaves invalid due to prior art up to the 
 courts.

That's how it works. The patent threat is always there. Someone can patent 
delegates, classes, and whatever language feature whenever they want. In the 
courts if Walter is much poorer than the competitor, he can't win. The SCO case 
was a great example. They didn't own the Unix rights and couldn't find any 
patent infringing code. Nevertheless, the Microsoft money kept them fighting. 
If Apple or Microsoft wants to compete with Walter, he simply can't win.


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Walter Bright

retard wrote:
Ubuntu doesn't drop support for widely used software. I'd use Google's 
Calendar instead.


I'm really not interested in Google owning my private data.


Re: DVCS

2011-01-22 Thread Walter Bright

Vladimir Panteleev wrote:
http://brizoma.wordpress.com/2010/05/04/sunbird-and-lightning-removed-from-ubuntu-10-04-lucid-lynx/ 


Thanks for finding that. But I think I'll stick for now with the ipod's 
calendar. It's more useful anyway, as it moves with me.


Re: more naming

2011-01-22 Thread Paul D. Anderson
Daniel Gibson Wrote:

 Am 22.01.2011 18:46, schrieb Andrei Alexandrescu:
  On 1/22/11 11:38 AM, Torarin wrote:
  2011/1/22 Andrei Alexandrescuseewebsiteforem...@erdani.org:
  OK, so we have replace(haystack, needle, nail) which replaces _all_
  occurrences of needle in haystack with nail. How would you call a
  function
  that replaces only the _first_ occurrence of needle with nail?
 
  Must be a distinct function, not a runtime parameter to the existing
  function. This is because the function that replaces only one occurrence
  only requires nail to be an input range.
 
 
  Andrei
 
 
  It sounds like the current replace should be named replaceAll.
 
  Torarin
 
  That's what I'm fearing - changing current replace to replaceAll and
  adding replace with the meaning of replaceFirst would silently change
  the semantics of existing code.
 
  Andrei
 
 IMHO replace (without eny suffix) sounds like it replaces every occurence.
 So just add replaceFirst for a function that replaces only the first 
 occurence :)
 
 Cheers,
 - Daniel

This was my first thought, too.

Paul


Re: DVCS

2011-01-22 Thread retard
Sat, 22 Jan 2011 13:12:26 -0800, Walter Bright wrote:

 Vladimir Panteleev wrote:
 http://brizoma.wordpress.com/2010/05/04/sunbird-and-lightning-removed-
from-ubuntu-10-04-lucid-lynx/
 
 Thanks for finding that. But I think I'll stick for now with the ipod's
 calendar. It's more useful anyway, as it moves with me.

Does the new Ubuntu overall work better than the old one? Would be 
amazing if the media players are still all broken.


replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Andrei Alexandrescu

OK, I added replaceFirst:

http://d-programming-language.org/cutting-edge/phobos/std_array.html#replaceFirst

http://www.dsource.org/projects/phobos/changeset/2365

I've also added two crucial abstractions that finally quench my many 
sleepless nights following my Boostcon keynote. Back then people said 
that STL's find() is better than D's find() because the former returns 
an iterator that can be combined with either the first iterator to get 
the portion before the match, or with the last iterator to get the 
portion starting at the match. D's find() only gives you the portion 
after the match.


The first abstraction is the takeExactly() function:

http://d-programming-language.org/cutting-edge/phobos/std_range.html#takeExactly

That function allows you to pick a determined number of elements from a 
range, assuming the range is never shorter than that. That sounds a bit 
obscure, but plays a pivotal role in findParts() (which is the name I 
settled on for the equivalent of Python's partition()):


http://d-programming-language.org/cutting-edge/phobos/std_algorithm.html#findParts

There are many nice things about findParts() that make it feel whole: 
all parts have lengths, their types are the best possible given the 
input, and the amount of information conveyed is maximized.


The implementations of findParts and takeExactly are simple and elegant too:

http://www.dsource.org/projects/phobos/changeset/2365


Andrei


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 3:03 PM, Walter Bright wrote:

retard wrote:

Ubuntu doesn't drop support for widely used software. I'd use Google's
Calendar instead.


I'm really not interested in Google owning my private data.


Google takes email privacy very seriously. Only last week they fired an 
employee for snooping through someone else's email.


http://techcrunch.com/2010/09/14/google-engineer-spying-fired/

Of course, that could be framed either as a success or a failure of 
Google's privacy enforcement.


Several companies are using gmail for their email infrastructure.


Andrei


Re: Python's partition

2011-01-22 Thread Christopher Nicholson-Sauls
On 01/22/11 11:44, Andrei Alexandrescu wrote:
 Looking through Python's string functions
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
 partition():
 
 partition(sep)
 Split the string at the first occurrence of sep, and return a
 3-tuple containing the part before the separator, the separator itself,
 and the part after the separator. If the separator is not found, return
 a 3-tuple containing the string itself, followed by two empty strings.
 New in version 2.5.
 
 Right now we find find and findSkip; partition would be a great
 complement, and can be implemented for all forward ranges.
 
 One question is naming - partition() is not good for us because
 std.algorithm.partition implements Hoare's in-place partition algorithm.
 How should we call the function?
 
 
 Andrei

Bisect?

-- Chris N-S



Conditional Pure?

2011-01-22 Thread %u
I wanted to suggest a feature similar to inout: conditional purity. That is,
sometimes a function is pure iff the delegates passed to it are pure, and as
of right now, I don't think there's any way to document this other than by
overloading the function as a template (which results in lots of code
duplication).

The idea would be to make this a bit more general than just a particular fix
for pure, though, since if in the future, new qualifiers arise (I guess this
might also work for @trusted and such), then the solution should work for
those too.


Re: Python's partition

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 3:33 PM, Christopher Nicholson-Sauls wrote:

On 01/22/11 11:44, Andrei Alexandrescu wrote:

Looking through Python's string functions
(http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
partition():

partition(sep)
 Split the string at the first occurrence of sep, and return a
3-tuple containing the part before the separator, the separator itself,
and the part after the separator. If the separator is not found, return
a 3-tuple containing the string itself, followed by two empty strings.
New in version 2.5.

Right now we find find and findSkip; partition would be a great
complement, and can be implemented for all forward ranges.

One question is naming - partition() is not good for us because
std.algorithm.partition implements Hoare's in-place partition algorithm.
How should we call the function?


Andrei


Bisect?

-- Chris N-S



Would be rather trisect, but that becomes a bit too cute.

Andrei


Re: renamepalooza time

2011-01-22 Thread Paul D. Anderson
My two cents.

(Incidentally, when I learned to type -- in the USA in 1970 -- a cents symbol 
was standard on the keyboard. Shift-2 or Shift-6, I think.)

Jacob Carlborg Wrote:

 
 LS - lineSeparator/LineSeparator
 PS - paragraphSeparator/ParagraphSeparator

These are established acronyms: 
(http://www.unicode.org/standard/reports/tr13/tr13-5.html). I would leave them 
as is.

 
 entab - entab/spacesToTabs
 expandtabs - expandTabs/tabsToSpaces

I prefer the more explicit spacesToTabs variants. I would have to double 
check to see what entab means.

 ljustify - leftJustify /justifyLeft

left/rightJustify is better, IMHO.

 lowercase - lowercaseChars

lowercase is fine as is.

 newline - newline

Mild preference for newLine, but either would be fine.

 stripl - stripLeft
 stripr - striptRight

Yes, even though differs from left/rightJustify usage.

 tolower - toLower/toLowercase/toLowerCase
 tolowerInPlace -  toLowerInPlace/toLowercaseInPlace/toLowerCaseInPlace

toLower and toLowerInPlace

 toupper - toUpper/toUppercase/toUpperCase
 toupperInPlace - toUpperInPlace/toUppercaseInPlace/toUpperCaseInPlace

Ditto: toUpper and toUpperInPlace

 whitespace - whitespaceCharsr

whitespace is fine as is.

 -- 
 /Jacob Carlborg



Re: Python's partition

2011-01-22 Thread bearophile
Andrei Alexandrescu:

 Would be rather trisect, but that becomes a bit too cute.

trisect name is acceptable :-)

Bye,
bearophile


Re: Python's partition

2011-01-22 Thread foobar
Andrei Alexandrescu Wrote:

 Looking through Python's string functions 
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed 
 partition():
 
 partition(sep)
  Split the string at the first occurrence of sep, and return a 
 3-tuple containing the part before the separator, the separator itself, 
 and the part after the separator. If the separator is not found, return 
 a 3-tuple containing the string itself, followed by two empty strings. 
 New in version 2.5.
 
 Right now we find find and findSkip; partition would be a great 
 complement, and can be implemented for all forward ranges.
 
 One question is naming - partition() is not good for us because 
 std.algorithm.partition implements Hoare's in-place partition algorithm. 
 How should we call the function?
 
 
 Andrei

sounds like JavaScript's split:
string.split(separator, limit)





Re: DVCS

2011-01-22 Thread Daniel Gibson

Am 22.01.2011 22:31, schrieb retard:

Sat, 22 Jan 2011 13:12:26 -0800, Walter Bright wrote:


Vladimir Panteleev wrote:

http://brizoma.wordpress.com/2010/05/04/sunbird-and-lightning-removed-

from-ubuntu-10-04-lucid-lynx/


Thanks for finding that. But I think I'll stick for now with the ipod's
calendar. It's more useful anyway, as it moves with me.


Does the new Ubuntu overall work better than the old one? Would be
amazing if the media players are still all broken.


And is the support for the graphics chip better, i.e. can you use full 
resolution?


Re: Conditional Pure?

2011-01-22 Thread bearophile
%u Wrote:

 I wanted to suggest a feature similar to inout: conditional purity. That is,
 sometimes a function is pure iff the delegates passed to it are pure,

I think this is useless. If this is possible, then you just mark every single 
not-pure function in the program with @conditionally_pure, and we are back to 
the beginning.

Bye,
bearophile


Re: Conditional Pure?

2011-01-22 Thread %u
 I think this is useless. If this is possible, then you just mark every single
not-pure function in the program with @conditionally_pure, and we are back to 
the
beginning.


Oh, but that's not what I meant! I meant something like this:

  int call(TFn)(TFn fn) pure(isPure!(TFn))
 if (isCallable!(TFn))
  {
 return fn(5);
  }

This way we specify purity based on a static boolean.


Re: DVCS

2011-01-22 Thread Walter Bright

Daniel Gibson wrote:
And is the support for the graphics chip better, i.e. can you use full 
resolution?


Yes, it recognized my resolution automatically. That's a nice improvement.


Re: easy to upgrade OS (was Re: DVCS)

2011-01-22 Thread Walter Bright

Andrei Alexandrescu wrote:
Google takes email privacy very seriously. Only last week they fired an 
employee for snooping through someone else's email.


http://techcrunch.com/2010/09/14/google-engineer-spying-fired/


That's good to know. On the other hand, Google keeps information forever. 
Ownership, management, policies, and practices change.


And to be frank, the fact that some of Google's employees are not authorized to 
look at emails means that others are. And those others are subject to the usual 
human weaknesses of bribery, blackmail, temptation, voyeurism, etc. Heck, the 
White House is famous for being a leaky organization, despite extensive security.


I rent storage on Amazon's servers, but the stuff I send there is encrypted 
before Amazon ever sees it. I don't have to depend at all on Amazon having a 
privacy policy or airtight security.


Google could implement their Calendar, etc., stuff the same way. I'd even pay 
for it (like I pay Amazon).


Re: DVCS

2011-01-22 Thread Walter Bright

retard wrote:
Does the new Ubuntu overall work better than the old one? Would be 
amazing if the media players are still all broken.


I haven't tried the sound yet, but the video playback definitely is better.

Though the whole screen flashes now and then, like the video mode is being reset 
badly. This is new behavior.


Re: renamepalooza time

2011-01-22 Thread Nick Sabalausky
Jonathan M Davis jmdavisp...@gmx.com wrote in message 
news:mailman.804.1295659471.4748.digitalmar...@puremagic.com...

 Personally, camelcase vs underscores isn't even something that I normally 
 think
 about. I just always use camelcase. On _rare_ occasion, I might use 
 underscores
 because it seems to fit a particular situation, but that's _really_ rare. 
 The
 only time that I normally stick underscores in variable names is to 
 indicate
 private member variables. But I find using underscores in names to 
 generally be
 ugly and noisy. I expect that a lot of that just comes down to what you're 
 used
 to though.


I'm the same way. Plus, I find it really awkward to constantly type a bunch 
of underscores. It feels less like typing and more like finger 
acobatics.




Re: Python's partition

2011-01-22 Thread Tomek Sowiński
Andrei Alexandrescu napisał:

 Looking through Python's string functions 
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed 
 partition():
 
 partition(sep)
  Split the string at the first occurrence of sep, and return a 
 3-tuple containing the part before the separator, the separator itself, 
 and the part after the separator. If the separator is not found, return 
 a 3-tuple containing the string itself, followed by two empty strings. 
 New in version 2.5.
 
 Right now we find find and findSkip; partition would be a great 
 complement, and can be implemented for all forward ranges.
 
 One question is naming - partition() is not good for us because 
 std.algorithm.partition implements Hoare's in-place partition algorithm. 
 How should we call the function?

Instead of a one-shot function, would a lazy range of pre-hit-post troikas be 
possible? That'd rhyme nicely with RegexMatch. In fact, match(string, string) 
overload is free...

-- 
Tomek



Re: more naming

2011-01-22 Thread Nick Sabalausky
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message 
news:ihf0kc$2fqj$1...@digitalmars.com...
 OK, so we have replace(haystack, needle, nail) which replaces _all_ 
 occurrences of needle in haystack with nail. How would you call a function 
 that replaces only the _first_ occurrence of needle with nail?

 Must be a distinct function, not a runtime parameter to the existing 
 function. This is because the function that replaces only one occurrence 
 only requires nail to be an input range.


replaceFirst

As for the question of renaming replace to replaceAll, I'd lean more 
towards replace, but I honestly don't actually care either way.




Re: renamepalooza time

2011-01-22 Thread Ali Çehreli

Jonathan M Davis wrote:

On Friday, January 21, 2011 13:30:11 Ali Çehreli wrote:

Andrei Alexandrescu wrote:
  iswhite

I like separating is with an underscore, like most coding styles do:

   is_whitespace

Warm and fuzzy... :)


Most? I've never dealt with a coding style that had underscores.


Sorry for being unclear. My comment was only in the context of is_. I 
like separating is with an underscore. Probably because is is not 
part of the name. It operates at a different linguistic level.


 It's generally
camelcase, though I get the impression that using underscores in C code is more 
common (I've mostly used C++ and Java).


Same here: always camelcase, except in our C libraries. Now I like 
underscore more than before. :)


 Regardless however, Phobos' coding style
uses camelcase, not underscores. And this whole thread was started to try and 
find better names for functions which need new names, because they don't 
currently follow Phobos' naming conventions.


I am aware of that. Then half seriously, let's change the standard to 
use underscore after is. Also when parts of a camelcased name are too 
loosely related.


For example, when NodeReader is an interface and when we already have a 
LovelyDb, we may have a class named LovelyDb_NodeReader.


Ali


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Nick Sabalausky
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message 
news:ihfm34$jvb$1...@digitalmars.com...
 On 1/22/11 4:16 PM, bearophile wrote:
 Andrei:

 Back then people said that STL's find() is better than D's find()
 because the former returns
 an iterator that can be combined with either the first iterator to get
 the portion before the match, or with the last iterator to get the
 portion starting at the match. D's find() only gives you the portion
 after the match.

 There's a HUGE problem here. This equivalence is sometimes true, but 
 surely not always true:
 more powerful != better


 That function allows you to pick a determined number of elements from a
 range, assuming the range is never shorter than that. That sounds a bit
 obscure, but plays a pivotal role in findParts() (which is the name I
 settled on for the equivalent of Python's partition()):

 trisect is way better than findParts :-) And it's a single word with 
 no uppercase letters in the middle.

 There is still time until the next release. Votes for trisect?


vote--

findParts is the sort of thing that once you read what it does just 
*once*, it immediately becomes both obvious and easy to remember. But 
trisect is 1. scary, 2. I'd never remember it, and 3. Whenever I'd come 
across it, I'd never remember what it meant.  Those are paricularly bad 
since I know right now I'm going to find it an incredibly useful function: 
There's already been too many times I've written this mess and felt dirty 
about it:

auto result = find(str, delim);
auto firstPart = str[0..$-result.length];

So I'm thrilled to see this function being added.




Re: Conditional Pure?

2011-01-22 Thread bearophile
%u:

 Oh, but that's not what I meant! I meant something like this:
 
   int call(TFn)(TFn fn) pure(isPure!(TFn))
  if (isCallable!(TFn))
   {
  return fn(5);
   }
 
 This way we specify purity based on a static boolean.

I see. I'd like a more general-purpose solution, something that works with 
nothrow too and other future attributes too. So I have suggested:
http://d.puremagic.com/issues/show_bug.cgi?id=5125

Bye,
bearophile


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 5:14 PM, Nick Sabalausky wrote:

Andrei Alexandrescuseewebsiteforem...@erdani.org  wrote in message
news:ihfm34$jvb$1...@digitalmars.com...

On 1/22/11 4:16 PM, bearophile wrote:

Andrei:


Back then people said that STL's find() is better than D's find()
because the former returns
an iterator that can be combined with either the first iterator to get
the portion before the match, or with the last iterator to get the
portion starting at the match. D's find() only gives you the portion
after the match.


There's a HUGE problem here. This equivalence is sometimes true, but
surely not always true:
more powerful != better



That function allows you to pick a determined number of elements from a
range, assuming the range is never shorter than that. That sounds a bit
obscure, but plays a pivotal role in findParts() (which is the name I
settled on for the equivalent of Python's partition()):


trisect is way better than findParts :-) And it's a single word with
no uppercase letters in the middle.


There is still time until the next release. Votes for trisect?



vote--

findParts is the sort of thing that once you read what it does just
*once*, it immediately becomes both obvious and easy to remember. But
trisect is 1. scary, 2. I'd never remember it, and 3. Whenever I'd come
across it, I'd never remember what it meant.  Those are paricularly bad
since I know right now I'm going to find it an incredibly useful function:
There's already been too many times I've written this mess and felt dirty
about it:

auto result = find(str, delim);
auto firstPart = str[0..$-result.length];

So I'm thrilled to see this function being added.


Yes, I'm absolutely in agreement with the naming (and thrilled too). I 
imagine a putative user looking through std.algorithm (let's see... 
what find functions are out there?). That makes findPieces easy to get 
to, whereas trisect would be oddly situated in the alphabetic list and 
oddly named enough to be virtually undiscoverable.



Andrei


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Tomek Sowiński
Andrei Alexandrescu napisał:

 On 1/22/11 5:14 PM, Nick Sabalausky wrote:
  Andrei Alexandrescuseewebsiteforem...@erdani.org  wrote in message
  news:ihfm34$jvb$1...@digitalmars.com...
  On 1/22/11 4:16 PM, bearophile wrote:
  Andrei:
 
  Back then people said that STL's find() is better than D's find()
  because the former returns
  an iterator that can be combined with either the first iterator to get
  the portion before the match, or with the last iterator to get the
  portion starting at the match. D's find() only gives you the portion
  after the match.
 
  There's a HUGE problem here. This equivalence is sometimes true, but
  surely not always true:
  more powerful != better
 
 
  That function allows you to pick a determined number of elements from a
  range, assuming the range is never shorter than that. That sounds a bit
  obscure, but plays a pivotal role in findParts() (which is the name I
  settled on for the equivalent of Python's partition()):
 
  trisect is way better than findParts :-) And it's a single word with
  no uppercase letters in the middle.
 
  There is still time until the next release. Votes for trisect?
 
 
  vote--
 
  findParts is the sort of thing that once you read what it does just
  *once*, it immediately becomes both obvious and easy to remember. But
  trisect is 1. scary, 2. I'd never remember it, and 3. Whenever I'd come
  across it, I'd never remember what it meant.  Those are paricularly bad
  since I know right now I'm going to find it an incredibly useful function:
  There's already been too many times I've written this mess and felt dirty
  about it:
 
  auto result = find(str, delim);
  auto firstPart = str[0..$-result.length];
 
  So I'm thrilled to see this function being added.
 
 Yes, I'm absolutely in agreement with the naming (and thrilled too). I 
 imagine a putative user looking through std.algorithm (let's see... 
 what find functions are out there?). That makes findPieces easy to get 
 to, whereas trisect would be oddly situated in the alphabetic list and 
 oddly named enough to be virtually undiscoverable.

Me a tad less, but not because of the name. I'd still rather see a lazy range 
of pre-hit-post tuples. Am I the only one to see findParts as a no-patterns 
variation of RegexMatch accepting all element types, not just char? Then even 
the name comes naturally -- match.

-- 
Tomek



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread so
Yes, I'm absolutely in agreement with the naming (and thrilled too). I  
imagine a putative user looking through std.algorithm (let's see...  
what find functions are out there?). That makes findPieces easy to get  
to, whereas trisect would be oddly situated in the alphabetic list and  
oddly named enough to be virtually undiscoverable.


If this is the reasoning. This is a split function, not a find.
There will be a few more of these split functions i suppose and this is  
the reason of my proposal splitAt.

It is in the definition of the function you quoted.

(Split) the string (at) the first occurrence of (sep)

splitAt(string, sep)

We can also overload it.

split(string, sep) // splits in two
split(string, sep, count)


Re: Conditional Pure?

2011-01-22 Thread %u
 I see. I'd like a more general-purpose solution, something that works with
nothrow too and other future attributes too.

Funny, that was going to be my next comment. :)
The only thing that scares me a bit is that code like this:

public(isPublic!(TFn)) static(isStatic!(TFn)) int memoize(TFn)(TFn fn)
pure(isPure!(TFn))
if (isCallable!(TFn))
{
//etc.
}

might turn out a bit unreadable. And, furthermore, I'd *like* to be able to say
something like this method returns a shared const value iff the given type is 
int
or long but this won't work with const() or shared() because of their syntax 
(you
can't say const(is(T == int))). Any ideas on how we might be able to get that 
to work?


Oh, and while on the note of const, here's a somewhat unrelated concern: I've
noticed that code like this:

static const int* addressOf(ref int x) { return x; }

is *very* tricky and misleading, because it's declaring the method as const, not
the pointer. Would it be a bad idea to forbid const, pure, nothrow, and the like
from coming before the method name? That way it won't be ambiguous like this.


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 5:41 PM, Tomek Sowiński wrote:

Andrei Alexandrescu napisał:


On 1/22/11 5:14 PM, Nick Sabalausky wrote:

Andrei Alexandrescuseewebsiteforem...@erdani.org   wrote in message
news:ihfm34$jvb$1...@digitalmars.com...

On 1/22/11 4:16 PM, bearophile wrote:

Andrei:


Back then people said that STL's find() is better than D's find()
because the former returns
an iterator that can be combined with either the first iterator to get
the portion before the match, or with the last iterator to get the
portion starting at the match. D's find() only gives you the portion
after the match.


There's a HUGE problem here. This equivalence is sometimes true, but
surely not always true:
more powerful != better



That function allows you to pick a determined number of elements from a
range, assuming the range is never shorter than that. That sounds a bit
obscure, but plays a pivotal role in findParts() (which is the name I
settled on for the equivalent of Python's partition()):


trisect is way better than findParts :-) And it's a single word with
no uppercase letters in the middle.


There is still time until the next release. Votes for trisect?



vote--

findParts is the sort of thing that once you read what it does just
*once*, it immediately becomes both obvious and easy to remember. But
trisect is 1. scary, 2. I'd never remember it, and 3. Whenever I'd come
across it, I'd never remember what it meant.  Those are paricularly bad
since I know right now I'm going to find it an incredibly useful function:
There's already been too many times I've written this mess and felt dirty
about it:

auto result = find(str, delim);
auto firstPart = str[0..$-result.length];

So I'm thrilled to see this function being added.


Yes, I'm absolutely in agreement with the naming (and thrilled too). I
imagine a putative user looking through std.algorithm (let's see...
what find functions are out there?). That makes findPieces easy to get
to, whereas trisect would be oddly situated in the alphabetic list and
oddly named enough to be virtually undiscoverable.


Me a tad less, but not because of the name. I'd still rather see a lazy range 
of pre-hit-post tuples. Am I the only one to see findParts as a no-patterns 
variation of RegexMatch accepting all element types, not just char? Then even 
the name comes naturally -- match.


Lazy in this case is not very helpful because you don't have the 
lengths. Turns out it's important to have the length. If not, you can 
always use until().


Andrei


druntime !!!!

2011-01-22 Thread bioinfornatics
They are something wrong with druntime management!!!
Why druntime do not support gdc or ldc2?
Its is very crap thing i hope druntime will add soon gdc support. We can send 
ldc and gdc patch.
Thanks for all

best regards


Re: Conditional Pure?

2011-01-22 Thread so

nothrow too and other future attributes too.

Funny, that was going to be my next comment. :)
The only thing that scares me a bit is that code like this:

public(isPublic!(TFn)) static(isStatic!(TFn)) int memoize(TFn)(TFn fn)
pure(isPure!(TFn))
if (isCallable!(TFn))
{
//etc.
}


A question,
Is this the only use case? I mean do we always want something like  
xxx(isxxx(T))?

If so, this mess is quite pointless.


Re: Conditional Pure?

2011-01-22 Thread bearophile
%u:

 might turn out a bit unreadable. And, furthermore, I'd *like* to be able to 
 say
 something like this method returns a shared const value iff the given type 
 is int
 or long but this won't work with const() or shared() because of their syntax 
 (you
 can't say const(is(T == int))). Any ideas on how we might be able to get that 
 to work?

@optional_tag(is(T == int) || is(T == long)), const)


 Oh, and while on the note of const, here's a somewhat unrelated concern: I've
 noticed that code like this:
 
 static const int* addressOf(ref int x) { return x; }
 
 is *very* tricky and misleading, because it's declaring the method as const, 
 not
 the pointer. Would it be a bad idea to forbid const, pure, nothrow, and the 
 like
 from coming before the method name? That way it won't be ambiguous like this.

I and few other people have asked for this, I think there is one closed 
enhancement request on this in Bugzilla, but I think Walter closed it on the 
basis of uniformity in attribute syntax (and maybe compiler simplicity too).
Sometimes it's worth breaking uniformity if this avoids some troubles, 
especially if all this breakage does is creating some easy-to-fix compile-time 
errors. I think this is one of such cases.

Bye,
bearophile


Re: renamepalooza time

2011-01-22 Thread so
I'm the same way. Plus, I find it really awkward to constantly type a  
bunch

of underscores. It feels less like typing and more like finger
acobatics.


It is worse for camelCase, at least you can bind _ to another key.
Only one thing i like about camelCase is that, it takes less space.


Re: druntime !!!!

2011-01-22 Thread Robert Clipsham

On 22/01/11 23:58, bioinfornatics wrote:

They are something wrong with druntime management!!!
Why druntime do not support gdc or ldc2?
Its is very crap thing i hope druntime will add soon gdc support. We can send 
ldc and gdc patch.
Thanks for all

best regards


I've been talking to you on IRC about this, but I'll reiterate it here 
for everyone elses benefit. Having support for each compiler in druntime 
is a bad idea. This is what druntime did initially when it was forked 
from tango. The trouble was that as the compiler got updated, the 
runtime needed to be updated too, and the compiler and runtime became 
out of sync very easily, and getting everything up to date again was a pain.


The solution to this is to have each compiler maintain its own druntime 
compiler-specifics, and have the non-compiler-specific code in a main 
druntime repository - this way all that is needed is to copy/paste the 
compiler specific code into druntime. This works, as when the compiler 
is updated, so is the compiler-specific portion of druntime and nothing 
gets out of sync.


Of course, a lot of druntime isn't compiler specific, for these parts 
patches should probably be applied. I'm not entirely sure where gdc and 
ldc are with respect to this kind of patch, I know they both have 
complete druntime implementations, but I'm sure if this kind of patch 
was made (preferably in smaller, individual patches for each feature/bug 
etc) it would be applied.


Of course, this is just the situation as I see it, and from memory, the 
druntime folk will probably chime in and give the full story.


--
Robert
http://octarineparrot.com/


Re: druntime !!!!

2011-01-22 Thread Daniel Gibson

Am 23.01.2011 01:32, schrieb Robert Clipsham:

On 22/01/11 23:58, bioinfornatics wrote:

They are something wrong with druntime management!!!
Why druntime do not support gdc or ldc2?
Its is very crap thing i hope druntime will add soon gdc support. We
can send ldc and gdc patch.
Thanks for all

best regards


I've been talking to you on IRC about this, but I'll reiterate it here
for everyone elses benefit. Having support for each compiler in druntime
is a bad idea. This is what druntime did initially when it was forked
from tango. The trouble was that as the compiler got updated, the
runtime needed to be updated too, and the compiler and runtime became
out of sync very easily, and getting everything up to date again was a
pain.

The solution to this is to have each compiler maintain its own druntime
compiler-specifics, and have the non-compiler-specific code in a main
druntime repository - this way all that is needed is to copy/paste the
compiler specific code into druntime. This works, as when the compiler
is updated, so is the compiler-specific portion of druntime and nothing
gets out of sync.

Of course, a lot of druntime isn't compiler specific, for these parts
patches should probably be applied. I'm not entirely sure where gdc and
ldc are with respect to this kind of patch, I know they both have
complete druntime implementations, but I'm sure if this kind of patch
was made (preferably in smaller, individual patches for each feature/bug
etc) it would be applied.

Of course, this is just the situation as I see it, and from memory, the
druntime folk will probably chime in and give the full story.



I think you're right and of course this makes sense.
I think we had this discussion before, but I can't find the thread.

A further note: As far as I know D's (dmd, phobos, druntime) development 
will soon move to git - maintaining compiler specific versions of 
druntime will probably be a lot easier then.


Cheers,
- Daniel


Re: druntime !!!!

2011-01-22 Thread Brad Roberts
On 1/22/2011 4:32 PM, Robert Clipsham wrote:
 On 22/01/11 23:58, bioinfornatics wrote:
 They are something wrong with druntime management!!!
 Why druntime do not support gdc or ldc2?
 Its is very crap thing i hope druntime will add soon gdc support. We can send
 ldc and gdc patch.
 Thanks for all

 best regards
 
 I've been talking to you on IRC about this, but I'll reiterate it here for
 everyone elses benefit. Having support for each compiler in druntime is a bad
 idea. This is what druntime did initially when it was forked from tango. The
 trouble was that as the compiler got updated, the runtime needed to be updated
 too, and the compiler and runtime became out of sync very easily, and getting
 everything up to date again was a pain.
 
 The solution to this is to have each compiler maintain its own druntime
 compiler-specifics, and have the non-compiler-specific code in a main druntime
 repository - this way all that is needed is to copy/paste the compiler 
 specific
 code into druntime. This works, as when the compiler is updated, so is the
 compiler-specific portion of druntime and nothing gets out of sync.
 
 Of course, a lot of druntime isn't compiler specific, for these parts patches
 should probably be applied. I'm not entirely sure where gdc and ldc are with
 respect to this kind of patch, I know they both have complete druntime
 implementations, but I'm sure if this kind of patch was made (preferably in
 smaller, individual patches for each feature/bug etc) it would be applied.
 
 Of course, this is just the situation as I see it, and from memory, the 
 druntime
 folk will probably chime in and give the full story.
 

Personally, I'd like to see one common runtime, but to achieve that requires
that the compiler/runtime interface be essentially the same between the
compilers.  That's an achievable goal, but it has to actually be an agreed upon
goal.  Today, both gdc and ldc's interface with the runtime don't match dmd's.

So, where do they differ today?  Why?  Can they evolve to a common interface?

I'll happily apply patches from anyone providing them that work to achieve that
goal.  Please use bugzilla to submit them.

One implied part of this goal is that dmd is, while an important stake holder,
needs to play nice too.  Changes need to go through a discussion round before
being made.. no unilateral changes.

Also, this discussion should probably drift over to the d-runt...@puremagic.com
mailing list.. at least the parts that are directly related to accomplishing the
changes.

My 2 cents,
Brad


Re: renamepalooza time

2011-01-22 Thread Nick Sabalausky
so s...@so.do wrote in message news:op.vpqi7ngy7dtt59@so-pc...
 I'm the same way. Plus, I find it really awkward to constantly type a 
 bunch
 of underscores. It feels less like typing and more like finger
 acobatics.

 It is worse for camelCase,

Don't see how. iT vs i_t:

iT:
[i] [hold shift] [t] [release shift]

i_t:
[i] [hold shift] [reach over to -] [release shift] [t]

 at least you can bind _ to another key.

I already use all my other keys.




Re: renamepalooza time

2011-01-22 Thread Andrej Mitrovic
That's why they invented the concept of rebinding the keys. And why
Vim is a modal editor. Etc etc etc..


Re: Conditional Pure?

2011-01-22 Thread %u
 Any ideas on how we might be able to get that to work?
 @optional_tag(is(T == int) || is(T == long)), const)

Ouch... a bit less pretty than I'd hoped (the underscore makes it a bit ugly
IMHO). Does it really need to be a tag, though? Why not just:
   optional(const, is(T == int) || is(T == long))
?


 I and few other people have asked for this, I think there is one closed
enhancement request on this in Bugzilla, but I think Walter closed it on the 
basis
of uniformity in attribute syntax (and maybe compiler simplicity too).
 Sometimes it's worth breaking uniformity if this avoids some troubles,
especially if all this breakage does is creating some easy-to-fix compile-time
errors. I think this is one of such cases.

Huh... but what's the difference between static and const, that allows 
const
to go after the header but doesn't allow static to?


Re: Conditional Pure?

2011-01-22 Thread Michel Fortin

On 2011-01-22 21:34:52 -0500, %u wfunct...@hotmail.com said:


Any ideas on how we might be able to get that to work?

@optional_tag(is(T == int) || is(T == long)), const)


Ouch... a bit less pretty than I'd hoped (the underscore makes it a bit ugly
IMHO). Does it really need to be a tag, though? Why not just:
   optional(const, is(T == int) || is(T == long))
?


If you're trying to make it pretty, I'd suggest this:

template func(T) {
const pure if (is(T == int) || is(T == long)) {
void func(T);
}
}

From what I know of the front end, I'm of the opinion that it'd be much 

easier to implement conditional attributes in the front end that way.

But things gets messed up once you consider the 'static' attribute. :-(

--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/



Re: renamepalooza time

2011-01-22 Thread spir

On 01/23/2011 12:03 AM, Ali Çehreli wrote:

Jonathan M Davis wrote:

On Friday, January 21, 2011 13:30:11 Ali Çehreli wrote:

Andrei Alexandrescu wrote:
 iswhite

I like separating is with an underscore, like most coding styles do:

is_whitespace

Warm and fuzzy... :)


Most? I've never dealt with a coding style that had underscores.


Sorry for being unclear. My comment was only in the context of is_. I
like separating is with an underscore. Probably because is is not
part of the name. It operates at a different linguistic level.

  It's generally

camelcase, though I get the impression that using underscores in C
code is more common (I've mostly used C++ and Java).


Same here: always camelcase, except in our C libraries. Now I like
underscore more than before. :)

  Regardless however, Phobos' coding style

uses camelcase, not underscores. And this whole thread was started to
try and find better names for functions which need new names, because
they don't currently follow Phobos' naming conventions.


I am aware of that. Then half seriously, let's change the standard to
use underscore after is. Also when parts of a camelcased name are too
loosely related.

For example, when NodeReader is an interface and when we already have a
LovelyDb, we may have a class named LovelyDb_NodeReader.

Ali


Nice  sensible way of mixing both conventions :-) Sounds similar to 
using whitespace for visual grouping like in

a*b + c*d
or
[ [1,2,3] , [4,5,6] ]

But may be a bit too complicated for a public, free-willing, style, 
don't you think? Rather for an enforced project or corporate one, I'd say...


Denis
_
vita es estrany
spir.wikidot.com



Re: renamepalooza time

2011-01-22 Thread spir

On 01/23/2011 02:39 AM, Nick Sabalausky wrote:

sos...@so.do  wrote in message news:op.vpqi7ngy7dtt59@so-pc...

I'm the same way. Plus, I find it really awkward to constantly type a
bunch
of underscores. It feels less like typing and more like finger
acobatics.


It is worse for camelCase,


Don't see how. iT vs i_t:

iT:
[i] [hold shift] [t] [release shift]

i_t:
[i] [hold shift] [reach over to -] [release shift] [t]


Depends on your keyboard, Nick: '_' does not require shift, on mine 
(don't ask why). But '['  ']' require AltGr :-( Think they are directly 
accessible on US keyboards, aren't they? This would explain they massive 
use in PLs.


denis
_
vita es estrany
spir.wikidot.com



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread spir

On 01/22/2011 11:16 PM, bearophile wrote:

That function allows you to pick a determined number of elements from a
  range, assuming the range is never shorter than that. That sounds a bit
  obscure, but plays a pivotal role in findParts() (which is the name I
  settled on for the equivalent of Python's partition()):

trisect is way better than findParts :-) And it's a single word with no 
uppercase letters in the middle.


Same for tripartite. Even better because it holds part and  is 
defined as:

   1. In three parts.
(http://en.wiktionary.org/wiki/tripartite)

My 2 cents.

(I find findParts uninformative and misleading. Kind of synonym of split.)

Denis
_
vita es estrany
spir.wikidot.com



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread spir

On 01/23/2011 12:40 AM, so wrote:

Yes, I'm absolutely in agreement with the naming (and thrilled too). I
imagine a putative user looking through std.algorithm (let's see...
what find functions are out there?). That makes findPieces easy to
get to, whereas trisect would be oddly situated in the alphabetic
list and oddly named enough to be virtually undiscoverable.


If this is the reasoning. This is a split function, not a find.
There will be a few more of these split functions i suppose and this is
the reason of my proposal splitAt.
It is in the definition of the function you quoted.

(Split) the string (at) the first occurrence of (sep)



splitAt(string, sep)


+++

splitAt is simply a Good Name! (even better than tripartite ;-)
Also for finding it in list of funcs.

Denis
_
vita es estrany
spir.wikidot.com



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread spir

On 01/23/2011 12:40 AM, so wrote:

Yes, I'm absolutely in agreement with the naming (and thrilled too). I
imagine a putative user looking through std.algorithm (let's see...
what find functions are out there?). That makes findPieces easy to
get to, whereas trisect would be oddly situated in the alphabetic
list and oddly named enough to be virtually undiscoverable.


If this is the reasoning. This is a split function, not a find.


Agreed, the function does not belong to the sub-list of find*, instead 
to split*. So's proposal splitAt not only respects that, but tells 
more accurate information. findPieces does not tell anything, thus 
anyone would expect it to cut the string into an arbitrary number of pieces.


Denis
_
vita es estrany
spir.wikidot.com



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Daniel Gibson

Am 23.01.2011 04:42, schrieb spir:

On 01/23/2011 12:40 AM, so wrote:

Yes, I'm absolutely in agreement with the naming (and thrilled too). I
imagine a putative user looking through std.algorithm (let's see...
what find functions are out there?). That makes findPieces easy to
get to, whereas trisect would be oddly situated in the alphabetic
list and oddly named enough to be virtually undiscoverable.


If this is the reasoning. This is a split function, not a find.
There will be a few more of these split functions i suppose and this is
the reason of my proposal splitAt.
It is in the definition of the function you quoted.

(Split) the string (at) the first occurrence of (sep)

 

splitAt(string, sep)


+++

splitAt is simply a Good Name! (even better than tripartite ;-)
Also for finding it in list of funcs.

Denis
_
vita es estrany
spir.wikidot.com



To be honest, tripartite sounds kind of strange.
I don't know why, but I think of spiders when I read it ;)


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread spir

On 01/22/2011 10:27 PM, Andrei Alexandrescu wrote:

The first abstraction is the takeExactly() function:

http://d-programming-language.org/cutting-edge/phobos/std_range.html#takeExactly


That function allows you to pick a determined number of elements from a
range, assuming the range is never shorter than that. That sounds a bit
obscure, but plays a pivotal role in findParts() (which is the name I
settled on for the equivalent of Python's partition()):


What is reasoning behind having length set on takeExactly's result 
(while if succeeds, you know it, or don't you?), and not on take's 
result (which can return a smaller number of elements)? I would expect 
the opposite, or both, but maybe it's only me?


Denis
_
vita es estrany
spir.wikidot.com



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread spir

On 01/23/2011 04:49 AM, Daniel Gibson wrote:

splitAt is simply a Good Name! (even better than tripartite ;-)
Also for finding it in list of funcs.

Denis
_
vita es estrany
spir.wikidot.com



To be honest, tripartite sounds kind of strange.
I don't know why, but I think of spiders when I read it ;)


Don't know why, neither, really poetic association ;-)

Denis
_
vita es estrany
spir.wikidot.com



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Andrei Alexandrescu

On 01/22/2011 10:16 PM, spir wrote:

On 01/22/2011 10:27 PM, Andrei Alexandrescu wrote:

The first abstraction is the takeExactly() function:

http://d-programming-language.org/cutting-edge/phobos/std_range.html#takeExactly



That function allows you to pick a determined number of elements from a
range, assuming the range is never shorter than that. That sounds a bit
obscure, but plays a pivotal role in findParts() (which is the name I
settled on for the equivalent of Python's partition()):


What is reasoning behind having length set on takeExactly's result
(while if succeeds, you know it, or don't you?), and not on take's
result (which can return a smaller number of elements)? I would expect
the opposite, or both, but maybe it's only me?

Denis


If the ranges involved are forward ranges, not passing around length 
information essentially throws away information painstakingly acquired 
(by means of O(n)).


Andrei


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread spir

On 01/23/2011 05:30 AM, Andrei Alexandrescu wrote:

On 01/22/2011 10:16 PM, spir wrote:

On 01/22/2011 10:27 PM, Andrei Alexandrescu wrote:

The first abstraction is the takeExactly() function:

http://d-programming-language.org/cutting-edge/phobos/std_range.html#takeExactly




That function allows you to pick a determined number of elements from a
range, assuming the range is never shorter than that. That sounds a bit
obscure, but plays a pivotal role in findParts() (which is the name I
settled on for the equivalent of Python's partition()):


What is reasoning behind having length set on takeExactly's result
(while if succeeds, you know it, or don't you?), and not on take's
result (which can return a smaller number of elements)? I would expect
the opposite, or both, but maybe it's only me?

Denis


If the ranges involved are forward ranges, not passing around length
information essentially throws away information painstakingly acquired (by
means of O(n)).


Agreed. But why not on take? (Did not check the code, but) the doc says for it:
If the range offers random access and length, Take offers them as well.
Length information is much more valuable info for take, as it may return less 
elements than specified. Or what do I miss? Why not (mixed with takeExactly's doc):
The result of take(range, n) always defines the length property (and 
initializea it to actual number of elements) even when range itself does not 
define length. If the range offers random access, Take offers them as well.

?

Denis
_
vita es estrany
spir.wikidot.com



Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Jonathan M Davis
On Saturday 22 January 2011 15:19:39 Andrei Alexandrescu wrote:
 On 1/22/11 5:14 PM, Nick Sabalausky wrote:
  Andrei Alexandrescuseewebsiteforem...@erdani.org  wrote in message
  news:ihfm34$jvb$1...@digitalmars.com...
  
  On 1/22/11 4:16 PM, bearophile wrote:
  Andrei:
  Back then people said that STL's find() is better than D's find()
  because the former returns
  an iterator that can be combined with either the first iterator to get
  the portion before the match, or with the last iterator to get the
  portion starting at the match. D's find() only gives you the portion
  after the match.
  
  There's a HUGE problem here. This equivalence is sometimes true, but
  surely not always true:
  more powerful != better
  
  That function allows you to pick a determined number of elements from
  a range, assuming the range is never shorter than that. That sounds a
  bit obscure, but plays a pivotal role in findParts() (which is the
  name I
  
  settled on for the equivalent of Python's partition()):
  trisect is way better than findParts :-) And it's a single word
  with no uppercase letters in the middle.
  
  There is still time until the next release. Votes for trisect?
  
  vote--
  
  findParts is the sort of thing that once you read what it does just
  *once*, it immediately becomes both obvious and easy to remember. But
  trisect is 1. scary, 2. I'd never remember it, and 3. Whenever I'd come
  across it, I'd never remember what it meant.  Those are paricularly bad
  since I know right now I'm going to find it an incredibly useful
  function: There's already been too many times I've written this mess and
  felt dirty about it:
  
  auto result = find(str, delim);
  auto firstPart = str[0..$-result.length];
  
  So I'm thrilled to see this function being added.
 
 Yes, I'm absolutely in agreement with the naming (and thrilled too). I
 imagine a putative user looking through std.algorithm (let's see...
 what find functions are out there?). That makes findPieces easy to get
 to, whereas trisect would be oddly situated in the alphabetic list and
 oddly named enough to be virtually undiscoverable.

vote

This will be a _fantastic_ function to have. I think that I probably even have 
an enhancement request somewhere that includes such a function. It's far too 
common that you have to find something and you want both what is before and 
after 
the point that you find. Now, that being the case, I'd probably more commonly 
find 
it useful to get the part before what was found and then the part beginning 
with 
what was found, but this works too.

It is essentially doing what find does, only giving you more stuff in the 
result, 
so I do think that it fits well with find, and having its name starting with 
find 
means that it will be near find in the documentation, which will make it much 
easier to find (no pun intended - though I do like puns). The term findParts 
doesn't really say what the function does (which parts are you looking for, 
after all?), but it _is_ a name which will be memorable, and once you've read 
the docs, it will be plenty clear what it does. I certainly can't think of a 
better name, and I definitely prefer it over the other names that I'm seeing 
suggested in this thread.

- Jonathan M Davis


Re: Conditional Pure?

2011-01-22 Thread Jonathan M Davis
On Saturday 22 January 2011 14:41:08 %u wrote:
  I think this is useless. If this is possible, then you just mark every
  single
 
 not-pure function in the program with @conditionally_pure, and we are back
 to the beginning.
 
 
 Oh, but that's not what I meant! I meant something like this:
 
   int call(TFn)(TFn fn) pure(isPure!(TFn))
  if (isCallable!(TFn))
   {
  return fn(5);
   }
 
 This way we specify purity based on a static boolean.

This has been suggested a time or two (I _definitely_ want something like this, 
and I think that we _need_ it if we want pure to be truly, generally useful), 
but nothing has come of it yet. Andrei's suggestion the last time this came up 
was  to do something similar to what you have there and make pure take a 
conditional argument to determine its purity. I don't know what it will take to 
get something like this in the language (I think that it's a given that it will 
have to wait untill after th 64-bit port is done), but I think that it's 
critical if we want purity to work with templates. And since so much of D is 
likely to be templatized (in particular, Phobos uses templates quite heavily), 
we _need_ purity to work with templates.

- Jonathan M Davis


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 10:57 PM, spir wrote:

On 01/23/2011 05:30 AM, Andrei Alexandrescu wrote:

On 01/22/2011 10:16 PM, spir wrote:

On 01/22/2011 10:27 PM, Andrei Alexandrescu wrote:

The first abstraction is the takeExactly() function:

http://d-programming-language.org/cutting-edge/phobos/std_range.html#takeExactly





That function allows you to pick a determined number of elements from a
range, assuming the range is never shorter than that. That sounds a bit
obscure, but plays a pivotal role in findParts() (which is the name I
settled on for the equivalent of Python's partition()):


What is reasoning behind having length set on takeExactly's result
(while if succeeds, you know it, or don't you?), and not on take's
result (which can return a smaller number of elements)? I would expect
the opposite, or both, but maybe it's only me?

Denis


If the ranges involved are forward ranges, not passing around length
information essentially throws away information painstakingly acquired
(by
means of O(n)).


Agreed. But why not on take? (Did not check the code, but) the doc says
for it:
If the range offers random access and length, Take offers them as well.
Length information is much more valuable info for take, as it may return
less elements than specified. Or what do I miss? Why not (mixed with
takeExactly's doc):
The result of take(range, n) always defines the length property (and
initializea it to actual number of elements) even when range itself does
not define length. If the range offers random access, Take offers them
as well.
?


take(r, n) takes at most n elements from r. It is unable to offer length 
because for an input or forward range that would cost O(n). (For an 
input range, that would also ruin the range.)


takeExactly(r, n) assumes that the range has at least n elements. As 
such, it is able to offer constant-time length.


These are quite different abstractions with different capabilities and 
power. I have been missing for years a complete solution to findPieces() 
because I've always wanted to express its results in terms of take() 
instead of takeExactly(). Only today I figured the puzzle out.



Andrei


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Andrei Alexandrescu

On 1/22/11 10:59 PM, Jonathan M Davis wrote:

This will be a _fantastic_ function to have. I think that I probably even have
an enhancement request somewhere that includes such a function. It's far too
common that you have to find something and you want both what is before and 
after
the point that you find. Now, that being the case, I'd probably more commonly 
find
it useful to get the part before what was found and then the part beginning with
what was found, but this works too.


I suspect there might be a simple and intuitive way to define a family 
of functions that give you whatever portions of the find you're 
interested in (before, match, after, before and match, match and after). 
That could be either a naming convention or a template argument. Any 
ideas, let me know.


Andrei


Re: Python's partition

2011-01-22 Thread Christopher Nicholson-Sauls
On 01/22/11 15:38, Andrei Alexandrescu wrote:
 On 1/22/11 3:33 PM, Christopher Nicholson-Sauls wrote:
 On 01/22/11 11:44, Andrei Alexandrescu wrote:
 Looking through Python's string functions
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
 partition():

 partition(sep)
  Split the string at the first occurrence of sep, and return a
 3-tuple containing the part before the separator, the separator itself,
 and the part after the separator. If the separator is not found, return
 a 3-tuple containing the string itself, followed by two empty strings.
 New in version 2.5.

 Right now we find find and findSkip; partition would be a great
 complement, and can be implemented for all forward ranges.

 One question is naming - partition() is not good for us because
 std.algorithm.partition implements Hoare's in-place partition algorithm.
 How should we call the function?


 Andrei

 Bisect?

 -- Chris N-S

 
 Would be rather trisect, but that becomes a bit too cute.
 
 Andrei

Yeah, you're right.  I hit on bi- because my mental image was like a
binary tree search.  Anywho, I actually kinda like trisect, even if it
is cute.

-- Chris N-S


Re: DVCS

2011-01-22 Thread retard
Sat, 22 Jan 2011 14:47:48 -0800, Walter Bright wrote:

 retard wrote:
 Does the new Ubuntu overall work better than the old one? Would be
 amazing if the media players are still all broken.
 
 I haven't tried the sound yet, but the video playback definitely is
 better.
 
 Though the whole screen flashes now and then, like the video mode is
 being reset badly. This is new behavior.

Ubuntu probably uses Compiz if you have enabled desktop effects. This 
might not work with ati's (open source) drivers. Turning Compiz off makes 
it use a safer 2d engine. In Gnome the setting can be changed here 
http://www.howtoforge.com/enabling-compiz-fusion-on-an-ubuntu-10.10-
desktop-nvidia-geforce-8200-p2

It's the none option in the second figure.


Re: replaceFirst, findPieces, and takeExactly

2011-01-22 Thread Jim
Andrei Alexandrescu Wrote:
 I suspect there might be a simple and intuitive way to define a family 
 of functions that give you whatever portions of the find you're 
 interested in (before, match, after, before and match, match and after). 
 That could be either a naming convention or a template argument. Any 
 ideas, let me know.


splitAt
splitBefore
splitAfter

?


Re: Type-qualified functions?

2011-01-22 Thread Christopher Nicholson-Sauls
On 01/21/11 14:43, Sean Eskapp wrote:
 
 templates:
 
 void foo(T)(T, void delegate(T) fn)
 {
 }
 
 This parameterizes foo based on T, which could be A, const A, or int, or
 whatever works to compile the function.
 
 What if the parameters are more general, for instance the first parameter is
 always a Foo, the second is a delegate which takes a Foo.Bar, but they're 
 always
 qualified the same way?

I believe this is the sort of thing the 'inout' qualifier was meant for,
except I don't know if it works with a void return type.  It's also
worth noting that mutable and immutable are both castable to const, so
if there is literally no difference between the two functions, see if
you can get away with just the one using const.

-- Chris N-S


  1   2   >