سؤال

I am trying to flatten the following type of Tcl lists:

-1587.500000 {} 1587.500000 

or

15.78 18.56 {} {} {} {} 15.6

So I try:

 [struct::list flatten -full $lineToFlatten]

But when lineToFlatten starts with the negative number the following type of error message is issued (for example):

  Unknown option "-1587.500000 {} 1587.500000", should be either -full, or --

How to resolve this?

هل كانت مفيدة؟

المحلول

Normally, the correct way is to use the -- to denote the end of the options. But there is a bug that prevents you from doing that (missing lrange).

The correct way to do that is:

struct::list flatten -full -- {-1587.500000 {} 1587.500000}

But this does not work because struct has a bug.

If you want to fix it, open the package file for struct::list, you can get the filename with

package ifneeded struct::list [package require struct::list]

Then edit the proc ::struct::list::Lflatten.
Change the line with

--      {break}

to

--      {set args [::lrange $args 1 end];break}

Anyway, I suggest filling a bug record.

نصائح أخرى

I just discovered how to use this function ^^

Okay, I can't say why it acts like this, but it throws me an error for anything like:

[struct::list flatten -full $lineToFlatten]

[struct::list flatten -full {-1587.500000 {} 1587.500000}]

It seems that it interprets the negative sign as a switch/flag instead of an element of the list. However, it works if I do:

[struct::list flatten -full {{-1587.500000} {} 1587.500000}]

[struct::list flatten -full [list $lineToFlatten]]

The first one isn't very practical, since you'll have a long command and you have to put the braces manually for the first negative number. I found the second workaround while testing a bit around.

I hope it helps :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top