• nx Package

    From Manfred Stelzhammer@21:1/5 to All on Sun Aug 20 15:23:48 2023
    Hi

    A small script:

    ####

    package require nx

    set ::DELETE1 0
    set ::DELETE2 0

    nx::Class create Number1 {
    :property -accessor public -incremental objects:object {
    :public object method value=delete {obj var args} {
    incr ::DELETE1
    next
    }
    }
    }
    nx::Class create Number2 {
    :property -accessor public -incremental objects:object {
    :public object method value=add {obj var value} {next}
    :public object method value=delete {obj var args} {
    incr ::DELETE2
    next
    }
    }
    }


    nx::Object create a
    nx::Object create b

    Number1 create nr1

    nr1 objects add ::a
    nr1 objects add ::b
    nr1 objects delete ::a

    Number2 create nr2
    nr2 objects add ::a
    nr2 objects add ::b
    nr2 objects delete ::a


    puts "DELETE1 = $::DELETE1 :: object in nr1 : [nr1 cget -objects]"
    puts "DELETE2 = $::DELETE2 :: object in nr2 : [nr2 cget -objects]"


    ##### Scrip end

    In my opinion both variables "::DELETE1" and "::DELETE2" should have the
    value "1".
    But only variable "::DELETE2" has value "1".

    In class "Number1" there is no effect with the method "value=delete".
    In class "Number2" there is the expected effect.
    In class "Number2" exist a method "value=add" in class "Number1" not.
    In both cases the value from objects is correct "::b".

    Is this the correct behavior?


    I use nx version 2.4 on Linux.

    regards

    Manfred

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Manfred Stelzhammer@21:1/5 to All on Sun Aug 20 21:25:15 2023
    Hi

    When I create the property only with the name without type (object) then
    it works like expected.

    ####
    nx::Class create Number3 {
    :property -accessor public -incremental objects {
    :public object method value=delete {obj var args} {
    incr ::DELETE3
    next
    }
    }
    }

    Number3 create nr3
    nr3 objects add ::a
    nr3 objects add ::b
    nr3 objects delete ::a

    puts "DELETE3 = $::DELETE3 :: object in nr3 : [nr3 cget -objects]"
    ###

    The variable ::DELETE3 has the value 1 like expected.

    regards

    Manfred


    Am 20.08.23 um 15:23 schrieb Manfred Stelzhammer:
    package require nx

    set ::DELETE1 0
    set ::DELETE2 0

    nx::Class create Number1 {
        :property -accessor public -incremental objects:object {
            :public object method value=delete {obj var args} {
                        incr ::DELETE1
                next
            }
        }
    }
    nx::Class create Number2 {
        :property -accessor public -incremental objects:object {
                :public object method value=add {obj var value} {next}
            :public object method value=delete {obj var args} {
                    incr ::DELETE2
                next
            }
        }
    }


    nx::Object create a
    nx::Object create b

    Number1 create nr1

    nr1 objects add ::a
    nr1 objects add ::b
    nr1 objects delete ::a

    Number2 create nr2
    nr2 objects add ::a
    nr2 objects add ::b
    nr2 objects delete ::a


    puts "DELETE1 = $::DELETE1 :: object in nr1 : [nr1 cget -objects]"
    puts "DELETE2 = $::DELETE2 :: object in nr2 : [nr2 cget -objects]"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From stefan@21:1/5 to All on Wed Aug 23 04:25:48 2023
    Hi Manfred!

    Thanks for reporting this issue, we confirm, and for providing minimal, viable snippets!

    In short: Yes, you need a workaround at this point to have your value=delete implementation become effective. You pointed out the options: (a) omit the type specifier ("object") or any other; (b) provide for an value=add implementation, which will also
    leave the value=delete method untouched.

    In our development mainline, we provide for a fix plus tests:

    See https://fisheye.openacs.org/changelog/nsf?cs=83355de2812519cf29dc92cfdc2fc4892303f6ab

    This will enter the maintenance release 2.4.1.

    Some remarks on providing custom implementations of value=add, value=delete. You need to be careful: any type validation (object, integer; name it) should also be performed on the method parameter "value" -> "value:object":

    :public object method value=delete {obj var value:object args} {
    next
    }

    This is important, in particular your value= implementation effectively overrides the base method (no next), but is also more local. We will consider some scaffolding for providing custom accessors/ mutators in the future.

    HTH, Stefan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)