Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing AppleScript Records with Variable Identifiers



On Mon, 04 Jul 2005 14:53:04 -0700, Paul Berkowitz <email@hidden>
said:
>On 7/4/05 2:30 PM, "Matt Neuburg" <email@hidden> wrote:

>>     NSMutableString* s =
>>         [NSMutableString stringWithString:@"howdy"];
>>     NSDictionary* d =
>>         [NSDictionary dictionaryWithObject:s forKey:@"greeting"];
>>     NSLog(@"%@",d); // {greeting = howdy; }
>>     [s setString: @"hello"];
>>     NSLog(@"%@",d); // {greeting = hello; }
>>
>> No "more rigid" than an AS record. m.
>
>Sure it is. That's a trick answer that you've set up to get around the
>limitations. If a dictionary's objects have all been defined to be mutable
>in the first place and you change the value of an object to another value of
>the same type without replacing the object, sure, OK. Not all types of
>objects can be defined as mutable, however

The shoe's on the other foot. It's AppleScript that's doing the trick: its
variables have no fixed types. After all, consider REALbasic, another
strongly typed language (much more strongly typed than Objective-C, indeed);
it has dictionaries, but that's possible only because there is a catch-all
"variant" type. Well, in AppleScript, variant is effectively the *only*
type.

Here, I'll make a sort of variant type for Objective-C:

@interface Thing : NSObject
{
    @public
    id whatever;
}
@end
@implementation Thing
- (NSString*) description {return [self->whatever description];}
@end
...
    Thing* thing = [[Thing alloc] init];
    thing->whatever = @"howdy";
    NSDictionary* d =
     [NSDictionary dictionaryWithObject: thing forKey: @"greeting"];
    NSLog(@"%@",d); // {greeting = howdy; }
    // "set greeting of d to 47"
    ((Thing*)[d objectForKey:@"greeting"])->whatever =
     [NSNumber numberWithInt: 47];
    NSLog(@"%@",d); // {greeting = 47; }

It's no use talking about pointers to pointers; implementation is not the
issue. Formally and externally, the two behaviors are exactly parallel - the
one collapses into the other as a purely syntactic-sugar variant.

So, my point is that from a formal, linguistic point of view you've got it
backwards; Cocoa/Objective-C with its NSDictionary is actually freer than an
AS record. You can make an NSDictionary behave as freely as an AS record,
but you can't make an AS record behave as restrictively as an NSDictionary.

m.

-- 
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.