Hello,
I'm am amateur programmer, new to gpc and rather new to Pascal as well. I wonder whether this list is a proper place to find help in learning the language, and in using it for a few projects of mine. If yes, then below is a first series of diverse questions. I will have some more as I discover the language (including some stupid ones, certainly ;-). [Note: I have a candidate answer to the questions, but ask anyway to be sure, and stop wondering.]
-1- writing arrays & records What is the literal notation for arrays & records? Can it apply to (a) const definition (b) var initialisation (c) var assignment? Is there a way to write back arrays & records to output (tostring(x), according to standard notation)? If not, how to write such a tool func? (super useful for learning, prototyping, testing...) Is it at all possible to write the following 'show' tool func: show(x); // 'x : 1' --> stdout show(x+1); // 'x+1 : 2' --> stdout ? (my dream debugging tool)
-2- traversing collections Is there a way to traverse arrays with elements directly? (--> foreach, or Eiffel's across) Is it possible to define traversal for custom collections?
-3- TP-like object system Is there more information in fpc's documentation about its object system (than chapter 6.8 in manual)? Else, are there good places online to find information about TP's object system?
Denis ________________________________
vit esse estrany ☣
spir.wikidot.com
On Mon, Jun 14, 2010 at 11:32:12AM +0200, spir wrote:
Is it at all possible to write the following 'show' tool func: show(x); // 'x : 1' --> stdout show(x+1); // 'x+1 : 2' --> stdout ? (my dream debugging tool)
Not a function, I guess, but you can do this easily with a preprocessor macro:
{$define show(X...) writeln (#X ': ', X)}
(The dots make it accept more than one argument.)
Kind regards, Emil Jerabek
On Mon, Jun 14, 2010 at 12:57:29PM +0200, Emil Jerabek wrote:
On Mon, Jun 14, 2010 at 11:32:12AM +0200, spir wrote:
Is it at all possible to write the following 'show' tool func: show(x); // 'x : 1' --> stdout show(x+1); // 'x+1 : 2' --> stdout ? (my dream debugging tool)
Not a function, I guess, but you can do this easily with a preprocessor macro:
{$define show(X...) writeln (#X ': ', X)}
(The dots make it accept more than one argument.)
Better yet, debugging info should probably go to stderr rather than stdout:
{$define show(X...) writeln (stderr, #X ': ', X)}
Regards, Emil
Denis Spir wrote:
-1- writing arrays & records What is the literal notation for arrays & records? Can it apply to (a) const definition (b) var initialisation (c) var assignment?
GPC supports ISO structured value constructors -- they can be used for variable initializtion and as elements of expressions (in particular for constant definitions and assignments).
If you want precise definiton look in ISO 10206 standard (available online). The test files 'init1x.pas', 'init3[a-g].pas' may serve as examples.
Hi,
On 6/14/10, spir denis.spir@gmail.com wrote:
I'm am amateur programmer, new to gpc and rather new to Pascal as well.
Ditto. ;-)
I wonder whether this list is a proper place to find help in learning the language, and in using it for a few projects of mine.
Honestly, I don't know. :-/ Traffic here (and comp.lang.pascal.*) seems low.
-1- writing arrays & records What is the literal notation for arrays & records? Can it apply to (a) const definition (b) var initialisation (c) var assignment?
Borland (mis)uses "const" while ISO 10206 Extended has its own (as Waldek mentioned).
-2- traversing collections Is there a way to traverse arrays with elements directly? (--> foreach, or Eiffel's across) Is it possible to define traversal for custom collections?
Not sure, but apparently a Borland way would be to use "for blah ..." with high() and low().
-3- TP-like object system Is there more information in fpc's documentation about its object system (than chapter 6.8 in manual)? Else, are there good places online to find information about TP's object system?
The problem here is that Borland and Delphi apparently use different object systems, so you'll have to choose one! Anyways, I'm not much on OOP, and I definitely don't (yet) grok Object Pascal, but ...
http://edn.embarcadero.com/article/20803
"Community member Bill Meyer was kind enough to scan in and convert the first two chapters of the TP 5.5 Object Oriented-Programming Chapter guide into a PDF. He has done a fantastic job with it. You can view (or download, it's 2.58MB) the Introduction and "All About OOP" chapters of the guide from the file TP_55_OOP_Guide.pdf. While it's old, the OOP chapter still does a good job of covering the concepts of Object-Oriented Programming."
http://edn.embarcadero.com/article/images/20803/TP_55_OOP_Guide.pdf
Thank you Emil, Waldek, Rugxulo. Think I have enough information on these points. I'll follow the pointers about extended Pascal and TP's OO model.
Denis ________________________________
vit esse estrany ☣
spir.wikidot.com