1. Display arguments sliced from a sequence

To display a series of 64 items at specific locations, I need to pick a series of formatting information from a long sequence. The original matrix, for use with printf, looked like:

rn_display_format = 
    { {  0, 35, "%12s", 1, 0, 12}, 
      {  1, 16, "%12s", 2, 0, 12}, 
      {  1, 58, "%12s", 2, 1, 12}, 
      {  2, 6,  "%12s", 4, 0, 12}, 
      {  2, 26, "%12s", 4, 1, 12}, 
      {  2, 48, "%12s", 4, 2, 12}, 
      {  2, 68, "%12s", 4, 3, 12}, 
      {  3, 1,  "%8s", 8, 0, 8}, 
      {  3, 11, "%8s", 8, 1, 8}, 
      {  3, 21, "%8s", 8, 2, 8}, 
      {  3, 31, "%8s", 8, 3, 8}, 
      {  3, 43, "%8s", 8, 4, 8}, 
      {  3, 53, "%8s", 8, 5, 8}, 
      {  3, 63, "%8s", 8, 6, 8}, 
      {  3, 73, "%8s", 8, 7, 8}, 
      ... etc. 


My test of extraction from a sequence for use with display is:

include std/io.e 
include std/filesys.e 
include std/error.e 
include std/console.e 
include std/graphics.e 
include std/sequence.e 
include std/cmdline.e 
include std/convert.e 
integer key_code, start_number, stop_number 
sequence test_sequence = "123456789" 
sequence display_portion, format_string, slice_start, slice_stop 
clear_screen() 
position (4,20) 
format_string = {1,2,3,4,5,6,7,8,9} 
slice_start = slice(format_string, 4,4) 
start_number = to_number(slice_start) 
slice_stop = slice(format_string, 9,9) 
stop_number = to_number(slice_stop) 
display_portion = slice(test_sequence, start_number, stop_number) 
display(display_portion) 
key_code = wait_key() 

There are no error messages, but it displays the entire string
123456789
whereas I expected
456789

What's wrong?

new topic     » topic index » view message » categorize

2. Re: Display arguments sliced from a sequence

When in doubt, write a small test:

 
include std/text.e 
include std/console.e 
include std/sequence.e 
include std/convert.e 
 
object format_string = {1,2,3,4,5,6,7,8,9}  
 
object slice_start = slice(format_string, 4,4)  
 
-- your start and stop are the same so you get {4} 
-- if you want to return a sequence of 4 numbers, you'd use slice(format_string,4,7) 
-- which would return {4,5,6,7}  
 
object start_number = to_number(slice_start)   
 
-- converting to a number isn't necessary, it's already an array of numbers. 
-- just get its value from the index: start_number = slice_start[1]  end_number = slice_start[$] 
 
? slice_start 
? start_number 
new topic     » goto parent     » topic index » view message » categorize

3. Re: Display arguments sliced from a sequence

alrobnett said...

To display a series of 64 items at specific locations, I need to pick a series of formatting information from a long sequence. The original matrix, for use with printf, looked like:

rn_display_format = 
    { {  0, 35, "%12s", 1, 0, 12}, 
      {  1, 16, "%12s", 2, 0, 12}, 
      {  1, 58, "%12s", 2, 1, 12}, 
      {  2, 6,  "%12s", 4, 0, 12}, 
      {  2, 26, "%12s", 4, 1, 12}, 
      {  2, 48, "%12s", 4, 2, 12}, 
      {  2, 68, "%12s", 4, 3, 12}, 
      {  3, 1,  "%8s", 8, 0, 8}, 
      {  3, 11, "%8s", 8, 1, 8}, 
      {  3, 21, "%8s", 8, 2, 8}, 
      {  3, 31, "%8s", 8, 3, 8}, 
      {  3, 43, "%8s", 8, 4, 8}, 
      {  3, 53, "%8s", 8, 5, 8}, 
      {  3, 63, "%8s", 8, 6, 8}, 
      {  3, 73, "%8s", 8, 7, 8}, 
      ... etc. 


My test of extraction from a sequence for use with display is:

include std/io.e 
include std/filesys.e 
include std/error.e 
include std/console.e 
include std/graphics.e 
include std/sequence.e 
include std/cmdline.e 
include std/convert.e 
integer key_code, start_number, stop_number 
sequence test_sequence = "123456789" 
sequence display_portion, format_string, slice_start, slice_stop 
clear_screen() 
position (4,20) 
format_string = {1,2,3,4,5,6,7,8,9} 
slice_start = slice(format_string, 4,4) 
start_number = to_number(slice_start) 
slice_stop = slice(format_string, 9,9) 
stop_number = to_number(slice_stop) 
display_portion = slice(test_sequence, start_number, stop_number) 
display(display_portion) 
key_code = wait_key() 

There are no error messages, but it displays the entire string
123456789
whereas I expected
456789

What's wrong?

Just as an aside, and I'm not sure what you are actually trying to do, but that looks way over complicated

sequences can be sliced on the fly, so

display_portion = slice(test_sequence, start_number, stop_number) is the same as display_portion = test_sequence[start_number..stop_number]

so to display what you want, display_portion = test_sequence[4..9] or as Irv said display_portion = test_sequence[4..$] where $ stands for the index of the last element of the sequence, if it is the last element you want of course.

and everything previous can flow from that.

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

4. Re: Display arguments sliced from a sequence

{ {  0, 35, "%12s", 1, 0, 12},  
  {  1, 16, "%12s", 2, 0, 12},  
  {  1, 58, "%12s", 2, 1, 12},  
  {  2, 6,  "%12s", 4, 0, 12}, ... 

We could be more helpful if we knew what those numbers represent. Just guessing, you are trying to position numbers in a tree form, displaying left or right "child" below the "parent", either left or right of the parent position. If that's the case, then the whole task can probably be done without any formatting table, just knowing the position of the parent and building a format string "on the fly" for that particular 'child'.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Display arguments sliced from a sequence

Your surmise is correct, Irv, but complicated by the fact that the tree is sufficiently deep that the whole tree cannot be displayed at one time; each descriptor is 12 characters (letters) wide. For a 16-level tree, the bottom level is 32,768 * 12 characters wide. The system works (or used to work) by using a system of "relative nodes". The original displayed tree was only 3 levels deep (with the increased window size, I can probably go to 4 levels). The number of characters displayed decreases as the tree descends. The cursor is initially at the top node. One descends the tree by pressing the left or right key. After each such selection, the tree is re-displayed with the selected node being the new top node, hence the need for the "rn-loc" matrix (relative node location). I think I see now that the sequence-slice can be accessed without reference to "slice". In fact, it is not clear what the purpose of "slice" really is. Thanks to both Irv and Chris for both of you continuing insights. Allen

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu