Page 1 of 2

Pascal?

Posted: Tue Feb 16, 2016 3:25 am
by DavidS
I find it interesting that the Pascal programming language is almost never menioned.

Do to its rules Pascal is likely one of the simplest languages to create an optimizing compiler for. Pascal is also among the simplest languages in which to implement many algorithms, which is most of the life of any Software Engeneer (that is creating an algorithm, optimizing the algorithm, implementing it as effeciently as possible in a programming language).

Though I also find it interesting that I can not find a single ARMv6/ARMv7 complient Pascal compiler, thus no Pascal with our chosen RPi/RPi2 + RISC OS.

The question is what good small well implemented Pascal Compilers are out there that are ARMv6/ARMv7 compatible and prodce code that is ARMv6/ARMv7 compatible?

Re: Pascal?

Posted: Tue Feb 16, 2016 3:46 am
by klricks
A quick search using Synaptic found 'free pascal' in the repository (Raspbian Jessie)

Re: Pascal?

Posted: Tue Feb 16, 2016 5:11 am
by stderr
DavidS wrote:I find it interesting that the Pascal programming language is almost never menioned.
Do to its rules Pascal is likely one of the simplest languages to create an optimizing compiler for. Pascal is also among the simplest languages
Though I also find it interesting that I can not find a single ARMv6/ARMv7 complient Pascal compiler,
Of course there's always Ada, which is just Pascal made into the most complicated language possible.

Re: Pascal?

Posted: Tue Feb 16, 2016 6:40 am
by hansotten
DavidS wrote:
The question is what good small well implemented Pascal Compilers are out there that are ARMv6/ARMv7 compatible and prodce code that is ARMv6/ARMv7 compatible?
Freepascal is a well implemented Pascal compiler generating ARMV6 or V7 code. Together with Lazarus a powerfull way to program the Pi, including GPIO (RPI Hal, LazWiringpi, TMS LCL HW Pack for Raspberry Pi and more).
Now Freepascal/Lazarus is not small, it is multiplatform an therefore viable.

Ultibo is an example where Freepascal and Lazarus is used via crosscompilation to produce a bare metal (some may say its a small OS ;) ) Raspberry Pi system without a Linux kernel.

Another example, and this one is small and targeted for ARM is XPL0 for Raspberry, http://www.xpl0.org/rpi/ . Complete with source, small and with interesting graphic abilities directly in the Framebuffer.
Based upon PL/0, the small example Pascal language by Wirth, extended and morphed into its own 'Wirth' dialect producing native ARM.

Re: Pascal?

Posted: Tue Feb 16, 2016 8:41 am
by Heater
Free Pascal works fine on the Pi. One of our core products is written in FPC of course I had to build it for the the Pi. No problem.

FPC and the Lazarus IDE get a mention around here from time to time.

Re: Pascal?

Posted: Tue Feb 16, 2016 12:53 pm
by hippy
DavidS wrote:I find it interesting that the Pascal programming language is almost never menioned.
Pascal was the flavour of the era when I was studying computer science. I quite liked it but there were limitations in the original implementation which, along with it being promoted as a teaching language, meant it end up being discredited as a useful programming language. I guess that stuck, especially as C became the flavour of the next era. With the passage of time it seems it has mostly been forgotten about.

Ultibo for the Pi is what has piqued my interest in Pascal again but, in all honesty, only as a means to an end.

Re: Pascal?

Posted: Mon Feb 29, 2016 9:27 am
by Bosse_B
discredited as a programming naguage
Where did you get that from?
Pascal is live and kicking. Have you used Skype recently? That is programmed using Pascal (in the Delphi flavour) on Windows platforms. Just an example.
I have worked with Industrial automation since 1995 and we use exclusively ObjectPascal from Borland-CodeGear-Embarcadero (the system has been transferred between owners during these 20+ years).
Now retired but working with Raspberry Pi and I am using FreePascal + Lazarus on RPi2 platforms.
The very big advantages of this combination is:
- Multi-platform (both operating systems and hardware)
- Code independence (you can develop on a PC and compile for any hardware/operating system you want)
- Both 32 and 64 bit compilers
- The Pascal strong typing menas that it is very difficult to "shoot ones own foot"
- Object Pascal is a very good OOP language!
- Delphi compatible (you can port Delphi programs very easily to Lazarus/FreePascal)
- It is a completely free system too. (Delphi is nowadays out of reach for the amateur user).

I highly recommend FreePascal + Lazarus!

Re: Pascal?

Posted: Mon Feb 29, 2016 9:40 am
by hippy
Bosse_B wrote:
discredited as a programming naguage
Where did you get that from?
I actually wrote; " I quite liked it but there were limitations in the original implementation which, along with it being promoted as a teaching language, meant it end up being discredited as a useful programming language.

And I stand by that. Variants on Pascal we have now are not Pascal as it was then. They evolved because of the limitations of Pascal.

Re: Pascal?

Posted: Mon Feb 29, 2016 12:12 pm
by Heater
Certainly modern day Pascal has moved on from the original definition. But then that is true of many languages.

If you write C++ using it's recently acquired features your code will look a lot different to original C++.

Similarly for Javascript. And so on.

The worst case perhaps is BASIC. Modern so called BASICs have almost nothing in common with the original language.

One issue in all this is: Is there a standard that everyone works to? A language can evolve but it's better if there is a standard that is evolving with it so that everyone is on the same page. This is the case with C++ and Javascript, for example, I am not aware of any such standards that modern day Pascal or BASICs follow.

As such I'd rather not be developing new projects in Pascal or BASIC etc.

Re: Pascal?

Posted: Mon Feb 29, 2016 12:34 pm
by Heater
Bosse_B,
Pascal is live and kicking.
Unfortunately it is. One of our key products is written in Pascal. It's a royal pain.
Have you used Skype recently?
I'm not sure that is a good example.

I can't argue with your list of advantages of Free Pascal. Except that: It's ugly as hell to read. There is no international standard for it. All that type checking is annoying and does not help stopping feet getting blown off. One can do all that and more in C++ with the Qt libraries.

Aside: Perhaps I'm having a little grump about Pascal today because just last Friday I was again reminded how pointless all that ugly type annotation and checking in Pascal is.

It was found that following the addition of a simple new feature to our Pascal monstrosity was causing it to crash after three or four days running. Or produce a rage check error if that is enabled. Same thing really if your code has made it into production.

Turned out that the implementation of blocking socket in the Synapse library maintains a count of bytes received on an open socket. That counter is of type "Integer". Which is 32 bits on our machines. Which means the thing explodes when it rolls over at 2 giga bytes. Which took a few days in our case.

That "feature" has been in that library, waiting to blow our feet off for some years!

Re: Pascal?

Posted: Wed Mar 02, 2016 11:35 am
by ZXDunny
My BASIC interpreter (a "classic" style BASIC modeled on Dartmouth and Sinclair) is written in Pascal - Well, Delphi to be precise, but builds for the Pi using Lazarus/FPC. I work professionally as a coder on a very popular pro music studio application, and that's written in Delphi too.

Personally, I prefer Pascal to C - it's more readable and much nicer to work in.

D.

Re: Pascal?

Posted: Wed Mar 02, 2016 8:18 pm
by Heater
Personally, I prefer C to Pascal - it's more readable and much nicer to work in.

Seems to me that both C and Pascal are conceptually the same thing. Your basic structured programming idea.

One has an uglier syntax that the other. I'll leave judgement of that to the reader.

One has a peculiar obsession with types and type checking. Which is mostly redundant.

Pascal does seem to have an advantage in that compilers for it are generally a lot faster than the C compilers I have used.

I have no idea if that is due to the syntax/semantics being easier for a compiler to deal with or just a happen stance.

Re: Pascal?

Posted: Wed Mar 02, 2016 8:33 pm
by scruss
Heater wrote: Modern so called BASICs have almost nothing in common with the original language.
Most BASICs that people remember have very little in common with the original language, too. It had some lovely matrix manipulation keywords that never made it to the micro versions of old.

Re: Pascal?

Posted: Mon Sep 05, 2016 4:28 am
by DavidS
As to BASIC:

It is unfortunate that there was never any base agreed on. There are a few things that all BASIC's share that I guess would be the defining charactor of BASIC.

Back to Pascal:
At least there are four standards for Pascal. There is the UCSD standard for Pascal, then there is ISO 7185 Pascal standard that is basicaly an extension of USCD Pascal and compatible, and there is ISO 10206 Extended Pascal, which is an extension of ISO 7185 Pascal, then there is the Object Pascal standard.

These can be looked at like the standards for C, there was K&R C, then C89, with C99 coming next, and now C11. Though would have to add the C++ stuff, as Object Pascal is to ISO 10206 Pascal as C++ is to C89.

I would note that all of these standards for Pascal include the use of units, suport for Pointers, and means of type conversion, as well as the standards for I/O and the language it self.

Re: Pascal?

Posted: Mon Sep 05, 2016 12:27 pm
by scruss
There are standards for BASIC: ISO 10279 for full BASIC, ISO 6373 for minimal BASIC, and a raft of related ANSI and ECMA standards. I only know of one implementation of Full BASIC (Decimal BASIC, from Japan; no ARM distro available). Minimal BASIC is almost too small to be useful, but it has an actively-maintained interpreter in bas55.

Like Pascal, though, it's not the standard versions of BASIC that many people use, but the de facto ones: Turbo Pascal to Delphi, MS QuickBASIC to Visual BASIC.

As a former Fortran programmer, having standard IO libraries is a good thing. Before Fortran-90, it could be anybody's guess what a FORMAT statement from an obscure system could represent.

Re: Pascal?

Posted: Mon Sep 05, 2016 5:17 pm
by DavidS
scruss wrote:There are standards for BASIC: ISO 10279 for full BASIC, ISO 6373 for minimal BASIC, and a raft of related ANSI and ECMA standards. I only know of one implementation of Full BASIC (Decimal BASIC, from Japan; no ARM distro available). Minimal BASIC is almost too small to be useful, but it has an actively-maintained interpreter in bas55.

Like Pascal, though, it's not the standard versions of BASIC that many people use, but the de facto ones: Turbo Pascal to Delphi, MS QuickBASIC to Visual BASIC.

As a former Fortran programmer, having standard IO libraries is a good thing. Before Fortran-90, it could be anybody's guess what a FORMAT statement from an obscure system could represent.
:) yes.

With Pascal we have a de facto Pascal though, that is the Pascal as implemented in Turbo Pascal 5. And many stick to that.

QuickBASIC seems to be the basis of most modern BASIC compilers. There is FreeBASIC, QB64, and a few other less known ones that all use the QuickBASIC 4.5 lexicon for there base grammar with extensions from there (even things like BASIC4GL use this form). Unfortunately QuickBASIC did not define pointers very well, or similar.

I am surprised that the newer BASIC versions are so much based on QuickBASIC 4.5. QuickBASIC 1.0e for the Macintosh would make more since, as it has POKEW, PEEKW, as well as commands to directly deal with common GUI operations. Ok QuickBASIC for the Macintosh is lacking one important thing, that is structured data types (using the TYPE keyword in QuickBASIC on DOS), though I do not think that the DOS version of QuickBASIC even had that until somewhere around version 4.0.

Re: Pascal?

Posted: Mon Sep 05, 2016 6:35 pm
DavidS wrote: I am surprised that the newer BASIC versions are so much based on QuickBASIC 4.5. QuickBASIC 1.0e for the Macintosh would make more since, as it has POKEW, PEEKW, as well as commands to directly deal with common GUI operations. Ok QuickBASIC for the Macintosh is lacking one important thing, that is structured data types (using the TYPE keyword in QuickBASIC on DOS), though I do not think that the DOS version of QuickBASIC even had that until somewhere around version 4.0.
I know this is a Pascal thread, but what exactly would you do with peek/poke in a BASIC running on a modern unix-like system with memory management, etc. ?

With regard to Pascal... I did a lot of work in UCSD Pascal on the Apple ][ once upon a time, and at uni. before that on various other systems. I liked it at the time, but also did a lot in BCPL and C and found C easier to get on with when it came to paid jobs so haven't really looked at it for almost 30 years now ...

-Gordon

Re: Pascal?

Posted: Mon Sep 05, 2016 8:09 pm
by DavidS
[email protected] wrote:
DavidS wrote: I am surprised that the newer BASIC versions are so much based on QuickBASIC 4.5. QuickBASIC 1.0e for the Macintosh would make more since, as it has POKEW, PEEKW, as well as commands to directly deal with common GUI operations. Ok QuickBASIC for the Macintosh is lacking one important thing, that is structured data types (using the TYPE keyword in QuickBASIC on DOS), though I do not think that the DOS version of QuickBASIC even had that until somewhere around version 4.0.
I know this is a Pascal thread, but what exactly would you do with peek/poke in a BASIC running on a modern unix-like system with memory management, etc. ?
You likely would not. That is unless your application does something like allocate a block that is mapped to the addresses for GPIO, and then changes the states of the GPIO pins, or reads there states.

On a bare metal situation though, that is another story. Then peek and poke are useful. And there are people developing entire Operating Systems in compiled BASIC (mostly FreeBASIC).

Though on modern systems we use pointers instead, even in BASIC.
With regard to Pascal... I did a lot of work in UCSD Pascal on the Apple ][ once upon a time, and at uni. before that on various other systems. I liked it at the time, but also did a lot in BCPL and C and found C easier to get on with when it came to paid jobs so haven't really looked at it for almost 30 years now ...

-Gordon
Yes C is a lot easier, because it does not force good coding. Unfortunitely it also means that a lot of C code is unreadable, because the author does not take the time to format the code in a readable way.

Re: Pascal?

Posted: Thu Sep 08, 2016 5:02 pm
by hippy
[email protected] wrote:I know this is a Pascal thread, but what exactly would you do with peek/poke in a BASIC running on a modern unix-like system with memory management, etc. ?
It depends on what capabilities the particular BASIC has. Peek and poke can be used as means to replicate pointers. I find it is not uncommon in BASIC to need or have a binary data structure held within a string and it is quicker and easier to do -

byte = Peek( AddressOf(s$) + n )

Poke AddressOf(s$) + n, byte

than -

byte = Asc( Mid$(s$, n+1, 1) )

s$ = Left$( s$, n ) + Chr$( byte ) + Right$( s$, Len(s$) - n - 1 )

Re: Pascal?

Posted: Thu Sep 08, 2016 5:19 pm
hippy wrote:
[email protected] wrote:I know this is a Pascal thread, but what exactly would you do with peek/poke in a BASIC running on a modern unix-like system with memory management, etc. ?
It depends on what capabilities the particular BASIC has. Peek and poke can be used as means to replicate pointers. I find it is not uncommon in BASIC to need or have a binary data structure held within a string and it is quicker and easier to do -

byte = Peek( AddressOf(s$) + n )

Poke AddressOf(s$) + n, byte

than -

byte = Asc( Mid$(s$, n+1, 1) )

s$ = Left$( s$, n ) + Chr$( byte ) + Right$( s$, Len(s$) - n - 1 )
Despite being a punk-rock BASIC programmer, I might suggest that BASIC isn't the best language for this sort of thing... However it's something to think about and I am working on a new release of RTB, so who knows...

-Gordon

Re: Pascal?

Posted: Fri Sep 09, 2016 1:21 am
by DavidS
[email protected] wrote:
hippy wrote:
[email protected] wrote:I know this is a Pascal thread, but what exactly would you do with peek/poke in a BASIC running on a modern unix-like system with memory management, etc. ?
It depends on what capabilities the particular BASIC has. Peek and poke can be used as means to replicate pointers. I find it is not uncommon in BASIC to need or have a binary data structure held within a string and it is quicker and easier to do -

byte = Peek( AddressOf(s$) + n )

Poke AddressOf(s$) + n, byte

than -

byte = Asc( Mid$(s$, n+1, 1) )

s$ = Left$( s$, n ) + Chr$( byte ) + Right$( s$, Len(s$) - n - 1 )
Despite being a punk-rock BASIC programmer, I might suggest that BASIC isn't the best language for this sort of thing... However it's something to think about and I am working on a new release of RTB, so who knows...

-Gordon
Well if it is a Return to the concepts presented in the BASIC of the Micro revolution (around 1973 through about 1993, on microcomputers), then pointers of some form are needed. Some BASIC's from that time used PEEK and POKE to implement close to pointers, others used true pointers.

Part of what made BASIC so great back then was that it could be used for system level work. Still can be, though now it requires compiling to do so (as there is no BASIC interpreter at the lowest level). Because of this I am surprised that there has not been more work toward targeting simple BASIC compilers at bare metal on any system, the BASIC's of the Micro revolution were well suited to the task.

I have not yet looked at RTB, though please, PLEASE, PLEASE support recursive parameterized Procedures, and integer variables (the two important things that were missing from some of the BASIC interpreters and compilers of that time). And please take some time to make the compiler optimizing, nothing fancy though some simple optimization's (like register order of use and redundant load/store elimination). Also please make it possible to compile with out the BASIC library (for OS specific I/O of all kinds), so that it can be used on a bare metal level.

Re: Pascal?

Posted: Fri Sep 09, 2016 12:44 pm
DavidS wrote:
Part of what made BASIC so great back then was that it could be used for system level work. Still can be, though now it requires compiling to do so (as there is no BASIC interpreter at the lowest level). Because of this I am surprised that there has not been more work toward targeting simple BASIC compilers at bare metal on any system, the BASIC's of the Micro revolution were well suited to the task.
When do you think "back then" is? BASIC was invented in 1964. It ran on a time-sharing system. It was not intended for "system level work". It was intended as an easy way to get people into programming where they would them progress on to FORTRAN and who knows what.
I have not yet looked at RTB, though please, PLEASE, PLEASE support recursive parameterized Procedures, and integer variables (the two important things that were missing from some of the BASIC interpreters and compilers of that time). And please take some time to make the compiler optimizing, nothing fancy though some simple optimization's (like register order of use and redundant load/store elimination). Also please make it possible to compile with out the BASIC library (for OS specific I/O of all kinds), so that it can be used on a bare metal level.
So hang on - you're asking me about and to support features in RTB and you haven't even had the curtsey to read the manual or run it? That's a bit unfair, don't you think?

RTB does support parametrised procedures and functions. It has done for since its first public outing which was about 5 years ago (Before the Pi, it ran under most x86 Linuxes) Recursion works, as does local variables. Remember "at the time", (1960's) recursion had barely been invented.

Here is an example. This reverses a string:

Code: Select all

// FN rev:
//    A reversed string is the last character of the string
//    followed by the rest of the string, reversed.

def fn rev(s$)
if len (s$) = 1 then
  = s$
else
  = right$ (s$, 1) + fn rev (left$ (s$, len (s$) - 1))
Here is another classic example:

Code: Select all

def proc hanoi (A, B, C, D)
  if A = 0 then endproc
  proc hanoi (A - 1, B, D, C)
  print "Move disk ";  A;  " from ";  B;  " to ";  C
  proc hanoi (A - 1, D, C, B)
endproc
RTB is interpreted - you'd have known that if you read the manual or downloaded it, so I'll ignore all your bleats about compiling and optimising. It's fast enough for what it is. RTB will never run on "bare metal" either. It needs an OS, it is not an OS. The OS provides a rich environment for it to run in and provide things like keyboard, mouse and screen to sound, networking (currently it only talks to a Pi Minecraft game, but I have more planned) and file handling to name a few.

Integer variables - well, I'll answer that after you show me an interpreter you have written that successfully mixes integer and floating point variables and constants in a sensible and efficient manner. I don't think its worth it for RTB.

If we fast forward from the 60's (which I think you are ignoring), then using BASIC for system-work... Well, that was more because there wasn't any other way - the early microcomputers of the 70's ran BASIC for a reason - at a time when we had Fortran, Algol and Pascal compilers running on big & expensive mainframe and mini computers with 100's of KB of memory, BASIC was small, cheap/free and easy to implement - a bonus when you had 4K of ROM and 4K of RAM (or less). In those systems BASIC was the OS - or rather subroutines in the interpreter provided the IO system - it was one big lump of code - limited by the memory (and probably cost as much as anything else). Towards the mid and later 70's some systems had evolved to having a small "monitor" ROM (or a bootstrap ROM and monitor loaded off a disk - and I'm thinking CP/M here) and a larger language section - the monitor providing rudimentary IO.

We had peek & poke really only to make up for shortcomings in the language and lack of space. Why load the expensive ROM with more and more keywords and code when one generic keyword would do? With peek & poke on the Apple II you could change video modes (2 resolutions, 2 pages each), make simple clicks, store machine code into RAM, read the keyboard without pausing program execution and so on. That was what they were for - to make up for shortcomings. The BBC Micro in 1981/2 had the luxury of more ROM space (so a bigger monitor, now much more like what we'd consider an OS these days), more features, but that was 4 years after the Apple II/Pet/C64/TRS-80, etc. and things were moving fast then. (and prices slowly dropping). Peek & poke in BBC BASIC were replaced by "indirection operators" taken directly from BCPL (as far as I can tell) and primarily designed for fast access to byte & word arrays - you typically didn't use them to talk to the hardware as it had dedicated OS calls to do that. (Although direct access to the "user port" was an exception IIRC. It still had overloaded operators though - the vdu and plot commands for example.

Anyway, enough here. Apologies to the Pascal people. If anyone want to chat about RTB then I'm all ears, but please do me the favour of actually trying it or at least reading the manual first.
-Gordon

Re: Pascal?

Posted: Fri Sep 09, 2016 1:04 pm
by DavidS
[email protected] wrote:
DavidS wrote:
Part of what made BASIC so great back then was that it could be used for system level work. Still can be, though now it requires compiling to do so (as there is no BASIC interpreter at the lowest level). Because of this I am surprised that there has not been more work toward targeting simple BASIC compilers at bare metal on any system, the BASIC's of the Micro revolution were well suited to the task.
When do you think "back then" is? BASIC was invented in 1964. It ran on a time-sharing system. It was not intended for "system level work". It was intended as an easy way to get people into programming where they would them progress on to FORTRAN and who knows what.
That is why I specified the BASIC of the micro revolution, much a diferent beast than the BASIC of 1964.
I have not yet looked at RTB, though please, PLEASE, PLEASE support recursive parameterized Procedures, and integer variables (the two important things that were missing from some of the BASIC interpreters and compilers of that time). And please take some time to make the compiler optimizing, nothing fancy though some simple optimization's (like register order of use and redundant load/store elimination). Also please make it possible to compile with out the BASIC library (for OS specific I/O of all kinds), so that it can be used on a bare metal level.
So hang on - you're asking me about and to support features in RTB and you haven't even had the curtsey to read the manual or run it? That's a bit unfair, don't you think?
By your wording I was thinking it was maybe a pre-alpha thing. Sorry, I am embarased.
RTB does support parametrised procedures and functions. It has done for since its first public outing which was about 5 years ago (Before the Pi, it ran under most x86 Linuxes) Recursion works, as does local variables. Remember "at the time", (1960's) recursion had barely been invented.
I did say the BASIC of the micro revolution (not the basic of the 1960's).

Thank you for some information on the interpreter. Sorry about the misunderstanding.

Re: Pascal?

Posted: Fri Sep 09, 2016 7:37 pm
by Heater
Problem is there is no such thing as BASIC.

There are many languages that carry that name and are somehow similar. But they are all incompatible. There is no coherent standard.

Similarly for Pascal.

I want any code I write to be available in as many places as possible. Even if nobody else uses it, it future proofs it against changes in hardware, operating systems etc.

That means I need standards that everybody strives to support.

That pretty much means C, C++ and Javascript now a days.

Re: Pascal?

Posted: Fri Sep 09, 2016 9:09 pm
by DavidS
Heater wrote:Problem is there is no such thing as BASIC.

There are many languages that carry that name and are somehow similar. But they are all incompatible. There is no coherent standard.

Similarly for Pascal.

I want any code I write to be available in as many places as possible. Even if nobody else uses it, it future proofs it against changes in hardware, operating systems etc.

That means I need standards that everybody strives to support.

That pretty much means C, C++ and Javascript now a days.
Or a reasonable Pascal usage. There is enough of Pascal that is constant between implementations that if you stick with that it will work on any Pascal.

That is stick with the standard for Pascal (not object pascal, just pascal), all compilers I know of support that.

I would strike Javascript off of that list, as I have a number of old JS code that will NOT work on current versions of JS. They are on some of my floppies from the mid 1990's.

On C and C++, yes I agree. So long as you mean C89 and C++ as it was before C++98 (that is without standard template library, etc, just plain C++ with the standard class library no template support). If these constraints are used then yes using only C and C++ is a good way of future proofing your code, so long as you avoid using toolkits, and other such things.