From Java to Smalltalk

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

From Java to Smalltalk

Andrea Gammachi
Hi. I'd like to know how to convert some simple Java code and values to Smalltalk. Hope anybody can help me, please no laughs, I have no idea of java:

4L
800000000L
aString.lastIndexOf("/");  ??

Does anybody know a chart of conversion table/guide from X language to Smalltalk?

Cheers


Reply | Threaded
Open this post in threaded view
|

Re: From Java to Smalltalk

Martin McClure
Andrea Gammachi wrote:
> Hi. I'd like to know how to convert some simple Java code and values to
> Smalltalk. Hope anybody can help me, please no laughs, I have no idea of
> java:
>

Having no idea of Java is for the best :-)

I spent three years doing Java but have been happily back to Smalltalk
for five years now. Let's see if I remember enough Java to answer your
question.

> 4L
> 800000000L

These are integer literals -- the "L" suffix indicates they are of type
long. The closest Smalltalk equivalent is to just remove the "L" which
makes them integer literals.

However, the behavior is slightly different -- if you add one to the
most positive possible Java long I believe you get the most negative
possible Java long. In Smalltalk, integers do not have a fixed range, so
adding one to any integer always gives you a more positive integer. This
difference is unlikely to cause problems in most programs moved from
Java to Smalltalk.


> aString.lastIndexOf("/");  ??

This should be pretty close:

   aString lastIndexOf: $/

Be careful of how the indexes are being used -- Smalltalk assigns the
index 1 to the first character in a string, while I believe Java assigns
that character the index 0.

These methods may also differ in how they handle the case in which *no*
/ is found.

Regards,

-Martin

Reply | Threaded
Open this post in threaded view
|

Re: From Java to Smalltalk

Jason Rogers-4
On 7/5/06, Martin McClure <[hidden email]> wrote:

> > aString.lastIndexOf("/");  ??
>
> This should be pretty close:
>
>    aString lastIndexOf: $/
>
> Be careful of how the indexes are being used -- Smalltalk assigns the
> index 1 to the first character in a string, while I believe Java assigns
> that character the index 0.
>
> These methods may also differ in how they handle the case in which *no*
> / is found.

Yes, they do.  In Java if the $/ isn't there you get back a -1, in
Smalltalk you get back a 0.

--
Jason Rogers

"Where there is no vision, the people perish..."
    Proverbs 29:18

Reply | Threaded
Open this post in threaded view
|

Re: From Java to Smalltalk

Roger Whitney
In reply to this post by Andrea Gammachi
Attached is a small conversion table between Java and Smalltalk. It  
does not cover the questions below, but hope it helps.



On Jul 5, 2006, at 2:53 PM, Andrea Gammachi wrote:

> Hi. I'd like to know how to convert some simple Java code and  
> values to Smalltalk. Hope anybody can help me, please no laughs, I  
> have no idea of java:
>
> 4L
> 800000000L
> aString.lastIndexOf("/");  ??
>
> Does anybody know a chart of conversion table/guide from X language  
> to Smalltalk?
>
> Cheers
>
>

----
Roger Whitney              Department of Computer Science
[hidden email]        San Diego State University
http://www.eli.sdsu.edu/   San Diego, CA 92182-7720
(619) 583-1978
(619) 594-3535 (office)
(619) 594-6746 (fax)


Java-Smalltalk Rosetta Stone.pdf (36K) Download Attachment