[Cuis-dev] How to use Events?

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Sep 10 09:18:36 PDT 2019


I think that ##(2 at 3) notation of Dolphin (compile time literal send) or [2 at 3]
once of Visualworks by Travis Griggs did solve the same problem, so it
means that there is a demand for it.

Le mar. 10 sept. 2019 à 12:59, Juan Vuletich via Cuis-dev <
cuis-dev at lists.cuis.st> a écrit :

> Some time ago, Phil didn't like (neither do I) that we say stuff like 'a
> := 2 at 3', 'a := Float pi', or 'a := { blah. blah. blah}', we are calling
> instance creation methods all the time, and allocating new objects that
> won't be modified. But not when we do 'a := 7.0' or 'a := #(1 2 3)',
> because in these cases the objects are created at compile time. I came
> up with the backtick idea and implemented it in Cuis. It is a rather
> nice addition, other Smalltalks could follow.
>
> For Philip, (and weak references in general) making these 'literals'
> true literals means that the CompiledMethod will hold a strong reference
> to them, so they won't vanish when needed.
>
> Someway related to this is that all that literal objects should be
> immutable. This was not done yet, but we'd do it some day.
>
> Cheers,
>
> --
> Juan Vuletich
> www.cuis-smalltalk.org
> https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
> https://github.com/jvuletich
> https://www.linkedin.com/in/juan-vuletich-75611b3
> @JuanVuletich
>
>
> On 9/9/2019 10:43 PM, Casey Ransberger via Cuis-dev wrote:
> > Hey Juan, is the backticks thing specific to Cuis, or is this yet
> another magic feature of Smalltalk that I didn’t know about?
> >
> > —Casey
> >
> >> On Sep 9, 2019, at 6:04 AM, Juan Vuletich via Cuis-dev<
> cuis-dev at lists.cuis.st>  wrote:
> >>
> >>> On 9/9/2019 3:17 AM, Philip Bernhart via Cuis-dev wrote:
> >>> Hello,
> >>>
> >>> I noticed that when I register events with when:send:to:with: with
> collections
> >>> as the with: paramater the contents of the collection the collection
> >>> becomes nil on the actually triggered event. Maybe that has something
> >>> todo with WeakMessageSend. Anyway an example tells better what I mean:
> >>>
> >>>
> >>> browserMorph
> >>>     setProperty: #editItemAction
> >>>     toValue: [:repository :record|
> >>>         | flashcardMorph card mapping |
> >>>         flashcardMorph _ FlashcardMorph new.
> >>>         card _ Flashcard new.
> >>>         card question: (record at: #question ifAbsent: '').
> >>>         card answer: (record at: #answer ifAbsent: '').
> >>>
> >>>         card when: #changed
> >>>              send: #saveRecordMappingWith:
> >>>              to: browser
> >>>              with: {card. record}.
> >>>
> >>>         flashcardMorph model: card.
> >>>         flashcardMorph showAnswer.
> >>>         flashcardMorph enableEditing.
> >>>         flashcardMorph openInWorld ].
> >>>
> >>> Then in Flashcard there is a foo method which does:
> >>> self triggerEvent: #changed.
> >>>
> >>> Here the {card. record} becomes for some reason (weak reference?) nil
> >>> and causes that the event isn't triggered. So #saveRecordMappingWith:
> >>> isn't called.
> >>>
> >>> With simple datatypes like Integers this works, with static arrays this
> >>> seems to work too.
> >>>
> >>> Maybe this style of doing that isn't the right one, maybe I'm using the
> >>> event system for things which it wasn't supposed to do.
> >>>
> >>> Suggestions?
> >>>
> >>>
> >>> Thanks for your time,
> >>> Philip
> >> Hi Philip,
> >>
> >> I believe the event system uses WeakMessageSend in all Smalltalk
> dialects. Folks, please correct me if I'm wrong.
> >>
> >> An easy way to fix the problem is to turn your collection into a
> literal, using backticks:
> >>
> >>         card when: #changed
> >>              send: #saveRecordMappingWith:
> >>              to: browser
> >>              with: `{card. record}`.
> >>
> >>
> >> Cheers,
> >>
> >> --
> >> Juan Vuletich
> >> www.cuis-smalltalk.org
> >> https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
> >> https://github.com/jvuletich
> >> https://www.linkedin.com/in/juan-vuletich-75611b3
> >> @JuanVuletich
> >>
> >> --
> >> Cuis-dev mailing list
> >> Cuis-dev at lists.cuis.st
> >> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20190910/200075a0/attachment.htm>


More information about the Cuis-dev mailing list