Menu

#2814 Setting dashtype in loop only works for string values

open
nobody
None
2025-07-04
2025-07-02
Anonymous
No

Outside of loops, dashtype can be set using a string or an even-length tuple of lengths:

set dashtype 1 "- "
set dashtype 1 (1,2)

However, in a loop, only the string variant seems to work. These two commands are accepted:

set for [i=1:3] dashtype i "- "
do for [i=1:3] { set dashtype i "- " }

But the following commands fail with the message undefined function: i:

set for [i=1:3] dashtype i (1,2)
do for [i=1:3] { set dashtype i (1,2) }

It would be nice to have both variants available in loops. If this is intentionally unsupported, it would be good to have a more appropriate error message.

The behavior reproduces on gnuplot 6.0 patchlevel 3 and on current master (63af8b2e7bf7dcb25cb4783476342e8c782516be).

Discussion

  • Ethan Merritt

    Ethan Merritt - 2025-07-03

    The problem here is not the loop. The problem is that the command set dashtype i (1,2) looks to gnuplot like the start of a command that invokes a 2-parameter function i(x,y) to find out what dashtype is being set. As in the hypothetical sequence of commands

    i(x,y) = abs(x-y)
    set dashtype i(2,5) "..."
    show dashtype
           dashtype 3,  dashtype "..." (2.00, 5.00, 2.00, 5.00, 2.00, 5.00)
    

    So this is a language design error. I'll have to think about whether there is a fix, and also whether the same ambiguity exists for other "set" commands.

     
    • Ethan Merritt

      Ethan Merritt - 2025-07-04

      Fixed now.
      A possible work-around for existing gnuplot versions is to put the iteration variable in parentheses.

      set for [i=1:3] dashtype (i) (1,2)
      
       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.