Hi,
I am in the process of rewriting my ALC compiler, whereby the back-end
is being rewritten from "tabular" to "object-oriented".
Both types of structures have their advantages and disadvantages. The "tabular" structure is suitable for cross-object analysis and the "object-oriented" structure is suitable for object-specific analysis.
Unfortunately, you can only ever use ONE type of data structure, so I
now use the "tabular" structure in the FRONT-END and the
"object-oriented" structure in the BACK-END.
Anyone who knows TCL knows that "refactoring" TCL code is cruel, because
it always ends in a huge amount of "broken" code.
Regardless of "broken code", TCL itself has some cruelties in its
syntax. Here, for example, the storage of an "array" with a namespace
path, which in TCL always has !! TWO !! commands. ONE command to
generate the namespace and ONE command to finally generate the array.
namespace eval ::funcDEF::MkErrN {}
array set ::funcDEF::MkErrN::my {
RETURN_MAPPING {}
argv {{ME_CXN_MK_MNGN
mng}}
class MkErrorC
classC MkErrorC
classM ME_CCC_MkErrorC
func MkErrN
prefix Class
prefixC ClassC
prefixM ME_CCC_MkErrorC
retC MkErrorC
retM ME_CCN_MkErrorC
retOM ME_CCN_MkErrorC
ty sm_
type0M ME_CXN_MK_MNGN
var0 mng
}
mfg
Hi,
...
Anyone who knows TCL knows that "refactoring" TCL code is cruel, because
it always ends in a huge amount of "broken" code.
Regardless of "broken code", TCL itself has some cruelties in its
syntax. Here, for example, the storage of an "array" with a namespace
path, which in TCL always has !! TWO !! commands. ONE command to
generate the namespace and ONE command to finally generate the array.
namespace eval ::funcDEF::MkErrN {}
array set ::funcDEF::MkErrN::my {
RETURN_MAPPING {}
argv {{ME_CXN_MK_MNGN
mng}}
class MkErrorC
classC MkErrorC
classM ME_CCC_MkErrorC
func MkErrN
prefix Class
prefixC ClassC
prefixM ME_CCC_MkErrorC
retC MkErrorC
retM ME_CCN_MkErrorC
retOM ME_CCN_MkErrorC
ty sm_
type0M ME_CXN_MK_MNGN
var0 mng
}
On 10/10/24 05:20, aotto1968 wrote:
Hi,
...
Anyone who knows TCL knows that "refactoring" TCL code is cruel, because it always ends in a huge amount of "broken" code.
Well I guess that is true if your code has lots of hidden dependencies and is otherwise not well designed in structured.
Regardless of "broken code", TCL itself has some cruelties in its syntax. Here, for example, the storage of an "array" with a
namespace path, which in TCL always has !! TWO !! commands. ONE command to generate the namespace and ONE command to finally
generate the array.
Ah, I don't know of a single language, including Python, where the namespace does not have to be "defined" prior to things being
"created" inside of it!
namespace eval ::funcDEF::MkErrN {}
array set ::funcDEF::MkErrN::my {
RETURN_MAPPING {}
argv {{ME_CXN_MK_MNGN mng}}
class MkErrorC
classC MkErrorC
classM ME_CCC_MkErrorC
func MkErrN
prefix Class
prefixC ClassC
prefixM ME_CCC_MkErrorC
retC MkErrorC
retM ME_CCN_MkErrorC
retOM ME_CCN_MkErrorC
ty sm_
type0M ME_CXN_MK_MNGN
var0 mng
}
As Ralf Fassel noted, you could have done:
namespace eval ::funcDEF::MkErrN {
variable my
array set my {
RETURN_MAPPING {}
...
var0 mng
}
}
If you can raise an error you can also create the namespace.
this is usually a "bad" habit because the maintainer try to know better what the programmer wantsas the programmer itself.
* aotto1968 <aotto1968@t-online.de>
| the core question is why the NS is *NOT* created by default.
| -> If you can raise an error you can also create the namespace.
If you have ever happend to have a namespace tpyo in your 'array set' command, and did not see it while looking straight at it for half an
hour, you would be grateful for TCL telling you that you mistyped it.
Anyway, this discussion is moot, as I don't think TCL will change in
that respect. I at least would object to auto-creating the namespace :-)
EOD4me...
R'
set myvar 1
set ::myns::myvar
"If you have ever happened to have a namespace typo in your 'array set'"
set myns_myvar 1
Hi,
I am in the process of rewriting my ALC compiler, whereby the back-end is being rewritten from "tabular" to "object-oriented".
Both types of structures have their advantages and disadvantages. The "tabular" structure is suitable for cross-object analysis
and the "object-oriented" structure is suitable for object-specific analysis.
Unfortunately, you can only ever use ONE type of data structure, so I now use the "tabular" structure in the FRONT-END and the
"object-oriented" structure in the BACK-END.
Anyone who knows TCL knows that "refactoring" TCL code is cruel, because it always ends in a huge amount of "broken" code.
Regardless of "broken code", TCL itself has some cruelties in its
syntax. Here, for example, the storage of an "array" with a
namespace path, which in TCL always has !! TWO !! commands. ONE
command to generate the namespace and ONE command to finally generate
the array.
namespace eval ::funcDEF::MkErrN {}
array set ::funcDEF::MkErrN::my {
RETURN_MAPPING {}
...
}
aotto1968 <aotto1968@t-online.de> wrote:
Regardless of "broken code", TCL itself has some cruelties in its
syntax. Here, for example, the storage of an "array" with a
namespace path, which in TCL always has !! TWO !! commands. ONE
command to generate the namespace and ONE command to finally generate
the array.
namespace eval ::funcDEF::MkErrN {}
array set ::funcDEF::MkErrN::my {
RETURN_MAPPING {}
...
}
This is Tcl. If something is that bothersome, just morph the language
to be the way you want it to work. I.e.:
proc ns-array-set {fullvarname contents} {
namespace eval [namespace qualifiers $fullvarname] {}
array set $fullvarname $contents
}
Create that once, then use it, instead of plain "array set" whenever
you want to create a namespace, and then set an array within, i.e.:
% ns-array-set abc::pdq::xyz [list a 1 b 2 c 3]
Which has now, in a single command, created the parent namespaces, and
the array variable therein:
% info exists abc::pdq::xyz
1
% parray abc::pdq::xyz
abc::pdq::xyz(a) = 1
abc::pdq::xyz(b) = 2
abc::pdq::xyz(c) = 3
%
And, given that the 'array' command is itself a namespace ensemble, you
could extend the 'array' ensemble to add a "ns-set" (or whatever name
you like) to the ensemble that performs the above "create ns - and
init" of a namespace variable, then you could do
"array ns-set [list a 1 b 2]"
in your code to replace the two commands.
1. namespace ensemble add array ns-set ::array-ns-set--- Synchronet 3.20a-Linux NewsLink 1.114
2. namespace ensemble delete array ns-set
1) but the CORE problem is not solved, for every "namespace ns-set ..." command TWO commands
are executed just to avoid FIRST namespace missing error.
→ (ALL pay runtime-speed just for FIRST benefit)
2) the syntax to extend an existing ensemble is still very "ugly.."
improvement:
1. namespace ensemble add array ns-set ::array-ns-set
2. namespace ensemble delete array ns-set
On 14.10.24 03:44, Rich wrote:
aotto1968 <aotto1968@t-online.de> wrote:
Regardless of "broken code", TCL itself has some cruelties in its
syntax. Here, for example, the storage of an "array" with a
namespace path, which in TCL always has !! TWO !! commands. ONE
command to generate the namespace and ONE command to finally generate
the array.
This is Tcl. If something is that bothersome, just morph the language
to be the way you want it to work. I.e.:
proc ns-array-set {fullvarname contents} {
namespace eval [namespace qualifiers $fullvarname] {}
array set $fullvarname $contents
}
Create that once, then use it, instead of plain "array set" ...
your hint with the "ensemble" feature was good but missing the required code.
to "extend" an ensemble is quite complicate in TCL… follow the code below:
1) but the CORE problem is not solved, for every "namespace ns-set
..." command TWO commands are executed just to avoid FIRST namespace
missing error. → (ALL pay runtime-speed just for FIRST benefit)
2) the syntax to extend an existing ensemble is still very "ugly.."
improvement:
1. namespace ensemble add array ns-set ::array-ns-set
2. namespace ensemble delete array ns-set
git diff --shortstat alc-new-1-lw .83 files changed, 5214 insertions(+), 5300 deletions(-)
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (0 / 10) |
Uptime: | 120:08:07 |
Calls: | 12,958 |
Files: | 186,574 |
Messages: | 3,265,642 |