Or #ifNotNil: class metaclass ifNotNil: [ :metaclass | metaclass xxx. metaclass yyy ]. With the added benefit to not do anything with nil. Christian
-----Ursprüngliche Nachricht----- Von: Pharo-users <pharo-users-bounces@lists.pharo.org> Im Auftrag von Sven Van Caekenberghe Gesendet: Montag, 4. März 2019 14:35 An: Any question about pharo is welcome <pharo-users@lists.pharo.org> Betreff: Re: [Pharo-users] A "with" construct like Pascal - easy to do, but is it terrible?
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