Recent

Author Topic: Native hash-maps in FPC  (Read 4339 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2402
    • UVviewsoft
Native hash-maps in FPC
« on: September 04, 2018, 10:41:35 pm »
IMO it will be good Pascal extension if FPC supports hash-maps (in python - dictionary).
Must extend Pascal syntax for it.
const V: TMap = [1: 'test', 'zzz': 20, True: 12.34] will be ok.

ps.
DLang 2.x released with hash-maps. (makes native code.)
« Last Edit: September 04, 2018, 10:43:57 pm by Alextp »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Native hash-maps in FPC
« Reply #1 on: September 04, 2018, 10:45:38 pm »
D also has garbage collection. Apparently not all its choices are sane :-)

AlexTP

  • Hero Member
  • *****
  • Posts: 2402
    • UVviewsoft
Re: Native hash-maps in FPC
« Reply #2 on: September 04, 2018, 10:52:21 pm »
Agree, not all choices.

If it's hard for FPC to make such any-type keys (int,str,object...) then at last homo-genous keys (only int, only str....) will be good. It can be TIntHashmap (only int keys), TStrHashmap (only str).

Advantage: easy usage V[2000] or V['key']

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Native hash-maps in FPC
« Reply #3 on: September 04, 2018, 10:57:18 pm »
In your example there is no typing of the pairs whatsoever. To me this looks like a scripting language construct, not something for a statically compiled language.


AlexTP

  • Hero Member
  • *****
  • Posts: 2402
    • UVviewsoft
Re: Native hash-maps in FPC
« Reply #4 on: September 04, 2018, 10:59:50 pm »
Agree, need types.
Maybe hashmap can be Generic like THashmap<integer, string>
(1st type for key, 2nd for values)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Native hash-maps in FPC
« Reply #5 on: September 04, 2018, 11:01:49 pm »
Well, Maps are library types in FPC. The compiler don't know what a map is.

So you would have to solve that in some way. FPC doesn't have much infrastructure for it.

If you want to implement it, the only example I can think of is maybe the duck typing of for ..in ?

Anyway this all gets horribly complicated for something that is not more than a shorthand. If you have to implement multiple whole new concepts to a language, maybe this feature is not meant to be :-)

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Native hash-maps in FPC
« Reply #6 on: September 04, 2018, 11:12:01 pm »
Indeed. FPC has some pretty good dictionaries(=maps, a hashmap is a specialzation we also have). in FGL and rtl-generics.
What really is incomprehensible is that you compare it to Python.
Note a hashmap is not a dictionary, it is a specialized form of a dictionary.
It it readily available.
« Last Edit: September 04, 2018, 11:13:58 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Native hash-maps in FPC
« Reply #7 on: September 04, 2018, 11:12:26 pm »
FPC already contains map types (fgl.TFPGMap<,> and Generics.Collections.TDictionary<,> to name two). I see no real reason to add yet another type plus a syntax to initialize them in constant/variable declarations. In the end they are rather complicated data structures so that they can't be easily stored in the binary's data section anyway so you can just as well initialize them in code instead.

 

TinyPortal © 2005-2018