Thanks Paolo. So where/when/what version of ST should new syntax be used ?
Is this a GST thing or a ST thing in general ? I don't recall seeing the old syntax in the "Smalltalk, Objects, and Design' book, but then it could be that I was not paying too much attention. I have seen it in the GST info pages, but that's the only place. On Thu, Feb 25, 2010 at 14:56, Paolo Bonzini <[email protected]> wrote: > On 02/25/2010 08:03 PM, Mehul Sanghvi wrote: >> >> Being new to Smalltalk, and learning it on and off when I get time >> here and there, what is "new" syntax if the "old" syntax is the "!" >> ? > > New syntax is like this: > > > Object subclass: Base64 [ > Base64 class >> encode: aString [ > | i j outSize c1 c2 c3 out b64string chars | > chars := ##('ABCDEFGHIJKLMNOPQRSTUVWXYZ', > 'abcdefghijklmnopqrstuvwxyz0123456789+/='). > outSize := aString size // 3 * 4. > (aString size \\ 3) = 0 ifFalse: [ outSize := outSize + 4 ]. > b64string := String new: outSize. > > i := 1. > 1 to: outSize by: 4 do: [ :j | > c1 := aString valueAt: i ifAbsent: [0]. > c2 := aString valueAt: i+1 ifAbsent: [0]. > c3 := aString valueAt: i+2 ifAbsent: [0]. > > out := c1 bitShift: -2. > b64string at: j put: (chars at: out + 1). > > out := ((c1 bitAnd: 3) bitShift: 4) bitOr: (c2 bitShift: -4). > b64string at: j+1 put: (chars at: out + 1). > > out := ((c2 bitAnd: 15) bitShift: 2) bitOr: (c3 bitShift: -6). > b64string at: j+2 put: (chars at: out + 1). > > out := c3 bitAnd: 16r13F. > b64string at: j+3 put: (chars at: out + 1). > > i := i + 3. > ]. > > b64string > replaceFrom: outSize - (i - aString size) + 2 > to: outSize withObject: $=. > > ^b64string > ] > ] > -- Mehul N. Sanghvi email: [email protected] Samuel Goldwyn - "I don't think anyone should write their autobiography until after they're dead." - http://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html _______________________________________________ help-smalltalk mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-smalltalk
