User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 456,601 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,464 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser: Programming Forums
Views: 1244 | Replies: 4
Reply
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

A C++ Tutorial Converted to Smalltalk:

  #1  
Sep 7th, 2007
Since i am going to have to learn Smalltalk well enough to convert it to .NET ( or so i have been told )

i decided to convert some of the C++ tutorials to Smalltalk.

Namely this one:

Write a program which performs addition, subtraction, multiplication of matrices. The dimensions of both the matrices would be specified by the user (dynamic memory allocation required). Use of structure or a class to define the matrix would be a good idea. (Expert)

Here is the output,

in its current state it can only add matrices but i will manage that later on.

I would have loved to uses classes and methods like in any modern language but since the version we are using here at work is about 12 years old and adding support for classes is cryptic at best i will simply hold out for now and submit my sad version :lol:

"
 Adding matrices together
"
| matriceA matriceB matriceResult matriceHeight matriceWidth mCountH mCountW mMessage |
 Transcript clear.
 
 "setup the initial heights and widths"
 matriceHeight := 0.
 matriceWidth := 0.
 [ ( ( matriceHeight > 0 ) & ( matriceWidth > 0 ) ) ] whileFalse: [
  matriceHeight := ( Dialog request: 'Please enter the height of the matrices' initialAnswer: 2 ) asNumber.
  matriceWidth := ( Dialog request: 'Please enter the width of the matrices' initialAnswer: 2 ) asNumber.
 ].
 
 "Create a collection at MatriceA, this collection is matriceHeight in size with each item being matriceWidth in size"
 matriceA := OrderedCollection new.
 matriceB := OrderedCollection new.
 matriceResult := OrderedCollection new.
 "used to count through the array and build elements"
 mCountH := 1.
 mCountW := 1.
 [ mCountW <= matriceWidth ] whileTrue: [
  "declare the jagged array"
  matriceA add: ( OrderedCollection new ).
  matriceB add: ( OrderedCollection new ).
  matriceResult add: ( OrderedCollection new ).
  mCountW := mCountW + 1.
 ].
 "reset counters for later use"
 mCountW := 1.
 "request users to fill in matrice A"
 [mCountW <= matriceWidth ] whileTrue: [
  [mCountH <= matriceHeight ] whileTrue: [
   ( matriceA at: mCountW ) add: 
     ( (Dialog request: 'MATRICE A' cr, 'please fill in the value at ' cr, mCountW printString, ',', mCountH printString initialAnswer: 0) asNumber ).
   mCountH := mCountH + 1.
  ].
  mCountH := 1.
  mCountW := mCountW + 1.
 ].
 mCountW := 1.
 "request users to fill in matrice B"
 [mCountW <= matriceWidth ] whileTrue: [
  [mCountH <= matriceHeight ] whileTrue: [
   ( matriceB at: mCountW ) add: 
     ( (Dialog request: 'MATRICE B' cr, 'please fill in the value at ' cr, mCountW printString, ',', mCountH printString initialAnswer: 0) asNumber ).
   mCountH := mCountH + 1.
  ].
  mCountH := 1.
  mCountW := mCountW + 1.
 ].
 mCountW := 1.
 mCountH := 1.
 
 "do math to add matrices"
 [ mCountW <= matriceWidth ] whileTrue: [
  [ mCountH <= matriceHeight ] whileTrue: [
   ( matriceResult at: mCountW ) add: ( ( ( matriceA at: mCountW ) at: mCountH )  + ( ( matriceB at: mCountW ) at: mCountH ) ).
    mCountH := mCountH + 1.
  ].
  mCountH := 1.
  mCountW := mCountW + 1.
 ].
 mCountH :=1.
 mCountW :=1.
 "Build message to draw Matrice"
 mMessage := 'The Matricies to be added:'cr.
 [ mCountH <= matriceHeight ] whileTrue: [
  [ mCountW <= matriceWidth ] whileTrue: [
   ( mCountW = 1 ) ifTrue: [
    mMessage := mMessage, '| ', ( ( matriceA at: mCountW ) at: mCountH ) printString.
   ] ifFalse: [
    ( mCountW = matriceWidth ) ifTrue: [
     mMessage := mMessage , ' , ', ( ( matriceA at: mCountW ) at: mCountH ) printString, ' |' tab.
    ] ifFalse: [
     mMessage := mMessage , ' , ', ( ( matriceA at: mCountW ) at: mCountH ) printString.
    ].
   ].
   mCountW := mCountW + 1.
  ].
  mCountW := 1.
  [ mCountW <= matriceWidth ] whileTrue: [
   ( mCountW = 1 ) ifTrue: [
    mMessage := mMessage, '| ', ( ( matriceB at: mCountW ) at: mCountH ) printString.
   ] ifFalse: [
    ( mCountW = matriceWidth ) ifTrue: [
     mMessage := mMessage , ' , ', ( ( matriceB at: mCountW ) at: mCountH ) printString, ' |' cr.
    ] ifFalse: [
     mMessage := mMessage , ' , ', ( ( matriceB at: mCountW ) at: mCountH ) printString.
    ].
   ].
   mCountW := mCountW + 1.
  ].  
  mCountW := 1.
  mCountH := mCountH + 1.
 ].
 Dialog warn: mMessage.
 
 "reset the counters"
 mCountW := 1.
 mCountH := 1.
 
 mMessage := 'And the Result is:'cr.
 [ mCountH <= matriceHeight ] whileTrue: [
  [ mCountW <= matriceWidth ] whileTrue: [
   ( mCountW = 1 ) ifTrue: [
    mMessage := mMessage, '| ', ( ( matriceResult at: mCountW ) at: mCountH ) printString.
   ] ifFalse: [
    ( mCountW = matriceWidth ) ifTrue: [
     mMessage := mMessage , ' , ', ( ( matriceResult at: mCountW ) at: mCountH ) printString, ' |' cr.
    ] ifFalse: [
     mMessage := mMessage , ' , ', ( ( matriceResult at: mCountW ) at: mCountH ) printString.
    ].
   ].
   mCountW := mCountW + 1.
  ].
  mCountW := 1.
  mCountH := mCountH + 1.
 ].
 
 Dialog warn: mMessage.

The language does a good job at over complicating itself in it's current state.

To even save a file is a hassle.

One must copy what they are working on from their "workspace" open up the file browser, type in the location of the directory in which you wish to save the file, then you must paste the contents of your file into the browsers lower pane and middle+click save as and give the directory name / file name.st and save.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 3
Reputation: dare_devil is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dare_devil dare_devil is offline Offline
Newbie Poster

Re: A C++ Tutorial Converted to Smalltalk:

  #2  
Sep 8th, 2007
which smalltalk are u using ?
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: A C++ Tutorial Converted to Smalltalk:

  #3  
Sep 8th, 2007
Originally Posted by dare_devil View Post
which smalltalk are u using ?


VisualWorks

www.cincomsmalltalk.com

At work we are using version 2.5.1 even though they are currently on version 7+
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Sep 2007
Posts: 3
Reputation: dare_devil is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dare_devil dare_devil is offline Offline
Newbie Poster

Re: A C++ Tutorial Converted to Smalltalk:

  #4  
Sep 9th, 2007
To write a method you do not need to use workspace. You do write code in lower pane of Browser itself and do accept to save it. And you do not need to save files individually. Just do Save Image.
You need to file-out the files only when you need to have a backup of a single method or a class only.

It is completely diffrent kind of IDE from the regular onces like Eclipse, Netbeans, Visual Studio.

Have you read the tutorials which comes with installation package ?
Also there are lots of free books for Smalltalk on http://www.iam.unibe.ch/~ducasse/FreeBooks.html
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: A C++ Tutorial Converted to Smalltalk:

  #5  
Sep 9th, 2007
actually have a handfull of those books at work. the only important ones to use are from visual works or just smalltalk80 books because of the age of the distro we are using.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Legacy and Other Languages Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Legacy and Other Languages Forum

All times are GMT -4. The time now is 7:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC