9 ms·
> 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. > [
by 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}". }
}