Forum > Suggestions

CASE statement with strings.

<< < (3/6) > >>

Remy Lebeau:

--- Quote from: Leledumbo on August 27, 2012, 05:36:30 pm ---
--- Quote ---btw the FPC 2.6.0 reference guide (pdf) makes no mention of this...
--- End quote ---
Please report a missing documentation, it's documented somewhere AFAIR (but I can't find it now).

--- End quote ---

https://www.freepascal.org/docs-html/ref/refsu56.html


--- Quote ---Free Pascal allows the use of strings as case labels, and in that case the case variable must also be a string. When using string types, the case variable and the various labels are compared in a case-sensitive way.


--- 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";}};} ---Case lowercase(OS) of   ’windows’,   ’dos’   : WriteLn (’Microsoft playtform);   ’macos’,   ’darwin’ : Writeln(’Apple platform’);   ’linux’,   ’freebsd’,   ’netbsd’ : Writeln(’Community platform’);  else    WriteLn (’Other platform’);  end;
The case with strings is equivalent to a series of if then else statements, no optimizations are performed.

However, ranges are allowed, and are the equivalent of an


--- 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";}};} ---if (value>=beginrange) and (value<=endrange) then    begin    end;
--- End quote ---

BeniBela:

--- Quote from: Remy Lebeau on May 07, 2020, 06:57:25 pm ---
The case with strings is equivalent to a series of if then else statements, no optimizations are performed.


--- End quote ---

Business as usual

A great idea and then a crap implementation

It should use a trie or at least a hashmap

Thaddy:

--- Quote from: BeniBela on May 07, 2020, 08:08:42 pm ---A great idea and then a crap implementation

--- End quote ---
Well, since you are opiniated, I am too: A lousy idea deserves a mediocre implementation at best. Not even that.
Switch to a scripting language.

To illustrate the best optimization available would be a collision free hash. case hashOf('string'|); (I used such techniques, but abandoned them)
Problem is they do not exist in an easily- speed - computable form. Some say if at all.
https://en.wikipedia.org/wiki/Perfect_hash_function
Best I came up with is a cuckoo hash, also available in several forms in the rtl.generics package .

winni:

--- Quote from: BeniBela on May 07, 2020, 08:08:42 pm ---
A great idea and then a crap implementation


--- End quote ---

I waited over 30 years for that feature.
I love it.

So I don't care about the implementation.

Winni

Thaddy:
As long as you grasp that it is slow by definition, that's fine with me, Winni.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version