Re: Reading nested lists from a preference file
Re: Reading nested lists from a preference file
- Subject: Re: Reading nested lists from a preference file
- From: Sander Tekelenburg <email@hidden>
- Date: Tue, 24 Apr 2001 07:54:00 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 14:00 +0900 UTC, on 24/04/2001, Yosuke Ichikawa wrote:
>
I'm working with a nested list. To give a simplified
>
example, I want the script to work like so;
>
>
set thelist to {"a", "b", {"c", "d", "e"}}
>
item 3 of thelist
>
--> {"c", "d", "e"}
>
>
...where the nested list is itself a list item in the
>
larger list.
>
>
Seems simple enough, but I want to keep this nested list
>
part as a separate preference file. I've never done this
>
before, and I cannot get AS to read it properly.
In my experience you can write a list to file by specifically saying so:
set theContent to {1, 2, 3}
set theFile to open for access (choose file) with write permission
write theContent to theFile as list
close access theFile
Except that writing as anything but text/string is completely broken in AS
1.5.5, which came with OS 9.1. It seems to have been fixed in AS 1.6 though.
Once written to a file as list, you can read it as list:
set theFile to open for access (choose file)
read theFile as list
close access theFile
But... when I just tried to verify this under Mac OS 9.0.4 (AS 1.4.3), I
found that though the above example seems to work fine, it breaks when
dealing with nested lists :(
In fact, when using the list in your example, Script Editor gives an "out of
memory" error (even with 30MB RAM assigned) when I try to read the file.
Trying a few times in a row results in Script Editor freezing completely.
Interestingly, when the list is
{1, 2, 3, "hi", {"a", "b", "c"}}
it reports no errors nor does it freeze, but it does give an interesting
result:
set theFile to open for access (choose file)
read theFile as list
close access theFile
--> {1, 2, 3, "hi", {"a",<<data
EXT544558540000000163000000000000000A94C670AB00001E00000070000EE4380000000010
000000000000186C69737400000004000000006C6F6E6700000004000000016C6F6E6700000004
000000026C6F6E670000000400000003544558540000000268690000000000200A824438000C00
0000000000677800050A94A1D00A94C6E0AB000008000001A0000EE24800000000089A74730000
00186C697374000000010000000054455854000000016154C75010000000000000200A82443845
58000008E25941434300000A94A1D00A94C75000000000000001500A824438554C000009124153
746C00000A94A1D0746E0000092A4153646C000009364153653100000942415365320000094E41
536E660000095A41536E700000096663636F6400020972494E49540000099670726F63000009A2
63667267000009AE66746167000009BA008000001000000000000A94C6F010000000000005700A
94CF30000>>, "a"}}
[Note that I changed the chevrons into brackets to keep the list server from
screwing them up.]
What the heck is going on here? I thought the "write as anything but text"
bug was introduced in AS 1.5.5, but this looks like it has been around for
much longer... (I'll have to boot into OS 9.1 to test if this has *really*
been fied in AS 1.6 or if I was just hallucinating.)
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBOuUU4usywKfXgqKdEQJovwCg9ZxvuUF4Ffo2yPQmI5dg6HYr8/YAoLLs
qI36Yik0LUvAr30NpC6NubQl
=vTEG
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!"