I don't find the example given very compelling, but there are probably some decent uses for it. Overall, I'm pretty neutral, though.
For this to make sense would require making "def foo(x)=(y)" valid syntax. Not much gained either way in my opinion, but it's up to Matz to decide if he wants to parse that. I doubt it, though.
It wouldn't. After all it's also def []=(index, to)
and not def [index]=(to)
.
This seems counterintuitive to me, but maybe that is because I have some experience in functional languages.
I would expect syntax like that to function like this:
words.first(2) = 3
words.first(2) # => 3
Allowing this syntax would be nice, because it would turn Ruby into a quasi-functional language(1), but I'm not sure Matz wants to go there. In any case, while I see what you're driving at, code like that would do what
I'd expect it to do.
And, one question for you: does your syntax make more sense to you than replacing the "=" with a "!"?
words = %w{hello world. how are you?}
words.first!(2, %w{hi ruby!})
words.last!( %w{things going?} )
words.join(" ") # => "hi ruby! how are things going?"
(1) I don't know enough about functional languages to know what sort of worms would come out of this particular can, but I do like a lot of the features in Haskell, such as list comprehension, and provable function definitions.
And, one question for you: does your syntax make more sense to you than replacing the "=" with a "!"?
IMHO bang versions of methods should do the same that non-bang versions do, but in-place instead of on a copy. -- I don't feel that words.first!(2, sth)
fits into this model.
I have a (sparse symmetric) matrix class which defines []=(i,j,a) for element assignment with bounds checking. Everything is working fine, and I decide it's time to use non-checked element assignment for internal use only.
I go helter-skelter with find-and-replace, changing all my self[i, j] = a to elem(i, j) = a. BOOM! 30 syntax errors.
I don't see a reason to give special status to []= over any other method name=().
I'm neutral (Gavin, 2003-10-02 19:19:34)
No (, 2003-10-03 11:23:28)
Re: No (flgr, 2003-10-03 20:20:04)
def []=(index, to)
and notdef [index]=(to)
.Interesting (, 2003-10-06 08:30:33)
I would expect syntax like that to function like this:
Allowing this syntax would be nice, because it would turn Ruby into a quasi-functional language(1), but I'm not sure Matz wants to go there. In any case, while I see what you're driving at, code like that would do what I'd expect it to do.And, one question for you: does your syntax make more sense to you than replacing the "=" with a "!"?
(1) I don't know enough about functional languages to know what sort of worms would come out of this particular can, but I do like a lot of the features in Haskell, such as list comprehension, and provable function definitions.
Re: Interesting (flgr, 2003-10-09 02:02:54)
IMHO bang versions of methods should do the same that non-bang versions do, but in-place instead of on a copy. -- I don't feel that
words.first!(2, sth)
fits into this model.A Necessity!
I have a (sparse symmetric) matrix class which defines []=(i,j,a) for element assignment with bounds checking. Everything is working fine, and I decide it's time to use non-checked element assignment for internal use only.
I go helter-skelter with find-and-replace, changing all my self[i, j] = a to elem(i, j) = a. BOOM! 30 syntax errors.
I don't see a reason to give special status to []= over any other method name=().