Recent

Author Topic: Pascal programs in the Rosetta Code collection  (Read 1915 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Pascal programs in the Rosetta Code collection
« Reply #15 on: August 10, 2019, 06:53:39 pm »
This entry is an exception. Added code for review.
Most people that want to use threading should learn to patch their jeans first: use a needle.

avk

  • Full Member
  • ***
  • Posts: 123
    • my self-education project
Re: Pascal programs in the Rosetta Code collection
« Reply #16 on: August 10, 2019, 07:13:03 pm »
@julkas, I beleave I understand what you are talking about: you do not like some of the Pascal suggestions. Well, after all, the wiki article mentioned in the first post is just about that. Correct what seems wrong to you if you are sure that you are doing the right thing, or add another solution.

@rvk, do they have any basis for this separation?

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Pascal programs in the Rosetta Code collection
« Reply #17 on: August 10, 2019, 07:28:59 pm »
@rvk, do they have any basis for this separation?
There is: on Rosetta code some entries are categorized depending on flavor, which is highly confusing.
But in this case the code is quite good.(imnsho). for the record: I did not write that entry.

Except:
https://rosettacode.org/wiki/Sieve_of_Eratosthenes#Delphi which has a lot to be desired. (And does not compile!)

I really wonder what entry he is referring to..
« Last Edit: August 10, 2019, 07:41:59 pm by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.

rvk

  • Hero Member
  • *****
  • Posts: 3836
Re: Pascal programs in the Rosetta Code collection
« Reply #18 on: August 10, 2019, 07:38:22 pm »
@rvk, do they have any basis for this separation?
There is a Object Pascal category.
https://rosettacode.org/wiki/Category:Object_Pascal

So it only seems logical that Object Pascal solutions would be in that category.
(And I think this qualifies as a OP solution)

Most Pascal solutions are just pure standard pascal. Otherwise it wouldn't make sense to have a separate OP category. But maybe I'm wrong.

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Pascal programs in the Rosetta Code collection
« Reply #19 on: August 10, 2019, 07:43:48 pm »
Well, if you mean that there is no object pascal entry for the sieve you are right, but the pascal entries are both sound. The delphi entry is not.

So are you going to add it? Or shall I do it? It is a 10 minute job.... O:-)
« Last Edit: August 10, 2019, 07:45:19 pm by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.

avk

  • Full Member
  • ***
  • Posts: 123
    • my self-education project
Re: Pascal programs in the Rosetta Code collection
« Reply #20 on: August 10, 2019, 07:53:11 pm »
@rvk, I am wondering if there is any standard that documents this separation (marketing slogans of commercial companies do not matter).
Heh, Ada-83, Ada-95 and Ada-2007 are different languages? Note that they have one entry.

rvk

  • Hero Member
  • *****
  • Posts: 3836
Re: Pascal programs in the Rosetta Code collection
« Reply #21 on: August 10, 2019, 08:20:39 pm »
@rvk, I am wondering if there is any standard that documents this separation (marketing slogans of commercial companies do not matter).
Heh, Ada-83, Ada-95 and Ada-2007 are different languages? Note that they have one entry.
Yes, but if there were such a seperation, one should put the code in the correct category.
I'm not aware of any official document explaining the seperation between Pascal, Object Pascal and Delphi. Also, when needed, one could add languages.

I'm not sure if there are more Object Pascal solutions posted in the Pascal category. The Object Pascal category seems to have much less entries.

So are you going to add it? Or shall I do it? It is a 10 minute job.... O:-)
You could do it. I'm on a little mobile screen at the moment  ::)

avk

  • Full Member
  • ***
  • Posts: 123
    • my self-education project
Re: Pascal programs in the Rosetta Code collection
« Reply #22 on: August 10, 2019, 08:38:30 pm »
Yes, but if there were such a seperation, one should put the code in the correct category.
I'm not aware of any official document explaining the seperation between Pascal, Object Pascal and Delphi. Also, when needed, one could add languages...
I believe that this separation was created by the contributors themselves. I would not want to aggravate this.

julkas

  • Sr. Member
  • ****
  • Posts: 382
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Pascal programs in the Rosetta Code collection
« Reply #24 on: August 11, 2019, 05:28:18 pm »
Most people that want to use threading should learn to patch their jeans first: use a needle.

julkas

  • Sr. Member
  • ****
  • Posts: 382
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Pascal programs in the Rosetta Code collection
« Reply #26 on: August 11, 2019, 06:03:39 pm »
That Delphi code: nothing wrong except maybe inline. Also compiles with FPC.
« Last Edit: August 11, 2019, 07:57:44 pm by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.

avk

  • Full Member
  • ***
  • Posts: 123
    • my self-education project
Re: Pascal programs in the Rosetta Code collection
« Reply #27 on: August 12, 2019, 12:50:32 pm »
Can this be suggested as a simple variant for the "Sieve of Eratosthenes" task?
Code: Pascal  [Select]
  1. program prime_sieve;
  2. {$mode objfpc}{$H+}
  3. uses
  4.   SysUtils;
  5. const
  6.   MAX_PRIME_LIMIT = {$ifdef cpu32}1024*1024*1024{$else}High(Integer){$endif};
  7. type
  8.   TIntArray = array of Integer;
  9.  
  10. function EstimatePrimeCount(aLimit: Integer): Integer; inline;
  11. begin
  12.   if aLimit <= 200 then
  13.     Result := Trunc((1.6 * aLimit)/Ln(aLimit)) + 1
  14.   else
  15.     Result := Trunc(aLimit/(Ln(aLimit) - 2)) + 1;
  16. end;
  17.  
  18. function SelectPrimes(aLimit: Integer): TIntArray;
  19. var
  20.   IsPrime: array of Boolean;
  21.   I, UpBound: Integer;
  22.   Counter: Integer = 0;
  23.   J: Int64;
  24. begin
  25.   SetLength(IsPrime, Succ(aLimit));
  26.   FillChar(Pointer(IsPrime)^, Succ(aLimit), Byte(True));
  27.   UpBound := Trunc(Sqrt(aLimit));
  28.   for I := 2 to UpBound do
  29.     if IsPrime[I] then
  30.       begin
  31.         J := Int64(I) * Int64(I);
  32.         while J <= aLimit do
  33.           begin
  34.             IsPrime[J] := False;
  35.             Inc(J, I);
  36.           end;
  37.       end;
  38.   SetLength(Result, EstimatePrimeCount(aLimit));
  39.   for I := 2 to aLimit do
  40.     if IsPrime[I] then
  41.       begin
  42.         Result[Counter] := I;
  43.         Inc(Counter);
  44.       end;
  45.   SetLength(Result, Counter);
  46. end;
  47.  
  48. var
  49.   Primes: TIntArray;
  50.   Limit: Integer = -1;
  51.   I: Integer;
  52.  
  53. function ReadLimit: Boolean;
  54. var
  55.   Lim: DWord;
  56. begin
  57.   if (ParamCount <> 1) or not DWord.TryParse(ParamStr(1), Lim) then
  58.     exit(False);
  59.   if (Lim < 2) or (Lim > MAX_PRIME_LIMIT) then
  60.     exit(False);
  61.   Limit := Integer(Lim);
  62.   Result := True;
  63. end;
  64.  
  65. begin
  66.   if not ReadLimit then
  67.     begin
  68.       WriteLn('Usage: prime_sieve Limit');
  69.       WriteLn('  where Limit in the range [2, ', MAX_PRIME_LIMIT, ']');
  70.       Halt;
  71.     end;
  72.   Primes := SelectPrimes(Limit);
  73.   for I := 0 to High(Primes) - 1 do
  74.     Write(Primes[I], ', ');
  75.   WriteLn(Primes[High(Primes)]);
  76. end.
  77.  

julkas

  • Sr. Member
  • ****
  • Posts: 382
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Pascal programs in the Rosetta Code collection
« Reply #28 on: August 12, 2019, 01:05:06 pm »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Pascal programs in the Rosetta Code collection
« Reply #29 on: August 12, 2019, 01:18:02 pm »
Most people that want to use threading should learn to patch their jeans first: use a needle.