short list of possible smalltalk extensions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

short list of possible smalltalk extensions

Paolo Bonzini-2
1) nested classes.  GNU Smalltalk already supports Class.ClassVar
notation to access class variables.  This could be easily extended to
support nested classes, all it requires is parser support.

Note these wouldn't be closures like Java inner classes, they would just
use the class pool dictionary as a namespace.

        hidden complications: GUI support, fileout support,
        reflection support


2) additional binary operators.  This can come in many ways:

2.a) ".." instead of #to:.  Also make the compiler recognize "a .. b do:
[]" and similar.

2.b) Unicode binary operators.  Less-than-or-equal for example.  Let's
wait for Perl 6 which also has those though. :)


3) additional literals.   #/abc/ for Regex, for example.


4) A magic DWIM "match" (I'll call it #=~) and "transform" (#<<) operator:

        [:a | true] =~ something   matches everything
        #/abc/ =~ something        means something matches regex
        #(1 3 5 10) =~ something   means something is in the collection
        'aeiouy' =~ something   strings are not special, but...
        #even =~ something         ... means "something even == true"

        [:a | a] << something      is the identity
        #/\[.*\]/ << something     gives the first regex match
        #(1 2 4 8) << something    maps key to value
        '0123456789' << something  strings are not special, but...
        #abs =~ something          ... symbols are

#select: and #reject: use #=~, #collect: uses #<<.  It is also possible
to use keyword methods, of course.


5) Extended blocks:

5.a) Anonymous variables for blocks.

        x select: [ _ even ]
        1..10 fold: [ _ + _ ]

5.b) Variable-argument blocks

        [ :r :m :a... | r perform: m withArguments: a ]
            value: 1 value: #+ value: 2

5.c) Optional (efficient) currying:

        plus := [ :r :m :a... | r perform: m withArguments: a ] curry
            value: 1 value: #+.

        plus value: 2 "=> 3"


Any more ideas?

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: short list of possible smalltalk extensions

Sungjin Chun
I like these extensions :-) But one question, how about compatibility?

On Sun, Dec 5, 2010 at 11:06, Paolo Bonzini <[hidden email]> wrote:

> 1) nested classes.  GNU Smalltalk already supports Class.ClassVar notation
> to access class variables.  This could be easily extended to support nested
> classes, all it requires is parser support.
>
> Note these wouldn't be closures like Java inner classes, they would just use
> the class pool dictionary as a namespace.
>
>        hidden complications: GUI support, fileout support,
>        reflection support
>
>
> 2) additional binary operators.  This can come in many ways:
>
> 2.a) ".." instead of #to:.  Also make the compiler recognize "a .. b do: []"
> and similar.
>
> 2.b) Unicode binary operators.  Less-than-or-equal for example.  Let's wait
> for Perl 6 which also has those though. :)
>
>
> 3) additional literals.   #/abc/ for Regex, for example.
>
>
> 4) A magic DWIM "match" (I'll call it #=~) and "transform" (#<<) operator:
>
>        [:a | true] =~ something   matches everything
>        #/abc/ =~ something        means something matches regex
>        #(1 3 5 10) =~ something   means something is in the collection
>        'aeiouy' =~ something      strings are not special, but...
>        #even =~ something         ... means "something even == true"
>
>        [:a | a] << something      is the identity
>        #/\[.*\]/ << something     gives the first regex match
>        #(1 2 4 8) << something    maps key to value
>        '0123456789' << something  strings are not special, but...
>        #abs =~ something          ... symbols are
>
> #select: and #reject: use #=~, #collect: uses #<<.  It is also possible to
> use keyword methods, of course.
>
>
> 5) Extended blocks:
>
> 5.a) Anonymous variables for blocks.
>
>        x select: [ _ even ]
>        1..10 fold: [ _ + _ ]
>
> 5.b) Variable-argument blocks
>
>        [ :r :m :a... | r perform: m withArguments: a ]
>            value: 1 value: #+ value: 2
>
> 5.c) Optional (efficient) currying:
>
>        plus := [ :r :m :a... | r perform: m withArguments: a ] curry
>            value: 1 value: #+.
>
>        plus value: 2 "=> 3"
>
>
> Any more ideas?
>
> Paolo
>
>
> _______________________________________________
> help-smalltalk mailing list
> [hidden email]
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
>
>

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: short list of possible smalltalk extensions

Paolo Bonzini-2
On 12/05/2010 09:55 AM, Sungjin Chun wrote:
> I like these extensions :-) But one question, how about compatibility?

These would all be backwards compatible.  To some extent, conversion to
other dialects could be achieved with rewrite rules
or with wrappers in the class library.

For example

    [ :args... | args asSet ]

could be equivalent to

    [ :args | args asSet ] asVariableArgumentsBlock

with

BlockClosure subclass: VariableArgumentsBlock [
     value [ ^super value: Array new ]
     value: x [ ^super value: {x} ]
     value: x value: y [ ^super value: {x. y} ]
     value: x value: y value: z [ ^super value: {x. y. z} ]
     valueWithArguments: args [ ^super value: args ]

     BlockClosure >> asVariableArgumentsBlock [
         ^self changeClassTo: VariableArgumentsBlock
     ]
]

Example:

st> b := [ :args  | args asSet ] asVariableArgumentsBlock
a VariableArgumentBlock
st> b value: 1 value: 232 value: 432
Set (432 1 232 )

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: short list of possible smalltalk extensions

Dmitry Matveev
Hello,

> 5.a) Anonymous variables for blocks.
>
>      x select: [ _ even]

As far as I know, the latest VisualWorks support another way to do it:

        x select: #even

I.e. pass a selector symbol, not a block. Just FYI :)

Dmitry

2010/12/5, Paolo Bonzini <[hidden email]>:

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: short list of possible smalltalk extensions

Paolo Bonzini-2
On 12/05/2010 01:14 PM, Dmitry Matveev wrote:

> Hello,
>
>> 5.a) Anonymous variables for blocks.
>>
>>       x select: [ _ even]
>
> As far as I know, the latest VisualWorks support another way to do it:
>
>          x select: #even
>
> I.e. pass a selector symbol, not a block. Just FYI :)

Yes, this is a fairly common extension but it has problems because
"#even numArgs" is 0 while "[:a | a even ] numArgs" is one.  This is the
main reason why GNU Smalltalk does _not_ provide Symbol>>#value (and
never will).

However, in my message there's also an alternative way to provide "x
select: #even" by tweaking the meaning of #select:'s argument.

BTW, "x select: #even" needs to use reflection so it will always be
slower than "x select: [ :a | a even]", especially when using a JIT
compiler.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: short list of possible smalltalk extensions

MrGwen
In reply to this post by Paolo Bonzini-2
Hi,

What about that:

 x foo: 1 :> bar: 2 :> baz: 3 :> zork: 4 instead of (((x foo: 1) bar:
2) baz: 3) zork: 4

(from vasily bikov blog: http://blog.3plus4.org/2007/08/30/message-chains/)

Gwen

On Sun, Dec 5, 2010 at 3:06 AM, Paolo Bonzini <[hidden email]> wrote:

> 1) nested classes.  GNU Smalltalk already supports Class.ClassVar notation
> to access class variables.  This could be easily extended to support nested
> classes, all it requires is parser support.
>
> Note these wouldn't be closures like Java inner classes, they would just use
> the class pool dictionary as a namespace.
>
>        hidden complications: GUI support, fileout support,
>        reflection support
>
>
> 2) additional binary operators.  This can come in many ways:
>
> 2.a) ".." instead of #to:.  Also make the compiler recognize "a .. b do: []"
> and similar.
>
> 2.b) Unicode binary operators.  Less-than-or-equal for example.  Let's wait
> for Perl 6 which also has those though. :)
>
>
> 3) additional literals.   #/abc/ for Regex, for example.
>
>
> 4) A magic DWIM "match" (I'll call it #=~) and "transform" (#<<) operator:
>
>        [:a | true] =~ something   matches everything
>        #/abc/ =~ something        means something matches regex
>        #(1 3 5 10) =~ something   means something is in the collection
>        'aeiouy' =~ something      strings are not special, but...
>        #even =~ something         ... means "something even == true"
>
>        [:a | a] << something      is the identity
>        #/\[.*\]/ << something     gives the first regex match
>        #(1 2 4 8) << something    maps key to value
>        '0123456789' << something  strings are not special, but...
>        #abs =~ something          ... symbols are
>
> #select: and #reject: use #=~, #collect: uses #<<.  It is also possible to
> use keyword methods, of course.
>
>
> 5) Extended blocks:
>
> 5.a) Anonymous variables for blocks.
>
>        x select: [ _ even ]
>        1..10 fold: [ _ + _ ]
>
> 5.b) Variable-argument blocks
>
>        [ :r :m :a... | r perform: m withArguments: a ]
>            value: 1 value: #+ value: 2
>
> 5.c) Optional (efficient) currying:
>
>        plus := [ :r :m :a... | r perform: m withArguments: a ] curry
>            value: 1 value: #+.
>
>        plus value: 2 "=> 3"
>
>
> Any more ideas?
>
> Paolo
>
>
> _______________________________________________
> help-smalltalk mailing list
> [hidden email]
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
>

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: short list of possible smalltalk extensions

Stefan Schmiedl
On Mon, 6 Dec 2010 10:18:28 +0100
Gwenaël Casaccio <[hidden email]> wrote:

> Hi,
>
> What about that:
>
>  x foo: 1 :> bar: 2 :> baz: 3 :> zork: 4 instead of (((x foo: 1) bar:
> 2) baz: 3) zork: 4


oooohhh... that would eliminate my favorite reason for hitting
the up arrow when writing code.

But it is a good step on the slippery slope towards complex
operator precedence rules.

s.

>
> (from vasily bikov blog: http://blog.3plus4.org/2007/08/30/message-chains/)
>
> Gwen

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk