Literal collections are coming to you :)
testNestedLiteralSet | compiler | compiler := OpalCompiler new. compiler compilationContext parserClass: RBParserLiteralCollection. self assert: (compiler evaluate: '{ :Set 1 . { :Set 2 . 2 } . 1}' ) equals: (Set new add: 1 ; add: (Set new add: 2; add: 2; yourself); add: 1 ;yourself). testOrderedCollection | compiler | compiler := OpalCompiler new. compiler compilationContext parserClass: RBParserLiteralCollection. self assert: (compiler evaluate: '{ :OrderedCollection 1 . 2 . 1 . 3}â ) equals: #(1 2 1 3) asOrderedCollection. testDictionary | compiler dict | compiler := OpalCompiler new. compiler compilationContext parserClass: RBParserLiteralCollection. dict := (compiler evaluate: '{ :Dictionary #a -> 33 . #b -> 44}' ). self assert: (dict at: #a) equals: 33 I want to thank dave mason for the design! S
Great!! Thanks, Stef! Now on to the parrot operator, initializing local variables at point of declaration, and destructuring collections.... (For those for whom these are new ideas, see: https://github.com/dvmason/Pharo-Functional ) ../Dave On Mon, 18 Sept 2023 at 15:40, stephane ducasse <stephane.ducasse@inria.fr> wrote:
testNestedLiteralSet
| compiler | compiler := OpalCompiler new. compiler compilationContext parserClass: RBParserLiteralCollection. self assert: (compiler evaluate: '{ :Set 1 . { :Set 2 . 2 } . 1}' ) equals: (Set new add: 1 ; add: (Set new add: 2; add: 2; yourself); add: 1 ;yourself).
testOrderedCollection
| compiler | compiler := OpalCompiler new. compiler compilationContext parserClass: RBParserLiteralCollection. self assert: (compiler evaluate: '{ :OrderedCollection 1 . 2 . 1 . 3}â ) equals: #(1 2 1 3) asOrderedCollection.
testDictionary
| compiler dict | compiler := OpalCompiler new. compiler compilationContext parserClass: RBParserLiteralCollection. dict := (compiler evaluate: '{ :Dictionary #a -> 33 . #b -> 44}' ). self assert: (dict at: #a) equals: 33
I want to thank dave mason for the design!
S
participants (2)
-
David Mason -
stephane ducasse