Hints

1: Introduction
2: Invoking Gre
3: Gre Grammar
4: Commands
5: Cookbook
6: Hints
7: History
8: Plans
9: Concept Index

6: Hints

6.1: Hints for C programmers

Users of the C language should note the following.

  1. The contents of loops and conditionals must be enclosed in curly braces, even if they consist of just one line. (As in the Perl language, this choice was made to simplify parsing of the grammar.)

6.2: Hints for Perl programmers

`gre' is not Perl, although much of the underlying grammar is designed to match Perl. Here are some things Perl programmers should bear in mind:

  1. Most functions require parentheses in `gre', e.g. `acos sin 3.14;' will not parse; you must write it as `acos(sin(3.14));'.

  2. `gre' is not object-oriented, and lacks the recent enhancements to Perl that attempt to make Perl object-oriented.

  3. `gre' has no `elsif' statement.

  4. Lists are only barely functional in `gre'. For example, One may not refer to a whole array using the `@' syntax, except in `@F = split();' see Split.

  5. Hash arrays are not available in `gre'.

  6. Some functions that in Perl may take an expression or be called with no expression (e.g. `warn') are required to have an argument in `gre'. This is to avoid ambiguities in the grammar design. To maintain compatibility with Gri, `gre' allows space-separated (as opposed to comma-separated) expressions as arguments for a command. An example is provided by the three constant expressions in the command `set x axis 0 1 0.1'. If one of these arguments were substituted with a function name, such as `warn', then an ambiguity would arise if `warn' were permitted to be called in an expressionless way. For example, if the first argument were the word `warn' instead of the constant `0', then the two possible meanings might be `set x axis warn() 1 0.1' or `set x axis warn(1) 0.1'. Such ambiguities are avoided in Perl because it uses a comma to separate expression lists.

  7. You may not assign values in a `my' command see My.

  8. Variable interpolation within strings is not as powerful as in Perl. Indices may not be expressions; only constants and scalars are allowed within the `[]' index see Variables.

  9. Subroutine prototypes are required in `gre', whereas they are optional in Perl.

  10. The `use' command refers only to `gre' modules, not the extensive list of Perl modules that you might be accustomed to.

  11. In a `for' loop, there are some limitations on the types of expressions one may have in the three-expression list see For.

  12. In `gre' subroutines, the return value must be indicated with a `return' statement, and cannot be implied by the last expression evaluated, as in Perl see Sub.

  13. A `substr' may not be used as an lvalue (that is, it may not be used to the left of an equals sign) see Substr.

6.3: Hints for Awk programmers

  1. Substrings start at offset zero, as in Perl and C, not at 1. This affects commands such as `substr' see Substr, and `index' see Index.

6.4: Hints for Gri programmers

`gre' is not Gri, although it was born of Gri.

Gri programmers should bear in mind the following.

  1. The `gri2gre' program, provide with `gre', does a rough conversion from Gri programs to `gre' programs. Although only about 75 percent of the available Gri commands are converted correctly by `gri2gre', warnings are given if a particular command cannot be converted.

  2. Semicolon is used to end commands, not newline. (This will be familiar to C, Perl, and Awk users.)

  3. Negative arguments to commands should be enclosed in parentheses. This is to prevent the `gre' parser from interpreting adjacent arguments as parts of a mathematial expression. Cautionary Notes On Syntax.

  4. Math-mode in strings (e.g. labels, titles) uses `\\(' at the start and `\\)' at the end, instead of `$' at both places. This is still in agreement with latex usage, but has the advantage that it allows perl-like variable interpolation into strings. Besides, it is usually easier for the programmer to figure out.

  5. Newcommands are now done by an extended subroutine format, directly analogous to Perl see Cmd.

  6. `rpn' mathematics is not available; use normal mathematical notation instead or let `gri2gre' handle the conversion.

  7. If-statements and loops end with curly braces, not `end if' and `end while'. (This will be familiar to C, Perl, and Awk users.)

  8. Because file handles are now used in `open' and `read' commands, the `read from "filename"' command is no longer needed.

  9. The `read' commands may be used instead of conventional Perl syntax in almost every circumstance.

  10. `draw isopycnal .value. unlabelled' is now called `draw isopycnal unlabelled $value'.

  11. The `set line cap' and `set line join' commands now have English indications of the styles, instead of numerical codes.

  12. `draw label whiteunder "\label" at .x. .y. [cm]' is now written `draw label "$label" whiteunder at $x $y [cm]'.

  13. `hsb' color-space is now called `hsv', in keeping with many graphics texts (and to make the 'v' not seem like a 'b' for blue)

  14. The `new' and `delete' Gri commands are not available in Gre. Mostly, Gri users employed these commands to get the equivalent of the Gre command `my' see My, so that most Gri programs won't suffer upon conversion. (Note: the conversion script `gri2gre' does not handle `new' and `delete' properly.)

  15. Some internal variables have been renamed. `..linewidthaxis..' and `..linewidthsymbol..' are now `$_linewidth_axis' and `$_linewidth_symbol'.

  16. `query' does not accept restriction lists yet -- but it will someday.

  17. `draw circle' is not available, since it can be handled with the command `draw symbol circ'; this conversion is done automatically by `gri2gre'

(c) 1997-1999 Dan E. Kelley, email Dan.Kelley@Dal.Ca