forked from rebolsource/r3
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New COMPOSE behavior: splice only if ((...))
This is a behavior change (on par with evaluative SWITCH) which makes COMPOSE not splice generated blocks until they are doubled up. >> block: [a b c] >> compose [normal: (block) spliced: ((block))] == [normal: [a b c] spliced: a b c] It was a desirable option when the idea of doubled groups came up, as the fatter appearance suggests some sort of multiplicity. But the first run of the idea was to let it be fatter to suggest "protection" against splicing. Yet pushing the desirability over the edge is the new semantics of quoting in compose, where a quoted group means quoting that thing: >> var: first [foo] >> compose [word: '(var)] == [word: 'foo] This concept of merging the quote onto the material is powerful, and does not go along with the idea of single-parentheses associating with a splice. >> block: [a b c] >> compose ['(block) (block): :(block)] == ['[a b c] [a b c]: :[a b c]] In practice, the change of making it clear where the splices are is extremely clarifying when reading code. It might look a little bit "cluttered" if you have to double up both your blocks and your groups wen writing things out literally: compose [ "item one" ((if condition [[ "item two" "item three" ]])) "item four" ] On the other hand, there are now quoted blocks plus soft quoted branch handling to make it look a bit more clear: compose [ "item one" ((if condition '[ "item two" "item three" ])) "item four" ] The mechanism for how this works is very interesting, because there is an option to run a post-processing function on each slot. And what (( )) is actually doing is asking not to run that function. But the default function behavior is ENBLOCK. Hence all slots actually are splicing...they're just splicing things in blocks, and (( )) asks not to put it in the block. That means if you want all slots to splice you just ask to use the function IDENTITY. compose /identity [ "item one" (if condition [[ "item two" "item three" ]]) "item four" ] The meaning of /ONLY is changed to mean "do not interpret ((...)) specially". This could technically come in handy if you have groups that wind up being generated from expressions and you are doing some kind of compose-of-a-compose, and you don't want that pattern appearing indavertently to splice. But the more important reason in the near term is so that old compose has the parameter to be used in a fast emulation: compose-redbol: specialize (adapt 'compose [ if only [predicate: null] ])[ predicate: :identity ] This makes an adaptation of compose which disables splicing when the only switch is used. Then it specializes the predicate out of the interface by defaulting it to true, leaving /only on the interface to control both properties. So that will be used to implement COMPOSE in the Redbol emulation.
- Loading branch information
1 parent
864ef4b
commit 31aa9be
Showing
35 changed files
with
250 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.