[squeak-dev] How to create a 'Hello world' example for environments

Frank Shearar frank.shearar at gmail.com
Sat Oct 1 02:02:28 UTC 2016


On Sep 30, 2016 09:50, "Nicolas Cellier" <nicolas.cellier.aka.nice at gmail.com>
wrote:
>
>
>
> 2016-09-30 14:57 GMT+02:00 Jakob Reschke <jakob.reschke at student.hpi.de>:
>>
>> Hello,
>>
>> Looks good to me as an outline. I have the following comments,
>> questions or doubts:
>>
>> 1. Currently, for me it does not feel like "entering" or "leaving" an
>> Environment, as that works with dynamic scoping in a block. So step 8
>> could turn out to be void.
>>
>> 2. Since all of this should go into a workspace, not into the browser,
>> what is the shortest applicable snippet of code that, given a source
>> code string and a class, creates a new method in that class?
>>
>> 3. I am not sure what will happen if you attempt to create a subclass
>> that has the same name as another imported class. Generally,
>> evaluating Superclass subclass: #Subclass ... a second time will
>> replace the former Subclass by the new Subclass. 'myEnvironment' would
>> have imported Hello from Smalltalk globals, so an "old" Hello is
>> already visible. We have to check that evaluating the subclass
>> expression will not try to update that existing Hello class, but
>> create a new one instead. Here, the "shallow" lookup mechanism would
>> be needed.
>>
> Don't import: Smalltalk globals entirely, just from: Smalltalk globals
import: #Transcript.
> and #Object too, depending in which environment you'll evaluate the
message for creating the class...
>
>>
>> Once I have figured out 2. I will try out and check 3. ;-)
>>
>> Kind regards,
>> Jakob
>>
>
> Here is a snippet that works, but is not especially short.
>
> | createHelloClass createHelloMethod english spanish |
>
> "Straight but verbose code to create a Hello class and compile a say
method.
>  There's one trick: Environment current, otherwise Compiler would
evaluate in nil class environment, not good"
> createHelloClass := [Object subclass: #Hello
>             instanceVariableNames: ''
>             classVariableNames: ''
>             poolDictionaries: ''
>             category: 'Test'].
> createHelloMethod := [:greeting |
>     | methodSource sourceCode |
>     methodSource := 'say Transcript cr; show: ' , greeting printString.
>     sourceCode := 'Hello class compile: ' , methodSource printString , '
classified: ' , 'test' printString.
>     Compiler evaluate: sourceCode environment: Environment current].
>
> "Create the english and spanish environments"
> english := Smalltalk globals.
> spanish := Environment withName: 'Spanish'.
> spanish importSelf.
> spanish from: english import: #Transcript.
>
> "Create the class and compile the method in each environment:"
>
> [createHelloClass value.
> createHelloMethod value: 'Hello world'] on: CurrentEnvironment do: [:exc
| exc resume: english].
>
> [createHelloClass value.
> createHelloMethod value: 'Buenos dias'] on: CurrentEnvironment do: [:exc
| exc resume: spanish].
>
> "Greet"
> Compiler evaluate: 'Hello say' environment: english.
> Compiler evaluate: 'Hello say' environment: spanish.
> Compiler evaluate: 'Hello say' environment: english.
>
> "Cleanup"
> [Compiler evaluate: 'Hello removeFromSystem' environment: Environment
current] on: CurrentEnvironment do: [:exc | exc resume: english].
> [Compiler evaluate: 'Hello removeFromSystem' environment: Environment
current] on: CurrentEnvironment do: [:exc | exc resume: spanish].
>
> Yes, a DynamicVariable:
>    CurrentEnvironment value: english during: ["load something"].
> would be nicer than:
>     ["load something"] on: CurrentEnvironment do: [:exc | exc resume:
english].
> Otherwise we coulf fileIn some chunk format stream thru en
EnvironmentLoader for: english...

I wrote Control to do pretty much that: give a nice interface through which
to create and change delimited dynamic variables (and delimited
continuations). I would link to it (it's on SS3) but my phone is a bit
limited...

frank

>> 2016-09-30 13:29 GMT+02:00 H. Hirzel <hannes.hirzel at gmail.com>:
>> > Starting a new thread, culled from the thread 'What are environments
for'.
>> >
>> > There are many more good questions and thoughts in the  thread 'What
>> > are environments for' but this thread is just about what the subject
>> > says:
>> >
>> > How to create a 'Hello world' example for environments
>> >
>> > --Hannes
>> >
>> > On 9/29/16, David T. Lewis <lewis at mail.msen.com> wrote:
>> >> On Thu, Sep 29, 2016 at 07:51:23AM +0200, H. Hirzel wrote:
>> >>> On 9/29/16, Jakob Reschke <jakob.reschke at student.hpi.de> wrote:
>> >>> > Hi Nicolas,
>> >>> >
>> >>> > First, thank you for answering me in the other thread.
>> >>> >
>> >>> > 2016-09-28 23:02 GMT+02:00 Nicolas Cellier
>> >>> > <nicolas.cellier.aka.nice at gmail.com>:
>> >>> >> Without clear goals or vision, fixing could essentially mean "let
>> >>> >> Environment be transparent", that is let it remain a promise, a
>> >>> >> potential,
>> >>> >> whithout too many side effects... Not exactly YAGNI, just a bit of
>> >>> >> over-engineered nice piece of code that might serve later. OK this
>> >>> >> sounds
>> >>> >> like a mandatory first step.
>> >
>> >
>> >>> > I don't quite get what you mean by transparent, other than fixing
it
>> >>> > and enhancing the documentation to shed some light on what it is,
why
>> >>> > it is there and how to use it.
>> > ..
>> > ...
>> >
>> >>> Another maybe simple use case could be to have a project specific
>> >>> environment set up when you enter a project
>> >>> (http://wiki.squeak.org/squeak/1020).
>> >>>
>> >>> We now have very nicely cleaned up Project code in Squeak 5.1
>> >>>
>> >>> 1) Subclass MorphicProject --- MyMorphicProject
>> >>> 2) Subclass PasteUpMorph  --- MyPasteUpMorph
>> >>> 3) Override #initialize in MyMorphicProject and use MyPasteUpMorph
>> >>> 4) ... some more adaptations ..... to enter a new Environment -- how?
>> >>>
>> >>
>> >> I like this idea a lot.
>> >>
>> >> I would love to see a simple "hello world!" level example of
Environments.
>> >> If someone could make an EnvironmentsDemoProject that opens a new
project
>> >> with
>> >> something that changes Duck>>speak ==> 'quack' to Duck>>speak ==>
'moo',
>> >> I think it might really help me to understand how to use Environments.
>> >>
>> >> Dave
>> >
>> > So let's focus on a 'hello world' example for environments and do it
>> > _slowly_ step by step so that people can catch up with the issues.
>> >
>> >
>> >
>> > Outline of steps of a 'Hello world' environments example
>> > =============================================
>> >
>> > Steps
>> >
>> >
>> > 1. subclass Object with a #Hello class.
>> >
>> > 2. compile a class method #say the method should write 'Hello' to the
Transcript
>> >
>> > 3. run
>> >     Hello say
>> >
>> >     The result should be 'Hello' on the Transcript
>> >
>> >
>> > 4. create a new Environment called "myEnvironment".
>> >
>> > 5. import the Smalltalk environmnet into myEnvironment
>> >
>> > 6. subclass Object with a #Hello class in myEnvironment
>> >
>> > 7. compile a method #say the method should write 'Buenas dias' to the
Transcript
>> >
>> >    run
>> >         Hello say
>> >
>> >    Result should be
>> >
>> >         30-Sept-2016
>> >
>> > Starting a new thread, culled from the thread 'What are environments
for'.
>> >
>> > There are many more good questions and thoughts in the  thread 'What
>> > are environments for' but this thread is just about what the subject
>> > says:
>> >
>> > How to create a 'Hello world' example for environments
>> >
>> > --Hannes
>> >
>> > On 9/29/16, David T. Lewis <lewis at mail.msen.com> wrote:
>> >> On Thu, Sep 29, 2016 at 07:51:23AM +0200, H. Hirzel wrote:
>> >>> On 9/29/16, Jakob Reschke <jakob.reschke at student.hpi.de> wrote:
>> >>> > Hi Nicolas,
>> >>> >
>> >>> > First, thank you for answering me in the other thread.
>> >>> >
>> >>> > 2016-09-28 23:02 GMT+02:00 Nicolas Cellier
>> >>> > <nicolas.cellier.aka.nice at gmail.com>:
>> >>> >> Without clear goals or vision, fixing could essentially mean "let
>> >>> >> Environment be transparent", that is let it remain a promise, a
>> >>> >> potential,
>> >>> >> whithout too many side effects... Not exactly YAGNI, just a bit of
>> >>> >> over-engineered nice piece of code that might serve later. OK this
>> >>> >> sounds
>> >>> >> like a mandatory first step.
>> >
>> >
>> >>> > I don't quite get what you mean by transparent, other than fixing
it
>> >>> > and enhancing the documentation to shed some light on what it is,
why
>> >>> > it is there and how to use it.
>> > ..
>> > ...
>> >
>> >>> Another maybe simple use case could be to have a project specific
>> >>> environment set up when you enter a project
>> >>> (http://wiki.squeak.org/squeak/1020).
>> >>>
>> >>> We now have very nicely cleaned up Project code in Squeak 5.1
>> >>>
>> >>> 1) Subclass MorphicProject --- MyMorphicProject
>> >>> 2) Subclass PasteUpMorph  --- MyPasteUpMorph
>> >>> 3) Override #initialize in MyMorphicProject and use MyPasteUpMorph
>> >>> 4) ... some more adaptations ..... to enter a new Environment -- how?
>> >>>
>> >>
>> >> I like this idea a lot.
>> >>
>> >> I would love to see a simple "hello world!" level example of
Environments.
>> >> If someone could make an EnvironmentsDemoProject that opens a new
project
>> >> with
>> >> something that changes Duck>>speak ==> 'quack' to Duck>>speak ==>
'moo',
>> >> I think it might really help me to understand how to use Environments.
>> >>
>> >> Dave
>> >
>> > So let's focus on a 'hello world' example for environments and do it
>> > _slowly_ step by step so that people can catch up with the issues.
>> >
>> >
>> >
>> > Outline of steps of a 'Hello world' environments example
>> > =============================================
>> >
>> > Steps
>> >
>> >
>> > 1. subclass Object with a #Hello class.
>> >
>> > 2. compile a class method #say the method should write 'Hello' to the
Transcript
>> >
>> > 3. run
>> >     Hello say
>> >
>> >     The result should be 'Hello' on the Transcript
>> >
>> >
>> > 4. create a new Environment called "myEnvironment".
>> >
>> > 5. import the Smalltalk environmnet into myEnvironment
>> >
>> > 6. subclass Object with a #Hello class in myEnvironment
>> >
>> > 7. compile a method #say the method should write 'Buenas dias' to the
Transcript
>> >
>> >    run
>> >         Hello say
>> >
>> >     The result should be 'Buenas dias' on the Transcript
>> >
>> >
>> > 8. Leave environment called 'myEnvironment'
>> >
>> >
>> > 9. run
>> >     Hello say
>> >
>> >     The result should be this time 'Hello' on the Transcript
>> >
>> >
>> >
>> > Any comments on these steps?
>> >
>>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20160930/21304582/attachment.htm


More information about the Squeak-dev mailing list