How about TBucketList?The problem I see with pascal is there is no single way to do it, you have way too many options.
In PHP everyone uses consistent syntax for the associative array. In php, if you want to use an associative array, you use the associative array.. In pascal we have all sorts of ways of doing it.
That is because PHP is hardly typed, and quite often stringly typed. Pascal is strong typed, and stringly typing is not done.
So the problem is that you transfer a concept from PHP to Pascal, and then conclude there is no good way. That's not true, you are trying to solve problems the PHP way. Don't! This is Pascal!
Because arrays in PHP are by default associative and it's a language construct (and no, you can't modify its complexity without recompiling the whole interpreter). In Pascal, it's implemented as a user defined type, contained in certain units.
{ Library: Fundamentals 4.00 }{ File name: cDataStructs.pas }{ File version: 4.31 }{ Description: Data structures }....DICTIONARIES Dictionaries are associative arrays where the key value is a string. Associative arrays, also referred to as mappings, are unordered collections where an arbitrary key can be used to index a value. This unit implements dictionary classes for each of the following types: + Integer + Cardinal + Int64 + Single + Double + Extended + Pointer + String + TObject + IInterface For example, the class TIntegerDictionary is used where the key is an arbitrary string and the value an integer. Ages := TIntegerDictionary.Create; Ages['John'] := 29; Ages['Tori'] := 35; if Ages.HasKey['John'] then Ages.Delete('John'); Ages.Free;
why can't we create a standard TAssociativeArray instead of renaming it HashList BucketList and all these things
I understand in some cases that some data structures are better than others in different situations.. Imagine if there was a TAssociativeArray and everyone just used that when they wanted an associative array.. that would end all the trouble, no?
Or how about IntToStr.. no one goes and reinvents IntToStr in there own units, we all use a standard IntToStr function since it has been created for us. Even though someone could reinvent IntToStr, most of us use the standard one provided. So if there was a standard associative array available... It would be good.
Quote from: marcov on January 31, 2012, 10:17:59 pmThat is because PHP is hardly typed, and quite often stringly typed. Pascal is strong typed, and stringly typing is not done.Actually in Pascal people use stringlists and use Name=Value pairs which emulates associative arrays,
Pascal is not fully strongly typed, that is why you use pointers in TLists which is dangerous and requires ugly casting that bloats up the source with line noise. generics and some other things help solve it, but as I am a minimalist I would like to see something simple without generics.
If generics is required to do it then i would use that.
But what about TBucketList
and what about your suggestion of using stringlist with arrays? I don't understand what you would do with arrays/stringlist.
would it require any pointers or casting?
Quote from: marcov on January 31, 2012, 10:17:59 pmSo the problem is that you transfer a concept from PHP to Pascal, and then conclude there is no good way. That's not true, you are trying to solve problems the PHP way. Don't! This is Pascal!I never concluded that there was no good way in pascal, I meant: how you would do this particular example with stringlists and arrays added to the stringlist like you suggested in this old post?
I would like to see something like TAssociativeArray in pascal, why can't that be done? We just call it something else because associative array is not the right name for it?
for i:='one' to 'four' do ;
What sucks greatly about PHP is that it has no STRUCT or RECORD. I do not like PHP, I was simply saying that at least PHP has an associative array that everyone uses consistently,
"ugly pointers and casts" -- There are two features that make (some) programming languages really powerful: pointers and recursion. Mastering those two is an almost lost art.
And IMO there is no need to work with pointers if having decent arrays, I have made tons of programs, used in the real world, and I have never used any pointers, but relied on the arrays etc (which might be created by the artists, and from my point of view something the compiler shall deal with, not me) in the toolbox I have been using.This is also why I like Pascal so much, as I do not need to enter the lions pit, and by the end of the day that is what keeping me productive.
I have been wondering how some of you would solve this programming exercise
I have been wondering how some of you would solve this programming exercise:
Read the description, get vibe that it is probably NP complete, unassign myself, and assign it to the person with a mathematics degree :-)