Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #3204

Re: Question about "sprintf" "@" "do for"

From Ethan A Merritt <sfeam@users.sourceforge.net>
Newsgroups comp.graphics.apps.gnuplot
Subject Re: Question about "sprintf" "@" "do for"
Date 2016-02-02 16:05 -0800
Organization gnuplot development
Message-ID <n8rg2s$8ps$1@dont-email.me> (permalink)
References <n8r13l$bdu$1@dont-email.me>

Show all headers | View raw


Jörg Buchholz wrote:

> Hello,
> 
> this works:
> 
> A1=1
> A2=2
> A3=3
> 
> i=1
> vari=sprintf("A%.f",i)
> print vari,"=",@vari
> i=i+1
> vari=sprintf("A%.f",i)
> print vari,"=",@vari
> i=i+1
> vari=sprintf("A%.f",i)
> print vari,"=",@vari
> 
> do for [i=1:3]{
> vari=sprintf("A%.f",i)
> print vari
> }
> 
> But I want to have "print vari,"=",@vari" in the loop. But it dosen't
> work. Why can't I use "print vari,"=",@vari" in the loop? 

The @ indicates macro expansion, which only happens once.
And that one time is before the loop is executed.
So whatever value @vari has at the start of loop execution, that
is the value it will have every time through.

> Is there a solution for?

You don't need macros for this

  do for [i=1:3] {
    vari = <whatever>
    print vari, ' = ', value(vari)
  }

 
> Jörg

Back to comp.graphics.apps.gnuplot | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Question about "sprintf" "@" "do for" Jörg Buchholz <bookwood4news@freenet.de> - 2016-02-02 20:49 +0100
  Re: Question about "sprintf" "@" "do for" Ethan A Merritt <sfeam@users.sourceforge.net> - 2016-02-02 16:05 -0800
    Re: Question about "sprintf" "@" "do for" Jörg Buchholz <bookwood4new@freenet.de> - 2016-02-03 07:30 +0100

csiph-web