Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collections and Stream classes equivalences between Smalltalk, Perl, Python and Ruby

I have few experience with languages like Python, Perl and Ruby, but I have developed in Smalltalk from some time. There are some pretty basic Smalltalk classes which are very popular and cross-Smalltalk implementation:

FileStream
ReadWriteStream
Set
Dictionary
OrderedCollection
SortedCollection
Bag
Interval
Array

Which classes would be the equivalent or valid semantic replacements in Python, Perl and Ruby? I've found several language comparison pages comparing syntax, however it seems there is little help when comes to the translation of core and base libraries.

I also wonder if there is a base or core class in Python, Perl or Ruby which is not present in Smalltalk or viceversa?

like image 420
user869097 Avatar asked Aug 25 '11 01:08

user869097


2 Answers

Perl

I'll answer for Perl, since I'm fluent in both Perl and Smalltalk.

Smalltalk's Dictionary is fairly close to Perl's hash type. A Dictionary uses object equivalence for the keys. Perl uses simple strings for keys, so the flexibility is somewhat limited.

Smalltalk's OrderedCollection is fairly close to Perl's array type.

Smalltalk's FileStream is somewhat like Perl's filehandles, in the sense that they represent a stream of data to an external file or device.

And that's about it, since Perl has only hashes and arrays and filehandles. :)

like image 145
Randal Schwartz Avatar answered Oct 21 '22 15:10

Randal Schwartz


Ruby

FileStream         -> File
ReadWriteStream    -> IO (or other things that duck type like it)
Set                -> require 'set', then use the Set class
Dictionary         -> Hash
OrderedCollection  -> Array
SortedCollection      nothing similar
Bag                   nothing similar
Interval           -> Range
Array                 Ruby has no fixed-length collection class.
like image 34
Ken Bloom Avatar answered Oct 21 '22 15:10

Ken Bloom