[squeak-dev] Re: [Pharo-project] [ENH] Syntax extension for
continuations
Levente Uzonyi
leves at elte.hu
Mon Nov 1 03:24:13 UTC 2010
On Mon, 1 Nov 2010, Igor Stasenko wrote:
> Here is more examples (found by searching .sources file with 3 or more '(((' ).
>
> ContextPart>>handleSignal:
>
> (((self tempAt: 1) handles: exception) and: [self tempAt: 3]) ifFalse: [
> ^ self nextHandlerContext handleSignal: exception].
>
>
> self tempAt: 1 ;; handles: exception ;; and: [self tempAt: 3] ;; ifFalse: [
> ^ self nextHandlerContext handleSignal: exception].
What about this?
((self tempAt: 3) and: [ (self tempAt: 1) handles: exception ]) ifFalse: [
^ self nextHandlerContext handleSignal: exception].
>
>
> Bezier3Segment.
>
> before:
>
> bezier2SegmentCount: pixelError
> "Compute the number of quadratic bezier segments needed to approximate
> this cubic with no more than a specified error"
> | a |
> a := (start x negated @ start y negated) + (3 * via1) - (3 * via2) +
> (end).
> ^ (((a r / (20.0 * pixelError)) raisedTo: 0.333333) ceiling) max: 1.
>
> after:
>
> bezier2SegmentCount: pixelError
> "Compute the number of quadratic bezier segments needed to approximate
> this cubic with no more than a specified error"
> | a |
> a := start x negated @ start y negated ;; + (3 * via1) - (3 * via2) +
> end.
> ^ a r / (20.0 * pixelError) raisedTo: 0.333333 ;; ceiling max: 1.
There are 2 superfluous parenthesis in the original code (which you
omitted in your code). Here's the same without them:
^(a r / (20.0 * pixelError) raisedTo: 0.333333) ceiling max: 1.
If I want to be "tricky", I can even remove another parenthesis:
^(0.05 * a r / pixelError raisedTo: 0.333333) ceiling max: 1.
>
>
> ZipArchive
>
> before:
>
> lastIndexOfPKSignature: aSignature in: data
> "Answer the last index in data where aSignature (4 bytes long)
> occurs, or 0 if not found"
> | a b c d |
> a := aSignature first.
> b := aSignature second.
> c := aSignature third.
> d := aSignature fourth.
> (data size - 3) to: 1 by: -1 do: [ :i |
> (((data at: i) = a)
> and: [ ((data at: i + 1) = b)
> and: [ ((data at: i + 2) = c)
> and: [ ((data at: i + 3) = d) ]]])
> ifTrue: [ ^i ]
> ].
> ^0
>
> after:
>
> lastIndexOfPKSignature: aSignature in: data
> "Answer the last index in data where aSignature (4 bytes long)
> occurs, or 0 if not found"
> | a b c d |
> a := aSignature first.
> b := aSignature second.
> c := aSignature third.
> d := aSignature fourth.
> data size - 3 to: 1 by: -1 do: [ :i |
> data at: i ;; = a
> and: [ data at: i + 1 ;; = b
> and: [ data at: i + 2 ;; = c
> and: [ data at: i + 3 ;; = d ]]]
> ifTrue: [ ^i ]
> ].
> ^0
Same as above, superfluous parenthesis. This is what you get after
removing 5 of them and a bit of reformatting:
data size - 3 to: 1 by: -1 do: [ :i |
(data at: i) = a and: [
(data at: i + 1) = b and: [
(data at: i + 2) = c and: [
(data at: i + 3) = d ] ] ])
ifTrue: [ ^i ]
].
>
>
> Character
>
> before:
>
> asUppercase
> "If the receiver is lowercase, answer its matching uppercase Character."
> "A tentative implementation. Eventually this should consult the
> Unicode table."
>
> | v |
> v := self charCode.
> (((8r141 <= v and: [v <= 8r172]) or: [16rE0 <= v and: [v <= 16rF6]])
> or: [16rF8 <= v and: [v <= 16rFE]])
> ifTrue: [^ Character value: value - 8r40]
> ifFalse: [^ self]
>
> after:
>
> asUppercase
> "If the receiver is lowercase, answer its matching uppercase Character."
> "A tentative implementation. Eventually this should consult the
> Unicode table."
>
> | v |
> v := self charCode.
> 8r141 <= v and: [v <= 8r172] ;; or: [16rE0 <= v and: [v <= 16rF6]] ;;
> or: [16rF8 <= v and: [v <= 16rFE]] ;;
> ifTrue: [^ Character value: value - 8r40]
> ifFalse: [^ self]
There's #between:and: or you can use better formatting to improve
readability here:
((v between: 8r141 and: 8r172) or: [
v between: 16rE0 and: 16rF6 ] or: [
v between: 16rF8 and: 16rFE ])
ifTrue: [ ^Character value: value - 8r40].
or
((8r141 <= v and: [ v <= 8r172 ]) or: [
(16rE0 <= v and: [ v <= 16rF6 ]) or: [
16rF8 <= v and: [ v <= 16rFE ] ] ])
ifTrue: [ ^Character value: value - 8r40].
Levente
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
>
More information about the Squeak-dev
mailing list
|