Has anyone ever proposed making Hash#+ a nondestructive equivalent of
Hash#update ?
I’m experimenting with keyword arguments and find myself passing things
like h1.dup.update(h2), where h1+h2 would feel more natural. h1 is
usually some often-used package of default args, and h2 specifies a few
changes and/or additions.
Has anyone ever proposed making Hash#+ a nondestructive equivalent of
Hash#update ?
Just my obfuscated memory but…
It was proposed early days and was denied due to a semantic problem,
and that was the reason Hash#update was introduced.
I’m experimenting with keyword arguments and find myself passing things
like h1.dup.update(h2), where h1+h2 would feel more natural. h1 is
usually some often-used package of default args, and h2 specifies a few
changes and/or additions.
That’s exactly the problem: That causes h1+h2 and h2+h1 yield
different hashes. Is this enough reasonable meaning? OK, String#+
has also such meaning, however it is concatenation and both operands
are fully preserved in a result.
Who can define good semantics with that “general” people agree under
the name of `Hash#+'?
While Hash#update is an enough reasonable name, isn’t it?
On the other hand large number of people won’t be confused,
`h1.dup.update(h2)’ is good candidate of meaning of Hash#+.
“YANAGAWA Kazuhisa” kjana@dm4lab.to wrote in message
news:20021222164523.DA84B1EE12@milestones.dm4lab.to…
That’s exactly the problem: That causes h1+h2 and h2+h1 yield
different hashes. Is this enough reasonable meaning? OK, String#+
has also such meaning, however it is concatenation and both operands
are fully preserved in a result.
What about using the ‘^’ operator?
In other languages it is also used for string concatenation.
Has anyone ever proposed making Hash#+ a nondestructive equivalent of
Hash#update ?
Just my obfuscated memory but…
It was proposed early days and was denied due to a semantic problem,
and that was the reason Hash#update was introduced.
I’m experimenting with keyword arguments and find myself passing things
like h1.dup.update(h2), where h1+h2 would feel more natural. h1 is
usually some often-used package of default args, and h2 specifies a few
changes and/or additions.
That’s exactly the problem: That causes h1+h2 and h2+h1 yield
different hashes. Is this enough reasonable meaning? OK, String#+
has also such meaning, however it is concatenation and both operands
are fully preserved in a result.
Who can define good semantics with that “general” people agree under
the name of `Hash#+'?
As you say, non-commutative ‘+’ is common enough in programming.
Array#+ is another example. Consider also that there is an intuitive
temporal sense to these expressions. In (hash1 + hash2), we are
starting with hash1. After hash2 is brought into the picture, the newer
bits would be expected to take precedence. I don’t really see a problem
here.
Regarding both operands being preserved, this is a good point, but in
none of the other ‘+’ methods (numbers, strings, arrays) can the
operands quite be recovered from the result. You get a new object that
is different from the first two; the operands were brought together in a
way that makes sense for the type.
While Hash#update is an enough reasonable name, isn’t it?
True, but Hash#update lives over in Destructive Methods Land.
On the other hand large number of people won’t be confused,
`h1.dup.update(h2)’ is good candidate of meaning of Hash#+.
That really sums it up. I don’t think Hash#+ can reasonably have a
different meaning.
In message “Re: Hash#update” on 02/12/23, Mark Slagell ms@iastate.edu writes:
As you say, non-commutative ‘+’ is common enough in programming.
Array#+ is another example. Consider also that there is an intuitive
temporal sense to these expressions. In (hash1 + hash2), we are
starting with hash1. After hash2 is brought into the picture, the newer
bits would be expected to take precedence. I don’t really see a problem
here.
No information lost by String#+ or Array#+, but Hash#update may lose
the value. That’s why I rejected the name “+”. It is possible to
provide the non destructive “update” under different name. Good name?
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.22 at 20.57.15
···
On Mon, 23 Dec 2002 08:05:00 +0900, Yukihiro Matsumoto wrote:
In message “Re: Hash#update” > on 02/12/23, Mark Slagell ms@iastate.edu writes:
As you say, non-commutative ‘+’ is common enough in programming.
Array#+ is another example. Consider also that there is an
intuitive |temporal sense to these expressions. In (hash1 +
hash2), we are starting with hash1. After hash2 is brought into
the picture, the newer bits would be expected to take precedence.
I don’t really see a problem here.
No information lost by String#+ or Array#+, but Hash#update may
lose the value. That’s why I rejected the name “+”. It is possible
to provide the non destructive “update” under different name. Good
name?
On Mon, 23 Dec 2002 08:05:00 +0900, Yukihiro Matsumoto wrote:
In message “Re: Hash#update” >>on 02/12/23, Mark Slagell ms@iastate.edu writes:
As you say, non-commutative ‘+’ is common enough in programming.
Array#+ is another example. Consider also that there is an
intuitive |temporal sense to these expressions. In (hash1 +
hash2), we are starting with hash1. After hash2 is brought into
the picture, the newer bits would be expected to take precedence.
I don’t really see a problem here.
No information lost by String#+ or Array#+, but Hash#update may
lose the value. That’s why I rejected the name “+”. It is possible
to provide the non destructive “update” under different name. Good
name?
Hash#union, also Hash#| (not Hash#^).
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.22 at 20.57.15
In message “Re: Hash#update” on 02/12/23, Austin Ziegler austin@halostatue.ca writes:
No information lost by String#+ or Array#+, but Hash#update may
lose the value. That’s why I rejected the name “+”. It is possible
to provide the non destructive “update” under different name. Good
name?
Hash#union, also Hash#| (not Hash#^).
Is it OK for you to lose values by the “union” method? Not for me.
In message “Re: Hash#update” > on 02/12/23, Austin Ziegler austin@halostatue.ca writes:
No information lost by String#+ or Array#+, but Hash#update may
lose the value. That’s why I rejected the name “+”. It is possible
to provide the non destructive “update” under different name. Good
name?
Hash#union, also Hash#| (not Hash#^).
Is it OK for you to lose values by the “union” method? Not for me.
I would definitely NOT expect loss of values in “+” or “union all”
(to use the SQL term).
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.24 at 09.40.12
···
On Tue, 24 Dec 2002 11:47:36 +0900, Yukihiro Matsumoto wrote:
In message “Re: Hash#update” on 02/12/23, Austin Ziegler > austin@halostatue.ca writes:
No information lost by String#+ or Array#+, but Hash#update may
lose the value. That’s why I rejected the name “+”. It is
possible to provide the non destructive “update” under different
name. Good name?
Hash#union, also Hash#| (not Hash#^).
Is it OK for you to lose values by the “union” method? Not for me.