Subject: Integer variables

From: Alexey Melnikov <[email-masked]>
Date: Mon, 14 Apr 2003 23:02:15 -0600

I don't think this was discussed, excuse me if I've missed the
discussion.
Am I allowed to do the following using "variables" extension:

set "NumVar" 100M;

If the answer is yes, two more questions:
1). How do we expand integer variables inside strings?
2). Can a variable get a string value after it was assigned an integer
value?

Regards,
Alexey
__________________________________________
R & D, ACI Worldwide/MessagingDirect
Watford, UK

Work Phone: +44 1923 81 2877
Home Page: http://orthanc.ab.ca/mel
IETF standard
related pages: http://orthanc.ab.ca/mel/devel/Links.html

I speak for myself only, not for my employer.
__________________________________________

---

From: Kjetil Torgrim Homme <[email-masked]>
Date: 15 Apr 2003 13:33:25 +0200

>   I don't think this was discussed, excuse me if I've missed the

it hasn't been discussed.

>   Am I allowed to do the following using "variables" extension:

no.

>   2). Can a variable get a string value after it was assigned an integer

the problem is rather that the variable can only be expanded inside a
string, so it would lose its integer property.

do you have a use for integer variables?

-- 
Kjetil T.

---

From: Alexey Melnikov <[email-masked]>
Date: Sat, 19 Apr 2003 01:26:56 -0600

> string, so it would lose its integer property.

Which is fine, as long as this is documented.
I believe the current document doesn't specify what types of variables are
allowed.
You have to either explicitly allow or prohibit this.

> do you have a use for integer variables?

You already have the "length" function. I was thinking something along the
lines of comparing lengths/counting headers/scoring.
However this will probably require some actions for simple arithmetic (+/-).

Cheers,
Alexey

---

From: Kjetil Torgrim Homme <[email-masked]>
Date: 19 Apr 2003 16:44:40 +0200

[Alexey Melnikov]:
>   > the problem is rather that the variable can only be expanded
>   > inside a string, so it would lose its integer property.
>   
>   Which is fine, as long as this is documented.  I believe the
>   current document doesn't specify what types of variables are
>   allowed.  You have to either explicitly allow or prohibit this.

it is explicit already, if you look in the right place:

|   Syntax:   set [MODIFIER] [COMPARATOR] <name: string> <value: string>
                                                          =============

it doesn't say anything about variable references being usable outside
of string interpretation, I guess that could be more explicit, but the
overall Sieve grammar doesn't allow an unadorned variable reference as
a syntactic element.

(if a numeric variable was to be introduced, it seems to me that to
access it, changing the allowed values for QUANTIFIER to include a
variable-ref would be the way to go, i.e. 1${count}, ref. 1M.)

>   You already have the "length" function.

yes, it may be a bit silly.  a determined hacker can use it to convert
numbers in unary to decimal (I've had to do this during crash recovery
in singleuser mode on SunOS ;-), but the lack of a looping construct
will cramp his style.

>   I was thinking something along the lines of comparing
>   lengths/counting headers/scoring.  However this will probably
>   require some actions for simple arithmetic (+/-).

with regex, you can do:

    set "score" "${score}1";  # several times inside if-blocks

    if string :regex "${score}" "1{5,}" {
        # five or more hits ...
    }

-- 
Kjetil T.