comp.lang.tcl
[Top] [All Lists]

Re: merging variables and arrays ...

Subject: Re: merging variables and arrays ...
From: Ralf Fassel
Date: Fri, 30 May 2008 15:43:55 +0200
Newsgroups: comp.lang.tcl

* Andreas Leitgeb <avl@xxxxxxxxxxxxxxxxxxxxxxxx>
| My own opinion is, that this change would
| get rid of more wtf's than it adds.
| % set a foo
| % set a bar; # assignment ok
| % set b(0) foo
| % set b bar; # assignment not ok  wtf?

In this particular case, there would be no WTF, since the error
message
  can't set "b": variable is array
should give a vague hint [TM] what the problem is.

Whereas in
  set a foo
  ...
  set a(someval) bar
  ...
  if {$a(soemval) eq bar} {
     # something nice happens
  } else {
     # something not so nice happens
  }
I could spend hours debugging the wrong path until I realize the
spelling error in the index.


Another question which needs clarification:
  set a default-value
  set a(3)
  => default-value
  
  array get a 3
  => default-value?
  (currently: empty string)

| I accept a dislike, when I'm confident that it's really a dislike of
| the proposed idea.  I wouldn't accept a dislike if it's a dislike of
| some mis- or halfunderstanding of the proposed idea.

I would not oppose to your idea if it were not for the inherent
coupling of scalars and arrays.

What about explicitely connecting scalars and arrays:
   array scalar  a s
   array default a s
=> use scalar variable s as default value for unset values in array a

You could not use the same variable name for array and scalar, though.

Ok, 'nuf said.
R'

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy