Forum > Suggestions
Proposal: Associative String Arrays
marcov:
I was talking about the need for in-language specifically, not the use of maps in general.
Warfley:
Data types that you use often should be language supported. There is technically no need for strings or arrays to be supported on a language level, yet they are because they are that often used that this level of ease is warranted. I argue that this list should be extended by associative array/dictionaries. Hell pascal has sets, and I use a dict much more often than a set
marcov:
I think I use sets more. Great for statemachines and the like.
PascalDragon:
--- Quote from: Warfley on May 11, 2023, 04:24:06 pm ---So my idea was, that this could be added on the language level as simpe associative array:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var map: Array[String] of Integer;begin map['foo'] := 42; if 'foo' in map then WriteLn(map['foo']);end;
On a syntactic level this would not be that dissimilar from the existing associative arrays for enums:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TTest = (test1, test2);var map: Array[TTest] of Integer;
Of course the underlying technology must be differently, as the above will just create an Array with test1..test2, but from a high level view it would not be that different, and be very useful.
--- End quote ---
Classes like Generics.Collections.TDictionary<,> and FGL.TFPGMap<,> already fullfill this purpose and work today and it's much easier to change the implementation than with a compiler-magic type. So, no, I'm against something like this. There are much more important things that need to be implemented that can't be easily done with existing functionality.
Warfley:
--- Quote from: marcov on May 11, 2023, 10:03:20 pm ---I think I use sets more. Great for statemachines and the like.
--- End quote ---
I also like them, but, similarly to the dict, I would like to see them be able to be used with more types like strings or doubles or so, with the compiler internally deciding when to use a hash set for large types and a bit set for small types. Like sets are amazing for ASCII parsing automatas, but for UTF codepoints they are too small
Navigation
[0] Message Index
[#] Next page
[*] Previous page