[Seaside] question on tutorial - contact manager

Randal L. Schwartz merlyn at stonehenge.com
Sat Feb 20 17:20:29 UTC 2010


>>>>> "sergio" == sergio 101 <sergiolist at village-buzz.com> writes:

sergio> i may have just missed the explanation.. but i am seeing a new syntax
sergio> that i don't understand here:

sergio> http://book.seaside.st/book/fundamentals/forms/drop-down


Contact> gender
sergio>     ^ gender ifNil: [ gender := #Male ]
Contact> isMale
sergio>     ^ self gender = #Male
Contact> isFemale
sergio>     ^ self gender = #Female

sergio> i don't understand the hash in front of the gender.. did i just gloss
sergio> over something?

That's a "Symbol" marker.  A symbol is an immutable string
that is "interned", meaning that there is always just one instance
with that value, no matter how many times it appears.  This means
that "equalty" and "identity" are the same.

Consider:

 a := 'foo'.
 b := 'foo'.
 a = b "true, but done by comparing character by character"
 a == b "false, because they are actually different String objects"

 c := #foo.
 d := #foo.
 c = d "true, but mapped into..."
 c == d "also true, they are the same object"

Symbols are often used in code like the above to ensure
that the comparisons are very quick.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


More information about the seaside mailing list