Re: [F-Script-talk] Re: Methods in F-Script.
Brought to you by:
pmougin
From: Todd B. <tbl...@ma...> - 2005-07-16 06:40:10
|
Yes, I'm working on building a little application with it to make =20 sure it is practical and I think I will release it at the end of summer. As for the special case behavior - I noticed that you already added =20 half (valueForKey:). I added the other half. :-) I spent some time trying to make NSManagedObject work with message =20 sends by overriding repondsToSelector: forwardInvocation: and =20 methodSignatureForSelector:. NSManagedObject didn't like this at all =20= and I found myself with a hung program and completely unresponsive =20 debugger. For what I'm doing, the special case is nice because before I did it, =20= all the rules had to use setValue:forKey: and this began to feel kind =20= of ugly. I can't decide yet if its worth the added complexity. I =20 got a very boring but useful application working very quickly using =20 coredata, IB, and clips rules, but I an now stuck in Hell with =20 various bits of AppKit as I try to get some custom UI working. I'll have a firmer opinion with more experience with it. On Jul 15, 2005, at 5:37 AM, Philippe Mougin wrote: > > Tood, this is quite interesting. Are you going to release this =20 > CLIPS/F-Script/Cocoa integration in some form? > About the automatic translation from setValue:val forKey:'foo' to =20 > setFoo:val for managed objects, this is something I'm considering =20 > adding to F-Script but I want to be sure it will be useful and is =20 > not going to cause unintended problems. Did you encountered any =20 > problem with it ? Do you think it's worth adding to the main F-=20 > Script distribution ? One problem I see with this kind of stuff is =20 > that the more you have such "special case" behavior, the more the =20 > language is complex and difficult to master for its users. > > Cheers, > > Philippe > > Le 14 juil. 05 =E0 03:07, Todd Blanchard a =E9crit : > >> Huh, seems like a theme. I've been working on an app based on =20 >> integrating the following components: >> >> CoreData - basic object modeling and persistence >> CLIPS - see http://www.ghg.net/clips/CLIPS.html - constraints/=20 >> intelligence/rules >> FScript - actions and predicates from CLIPS. >> >> (Yes Philippe - this is based on the thing I showed you at the =20 >> Paris Squeaknic a couple years ago). >> >> CLIPS is pretty pluggable - you can install new functions into the =20= >> interpreter by handing it a C function pointer and registering =20 >> it. You can also register a custom parser to parse the rest of =20 >> the function line. I registered a function named '[' and in the =20 >> parser I just scan to the matching ']' and then pick out the =20 >> variables in the expression and bind them in the FScript symbol =20 >> table. With this you can write predicates in FScript. So you =20 >> could write the clips rule: >> >> (defrule event-is-active >> ?event<-(Event (startDate ?start&:([NSDate date > ?start])) =20 >> (endDate ?end&:([NSDate date < endDate])) (status ~active)) >> =3D> >> ([?event setStatus: 'active'])) >> >> Which says - match any Event with a startDate later than now, an =20 >> endDate earlier than now, and status not set to active >> =3D> (then) >> set the status to active. >> >> The CoreData/CLIPS integration allows you to assert CoreData =20 >> objects as 'facts' in the CLIPS knowledge base so the rules can =20 >> match them. This is why the above rule even works. Each core =20 >> data object has a 'fact' that shadows the values. KVO allows me =20 >> to keep the fact sync'd with the object. >> >> Lately I've been wishing I could have derived attributes that are =20 >> calculated based on other attributes. This is useful for binding =20 >> table columns and such. To do this, I override valueForKey: in =20 >> KBManagedObject (my NSManagedObject subclass) to look up the =20 >> userInfo on the attribute description and look for a key called =20 >> "value". This should be an FScript expression that I toss into a =20= >> block and evaluate. I'm using this to model a Week object where I =20= >> just have one real persistent attribute 'sunday'. The 'monday', =20 >> 'tuesday' etc are transient attributes that have FScript =20 >> expressions like 'self sunday dateByAddingDays: 1'. I slap this =20 >> into a template that looks like '[:self | %@ ]' and evaluate it as =20= >> a block with the managed object as an argument. >> >> I've also notice that the latest FScript has a special case for =20 >> NSManagedObject's and "fakes" zero argument message sends that are =20= >> the same name as an attribute and calls valueForKey: I've =20 >> extended it to include mutator support as well. So even if you =20 >> are using vanilla managed objects, you can still do setFoo: val =20 >> instead of setValue: val forKey: 'Foo' >> >> This little combination has proven really powerful. I've build a =20 >> working project management app with just clips rules, IB bindings, =20= >> and a CoreData model. It works OK but its pretty vanilla. I've =20 >> been working on sexing up the UI and this is rapidly turning into =20 >> a black hole. But for quickie apps based on calculations and =20 >> constraints, this little framework is da bomb. >> >> I added the following to ExecEngine.m >> >> static NSString* keyFromMutator(NSString* key) >> { >> if([key hasPrefix: @"set"]) >> { >> key =3D [[[key substringWithRange: NSMakeRange(3,1)] =20 >> lowercaseString] >> stringByAppendingString: [key substringWithRange: =20 >> NSMakeRange(4,[key length]-5)]]; >> } >> return key; >> } >> >> and changed the special case for NSMangedObject in =20 >> sendMsgNoPattern to read: >> >> else if (![receiver isProxy] && [receiver =20 >> isKindOfClass:NSClassFromString(@"NSManagedObject")] && =20 >> [[[[receiver entity] propertiesByName] allKeys] =20 >> containsObject:keyFromMutator(selectorStr)]) >> // We don't support proxy here because it will crash when the =20 >> isKindOfClass:NSClassFromString(@"NSManagedObject") message is =20 >> executed on Mac OS X < 10.4 >> { >> if([selectorStr hasPrefix: @"set"] && [selectorStr =20 >> hasSuffix: @":"] && numbersOfArguments =3D=3D 3) >> { >> return [receiver performSelector:@selector=20 >> (setValue:forKey:) withObject: args[2] withObject: keyFromMutator=20 >> (selectorStr)]; >> } >> else >> { >> return [receiver performSelector:@selector(valueForKey:) =20 >> withObject:selectorStr]; >> } >> } >> >> >> On Jul 13, 2005, at 4:55 AM, Marcel Weiher wrote: >> >>> >>> On 13 Jul 2005, at 12:36, Massimiliano Gubinelli wrote: >>> >>> >>>> recently I wrote some code which allows to override an =20 >>>> arbitrary objc methods by sending the corresponding NSInvocation =20= >>>> to a delegate for handling. >>>> >>> >>> Cool. I wrote something very similar for Objective-Smalltalk, =20 >>> which I haven't been able to work much on recently. >>> >>> >>>> My purpose is to use this technique to extend objc classes from =20 >>>> an external language (Io, in my case). However I think that such =20= >>>> a mechanism can be also useful in F-Script to replace native =20 >>>> methods with scripts (and ultimately to be able to define ObjC =20 >>>> classes in F-Script). >>>> >>> >>> Yup. >>> >>> >>> --=20 >>> >>> Marcel Weiher Metaobject Software Technologies >>> ma...@me... www.metaobject.com >>> Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc. >>> 1d480c25f397c4786386135f8e8938e4 >>> >>> >>> >>> >>> ------------------------------------------------------- >>> This SF.Net email is sponsored by the 'Do More With Dual!' =20 >>> webinar happening >>> July 14 at 8am PDT/11am EDT. We invite you to explore the latest =20 >>> in dual >>> core and dual graphics technology at this free one hour event =20 >>> hosted by HP,AMD, and NVIDIA. To register visit http://=20 >>> www.hp.com/go/dualwebinar >>> _______________________________________________ >>> F-Script-talk mailing list >>> F-S...@li... >>> https://lists.sourceforge.net/lists/listinfo/f-script-talk >>> >> > |