[squeak-dev] Further steps on BlockClosure controlling methods (was: The Trunk: Kernel-ct.1295.mcz)
Eliot Miranda
eliot.miranda at gmail.com
Mon Mar 9 22:05:19 UTC 2020
Hi Christoph,
On Sat, Mar 7, 2020 at 6:01 AM Thiede, Christoph <
Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:
> Take this as a memo for myself -- of course, it would be great to hear
> your ideas about the following points!
>
>
> Further steps:
>
>
>
> - Implement the same return logic for #while(True|False)[:]. This
> might also require changes in the Compiler.
> - Inline #whileNil(:) implementation as well.
> General question: Is there such a thing as "too much inlining"? Would
> it be desirable to inline #cull: and others? Where do we draw the line
> between performance and Smalltalk-essential explorability?
> - Implement all these controlling methods in a way that could work
> without inlining (though slow). At the moment, #whileTrue: refers to itself.
> An approach that completely foregos inline code would either need to
> use recursion (linear complexity) or "thisContext restart" (constant
> time complexity).
> - Should we maybe find a way to highlight methods that are inlined?
> For example, by using a pragma <inlined>. Or rather ask Encoder for it than
> storing this information in the methods.
> Should we warn or forbid the user to override (or even overwrite) such
> methods?
> - Similar concern: It is dangerous to override #class et al.,
> should we warn here, too?
>
>
BTW, this is a hack, I would argue one that is extremely confusing for the
beginner:
whileTrue: aBlock
"Ordinarily compiled in-line, and therefore not overridable.
This is in case the message is sent to other than a literal block.
Evaluate the argument, aBlock, as long as the value of the receiver is
true."
^ [self value] whileTrue: [aBlock value]
It should read something like
whileTrue: aBlock
"Ordinarily compiled in-line, and therefore not overridable, and not
recursive.
This method exists in case the message is sent to other than a literal
block.
Evaluate the argument, aBlock, as long as the value of the receiver is
true."
self value ifTrue:
[aBlock value.
^self whileTrue: aBlock].
^nil
or
whileTrue: aBlock
"Ordinarily compiled in-line, and therefore not overridable, and not
recursive.
This method will be used if the message is sent to other than a literal
block.
Evaluate the argument, aBlock, as long as the value of the receiver is
true."
self value ifTrue:
[aBlock value.
[self value] whileTrue: aBlock].
^nil
this is what it read in Smalltalk-80 v2:
whileTrue: aBlock
"Evaluate the argument, aBlock, as long as the value
of the receiver is true. Ordinarily compiled in-line.
But could also be done in Smalltalk as follows"
^self value
ifTrue:
[aBlock value.
self whileTrue: aBlock]
Best,
> Christoph
>
> ------------------------------
> *Von:* Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im
> Auftrag von commits at source.squeak.org <commits at source.squeak.org>
> *Gesendet:* Dienstag, 3. März 2020 22:38 Uhr
> *An:* squeak-dev at lists.squeakfoundation.org;
> packages at lists.squeakfoundation.org
> *Betreff:* [squeak-dev] The Trunk: Kernel-ct.1295.mcz
>
> Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
> http://source.squeak.org/trunk/Kernel-ct.1295.mcz
>
> ==================== Summary ====================
>
> Name: Kernel-ct.1295
> Author: ct
> Time: 24 January 2020, 5:20:51.814415 pm
> UUID: 18ea3b5d-ee42-2944-9d01-aa48e43207a7
> Ancestors: Kernel-nice.1292
>
> Extends BlockClosure >> #whileNil: by returning the final non-nil value.
> Adds #whileNil analogous to #whileTrue and #whileFalse.
>
> [Project uiManager chooseFrom: #(foo bar) values: #(Foo Bar)]
> whileNil.
>
> [Project uiManager chooseFrom: #(foo bar) values: #(Foo Bar)]
> whileNil: [self inform: 'You have to decide!']
>
> =============== Diff against Kernel-nice.1292 ===============
>
> Item was added:
> + ----- Method: BlockClosure>>whileNil (in category 'controlling') -----
> + whileNil
> + "Unlike #whileTrue/False this is not compiled inline."
> + | result |
> + [(result := self value) isNil] whileTrue.
> + ^ result
> + !
>
> Item was changed:
> ----- Method: BlockClosure>>whileNil: (in category 'controlling') -----
> whileNil: aBlock
> "Unlike #whileTrue/False: this is not compiled inline."
> + | result |
> + [(result := self value) isNil] whileTrue: [aBlock value].
> + ^ result
> - ^ [self value isNil] whileTrue: [aBlock value]
> !
>
>
>
>
--
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200309/a1b6e709/attachment.html>
More information about the Squeak-dev
mailing list
|