SORU
7 EYLÜL 2010, Salı


Neden yok't Ruby ya da ben ... (arttırma/azaltma) destekler mi?

Pre/post arttırma/azaltma operatörü ( --) standart bir dil sözdizimi programlama (usul ve nesne yönelimli diller için, en azından).

Neden Ruby onlara destek olmuyor? = -= ile aynı şeyi yapabileceğini anlıyorum ama garip bir şekilde keyfi özellikle çok özlü ve geleneksel olduğu için böyle bir şey çıkarmak gibi görünüyor.

Örnek:

i = 0    #=> 0
i  = 1   #=> 1
i        #=> 1
i        #=> expect 2, but as far as I can tell, 
         #=> irb ignores the second   and waits for a second number to add to i

Ben Fixnum değişmez olduğunu biliyorum ama = Fixnum Yeni instanciate ve ayarlarsanız, neden için aynı değil mi?

Atamaları = karakter içeren tutarlılık bunun tek nedeni, ya da ben bir şey eksik?

CEVAP
7 EYLÜL 2010, Salı


Matz(Yukihiro Matsumoto) thread eski bir boru.

Hi,

In message "[ruby-talk:02706] X  ?"
    on 00/05/10, Aleksi Niemelä <aleksi.niemela@cinnober.com> writes:

|I got an idea from http://www.pragprog.com:8080/rubyfaq/rubyfaq-5.html#ss5.3
|and thought to try. I didn't manage to make "auto(in|de)crement" working so
|could somebody help here? Does this contain some errors or is the idea
|wrong?

  (1)    and -- are NOT reserved operator in Ruby.

  (2) C's increment/decrement operators are in fact hidden assignment.
      They affect variables, not objects.  You cannot accomplish
      assignment via method.  Ruby uses  =/-= operator instead.

  (3) self cannot be a target of assignment.  In addition, altering
      the value of integer 1 might cause severe confusion throughout
      the program.

                            matz.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BigBoyTV

    BigBoyTV

    25 EYLÜL 2013
  • Joshua Kywn

    Joshua Kywn

    17 Mayıs 2010
  • Kyletiv7

    Kyletiv7

    28 Mayıs 2007