Teaching Smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Teaching Smalltalk

Samuel Williams
Dear Friends,

I'm looking for some help from the Smalltalk community. I hope this is the right place to ask for information.

I'm putting together a website aimed at high school students and teachers, and would like to make sure the following page is as good as possible:


In particular, "Why would I learn this language?" section needs to have a few paragraphs. I don't use Smalltalk so I hoped that you could provide the main reasons why Smalltalk is a language someone would want to learn about.

It would also be great if someone could rewrite the Smalltalk source code example so that it is as close as possible to the C implementation:


I understand that Smalltalk is very different from C, and uses different paradigms, so it doesn't have to be identical, however it would be great if it worked in generally the same way. It would be great if you could include comments explaining how it works and what is happening (like the C example).

Any other suggestions or ideas for the Smalltalk page would be fantastic, and any suggestions to other pages in general is also very helpful.

http://programming.dojo.net.nz/

Kind regards,
Samuel

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

David Mitchell-10
For why smalltalk, you might check whysmalltalk.org.

I wrote a little piece on what makes Squeak special on my blog last year:
http://www.withaguide.com/2009/04/what-makes-squeak-special.html

Don't have time this AM to rewrite the C code, but will look tonight. You might want to look at the first chapter of "A Taste of Smalltalk" which rewrites a simple Pascal program in Pascal style code with Smalltalk.

On Mon, May 3, 2010 at 7:20 AM, Samuel Williams <[hidden email]> wrote:
Dear Friends,

I'm looking for some help from the Smalltalk community. I hope this is the right place to ask for information.

I'm putting together a website aimed at high school students and teachers, and would like to make sure the following page is as good as possible:


In particular, "Why would I learn this language?" section needs to have a few paragraphs. I don't use Smalltalk so I hoped that you could provide the main reasons why Smalltalk is a language someone would want to learn about.

It would also be great if someone could rewrite the Smalltalk source code example so that it is as close as possible to the C implementation:


I understand that Smalltalk is very different from C, and uses different paradigms, so it doesn't have to be identical, however it would be great if it worked in generally the same way. It would be great if you could include comments explaining how it works and what is happening (like the C example).

Any other suggestions or ideas for the Smalltalk page would be fantastic, and any suggestions to other pages in general is also very helpful.

http://programming.dojo.net.nz/

Kind regards,
Samuel

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Hannes Hirzel
In reply to this post by Samuel Williams
Hello Samuel

I would include the link

 http://www.world.st/

The World of Smalltalk

Recently created web site, gives a good overview and has entry points
to further information.

This includes links to videos.

--Hannes

On 5/3/10, Samuel Williams <[hidden email]> wrote:

> Dear Friends,
>
> I'm looking for some help from the Smalltalk community. I hope this is the
> right place to ask for information.
>
> I'm putting together a website aimed at high school students and teachers,
> and would like to make sure the following page is as good as possible:
>
> http://programming.dojo.net.nz/languages/smalltalk/index
>
> In particular, "Why would I learn this language?" section needs to have a
> few paragraphs. I don't use Smalltalk so I hoped that you could provide the
> main reasons why Smalltalk is a language someone would want to learn about.
>
> It would also be great if someone could rewrite the Smalltalk source code
> example so that it is as close as possible to the C implementation:
>
> http://programming.dojo.net.nz/languages/c/index
>
> I understand that Smalltalk is very different from C, and uses different
> paradigms, so it doesn't have to be identical, however it would be great if
> it worked in generally the same way. It would be great if you could include
> comments explaining how it works and what is happening (like the C example).
>
> Any other suggestions or ideas for the Smalltalk page would be fantastic,
> and any suggestions to other pages in general is also very helpful.
>
> http://programming.dojo.net.nz/
>
> Kind regards,
> Samuel
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Samuel Williams
Dear Hannes,

Thanks for providing this really good link.

Kind regards,
Samuel

On 4/05/2010, at 1:00 AM, Hannes Hirzel wrote:

> Hello Samuel
>
> I would include the link
>
> http://www.world.st/
>
> The World of Smalltalk
>
> Recently created web site, gives a good overview and has entry points
> to further information.
>
> This includes links to videos.
>
> --Hannes
>
> On 5/3/10, Samuel Williams <[hidden email]> wrote:
>> Dear Friends,
>>
>> I'm looking for some help from the Smalltalk community. I hope this is the
>> right place to ask for information.
>>
>> I'm putting together a website aimed at high school students and teachers,
>> and would like to make sure the following page is as good as possible:
>>
>> http://programming.dojo.net.nz/languages/smalltalk/index
>>
>> In particular, "Why would I learn this language?" section needs to have a
>> few paragraphs. I don't use Smalltalk so I hoped that you could provide the
>> main reasons why Smalltalk is a language someone would want to learn about.
>>
>> It would also be great if someone could rewrite the Smalltalk source code
>> example so that it is as close as possible to the C implementation:
>>
>> http://programming.dojo.net.nz/languages/c/index
>>
>> I understand that Smalltalk is very different from C, and uses different
>> paradigms, so it doesn't have to be identical, however it would be great if
>> it worked in generally the same way. It would be great if you could include
>> comments explaining how it works and what is happening (like the C example).
>>
>> Any other suggestions or ideas for the Smalltalk page would be fantastic,
>> and any suggestions to other pages in general is also very helpful.
>>
>> http://programming.dojo.net.nz/
>>
>> Kind regards,
>> Samuel
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Samuel Williams
In reply to this post by David Mitchell-10
Dear David,

That link doesn't seem to work (whysmalltalk). Is there some problem on my end? I tried Google, but it also didn't show anything with that name..?

Thanks for the link to your blog, I enjoyed reading the article, and it is a useful resource for understanding Smalltalk.

On 4/05/2010, at 12:58 AM, David Mitchell wrote:

For why smalltalk, you might check whysmalltalk.org.

I wrote a little piece on what makes Squeak special on my blog last year:
http://www.withaguide.com/2009/04/what-makes-squeak-special.html

Don't have time this AM to rewrite the C code, but will look tonight. You might want to look at the first chapter of "A Taste of Smalltalk" which rewrites a simple Pascal program in Pascal style code with Smalltalk.

It would be really fantastic if you can rewrite the code. It isn't urgent. I simply want to ensure that the best possible code is made available as an example program. If you rewrite the code, are you happy that I include your name in the site credits?

Kind regards,
Samuel


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Louis LaBrunda
Hi Samuel,

>That link doesn't seem to work (whysmalltalk). Is there some problem on my end? I tried Google, but it also didn't show anything with that name..?

I think the link is actually http://whysmalltalk.com.

Lou
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:[hidden email] http://www.Keystone-Software.com

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Samuel Williams
Isn't that just some junk spam website?

Thanks
Samuel

On 4/05/2010, at 2:11 AM, Louis LaBrunda wrote:

> Hi Samuel,
>
>> That link doesn't seem to work (whysmalltalk). Is there some problem on my end? I tried Google, but it also didn't show anything with that name..?
>
> I think the link is actually http://whysmalltalk.com.
>
> Lou
> -----------------------------------------------------------
> Louis LaBrunda
> Keystone Software Corp.
> SkypeMe callto://PhotonDemon
> mailto:[hidden email] http://www.Keystone-Software.com
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Louis LaBrunda
>Isn't that just some junk spam website?
>Thanks
>Samuel

It does look very different than what I remember but the links to Cincom
Smalltalk and VA Smalltalk are real and appear to be paid for, so it seems
real.

Lou
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:[hidden email] http://www.Keystone-Software.com

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Ralph Johnson
I think the WhySmalltalk site has gone away.  The link that was posted has no content, just ads.

-Ralph

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

David Mitchell-10
In reply to this post by David Mitchell-10
Bummed that Why Smalltalk is gone.

Here is my crack at translating. Wouldn't say this is idiomatic Smalltalk (transliterated C never will be). But it ran in the transcript.

Tried to only use ANSI Smalltalk:

| count doors |
count := 10.
"Initialize the array of doors to 0 (closed)"
doors := (Array new: count) atAllPut:  false.

"Process the doors"
1 to: count do:
    [ :pass |
    pass to: count by: pass do:
        [ :door |
        doors
            at: door
            put: (doors at: door) not ] ].

"Print out the results"
1 to: count do:
    [ :n |
    Transcript
        show: 'door #', n, ' is ';
        show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
        cr]


On Mon, May 3, 2010 at 7:58 AM, David Mitchell <[hidden email]> wrote:
For why smalltalk, you might check whysmalltalk.org.

I wrote a little piece on what makes Squeak special on my blog last year:
http://www.withaguide.com/2009/04/what-makes-squeak-special.html

Don't have time this AM to rewrite the C code, but will look tonight. You might want to look at the first chapter of "A Taste of Smalltalk" which rewrites a simple Pascal program in Pascal style code with Smalltalk.


On Mon, May 3, 2010 at 7:20 AM, Samuel Williams <[hidden email]> wrote:
Dear Friends,

I'm looking for some help from the Smalltalk community. I hope this is the right place to ask for information.

I'm putting together a website aimed at high school students and teachers, and would like to make sure the following page is as good as possible:


In particular, "Why would I learn this language?" section needs to have a few paragraphs. I don't use Smalltalk so I hoped that you could provide the main reasons why Smalltalk is a language someone would want to learn about.

It would also be great if someone could rewrite the Smalltalk source code example so that it is as close as possible to the C implementation:


I understand that Smalltalk is very different from C, and uses different paradigms, so it doesn't have to be identical, however it would be great if it worked in generally the same way. It would be great if you could include comments explaining how it works and what is happening (like the C example).

Any other suggestions or ideas for the Smalltalk page would be fantastic, and any suggestions to other pages in general is also very helpful.

http://programming.dojo.net.nz/

Kind regards,
Samuel

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

David Mitchell-10
Doh! Was only playing with 10 doors. This makes it 100.

| count doors |
count := 100.
"Initialize the array of doors to 0 (closed)"
doors := (Array new: count) atAllPut:  false.

"Process the doors"
1 to: count do:
    [ :pass |
    pass to: count by: pass do:
        [ :door |
        doors
            at: door
            put: (doors at: door) not ] ].

"Print out the results"
1 to: count do:
    [ :n |
    Transcript
        show: 'door #', n, ' is ';
        show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
        cr]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

="post-count60864 avatar-label weak-color">
Dear David,

Thanks for this.

I'm happy to use idiomatic Scheme concepts.

Are you able to make this a function which can work for n doors?
        Example: http://programming.dojo.net.nz/languages/cpp/index

Kind regards,
Samuel

On 4/05/2010, at 3:31 PM, David Mitchell wrote:

> Doh! Was only playing with 10 doors. This makes it 100.
>
> | count doors |
> count := 100.
> "Initialize the array of doors to 0 (closed)"
> doors := (Array new: count) atAllPut:  false.
>
> "Process the doors"
> 1 to: count do:
>     [ :pass |
>     pass to: count by: pass do:
>         [ :door |
>         doors
>             at: door
>             put: (doors at: door) not ] ].
>
> "Print out the results"
> 1 to: count do:
>     [ :n |
>     Transcript
>         show: 'door #', n, ' is ';
>         show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
>         cr]
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

John Foster-3
And here we see how someone who doesn't grok smalltalk sees the world.  A
closure could work like a function though.

What I'm trying to work out is how to get rid of all the to:by:do: code -
I feel as if it should be possible to use inject:into: to get to the
answer much faster.

John

doorProblem := [ :count |
a  := Array new: count withAll: false.

a withIndexDo: [ :each :index |
    index to: (a size) by: index do: [:this |
         a at: this put: (a at: this) not
    ]
 ].

 "output"
 a withIndexDo: [ :each :index |
        each ifTrue: [Transcript show: ('Door ', index asString, ' is
open') ; cr]
 ].
 Transcript show: 'All the rest are closed';cr.
].

doorProblem value: 100.


> Dear David,
>
> Thanks for this.
>
> I'm happy to use idiomatic Scheme concepts.
>
> Are you able to make this a function which can work for n doors?
> Example: http://programming.dojo.net.nz/languages/cpp/index
>
> Kind regards,
> Samuel
>
> On 4/05/2010, at 3:31 PM, David Mitchell wrote:
>
>> Doh! Was only playing with 10 doors. This makes it 100.
>>
>> | count doors |
>> count := 100.
>> "Initialize the array of doors to 0 (closed)"
>> doors := (Array new: count) atAllPut:  false.
>>
>> "Process the doors"
>> 1 to: count do:
>>     [ :pass |
>>     pass to: count by: pass do:
>>         [ :door |
>>         doors
>>             at: door
>>             put: (doors at: door) not ] ].
>>
>> "Print out the results"
>> 1 to: count do:
>>     [ :n |
>>     Transcript
>>         show: 'door #', n, ' is ';
>>         show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
>>         cr]
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Samuel Williams
Thanks John.

I don't know Smalltalk syntax, so I can't make the adjustments myself. It isn't that I don't understand functional programming concepts.

Kind regards,
Samuel

On 4/05/2010, at 4:45 PM, John Foster wrote:

> And here we see how someone who doesn't grok smalltalk sees the world.  A
> closure could work like a function though.
>
> What I'm trying to work out is how to get rid of all the to:by:do: code -
> I feel as if it should be possible to use inject:into: to get to the
> answer much faster.
>
> John
>
> doorProblem := [ :count |
> a  := Array new: count withAll: false.
>
> a withIndexDo: [ :each :index |
>    index to: (a size) by: index do: [:this |
>         a at: this put: (a at: this) not
>    ]
> ].
>
> "output"
> a withIndexDo: [ :each :index |
>        each ifTrue: [Transcript show: ('Door ', index asString, ' is
> open') ; cr]
> ].
> Transcript show: 'All the rest are closed';cr.
> ].
>
> doorProblem value: 100.
>
>
>> Dear David,
>>
>> Thanks for this.
>>
>> I'm happy to use idiomatic Scheme concepts.
>>
>> Are you able to make this a function which can work for n doors?
>> Example: http://programming.dojo.net.nz/languages/cpp/index
>>
>> Kind regards,
>> Samuel
>>
>> On 4/05/2010, at 3:31 PM, David Mitchell wrote:
>>
>>> Doh! Was only playing with 10 doors. This makes it 100.
>>>
>>> | count doors |
>>> count := 100.
>>> "Initialize the array of doors to 0 (closed)"
>>> doors := (Array new: count) atAllPut:  false.
>>>
>>> "Process the doors"
>>> 1 to: count do:
>>>    [ :pass |
>>>    pass to: count by: pass do:
>>>        [ :door |
>>>        doors
>>>            at: door
>>>            put: (doors at: door) not ] ].
>>>
>>> "Print out the results"
>>> 1 to: count do:
>>>    [ :n |
>>>    Transcript
>>>        show: 'door #', n, ' is ';
>>>        show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
>>>        cr]
>>> _______________________________________________
>>> Beginners mailing list
>>> [hidden email]
>>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>>
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Bert Freudenberg
In reply to this post by David Mitchell-10
On 03.05.2010, at 20:30, David Mitchell wrote:
Bummed that Why Smalltalk is gone.

Yeah. It's still in the archive though:


Here is my crack at translating. Wouldn't say this is idiomatic Smalltalk (transliterated C never will be). But it ran in the transcript.

Tried to only use ANSI Smalltalk:

| count doors |
count := 10.
"Initialize the array of doors to 0 (closed)"
doors := (Array new: count) atAllPut:  false.

"Process the doors"
1 to: count do:
    [ :pass |
    pass to: count by: pass do:
        [ :door |
        doors
            at: door
            put: (doors at: door) not ] ].

"Print out the results"
1 to: count do:
    [ :n |
    Transcript
        show: 'door #', n, ' is ';
        show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
        cr]


This looks a lot like
(although that code doesn't even run - could someone fix?)

How about this one - demonstrates better what Squeak provides:

| doors |
doors := Array new: 100 withAll: false.
1 to: doors size do: [:pass |
doors := doors collectWithIndex: [ :isOpen :door |
(door isDivisibleBy: pass) xor: isOpen]].
^ (1 to: doors size) select: [:door | doors at: door]


- Bert -



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

LawsonEnglish
In reply to this post by Samuel Williams
On 5/3/10 9:53 PM, Samuel Williams wrote:
> Thanks John.
>
> I don't know Smalltalk syntax, so I can't make the adjustments myself. It isn't that I don't understand functional programming concepts.
>
> Kind regards,
> Samuel
>    

It seems to me that for a brief representative example, clarity, as long
as it isn't contrived, is more important than making sure you have the
shortest example using the best syntax.

Also, an important Smalltalk strength is in the "liveness" of its
objects. You mention that Smalltalk is highly productive, but it might
be good to mention that for this reason, Smalltalk has been used to
develop or refine a remarkable number of concepts and techniques used in
computer programming, starting with the term "object oriented
programming" itself, and including graphical user interfaces, many of
the most important design patterns, Unit Testing, etc.

Lawson
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Hannes Hirzel
In reply to this post by Bert Freudenberg
On 5/4/10, Bert Freudenberg <[hidden email]> wrote:

> On 03.05.2010, at 20:30, David Mitchell wrote:
>> Bummed that Why Smalltalk is gone.
>
> Yeah. It's still in the archive though:
>
> http://web.archive.org/web/*/whysmalltalk.com
>
>> Here is my crack at translating. Wouldn't say this is idiomatic Smalltalk
>> (transliterated C never will be). But it ran in the transcript.
>>
>> Tried to only use ANSI Smalltalk:
>>
>> | count doors |
>> count := 10.
>> "Initialize the array of doors to 0 (closed)"
>> doors := (Array new: count) atAllPut:  false.
>>
>> "Process the doors"
>> 1 to: count do:
>>     [ :pass |
>>     pass to: count by: pass do:
>>         [ :door |
>>         doors
>>             at: door
>>             put: (doors at: door) not ] ].
>>
>> "Print out the results"
>> 1 to: count do:
>>     [ :n |
>>     Transcript
>>         show: 'door #', n, ' is ';
>>         show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
>>         cr]
>>
>
> This looks a lot like
> http://programming.dojo.net.nz/languages/smalltalk/index
> (although that code doesn't even run - could someone fix?)
>
> How about this one - demonstrates better what Squeak provides:
>
> | doors |
> doors := Array new: 100 withAll: false.
> 1 to: doors size do: [:pass |
> doors := doors collectWithIndex: [ :isOpen :door |
> (door isDivisibleBy: pass) xor: isOpen]].
> ^ (1 to: doors size) select: [:door | doors at: door]
>
>
> - Bert -
>
>
>
I would include both examples. The first one using C-like constructs
thus giving some idea how the syntax constructs relate, the other one
as an example of idiomatic Smalltalk which allows for compact code.

--Hannes
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Bert Freudenberg
On 04.05.2010, at 08:26, Hannes Hirzel wrote:

>
> On 5/4/10, Bert Freudenberg <[hidden email]> wrote:
>> On 03.05.2010, at 20:30, David Mitchell wrote:
>>> Bummed that Why Smalltalk is gone.
>>
>> Yeah. It's still in the archive though:
>>
>> http://web.archive.org/web/*/whysmalltalk.com
>>
>>> Here is my crack at translating. Wouldn't say this is idiomatic Smalltalk
>>> (transliterated C never will be). But it ran in the transcript.
>>>
>>> Tried to only use ANSI Smalltalk:
>>>
>>> | count doors |
>>> count := 10.
>>> "Initialize the array of doors to 0 (closed)"
>>> doors := (Array new: count) atAllPut:  false.
>>>
>>> "Process the doors"
>>> 1 to: count do:
>>>    [ :pass |
>>>    pass to: count by: pass do:
>>>        [ :door |
>>>        doors
>>>            at: door
>>>            put: (doors at: door) not ] ].
>>>
>>> "Print out the results"
>>> 1 to: count do:
>>>    [ :n |
>>>    Transcript
>>>        show: 'door #', n, ' is ';
>>>        show: ((doors at: door) ifTrue: [#open] ifFalse: [#closed]);
>>>        cr]
>>>
>>
>> This looks a lot like
>> http://programming.dojo.net.nz/languages/smalltalk/index
>> (although that code doesn't even run - could someone fix?)
>>
>> How about this one - demonstrates better what Squeak provides:
>>
>> | doors |
>> doors := Array new: 100 withAll: false.
>> 1 to: doors size do: [:pass |
>> doors := doors collectWithIndex: [ :isOpen :door |
>> (door isDivisibleBy: pass) xor: isOpen]].
>> ^ (1 to: doors size) select: [:door | doors at: door]
>>
>>
>> - Bert -
>>
>>
>>
> I would include both examples. The first one using C-like constructs
> thus giving some idea how the syntax constructs relate, the other one
> as an example of idiomatic Smalltalk which allows for compact code.


Though (at least in this case) the "C-like" version is equally compact if formatted similarly:

        | doors |
        doors := Array new: 100 withAll: false.
        1 to: doors size do: [:pass |
                pass to: doors size by: pass do: [ :door |
                        doors at: door put: (doors at: door) not ] ].
        ^ (1 to: doors size) select: [:door | doors at: door]

I have to admit I don't like most examples involving Transcript. They are usually written by people who expect output to work like a teletype console from the 1960s. This completely misses the point about Smalltalk as an interactive development environment.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

John McKeon
Looking at rosettacode most languages look nearly identical (or, at the very least, ugly/crappy) when written out procedurely so that one might end up deciding to just stick with C.

I know I am going off the deep end a bit, but the whole answer to "why Smalltalk?" lies in the fact that problems should/would be approached in a completely different manner. As I am sure they would in most of the other languages if one were not restricted to 20 or so lines of code.

Since it is example code, at least in the case of Smalltalk, an object oriented solution would be in order - i.e. show how it would be solved using "everything is an object". Unfortunately, it doesn't really fit into "a few lines of code" to display on a page (even though the classes/objects and code required to implement them is little more than a few lines). And you also don't get any feel for the great tools. Perhaps, some insight into how one would run the code in Java/Eclipse, or Visual C <chuckle> with all the includes and project setup, etc might be a useful addition to the comparisons...

Object subclass: #Corridor
    instanceVariableNames: 'doors count'
    classVariableNames: ''
    poolDictionaries: ''
    category: '100Doors'

initialize: anInteger
    "initialize the receiver with the given number of doors"
    count := anInteger.
    doors := OrderedCollection new.
    anInteger timesRepeat: [ doors add: Door new ]

pass
    "iterate over the doors"
    1 to: count do: [ :i | self passBy: i ]

passBy: anInteger
    "if the nth door is open close it otherwise open it"
    doors by: anInteger do: [ :door | door toggle ]

printOn: aStream
    "print  the open doors"
    aStream cr.
    doors withIndexDo: [ :door :i | door isOpen ifTrue: [ aStream nextPutAll: i asString, ' is open'; cr ]]

Corridor class

pass: anInteger
    "return a new Corridor with the given number of doors that has been passed thru"
    ^self new
        initialize: anInteger;
        pass


==================================================================

Object subclass: #Door
    instanceVariableNames: 'isOpen'
    classVariableNames: ''
    poolDictionaries: ''
    category: '100Doors'

isOpen
    "Answer the value of isOpen"
    ^ isOpen

toggle
    "if the receiver is open close it else open it"
    isOpen := isOpen not

initialize
    "initialize the receiver to be closed"
    super initialize.
    isOpen := false

===========================================================
Patch to iterate over a collection by each nth item

OrderedCollection>>by: anInteger do: aBlock
    | index |
    index := anInteger.
    [index <= lastIndex]
        whileTrue:
            [aBlock value: (array at: index).
            index := index + anInteger]


Probably silly for the problem given but just my 2 cents
John


--
http://john-mckeon.us/seaside

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Teaching Smalltalk

Hannes Hirzel
No I do not think it is silly.
It is a simple example and illustrates the OO paradigm.

This would be a nice case for a video. That brings out the usefulness
of the tools.

--Hannes

On 5/4/10, John McKeon <[hidden email]> wrote:

> Looking at rosettacode <http://rosettacode.org/wiki/100_doors> most
> languages look nearly identical (or, at the very least, ugly/crappy) when
> written out procedurely so that one might end up deciding to just stick with
> C.
>
> I know I am going off the deep end a bit, but the whole answer to "why
> Smalltalk?" lies in the fact that problems should/would be approached in a
> completely different manner. As I am sure they would in most of the other
> languages if one were not restricted to 20 or so lines of code.
>
> Since it is example code, at least in the case of Smalltalk, an object
> oriented solution would be in order - i.e. show how it would be solved using
> "everything is an object". Unfortunately, it doesn't really fit into "a few
> lines of code" to display on a page (even though the classes/objects and
> code required to implement them is little more than a few lines). And you
> also don't get any feel for the great tools. Perhaps, some insight into how
> one would run the code in Java/Eclipse, or Visual C <chuckle> with all the
> includes and project setup, etc might be a useful addition to the
> comparisons...
>
> Object subclass: #Corridor
>     instanceVariableNames: 'doors count'
>     classVariableNames: ''
>     poolDictionaries: ''
>     category: '100Doors'
>
> initialize: anInteger
>     "initialize the receiver with the given number of doors"
>     count := anInteger.
>     doors := OrderedCollection new.
>     anInteger timesRepeat: [ doors add: Door new ]
>
> pass
>     "iterate over the doors"
>     1 to: count do: [ :i | self passBy: i ]
>
> passBy: anInteger
>     "if the nth door is open close it otherwise open it"
>     doors by: anInteger do: [ :door | door toggle ]
>
> printOn: aStream
>     "print  the open doors"
>     aStream cr.
>     doors withIndexDo: [ :door :i | door isOpen ifTrue: [ aStream
> nextPutAll: i asString, ' is open'; cr ]]
>
> Corridor class
>
> pass: anInteger
>     "return a new Corridor with the given number of doors that has been
> passed thru"
>     ^self new
>         initialize: anInteger;
>         pass
>
>
> ==================================================================
>
> Object subclass: #Door
>     instanceVariableNames: 'isOpen'
>     classVariableNames: ''
>     poolDictionaries: ''
>     category: '100Doors'
>
> isOpen
>     "Answer the value of isOpen"
>     ^ isOpen
>
> toggle
>     "if the receiver is open close it else open it"
>     isOpen := isOpen not
>
> initialize
>     "initialize the receiver to be closed"
>     super initialize.
>     isOpen := false
>
> ===========================================================
> Patch to iterate over a collection by each nth item
>
> OrderedCollection>>by: anInteger do: aBlock
>     | index |
>     index := anInteger.
>     [index <= lastIndex]
>         whileTrue:
>             [aBlock value: (array at: index).
>             index := index + anInteger]
>
>
> Probably silly for the problem given but just my 2 cents
> John
>
>
> --
> http://john-mckeon.us/seaside
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
12