Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smalltalk - Dictionary equivalent that takes alphanumeric as key?

Tags:

smalltalk

Is there a Dictionary equivalent that will accept alphanumerics as the key? After spending some time on here getting you guys to help with assigning UUID values, I now realize that Dictionaries only take integers. I had planned on using the UUID as the key.

My design is for a General Ledger - my ledger member is initialized as ledger := Dictionary new, and I had hoped on doing something along the lines of:

postTransaction: GLEntry
    ledger at: GLEntry UID put: GLEntry
like image 380
MrDuk Avatar asked Jan 29 '26 12:01

MrDuk


1 Answers

A Dictionary can use anything you like as a key. Using Strings for keys in a Dictionary is quite common. For example, in Dolphin Smalltalk v6.x evaluating the following:

d := Dictionary new.

d
  at: 'a' put: 'a string';
  at: 'b' put: 'b string';
  at: 'c' put: 'c string'.

Transcript
  show: (d at: 'a'); cr;
  show: (d at: 'b'); cr;
  show: (d at: 'c'); cr

will result in

a string
b string
c string

being shown in the Transcript window.

Share and enjoy.

like image 91


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!