Recent

Author Topic: functions in pascal  (Read 9341 times)

italyrobert

  • New member
  • *
  • Posts: 7
functions in pascal
« on: March 12, 2021, 04:05:20 pm »
So far I know that arraytypes in Pascal is declared with an array length, but is there functions which might cannot be implemented because of that? and maybe still be written in C# for example?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: functions in pascal
« Reply #1 on: March 12, 2021, 04:08:07 pm »
So far I know that arraytypes in Pascal is declared with an array length, but is there functions which might cannot be implemented because of that? and maybe still be written in C# for example?

It is unclear what you mean. Do you mean static array declaration like

Code: Pascal  [Select][+][-]
  1. var
  2.   v : array[2..10] of integer;
  3.  

or dynamic array usage like

Code: Pascal  [Select][+][-]
  1. var v : array of integer;
  2. begin
  3.   setlength(v,10);
  4. end;

Free Pascal as a language has no relation with C# whatsoever, or do you mean with that which one of these are COM compatible?

italyrobert

  • New member
  • *
  • Posts: 7
Re: functions in pascal
« Reply #2 on: March 12, 2021, 04:37:27 pm »
Hi marcov,

I mean the static array

So as you text I can declare an array type as: type somearray = array [2..10] of integer

So I'm looking for an example of a function which cannot be written in pascal because of this type declaration, but on the other hand is possible to write in C# instead.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: functions in pascal
« Reply #3 on: March 12, 2021, 04:58:20 pm »
Hi marcov,

I mean the static array

So as you text I can declare an array type as: type somearray = array [2..10] of integer

So I'm looking for an example of a function which cannot be written in pascal because of this type declaration, but on the other hand is possible to write in C# instead.

In that case I suggest asking in a C# forum, and then coming back here with the response in case it overlooks something.

I for one have better things to do with my time that gratuitously search for claws in my favoured development tool (which doesn't stop me from being critical when I find any :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cdbc

  • Hero Member
  • *****
  • Posts: 1088
    • http://www.cdbc.dk
Re: functions in pascal
« Reply #4 on: March 12, 2021, 05:00:58 pm »
Hi
Ok then:
Code: Pascal  [Select][+][-]
  1. var
  2.   a: array[2..10] of byte;
  3.   Idx: integer;
  4. begin
  5.   for Idx:= 2 to 10 do begin
  6.     a[Idx]:= Idx;
  7.     writeln('Array of index: ',a[Idx]);
  8.   end;
  9. end;
  10.  

Sometimes life is easy  ;D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

italyrobert

  • New member
  • *
  • Posts: 7
Re: functions in pascal
« Reply #5 on: March 12, 2021, 05:19:09 pm »
Hi
Ok then:
Code: Pascal  [Select][+][-]
  1. var
  2.   a: array[2..10] of byte;
  3.   Idx: integer;
  4. begin
  5.   for Idx:= 2 to 10 do begin
  6.     a[Idx]:= Idx;
  7.     writeln('Array of index: ',a[Idx]);
  8.   end;
  9. end;
  10.  

Sometimes life is easy  ;D
Regards Benny

Hi cdbc,

But this seems to work as I read it in pascal, because the loop is running in the range of the array 1..10, should this not work? and work instead in c#?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: functions in pascal
« Reply #6 on: March 12, 2021, 05:34:43 pm »
So I'm looking for an example of a function which cannot be written in pascal because of this type declaration, but on the other hand is possible to write in C# instead.

I don't know what C# can do into that detail. But what FPC can't (yet) do is having dynamically (runtime) sized arrays  with a non-zero bound.

balazsszekely

  • Guest
Re: functions in pascal
« Reply #7 on: March 12, 2021, 05:43:10 pm »
What is the question again? A limitation of static arrays in pascal, that does not exists in c#?

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: functions in pascal
« Reply #8 on: March 12, 2021, 06:00:34 pm »
So far I know that arraytypes in Pascal is declared with an array length...
'


Not always.  Dynamic arrays are supported in Free Pascal.

What are you actually trying to find out?
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: functions in pascal
« Reply #9 on: March 12, 2021, 09:07:52 pm »
So far I know that arraytypes in Pascal is declared with an array length, but is there functions which might cannot be implemented because of that? and maybe still be written in C# for example?

It is not quiet clear what you mean.

Do you want a correct result or do you want to stop the compiler to moan??

As you are talking about C# I assume the last.

Winni

egsuh

  • Hero Member
  • *****
  • Posts: 1296
Re: functions in pascal
« Reply #10 on: March 13, 2021, 04:19:32 am »
He is asking something that C# can, but Pascal cannot, because of the definition of static array.  If C# can define something like array with indexes (not values) of [1,4,7,9] then Pascal would not be able to do that.

 

cdbc

  • Hero Member
  • *****
  • Posts: 1088
    • http://www.cdbc.dk
Re: functions in pascal
« Reply #11 on: March 13, 2021, 09:56:38 am »
Hi
It's rhe same man, who developed Delphi and C#!!!!
Anders Hejlsberg, with et.al!
A couple of nights reading and "Bob's your uncle"
Sorry, Who's trying here?????????????
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

italyrobert

  • New member
  • *
  • Posts: 7
Re: functions in pascal
« Reply #12 on: March 13, 2021, 10:07:34 am »
What is the question again? A limitation of static arrays in pascal, that does not exists in c#?

The static type array declaration in pascal, as I understand make it not possible to implement certain functions and I'm looking for an simple example of a function like that, but it should instead be possible to implement in C# instead,.

italyrobert

  • New member
  • *
  • Posts: 7
Re: functions in pascal
« Reply #13 on: March 13, 2021, 10:22:27 am »
So far I know that arraytypes in Pascal is declared with an array length...
'


Not always.  Dynamic arrays are supported in Free Pascal.

What are you actually trying to find out?

The static type array declaration in pascal, as I understand make it not possible to implement certain functions and I'm looking for an simple example of a function like that, but it should instead be possible to implement in C# instead,.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: functions in pascal
« Reply #14 on: March 13, 2021, 10:35:55 am »
The static type array declaration in pascal, as I understand make it not possible to implement certain functions and I'm looking for an simple example of a function like that, but it should instead be possible to implement in C# instead,.

In that case ask on a C# forum.

As has been pointed out, Turbo Pascal (and later Delphi) and C# had the same designer, and it's reasonable to assume that a high proportion of C# users are intimately familiar with Pascal implementations. However you will need to appreciate that FPC implements a significant amount that's not in "classical" Pascal implementations, and in particular that's not in the ISO definition.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018