Frp

Inviato da smartphone Samsung Galaxy.-------- Messaggio originale --------Da: 
Ben Coman <[email protected]> Data: 02/10/2016  16:19  (GMT+01:00) A: Pharo 
Development List <[email protected]> Oggetto: Re: [Pharo-dev] New to 
Pharo; a bunch of questions. 
On Sun, Oct 2, 2016 at 8:10 PM, Peter Uhnak <[email protected]> wrote:
> Hi,
>
> a) creating a class is message send like any other... and the returned value 
> is the newly created class.
>
> So you can do
>
> locellClass := Object subclass: #LOCell.
> locellClass compile: 'myMethod'.
>
> b) Alternatively (what I usually do), is `#MyClass asClass` (or Smalltalk 
> classNamed: #MyClass).
>
> Note that using the former (`asClass`) is (justly) frowned upon when used in 
> regular code, but it is perfectly fine in Playground. (Just like 'MyPackage' 
> asPackage, etc.)
>
> As for distribution (which you've mentioned in another mail), I write code 
> like this in my startup scripts, e.g. 
> https://github.com/peteruhnak/pharo-scripts/blob/master/config/5.0/roassal-zoomableInteraction.st
>
> Likewise you can just file-out a method, class, or package(s) and send that 
> to another person, who can just file it in.
>
> Final note regarding your string operations... try to avoid using comma to 
> concat many strings, using stream is preferable (from both performance and 
> readability), e.g.

The performance aspect is not absolute and depends on usage...
http://forum.world.st/Stream-instead-of-string-concatenation-td4856891.html
http://forum.world.st/When-to-use-a-stream-for-concatenating-text-td4811093.html

cheers -ben

>
> LOCell compile: (String streamContents: [ :stream |
>         stream
>                 nextPutAll: 'initialize'; cr;
>                 nextPutAll: '    super initialize.'; cr.
> ]).
>
> Also Pharo understands multiline strings just fine, so you can do this:
>
> LOCell compile: 'initialize
>     super initialize.
>     self label: ''''.
>     self borderWidth: 2'
>
>
> If you need to specify parameters, take a look at String>>format:
>
> 'Today is {1}.' format: {Date today}.
> 'Today is {date}.' format: (Dictionary with: #date->Date today).
>
> Peter
>
>
> On Sat, Oct 01, 2016 at 12:39:26PM -0700, CodeDmitry wrote:
>>
>> ([
>>     LOCell compile:
>>         'initialize', (String cr),
>>         '    super initialize.', (String cr),
>>         '    self label: ''''.', (String cr),
>>         '    self borderWidth: 2.', (String cr),
>>         '    bounds := (0@0) corner: (16@16).', (String cr),
>>         '    offColor := Color paleYellow.', (String cr),
>>         '    onColor := Color paleBlue darker.', (String cr),
>>         '    self useSquareCorners.', (String cr),
>>         '    self turnOff.'
>> ] value).
>>
>> ([
>>     LOGame compile:
>>         'cellsPerSide', (String cr),
>>         '    ^10'
>> ] value).
>>
>> ([
>>     LOGame compile:
>>         'toggleNeighboursOfCellAt: i at: j', (String cr),
>>         '    (i > 1) ifTrue: [', (String cr),
>>         '        (cells at: i - 1 at: j) toggleState.', (String cr),
>>         '    ].', (String cr),
>>         (String cr),
>>         '    (i < self cellsPerSide) ifTrue: [', (String cr),
>>         '        (cells at: i + 1 at: j) toggleState.', (String cr),
>>         '    ].', (String cr),
>>         (String cr),
>>         '    (j > 1) ifTrue: [', (String cr),
>>         '        (cells at: i at: j - 1) toggleState.', (String cr),
>>         '    ].', (String cr),
>>         (String cr),
>>         '    (j < self cellsPerSide) ifTrue: [', (String cr),
>>         '        (cells at: i at: j + 1) toggleState.', (String cr),
>>         '    ].'
>> ] value).
>>
>> ([
>>     LOGame compile:
>>         'newCellAt: i at: j', (String cr),
>>         '    | c origin | ', (String cr),
>>         (String cr),
>>         '    c := LOCell new.', (String cr),
>>         '    origin := self innerBounds origin.', (String cr),
>>         (String cr),
>>         '    self addMorph: c.', (String cr),
>>         '    ', (String cr),
>>         '    c position: ([', (String cr),
>>         '        | x_index y_index c_width c_height |', (String cr),
>>         (String cr),
>>         '        x_index := i - 1.', (String cr),
>>         '        y_index := j - 1.', (String cr),
>>         '        c_width := c width.', (String cr),
>>         '        c_height := c height.', (String cr),
>>         '        ', (String cr),
>>         '        (x_index * c_width)@(y_index * c_height) + origin', (String
>> cr),
>>         '    ] value).', (String cr),
>>         (String cr),
>>         '    c mouseAction: [', (String cr),
>>         '        self toggleNeighboursOfCellAt: i at: j.', (String cr),
>>         '    ].', (String cr),
>>         '    ^ c.', (String cr)
>> ] value).
>>
>> ([
>>     LOGame compile:
>>         'initialize', (String cr),
>>         '    | sampleCell width height n |', (String cr),
>>         (String cr),
>>         '    super initialize.', (String cr),
>>         '    n := self cellsPerSide.', (String cr),
>>         (String cr),
>>         '    sampleCell := LOCell new.', (String cr),
>>         '    width := sampleCell width.', (String cr),
>>         '    height := sampleCell height.', (String cr),
>>         (String cr),
>>         '    self bounds: ', (String cr),
>>         '        ((5@5) extent:', (String cr),
>>         '            (width * n)@(height * n) + ', (String cr),
>>         '            (2 * (self borderWidth))).', (String cr),
>>         (String cr),
>>         '    cells := Matrix new: n tabulate: [:i :j |', (String cr),
>>         '        self newCellAt: i at: j.', (String cr),
>>         '    ].'
>> ] value).
>>
>>
>>
>>
>> --
>> View this message in context: 
>> http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917707.html
>> Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
>>
>

Reply via email to