3 ms·
And You Thought C++ Was Bad
- prophetjohn 15y agoI don't see how this is supposed to be comparable to C++. AppleScript is buggy and C++ is, I dunno, hard to learn? I guess that's the point that's being made. The thing with C++ is that if you have bugs in your C++ code, it's probably your fault and not the language's. p.s. Not trying to debate the merits of C++.
- zackmorris 15y agoYa I posted a few of my problems with C++ in the comments of the post, mainly with things like std::map<int, std::map<int, int>> being fixed in C++11 instead of the compiler thinking it's shift right. So c++ can have bugs but far less often. The point I was trying to make was that people do a lot of "real work" with VB, Applescript and other high level languages and it's completely unacceptable for them to have a bug this prevalent. I just had one of those canary in a coal mine moments where the whole language is now suspect for me.
- js2 15y agoThis is one of the subtleties of Applescript, but it is not a bug. See http://macscripter.net/viewtopic.php?pid=96613#p96613 http://macscripter.net/viewtopic.php?pid=96613#p96613 and http://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScriptLanguageGuide.pdf http://developer.apple.com/library/mac/documentation/AppleSc... Note that within the loop, the loop variable (currentWord) is a reference to an item in a list, so in the test statement (if contents of currentWord is equal to "hammer" then) it must be cast to text (as text). So you can either use something like: contents of theItem is "hello" or theItem as text is "hello" A reduction of your example: set hello to "hello" set ref_hello to a reference to hello log (ref_hello = hello) -- false log (contents of ref_hello = hello) -- true log (ref_hello as text = hello) -- true A similar gotcha to Java's hashCode/equals perhaps.
- zackmorris 15y agoThanks very much for this, I've updated the post and hopefully it will help somebody in the future.
- teyc 15y agoSo is a string a value type in AppleScript?
- tzs 15y agoI have never been able to build a mental model of Applescript sufficient to allow me to work with it. For example, when trying to script the Terminal application, this works: set current settings of first tab of first window to first settings set this does not: set first_set to first settings set set current settings of first tab of first window to first_set but this does: set first_set to a reference to first settings set set current settings of first tab of first window to first_set Or suppose you have a tab ("get first tab of first window"). You want the container of that, so you try to apply the obvious "container of" to the tab. Nope. Nearly every attempt I've made to use Applescript has ended in frustration when something that every book I've found tells me should work nearly everywhere does not work in the specific application I'm trying to script, and either I can't figure out a work around, or I eventually come up with something I don't understand like my first example above of referencing terminal settings.
- js2 15y agoTry reading "AppleScript: The Definitive Guide". It's the only Applescript book I've read that's worth anything and clarified a lot for me.