View Single Post
Old 6 Jun 2019, 06:35 PM   #1
xyzzy
Essential Contributor
 
Join Date: May 2018
Posts: 478
Sieve variable assignments - using a variable to set the same variable

Before I submit a ticket on this I thought I would bounce it off you guys. The problem is a variable set command to assign strings to sieve variables. Apparently you cannot set a variable where that variable is also used to supply the value to be set. Here's a simple illustration:

Code:
require ["fileinto", "variables"];

set "x" "1";
set "x" "${x}";       # x is set from itself but it doesn't work
fileinto "x = ${x}";  # expect "1" but get null

set "y" "1";
set "x" "${y}";       # x is set from a different variable
fileinto "x = ${x}" ; # expect 1 and get it
I wasn't actually doing this in real life. I was actually trying to concatenate two variables and assigning it to one of the variables used in the concatenation, i.e., set "x" "${x}${y}"; and I couldn't figure out why I only ended up with ${y}'s value. The above test case is a reduced simplified example illustrating the problem.

Note, if there is something in the standards addressing (variables rfc5229) this I'm missing it. To get around it I need to assign the variable I want to set to a temp variable to be used on the right side of the set.

By the way, I could envision a pretty brain dead parser where it sees the set "x" part of the statement and initializes x to null before continuing on parsing the value to be assigned to x. Can the (FM) sieve parse be that dumb?

Last edited by xyzzy : 6 Jun 2019 at 07:05 PM. Reason: tried to change the title
xyzzy is offline   Reply With Quote