Literal collections are coming to you :)

SD
stephane ducasse
Mon, Sep 18, 2023 7:36 PM

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

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
DM
David Mason
Mon, Sep 18, 2023 10:28 PM

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

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 > > >