Question about Ivan Tomek's Introduction to VW 
Author Message
 Question about Ivan Tomek's Introduction to VW

Hello,

Quote:

> Hi,

> I'm new to Smalltalk. I started by reading through Ivan Tomek's Introduction
> to VW Smalltalk. There are few things I don't get.

> 1] When trying to execute following example with "Print it" I got an
> exception: Message not understood: #withKeysAndValues. I've tried to locate
> the method but with a little success. It looks like it isn't implemented in
> the system. What do I miss? Do I need to load any additional parcels or
> something?

> Dictionary withKeysAndValues:
>  #('overdo' 'do to death, go to extremes' 'overheated' 'agitated, e{*filter*}d'
> 'playmate' 'buddy, companion')

I've never seen the selector #withKeysAndValues: in VisualWorks, so
maybe Ivan has added it himself to
the base image.
You could replace the code with:
Dictionary
        with: (Association key:'overdo' value:'do to death, go to extremes')
        with: 'overheated'->'agitated, e{*filter*}d'
        with: 'playmate'->'buddy, companion'
This instantiates a dictionary, and fills it with 3 associations.
(your next assignment is: implement ##withKeysAndValues: , to make the
example code work ;-)

- Show quoted text -

Quote:

> 2] When trying this example

> | price tax total |
> price := (Dialog request: 'Please enter price' initialAnswer: '100')
> asNumber.
> tax := (Dialog request: 'Please enter price %'  initialAnswer: '10')
> asNumber.

> self halt.

> total := price + (price * tax / 100).
> Transcript clear;
>  show: 'price: ', price printString; cr;
>  show: 'tax: ', tax printString; cr;
>  show: 'total: ', total printString

> I expected an Exception window saying 'Halt encountered' to open as
> described in text however I got the following message instead.

> Attempt to read the receiver in a context where it is not permitted

It seems workspaces in VW5i can not use 'self' anymore.
Up to VW3 this code would work ('self' would refer to 'an
UndefinedObject', or 'nil'
You can make the code work by replacing 'self' with any object, like
'Object' or 'nil'

good luck,

Tom Kroon



Mon, 15 Mar 2004 04:30:41 GMT  
 Question about Ivan Tomek's Introduction to VW
Hi,

Method withkeysAndValues: was part of VsualWorks until the latest release. The
following is the old definition that was included as a class method in classes
Dictionary and MethodDictionary:

withKeysAndValues: keyAndValueArray
 " Answer an instance whose keys and values  are obtained from alternate elements
of the keyAndValueArray. "

 | dict |
 dict := self new: keyAndValueArray size.
 1 to: keyAndValueArray size by: 2 do: [:i |
  dict at: (keyAndValueArray at: i) put: (keyAndValueArray at: i + 1)].
 ^dict

The reason that it is in my Introduction is that I wrote it without any knowledge
of VW 5i.4 and didn't know that it was removed.

Ivan

Quote:

> Hello,


> > Hi,

> > I'm new to Smalltalk. I started by reading through Ivan Tomek's Introduction
> > to VW Smalltalk. There are few things I don't get.

> > 1] When trying to execute following example with "Print it" I got an
> > exception: Message not understood: #withKeysAndValues. I've tried to locate
> > the method but with a little success. It looks like it isn't implemented in
> > the system. What do I miss? Do I need to load any additional parcels or
> > something?

> > Dictionary withKeysAndValues:
> >  #('overdo' 'do to death, go to extremes' 'overheated' 'agitated, e{*filter*}d'
> > 'playmate' 'buddy, companion')

> I've never seen the selector #withKeysAndValues: in VisualWorks, so
> maybe Ivan has added it himself to
> the base image.
> You could replace the code with:
> Dictionary
>         with: (Association key:'overdo' value:'do to death, go to extremes')
>         with: 'overheated'->'agitated, e{*filter*}d'
>         with: 'playmate'->'buddy, companion'
> This instantiates a dictionary, and fills it with 3 associations.
> (your next assignment is: implement ##withKeysAndValues: , to make the
> example code work ;-)

> > 2] When trying this example

> > | price tax total |
> > price := (Dialog request: 'Please enter price' initialAnswer: '100')
> > asNumber.
> > tax := (Dialog request: 'Please enter price %'  initialAnswer: '10')
> > asNumber.

> > self halt.

> > total := price + (price * tax / 100).
> > Transcript clear;
> >  show: 'price: ', price printString; cr;
> >  show: 'tax: ', tax printString; cr;
> >  show: 'total: ', total printString

> > I expected an Exception window saying 'Halt encountered' to open as
> > described in text however I got the following message instead.

> > Attempt to read the receiver in a context where it is not permitted

> It seems workspaces in VW5i can not use 'self' anymore.
> Up to VW3 this code would work ('self' would refer to 'an
> UndefinedObject', or 'nil'
> You can make the code work by replacing 'self' with any object, like
> 'Object' or 'nil'

> good luck,

> Tom Kroon



Mon, 15 Mar 2004 20:06:17 GMT  
 Question about Ivan Tomek's Introduction to VW
Dear Domini,
        a few weeks ago, I noted a few points about the 5i3 tutorials which I've been
meaning to email them about or post.  Your message is a covenient opportunity.

Tomek's tutorial in VW5i3
========================
Part 1. 6. Variables
        Rounding the total to two decimal places would look better (c.f. recent
discussion in c.l.s about fixed v floating points).

Part 3. 6. Collection classes are one Smalltalk's greatest strengths.
        typo: missing 'of'

Dictionary withKeysAndValues:
        Dictionary has no such message in VW5i.3. Substitute VW example, e.g.
#keysAndValuesDo: (ideally, make the example dialect-neutral).

Refactoring Browser
        not present in VW5i.3 but soon in 5i.4 so not an issue, so omit caveat

Part 7: Smalltalk style
        This explanation of why Smalltalk has no case construct is too brief and should
explain all the ways case statements are handled in Smalltalk, not just polymorphism.

(You can find my material on this by navigating from

http://wiki.cs.uiuc.edu/CampSmalltalk
        Discussion Topics
                Smalltalk Books
                        Smalltalk for Java Programmers

Near the bottom of this page, the 'new syntax' link takes you to a page at whose
foot the 'control flow' link points to relevant material.)

SLesson Tutorial in VW5i.3
==========================
- The Polymorphism text in LessonBrowser04, "If Inheritance in the real world is
when you get the wealth that someone else has accumulated, then Polymorphism is
when you get the wealth and use it for your own needs." is less than clear
(easier to say that to rewrite it, I concede, plus once you've encountered the
text further on, things get clearer).  My first attempt: "If Inheritance in the
real world is when you get the wealth that someone else has accumulated, then
Polymorphism is when you spend that wealth for purposes unforeseen when you
inherited it."

The 'no switch-case' explanation needs expansion, as in Ivan's tutorial (see
above); polymorphism is _one_ way to avoid case statements, not always the right way.

 - In the ReadStream Lesson, use 'SmallTalk Best Practice Patterns', not 'XP
explained', as the example book.  It is more immediately relevant to the
audience of this material.

In general I'm delighted to see this material.  It makes Smalltalk and VW more
accessible to newbies.

                        Yours faithfully
                                Niall Ross



Mon, 15 Mar 2004 21:12:22 GMT  
 Question about Ivan Tomek's Introduction to VW
Nial,

I am aware of some mistakes and I will correct the text. Thank you for your suggestions.

Ivan

P.S. Where did the 'Domini' come from?

Quote:

> Dear Domini,
>         a few weeks ago, I noted a few points about the 5i3 tutorials which I've been
> meaning to email them about or post.  Your message is a covenient opportunity.

> Tomek's tutorial in VW5i3
> ========================
> Part 1. 6. Variables
>         Rounding the total to two decimal places would look better (c.f. recent
> discussion in c.l.s about fixed v floating points).

> Part 3. 6. Collection classes are one Smalltalk's greatest strengths.
>         typo: missing 'of'

> Dictionary withKeysAndValues:
>         Dictionary has no such message in VW5i.3. Substitute VW example, e.g.
> #keysAndValuesDo: (ideally, make the example dialect-neutral).

> Refactoring Browser
>         not present in VW5i.3 but soon in 5i.4 so not an issue, so omit caveat

> Part 7: Smalltalk style
>         This explanation of why Smalltalk has no case construct is too brief and should
> explain all the ways case statements are handled in Smalltalk, not just polymorphism.

> (You can find my material on this by navigating from

> http://wiki.cs.uiuc.edu/CampSmalltalk
>         Discussion Topics
>                 Smalltalk Books
>                         Smalltalk for Java Programmers

> Near the bottom of this page, the 'new syntax' link takes you to a page at whose
> foot the 'control flow' link points to relevant material.)

> SLesson Tutorial in VW5i.3
> ==========================
> - The Polymorphism text in LessonBrowser04, "If Inheritance in the real world is
> when you get the wealth that someone else has accumulated, then Polymorphism is
> when you get the wealth and use it for your own needs." is less than clear
> (easier to say that to rewrite it, I concede, plus once you've encountered the
> text further on, things get clearer).  My first attempt: "If Inheritance in the
> real world is when you get the wealth that someone else has accumulated, then
> Polymorphism is when you spend that wealth for purposes unforeseen when you
> inherited it."

> The 'no switch-case' explanation needs expansion, as in Ivan's tutorial (see
> above); polymorphism is _one_ way to avoid case statements, not always the right way.

>  - In the ReadStream Lesson, use 'SmallTalk Best Practice Patterns', not 'XP
> explained', as the example book.  It is more immediately relevant to the
> audience of this material.

> In general I'm delighted to see this material.  It makes Smalltalk and VW more
> accessible to newbies.

>                         Yours faithfully
>                                 Niall Ross



Mon, 15 Mar 2004 23:31:55 GMT  
 Question about Ivan Tomek's Introduction to VW
Dear Ivan,

Quote:
> P.S. Where did the 'Domini' come from?

I was replying to the top poster, and assuming you would also read it.  I should
have written 'Dear Domini and Ivan'.

                                Yours faithfully
                                        Niall Ross



Tue, 16 Mar 2004 23:16:55 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. code for Ivan Tomek's book

2. Tomek's JOS: location of examples?

3. Introduction to VW Open Enrollment at KSC

4. Introduction to VW Open Enrollment at KSC

5. VA introduction for VW programers?

6. A C++/Java programmer's introduction to Objective Caml

7. Kid's introduction book?

8. Kid's introduction book?

9. VW - VA Wanted: 'neutral' comparison

10. http://www.mpa-garching.mpg.de/~tomek/

11. http://www.mpa-garching.mpg.de/~tomek/ (mirror sites)

12. http://www.mpa-garching.mpg.de/~tomek/

 

 
Powered by phpBB® Forum Software