Re: as is what?
Re: as is what?
- Subject: Re: as is what?
- From: Doug McNutt <email@hidden>
- Date: Sun, 24 Aug 2003 07:31:00 -0600
At 12:51 +0900 8/24/03, micro-people wrote, and I snipped:
>
set a to 2 ^ 32
>
set b to 99991231 + 99991231
>
set fileNum to open for access file "sarigama:as:test" with write permission
>
set fileEnd to get eof fileNum
>
write (a as text) & return to fileNum starting at (fileEnd + 1)
AppleScript has an artificially short limit for integers. It's +/- (2^29 -3) = 536870909. After that numbers are converted to floating point. Long double (64) bit integers are never used. The same for unsigned long integers which would almost, but not quite, allow your 2^32. Your item b remains in integer form but whether AppleScript converts to floats before doing the addition is not documented.
AppleScript doesn't do formatting for you. E+9 is all that it offers. There are probably some free contributions on the WWW to fix that. Someone recently mentioned using the UNIX bc calculator from AppleScript.
It is reasonable for AppleScript to require that you specify something about the format of an item to be written to a file. Your "weird = couldn't read it" things were probably just the bytes representing the internal floating point or integer representation of the numbers. Dumped with a hex editor they might have been more understandable. Adding the "as text" is the same as doing a "print" or "sprint" in most other languages except that it's not as flexible. Both convert a binary number to ASCII (or another) character encoding. Coertion is a buzzword for searching documentation. AppleScript automatically coerces some types but you have discovered that it does not automatically coerce numeric types to text in the context of a write command.
These lines work for appending to an existing file:
set logPath to "Ganymede:WebPages:Logs:mail_log_appl"
set startline to "#### Starting APPL " & (current date) & return
set thelog to (open for access file logPath with write permission)
write startline to thelog starting at eof
--
--> There are 10 kinds of people: those who understand binary, and those who don't <--
_______________________________________________
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.
References: | |
| >as is what? (From: micro-people <email@hidden>) |