Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#635 New syntax for "call" ARGC + ARG0 + ARG1...ARG9

None
closed-accepted
nobody
None
5
2013-12-30
2013-09-15
Ethan Merritt
No

I've been struggling to update the "call" syntax to something more compatible with current gnuplot capabilities. The original syntax performs macro-like expansion triggered by the character sequences $0 ... $9, with the count of parameters substituted for $#.

Problems with the original syntax:
1) Consumes quote marks on input, ignores quotes during macro expansion
2) Because of (1) it handles string variables and string constants poorly
3) The $# expansion has been broken for years because it looks like a comment
4) This use of $N conflicts with the use of $N as shorthand for column(N)
5) The use of $ and the peculiar handling of quotes makes it very hard to generate or pass through lines from a unix-like shell script

This patch introduces an alternative syntax for the "call" arguments. They are loaded into ordinary gnuplot variables that are saved/restored across the call.
ARG0 = name of the script being executed
ARGC = count of parameters passed to the script
ARG1..ARG9 = the arguments stored as strings

Notes:
- Because the arguments are constructed and accessed as regular string variables, you have the choice of using them directly (e.g. set title ARG3) or expanding them as macros (e.g. plot @ARG3). The former is usually appropriate for strings, the latter is usually appropriate for numerical values or expressions.
- ARG0 holds the name of the script being executed during "load" also, as well as during execution of files named on the gnuplot command line.

The patch contains a simple demo "calltest.dem" that illustrates this.

1 Attachments

Discussion

  • Ethan Merritt
    Ethan Merritt
    2013-09-15

    Here's the output of running the demo script:

    stonelion [1188] ./gnuplot calltest.dem
    Entering calltest.dem with 0 parameters
    Now Exercise the call mechanism
    Entering calltest.dem with 5 parameters
    
            Variables beginning with ARG:
            ARGC = 5
            ARG0 = "calltest.dem"
            ARG1 = "1.23e4"
            ARG2 = "string constant"
            ARG3 = "FOO"
            ARG4 = "BAZ"
            ARG5 = "3 + log(BAZ)"
            ARG6 = ""
            ARG7 = ""
            ARG8 = ""
            ARG9 = ""
    
    ARG1 (numerical constant) came through as 1.23e4
         @ARG1 = 12300.0
         (ARG1 == @ARG1) is TRUE
    ARG2 (string constant) came through as string constant
         words(ARG2) = 2
    ARG3 (undefined variable FOO) came through as FOO
    ARG4 (numerical variable BAZ=5.67) came through as BAZ
         @ARG4 = 5.67
    ARG5 (quoted expression) came through as 3 + log(BAZ)
         @ARG5 = 4.73518911773966
    
     
    Last edit: Ethan Merritt 2013-09-15
  • Ethan Merritt
    Ethan Merritt
    2013-09-17

    fix lf_pop of undefined variable

     
    Attachments
  • Ethan Merritt
    Ethan Merritt
    2013-12-30

    • status: open --> closed-accepted
    • Group: -->