Question

I am learning OOP with the pascal programming language.After googling the Internet, I found the OOP -- The GNU Pascal Manaul.

What does this function declaration mean?

function Baz (b, a, z: Char) = s: Str100; { not virtual }

I have never seen = xx before, and it seems that the pascal syntax does not have it.

Was it helpful?

Solution

That appears to be some nonstandard extension. The implementation of the function in question is:

function FooParent.Baz (b, a, z: Char) = s: Str100;
begin
  WriteStr (s, 'FooParent.Baz (', b, ', ', a, ', ', z, ')')
end;

Normally in Pascal, the name of the function is used as the function return variable, so the above function would be written like this:

function FooParent.Baz (b, a, z: Char): Str100;
begin
  WriteStr (Baz, 'FooParent.Baz (', b, ', ', a, ', ', z, ')')
end;

It appears that the = s syntax indicates that the return value of the function is stored in the variable s inside the function body. I'm not sure why that would need to be exposed in the object interface, though.

OTHER TIPS

I can't answer your question but I suggest to learn OOP with a language like Python or Groovy. Pascal isn't really something on which you'll be able to build a career. I'd rather suggest that as a third or fourth language to give you some ideas how other languages work but not as your first/main language.

Both offer an interactive console (for Python, I suggest iPython) where you can do small experiments.

Note: Some people attack me on the grounds that I don't know much about Pascal. I'm not sure where you get that idea. I have over 200K points on SO, I know 30 programming languages (know == written large amounts of code in it), I've written code in Pascal at the beginning of my career.

I understand it hurts when your beloved programming language doesn't get the recognition you feel it deserves. A no brainer: You made the decision to use that language, so it must be the best one - otherwise your decision would be wrong.

But when I compare code written in all the languages that I know, Pascal/Delphi/Modula/Oberon are among those which I don't recommend for various reasons. Delphi got some traction because of Borland but that's over. I've seen the code which good Delphi programmers wrote and my first thought was: Maintenance cost.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top