• An XOTcl question

    From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Thu Jun 27 00:17:41 2024
    From Newsgroup: comp.lang.tcl

    Hello out there,
    I am reviving an old project of mine from around 2008 / 2010 because
    I thought I could use some of its parts. The XOTcl version used then
    was 1.4 IIRC. The current version is 2.3 which I think is fairly
    recent.
    My grief is the error message produced when something goes wrong
    constructing a new object: The exact reason is - so it seems - never
    told - let alone the offending location. This makes it extremely
    tedious to advance.
    Look at the following example. Context: Having set a particular 'mode'
    I click at some place where I want a new line to start. The code:
    ---
    # ctor - coords are <x, y, starting widget>
    Line instproc init {canvas coordLst {cName ""}} {
    my instvar c cfg coords id

    # call base class ctor
    lassign $coordLst x y widgets
    next $canvas [list $x $y] ;#$cfg ;#$options

    set coords {} ; set widgets {}
    puts lb
    # create first point
    my newLinePoint $x $y
    puts lc
    bindC $c $id <Enter> {s::mkLargePointCurs $c}
    }

    # Create a new point
    Line instproc newLinePoint {x y} {
    my instvar c children coords
    set x [$c canvasx $x] ; set y [$c canvasy $y]
    lappend children [LinePoint [LinePoint autoname Point%d] $c [list
    $x $y] \
    -parent [self]]
    lappend coords $x $y
    }
    ----
    I want to create a line starting with a 1st point.
    This is the result:
    ---
    Microsoft Windows [Version 10.0.19045.4529]
    (c) Microsoft Corporation. Alle Rechte vorbehalten.

    d:\x\Test>tclsh main.tcl
    lb

    and an error window.
    ---
    My conclusions:
    - I see 'lb' but not 'lc' - my conclusion is: The error must be in 'newLinePoint'.
    - But this is the error message:
    --
    wrong # args: should be "next canvas coordinates ?mainDict?"
    wrong # args: should be "next canvas coordinates ?mainDict?"
    ::Line ::xotcl::Class->create
    invoked from within
    "::Line create Line1 .mainFr.c {72 66 ::LEDBtn1} -parent ::C"
    ("uplevel" body line 1)
    invoked from within
    "::uplevel $lvl [list [self] create {*}$args]"
    (procedure "unknown" line 7)
    ::Line ::xotcl::Class->unknown
    invoked from within
    "Line Line$lineNo $c [list $x $y $state] -parent [self]"
    (procedure "startCreateLine" line 10)
    ::C ::Canvas->startCreateLine
    invoked from within
    "my startCreateLine $state $x $y $line"
    ...
    ---
    What is this? The call to 'next' has well been passed when it puts out
    the 'lb', and in 'newLinePoint' I don't call 'next'.

    Questions:
    - Has anybody a strategy to cope with this behaviour?
    - Or is there a newer version which produces usable error messages?
    - I have read that there is a successor to XOTcl.
    -- Does it have this same deficiency?
    -- If not: Is it somehow upwards compatible with XOTcl?

    Oh, this is on Windows 10, 64 bit under tcl 8.6.10.
    Any help or idea will be greatly appreciated.
    Helmut
    PS: Sorry for the long rant.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Stefan Sobernig@stefan.sobernig@wu.ac.at to comp.lang.tcl on Thu Jul 11 00:36:28 2024
    From Newsgroup: comp.lang.tcl

    Hi Helmut!

    Any help or idea will be greatly appreciated.

    I tried to reproduce the erroneous behaviour using XOTcl 2.3 and Tcl
    8.6.13 on macOS, but I failed, I am afraid.

    Could you create a minimal, reproducible script?

    What I tried:

    ---------------%<---------------
    puts [package req Tcl]
    puts [package req XOTcl]

    ## setup

    xotcl::Class Base -parameter {parent} \
    -instproc init {canvas coordinates {mainDict ""}} {;}

    xotcl::Class Line -parameter {{id 321}} -superclass Base

    xotcl::Class Point -superclass Base -instproc init {args} {
    puts $args
    }
    xotcl::Class LinePoint -superclass Point
    proc ::bindC {args} {;}


    ## distilled

    LinePoint instproc init {canvas {coords ""}} { next }

    # ctor - coords are <x, y, starting widget>
    Line instproc init {canvas coordLst {cName ""}} {
    my instvar c cfg coords id
    set c .cc
    # call base class ctor
    lassign $coordLst x y widgets
    set tgt [self next]; puts "$tgt === [[lindex $tgt 0] info instargs [lindex $tgt 2]]"
    next $canvas [list $x $y] ;#$cfg ;#$options

    set coords {} ; set widgets {}
    puts lb
    # create first point
    my newLinePoint $x $y
    puts lc
    bindC $c $id <Enter> {s::mkLargePointCurs $c}
    }

    # Create a new point
    Line instproc newLinePoint {x y} {
    my instvar c children coords
    # set x [$c canvasx $x] ; set y [$c canvasy $y]
    lappend children [LinePoint [LinePoint autoname Point%d] $c [list
    $x $y] -parent [self]]
    lappend coords $x $y
    }

    ## main.tcl ?
    ::Line Line1 .mainFr.c {72 66 ::LEDBtn1} -parent ::C ---------------%<---------------

    This produces:

    ---------------%<---------------
    8.6.13
    2.3
    ::Base instproc init === canvas coordinates mainDict
    lb
    .cc {72 66}
    lc
    ---------------%<---------------

    Could you add the following introspection line just before [next] is
    called in your actual script?

    ---------------%<---------------
    set tgt [self next]; puts "$tgt === [[lindex $tgt 0] info instargs
    [lindex $tgt 2]]"
    ---------------%<---------------

    Best, Stefan


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Thu Jul 11 23:04:44 2024
    From Newsgroup: comp.lang.tcl

    Hi Stefan,
    thanks for caring, but I'm afraid I cannot reproduce it any more - the
    project has progressed. It turned out that the error message was in
    fact correct (it was a call to 'next') but this call wasn't in
    'newLinePoint' but in 'LinePoint'.
    That's in fact my only grief wth XOTcl: The error message produced
    when something goes wrong in a constructor. In other situations the
    error message pin points the exact location. I just made a quick test
    by 'provoquing' an error. The result was as expected:

    Provoqued error
    while executing
    "error "Provoqued error""
    (procedure "checkRelPos" line 3)
    ::s::Line1 ::s::Line->checkRelPos
    invoked from within
    "my checkRelPos "
    (procedure "straightSegment" line 129)
    ::s::Line1 ::s::Line->straightSegment
    ... and so on until
    "::s::State2 moveStateHL 435 110 1"
    (command bound to event)

    Only in a constructor this mechanism apparently doesn't work. Well, I
    trust that there is a technical reason for this behaviour and it
    cannot be helped.

    Apart from that XOTcl is a fantastic tool.
    Thanks again, Stefan, and best regards
    Helmut
    --- Synchronet 3.20a-Linux NewsLink 1.114