{...} syntactic sugar to create late bound arrays

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

{...} syntactic sugar to create late bound arrays

Louis LaBrunda
Hi,

Squeak and I expect Pharo have the ability to create arrays by putting a bunch of Smalltalk code between {} similar to #() for constants.  I think this is some syntactic sugar to create the late bound array.  For example: {Date today. Time now} will create a two element array with the todays date in the first element and the current time in the second.

There are times when I think this would be very useful.  Does VA Smalltalk have this feature?  If it does I've missed it.  Any chance of it being added to VA Smalltalk?  I don't know if the Seaside code uses this.  If it doesn't it could in the future.

Is this a good thing to add to VA Smalltalk or is it too different from the normal syntax?

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

John O'Keefe-3
Lou -
 
Yes, Squeak and Pharo both use #{ } to create dynamic arrays. For readers who are not familiar with dynamic arrays, your example of #{Date today. Time now} is equivalent to Array with: Date today with: Time now.
 
Can you give some examples of "...times when I think this would be very useful"?
 
VA Smalltalk does not support the #{ } syntax; Seaside does not (and will not) use the #{ } syntax because it is not portable across Smalltalk platforms; we have no current plans to implement the #{ } form of creating arrays.
 
John
On Wednesday, July 10, 2013 4:28:52 PM UTC-4, Louis LaBrunda wrote:
Hi,

Squeak and I expect Pharo have the ability to create arrays by putting a bunch of Smalltalk code between {} similar to #() for constants.  I think this is some syntactic sugar to create the late bound array.  For example: {Date today. Time now} will create a two element array with the todays date in the first element and the current time in the second.

There are times when I think this would be very useful.  Does VA Smalltalk have this feature?  If it does I've missed it.  Any chance of it being added to VA Smalltalk?  I don't know if the Seaside code uses this.  If it doesn't it could in the future.

Is this a good thing to add to VA Smalltalk or is it too different from the normal syntax?

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

Louis LaBrunda
Hi John,

I did say  "...times when I think this would be very useful" didn't I, that was probably too strong.  I guess when I'm feeling terse, it would be a nice to have and would look neater than "Array with:...".  Given that it is not widely supported and would require a compiler change and not just some new methods, I think it is not worth the effort.  Thanks anyway.

Lou

On Thursday, July 11, 2013 10:54:05 AM UTC-4, John O'Keefe wrote:
Lou -
 
Yes, Squeak and Pharo both use #{ } to create dynamic arrays. For readers who are not familiar with dynamic arrays, your example of #{Date today. Time now} is equivalent to Array with: Date today with: Time now.
 
Can you give some examples of "...times when I think this would be very useful"?
 
VA Smalltalk does not support the #{ } syntax; Seaside does not (and will not) use the #{ } syntax because it is not portable across Smalltalk platforms; we have no current plans to implement the #{ } form of creating arrays.
 
John
On Wednesday, July 10, 2013 4:28:52 PM UTC-4, Louis LaBrunda wrote:
Hi,

Squeak and I expect Pharo have the ability to create arrays by putting a bunch of Smalltalk code between {} similar to #() for constants.  I think this is some syntactic sugar to create the late bound array.  For example: {Date today. Time now} will create a two element array with the todays date in the first element and the current time in the second.

There are times when I think this would be very useful.  Does VA Smalltalk have this feature?  If it does I've missed it.  Any chance of it being added to VA Smalltalk?  I don't know if the Seaside code uses this.  If it doesn't it could in the future.

Is this a good thing to add to VA Smalltalk or is it too different from the normal syntax?

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

Richard Sargent (again)
In reply to this post by John O'Keefe-3
On Thursday, 11 July 2013 07:54:05 UTC-7, John O'Keefe wrote:

VA Smalltalk does not support the #{ } syntax; Seaside does not (and will not) use the #{ } syntax because it is not portable across Smalltalk platforms; we have no current plans to implement the #{ } form of creating arrays.
 
 GemStone Smalltalk also supports the {} syntax. One of Smalltalk's strengths is readability. I have many a time had to write:

(OrderedCollection new
add: something;
add: something else;
...
add: yet another thing;
yourself) asArray.


The low-level clutter of this hides the things the collection is composed of.

(By the way, I started hacking the compiler to add this, but didn't get too far.)


[And, if you are going to modify the compiler, make sure the literals in an Atom get reflected in the compiled method's literal pool. The last time I checked, they weren't.]


Thanks,
Richard

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

gcotelli
In reply to this post by John O'Keefe-3
Hi,

I find this particular construct useful in various cases for improving readability:
  • Senders of #bindWithArguments:
  • Implementors of TestCase>>#resources 
  • Platform Function calls (specially with more than six parameters) 
  • In TestCases for methods returning a collection of expected results
In this cases usually I do something similar to Richard suggestion, but it's too much verbose.

Gabriel


On Thursday, July 11, 2013 11:54:05 AM UTC-3, John O'Keefe wrote:
Lou -
 
Yes, Squeak and Pharo both use #{ } to create dynamic arrays. For readers who are not familiar with dynamic arrays, your example of #{Date today. Time now} is equivalent to Array with: Date today with: Time now.
 
Can you give some examples of "...times when I think this would be very useful"?
 
VA Smalltalk does not support the #{ } syntax; Seaside does not (and will not) use the #{ } syntax because it is not portable across Smalltalk platforms; we have no current plans to implement the #{ } form of creating arrays.
 
John
On Wednesday, July 10, 2013 4:28:52 PM UTC-4, Louis LaBrunda wrote:
Hi,

Squeak and I expect Pharo have the ability to create arrays by putting a bunch of Smalltalk code between {} similar to #() for constants.  I think this is some syntactic sugar to create the late bound array.  For example: {Date today. Time now} will create a two element array with the todays date in the first element and the current time in the second.

There are times when I think this would be very useful.  Does VA Smalltalk have this feature?  If it does I've missed it.  Any chance of it being added to VA Smalltalk?  I don't know if the Seaside code uses this.  If it doesn't it could in the future.

Is this a good thing to add to VA Smalltalk or is it too different from the normal syntax?

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

Louis LaBrunda
Hi Guys,

As I said, I like this little bit of syntactic sugar but when asked by John, I couldn't come up with good examples.  I think it can often help readability, not just by putting what you want in an array with less messages but by not breaking up the code above and below it.  Thanks for the examples and the support.  Hopefully it won't take much to add it if Instantiations chooses to take a look at doing so.

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

jtuchel
In reply to this post by gcotelli
Gabriel,

good points, especially the tests and bidWithArguments.

I see at least one more case: when I want to port code from Pharo/Squeak to VAST. The problem with porting is that it is not a one-time thing, you need to reimport the code for every new release of a tool that you want to import.

On the other hand, I don't really like the construct, because I find it hard to read. You need to remember what Collection class is constructed with {}, and that is not very consistent with the rest of Smalltalk. At least IMO.

Joachim



Am Freitag, 12. Juli 2013 14:55:17 UTC+2 schrieb Gabriel Cotelli:
Hi,

I find this particular construct useful in various cases for improving readability:
  • Senders of #bindWithArguments:
  • Implementors of TestCase>>#resources 
  • Platform Function calls (specially with more than six parameters) 
  • In TestCases for methods returning a collection of expected results
In this cases usually I do something similar to Richard suggestion, but it's too much verbose.

Gabriel


On Thursday, July 11, 2013 11:54:05 AM UTC-3, John O'Keefe wrote:
Lou -
 
Yes, Squeak and Pharo both use #{ } to create dynamic arrays. For readers who are not familiar with dynamic arrays, your example of #{Date today. Time now} is equivalent to Array with: Date today with: Time now.
 
Can you give some examples of "...times when I think this would be very useful"?
 
VA Smalltalk does not support the #{ } syntax; Seaside does not (and will not) use the #{ } syntax because it is not portable across Smalltalk platforms; we have no current plans to implement the #{ } form of creating arrays.
 
John
On Wednesday, July 10, 2013 4:28:52 PM UTC-4, Louis LaBrunda wrote:
Hi,

Squeak and I expect Pharo have the ability to create arrays by putting a bunch of Smalltalk code between {} similar to #() for constants.  I think this is some syntactic sugar to create the late bound array.  For example: {Date today. Time now} will create a two element array with the todays date in the first element and the current time in the second.

There are times when I think this would be very useful.  Does VA Smalltalk have this feature?  If it does I've missed it.  Any chance of it being added to VA Smalltalk?  I don't know if the Seaside code uses this.  If it doesn't it could in the future.

Is this a good thing to add to VA Smalltalk or is it too different from the normal syntax?

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

jtuchel
There's one more scenario, ich which I sometimes wish for a quick, hacky way to produce some collection: when I write a snippet of coe in a workspace that's just a quick hack to test something.

Not really a string argument in advance of the {} syntax...

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

Louis LaBrunda
In reply to this post by John O'Keefe-3
Hi John,

On Thursday, July 11, 2013 10:54:05 AM UTC-4, John O'Keefe wrote:
Lou -
 
snip..
 
Can you give some examples of "...times when I think this would be very useful"?
 
snip..

I just ran into a case where this would be useful.  I would like to create a large (100+ elements) array of points.  I would like to treat/create the points as constants in the array like: {4@5. 7@6. 8@9....}

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

Dusty-2
Allthough not relevent for VAST, Pharo Morphic uses this for building its interfaces easily, eg:

toolbar
    ^ toolbar ifNil: [ | tools |
        tools := self newToolbar: {
            self newButtonFor: self getState: nil action: #save arguments: nil getEnabled: nil
                labelForm: (ArchiImages save scaledToSize: 16@16) help: 'Save'.
            self newToolSpacer.
            self newButtonFor: self getState: nil action: #saveAs arguments: nil getEnabled: nil
                labelForm: (ArchiImages saveas scaledToSize: 16@16) help: 'Save As'.
            self newToolSpacer.....}
.

        toolbar := self newToolDockingBar addMorph: tools]



On Thu, Aug 1, 2013 at 9:50 PM, Louis LaBrunda <[hidden email]> wrote:
Hi John,

On Thursday, July 11, 2013 10:54:05 AM UTC-4, John O'Keefe wrote:
Lou -
 
snip..
 
Can you give some examples of "...times when I think this would be very useful"?
 
snip..

I just ran into a case where this would be useful.  I would like to create a large (100+ elements) array of points.  I would like to treat/create the points as constants in the array like: {4@5. 7@6. 8@9....}

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
bpi
Reply | Threaded
Open this post in threaded view
|

Re: {...} syntactic sugar to create late bound arrays

bpi
Hi all,

Just for the record. I also find it very useful, and would love to have it in VA Smalltalk as well.

Cheers,
Bernhard

Am 02.08.2013 um 10:42 schrieb Dusty:

> Allthough not relevent for VAST, Pharo Morphic uses this for building its interfaces easily, eg:
>
> toolbar
>     ^ toolbar ifNil: [ | tools |
>         tools := self newToolbar: {
>             self newButtonFor: self getState: nil action: #save arguments: nil getEnabled: nil
>                 labelForm: (ArchiImages save scaledToSize: 16@16) help: 'Save'.
>             self newToolSpacer.
>             self newButtonFor: self getState: nil action: #saveAs arguments: nil getEnabled: nil
>                 labelForm: (ArchiImages saveas scaledToSize: 16@16) help: 'Save As'.
>             self newToolSpacer.....}.
>
>         toolbar := self newToolDockingBar addMorph: tools]
>
>
> On Thu, Aug 1, 2013 at 9:50 PM, Louis LaBrunda <[hidden email]> wrote:
> Hi John,
>
> On Thursday, July 11, 2013 10:54:05 AM UTC-4, John O'Keefe wrote:
> Lou -
>  
> snip..
>  
> Can you give some examples of "...times when I think this would be very useful"?
>  
> snip..
>
> I just ran into a case where this would be useful.  I would like to create a large (100+ elements) array of points.  I would like to treat/create the points as constants in the array like: {4@5. 7@6. 8@9....}
>
> Lou
>
> --
> You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/va-smalltalk.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>
>
> --
> You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/va-smalltalk.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.