4 ms·
Interesting project, but I have a couple of nitpicks about the examples page (http://www.objective.st/Examples/ http://www.objective.st/Examples/): > A method
by saagarjha 8y ago
Interesting project, but I have a couple of nitpicks about the examples page (http://www.objective.st/Examples/ http://www.objective.st/Examples/):
> A method that deletes a file and fades out the icon representing that file:
-<void>deleteFile:filename {
thumbs := self thumbsView subviews.
viewsToRemove := thumbs selectWhereValueForKey:'filename' isEqual:filename.
aView := viewsToRemove firstObject.
UIView animateWithDuration:0.4
animations: { aView setAlpha: 0.0. }
completion: { aView removeFromSuperview.
UIView animateWithDuration: 0.2
animations: { self thumbsView layoutSubviews. }
completion: { 3 }.
}.
url := self urlForFile:aFilename.
NSFileManager defaultManager removeItemAtURL:url error:nil.
self thumbsView afterDelay:0.4 | setNeedsLayout.
}
> Blocks become significantly more readable with Smalltalk syntax.
I'm not really seeing this–the only thing you're missing is the caret and a parameter list, which is strange because it now seems like you can't name your parameters anymore? Are you forced to use the names that the headers suggest? What if there are none in the prototype? (Also, I'm assuming '|' is a separator to make up for the lack of brackets?)
> As shown in some of the previous examples, Higher Order Messaging (HOM) is fully supported and helps make code more compact and readable. Take as an example the following code:
self view subviews do setNeedsDisplay.
> This code iterates the subviews of the view controllers view and sends each one the setNeedsDisplay message. In Objective-C the code would probably look as follows:
for ( NSView *aView in [[self view] subviews] ) {
[aView setNeedsDisplay];
}
> While the code is not that much longer, it obscures the central point of the code, the setNeedsDisplay message, with the machinery for iterating the subviews.
Objective-C has -[NSArray makeObjectsPerformSelector:]:
[self.view.subviews makeObjectsPerformSelector:@selector(setNeedsDisplay)]
Finally, can I actually use this to write an app? From your code examples, it looks like you can interact with UIKit, but can I publish an app with Obejctive-Smalltalk in it to the App Store?
- mpweiher 8y ago> nitpicks Yeah, the examples page isn't very good right now. Also out of date. I actually didn't expect this to go to the front page quite yet. Ooops. > [blocks] There is http://fuckingblocksyntax.com http://fuckingblocksyntax.com ¯\_(ツ)_/¯ But yes, the block examples certainly aren't very revealing. One reason is that I wanted to take examples from actual Objective-Smalltalk "production" code, not just make up good-looking examples, and so the choices were more limited (not that much production code yet...). One reason is that all these blocks are parameterless blocks, which is also why you don't see parameter lists. > makeObjectsPerformSelector: Yes, that was an inspiration for enum-filters, which then turned into HOM. See http://www.metaobject.com/papers/HOM-Presentation.pdf http://www.metaobject.com/papers/HOM-Presentation.pdf (via https://en.wikipedia.org/wiki/Higher_order_message https://en.wikipedia.org/wiki/Higher_order_message) However, this also obscures the central point of the code, forcing you to put it in an argument of the -makeObjectsPerformSelector: message (the MacHack presentation talks about this a bit). Note also that it says "HOM is fully supported". HOM is actually implemented in/for Objective-C, so you can also use it there: [[self.view.subviews do] setNeedsDisplay] [self.view.subviews makeObjectsPerformSelector:@selector(setNeedsDisplay)] You can see more HOM examples in the README for the Docker container script: https://github.com/mpw/objective-smalltalk-container https://github.com/mpw/objective-smalltalk-container It is part of MPWFoundation: https://github.com/mpw/MPWFoundation https://github.com/mpw/MPWFoundation (which also has the ifResponds examples) 1 to: 100 | reduce + 0 > (Also, I'm assuming '|' is a separator to make up for the lack of brackets?) No, you can always parenthesise expressions: (1 to:100 ) reduce + 0 The | is actually a bit deeper, Objective-Smalltalk integrates support for pipes and filters, via Object Streams/Object Filters (https://github.com/mpw/MPWFoundation/blob/master/Documentation/Streams.md https://github.com/mpw/MPWFoundation/blob/master/Documentati...). This also means that "nested" expressions are treated as chained "expression filters", with the result of the previous expression being "piped" into the next expression as the receiver. This isn't fully integrated yet, but here's an example of a filter as a script: #!/usr/local/bin/stsh (stdin -> { $0 stringValue uppercaseString. } -> rawstdout ) run (Yeah, it uses '->' instead of '|', as I wrote, it isn't fully integrated yet). The | also solves an oddity/asymmetry in the Smalltalk syntax, which is that the cascade "operator" (;) doesn't have an equivalent for message chains. receiver firstmsg; secondmsg:arg1; thirdmsg:arg2; All these messages go to the receiver. Let's try the same thing with chaining, meaning each subsequent message goes to the result of the previous message: receiver firstmsg secondmsg:arg1 thirdmsg:arg2. The first message works as expected. However, due to the keyword message syntax, the rest gets interpreted as the single message -secondmsg:arg1 thirgmsg:arg2. Not what we wanted. So you have to use parentheses to disambiguate: (receiver firstmsg secondmsg:arg1) thirdmsg:arg2. You didn't need them for the unary message -firstmsg and also not for the final one because it's not chained. But let's add another: (receiver firstmsg secondmsg:arg1) thirdmsg:arg2. fourthmessage. That also doesn't work quite right because unary messages bind stronger, so this is actually ... thirdmsg:(arg2 fourthmessage). Yikes. receiver firstmsg | secondmsg:arg1 | thirdmsg: arg2 | fourhtmsg. The fact that you don't have to go back and add parentheses at the front if you add messages at the end is particular helpful in REPLs like stsh. > can I publish an app with Objective-Smalltalk in it to the App Store? Yes. BookLightning is in Mac AppStore and written in part in Objective-Smalltalk. Objective-Smalltalk doesn't violate any AppStore rules. And the syntax page doesn't talk about property paths at all, which generalise properties and allow you to easily create scheme-handlers for Polymorphic Identifiers. See https://github.com/mpw/Objective-Smalltalk/blob/master/scripts/sqlitescheme.stsh https://github.com/mpw/Objective-Smalltalk/blob/master/scrip.... /:table { |= { self dictionariesForQuery: "select * from {table}". } }