Re: abs bug?
Re: abs bug?
- Subject: Re: abs bug?
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 29 Nov 2003 11:29:34 -0800
On 11/29/03 10:51 AM, "Robert Poland" <email@hidden> wrote:
>
> How was the dictionary misleading you? It's just standard AppleScript (or
>
> any language) logic, which you were getting wrong. What did the dictionary
>
> have to do with it?
>
>
The dictionary;
>
abs : absolute value of direct parameter
>
abs real
>
Result : real
>
>
Not being familar with how to read the dictionary, i saw "abs real"
>
and took it as an example.
It's not an example, as you say, but I'm still not sure that you understand
what your error was. The problem has nothing to do with it being an
explanation of the syntax rather than an example of the syntax.
The dictionary excerpt shows that abs acts on real numbers (floating point
numbers) with decimal points and produces the same type as a result. (It
also apparently will act on integers and produce the result as an integer,
without converting it to a real, but that's by the way.)
So if x is -44, you can do
abs x
and the result will be 44, just like this:
set x to -44
abs x
--> 44
So there's an example, exactly paralleling the dictionary.
Your error was in thinking that x itself would be equal to the result of the
operation, even though you hadn't re-set it to be so. Changing the item of
a list or record (or changing a component of a date) does actual change the
list or record or date, because AppleScript uses what it calls "data
sharing" - just for those forms. (Other people refer to these types - list,
record, date - as being "mutable" in AppleScript, with all other types being
"immutable".) That doesn't happen with any other type. Performing an
operation on a real, or integer, or string, does not change the value of a
variable you have previously set to that real, or number, or string. Thus
set x to 44
x + 3
--> 47
BUT:
set x to 44
x + 3
x
--> 44
The '+' operator doesn't change the value of x, it just does its operation
and produces its result, with no variable set to the result because you
haven't requested it. Same with the 'abs' operator.:
set x to -44
abs x
--> 44
BUT:
set x to -44
abs x
x
--> -44
It's exactly the same. If you want to change the value of your original
variable x you have to reset it explicitly to the result of your operation:
set x to 44
set x to (x + 3)
x
--> 47
set x to -44
set x to (abs x)
x
--> 44
The dictionary isn't going to demonstrate how to re-set your variable,
because it's nothing to do with what a dictionary does. That's basic
AppleScript.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.