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


Groups > comp.graphics.apps.gnuplot > #3201 > unrolled thread

Question about "sprintf" "@" "do for"

Started byJörg Buchholz <bookwood4news@freenet.de>
First post2016-02-02 20:49 +0100
Last post2016-02-03 07:30 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  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

#3201 — Question about "sprintf" "@" "do for"

FromJörg Buchholz <bookwood4news@freenet.de>
Date2016-02-02 20:49 +0100
SubjectQuestion about "sprintf" "@" "do for"
Message-ID<n8r13l$bdu$1@dont-email.me>
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? Is there a 
solution for?

Jörg

[toc] | [next] | [standalone]


#3204

FromEthan A Merritt <sfeam@users.sourceforge.net>
Date2016-02-02 16:05 -0800
Message-ID<n8rg2s$8ps$1@dont-email.me>
In reply to#3201
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

[toc] | [prev] | [next] | [standalone]


#3206

FromJörg Buchholz <bookwood4new@freenet.de>
Date2016-02-03 07:30 +0100
Message-ID<n8s6ok$reg$1@newsserver.rrzn.uni-hannover.de>
In reply to#3204
On 03.02.2016 01:05, Ethan A Merritt wrote:

> You don't need macros for this
>
>    do for [i=1:3] {
>      vari = <whatever>
>      print vari, ' = ', value(vari)
>    }

Thanks a lot Ethan, with the keyword "value" I also found the relevant 
side in the manuel.

Jörg

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web