Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1011577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:15:18+00:00 2026-05-16T09:15:18+00:00

Smalltalk has the whileTrue:-Message implemented through recursion (in VisualWorks) or through compiler-inlining (in Squeak/Pharo).

  • 0

Smalltalk has the whileTrue:-Message implemented through recursion (in VisualWorks) or through compiler-inlining (in Squeak/Pharo). Is there a way to define such a method without using one of them? If not, is there a proof for that avaiable somewhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:15:19+00:00Added an answer on May 16, 2026 at 9:15 am

    whileTrue: & whileFalse: always return nil.
    e.g. if there is a normal recursive definition:

    whileTrue: aBlock
        ^self value ifTrue: [self whileTrue: aBlock]
    

    the ifTrue: will return nil if self value is false and so the value should always be nil. That’s reflected in the compiler’s optimization. The original blue book Smalltalk-80 V2 definition is

    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]
    

    So just change your’s to

    BlockContext>>myWhileTrue: aBlock 
        | start |
        start := thisContext pc.
        self value ifFalse: [ ^ nil ].
        aBlock value.
        thisContext pc: start
    

    or??

    BlockContext>>myWhileTrue: aBlock 
        | start |
        start := thisContext pc.
        ^self value ifTrue:
            [aBlock value.
             thisContext pc: start]
    

    But alas both of these crash the VM sometime after the second iteration because thisContext pc doesn’t answer the pc on the next iteration, but instead whatever the top of stack is 🙂

    However the following does work:

    ContextPart methods for controlling
    label
        ^{ pc. stackp }
    
    goto: aLabel
        "N.B. we *must* answer label so that the
         top of stack is aLabel as it is when we send label"
        pc := aLabel at: 1.
        self stackp: (aLabel at: 2).
        ^aLabel
    
    BlockContext>>myWhileTrue: aBlock 
        | label |
        label := thisContext label.
        self value ifFalse: [^nil].
        aBlock value.
        thisContext goto: label
    
    BlockClosure>>myWhileTrue: aBlock 
        | label |
        label := thisContext label.
        ^self value ifTrue:
            [aBlock value.
             thisContext goto: label]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a practical way to get the sender of a message in Smalltalk
Is there a QuickCheck module for Smalltalk, especially for Gnu Smalltalk, Squeak, and/or Pharo?
I'm trying to learn some Smalltalk. First found was Squeak, but since it has
In Smalltalk there is a message DoesNotUnderstand that is called when an object does
In the Squeak Smalltalk environment, I am trying to learn Morphic. There are many,
What languages are there with a message-passing syntax similar to Smalltalk's? Objective-C is the
Is there a version of Smalltalk that allows distributed message passing, much as Erlang
Does Smalltalk(especially Squeak/Pharo) have some form of variadic functions? I was just reading about
Is there a way to simulate Smalltalk's doesNotUnderstand or Ruby's method_missing in Javascript?
There is a project I'm about to build in Smalltalk (Pharo). And there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.