There is #in: that does exactly that:

class metaclass in: [ :metaclass |
  metaclass xxx.
  metaclass yyy ].

This is quite similar to lisp's let.

You can do almost anything with blocks/closures.

Although not relevant in most cases, there is a small performance price to pay 
- but again this is only relevant inside performance critical loops.

> On 4 Mar 2019, at 14:06, Tim Mackinnon <tim@testit.works> wrote:
> 
> I’ve noticed that as we’ve progressed there has been a move to more concise 
> and fluid code - e.g. I quite like the new String streaming stuff
> 
> e.g. 
> 
> ^ String
>               streamContents: [ :stream | 
>                       stream nextPut: …. ]
> 
> 
> So I was wondering why we don’t have a construct like Pascals with  to avoid 
> Book1.title, Book1.author etc.
> 
> (* book 1 specification *)
> With Book1 do
> begin
> 
>    title  
> := 'C Programming';
> 
>    author 
> := 'Nuha Ali ';
>  
>    subject 
> := 'C Programming Tutorial';
> 
>    book_id 
> := 6495407;
> end;
> 
> I often find it a bit tedious with code like the following which then needs 
> an instvar...
> 
> self classes do: [ :class |
>       | metaclass |
>       metaclass := class metaclass.
>       metaclass xxxx.
>       mataclass yyyy.
> ]
> 
> 
> I’m wondering why we don’t have #with:do:  
> 
>       class with: class metaclass do: [:metaclass |
>               metaclass xxx.
>       ]
> 
> 
> But when such things aren’t there - there is usually a good reason and I’m 
> curious … this said, there are all kinds of other such tricks (which I rarely 
> use that I keep coming across).
> 
> Tim
> 


Reply via email to