r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

Graham
15-May-2009
[2418]
well, I think you need to work with a few small examples .. as what 
you're doing is way out ...
mhinson
15-May-2009
[2419x2]
ok, this is a reduced set...  but it does not work. I wonder if I 
have a problem with context?

PortAttributesObj: make object! [

 vlan: copy []     ;; will hold a number or perhaps a list of numbers 
 e.g. 20 or 3,5,7
	UpState: copy []  ;; none or "disabled"
	name: copy []     ;; any string
]

PortNumberObj: make object! [
	p1: make PortAttributesObj []
	p2: make PortAttributesObj []
	p3: make PortAttributesObj []
	p4: make PortAttributesObj []
;; so on up to
	p48: make PortAttributesObj []
]

ModuleNumberObj: make object! [
	m1: make ModuleNumberObj []
	m2: make ModuleNumberObj []
	m3: make ModuleNumberObj []
;; so on up to
	m13: make ModuleNumberObj []
]	

record: make ModuleNumberObj []
it is not quite wat I want either, because I now have to reference 
my data structure lil record/m1/p2/vlan   rather than the simple 
record/1/2/vlan
sqlab
15-May-2009
[2421]
I did not follow exactly your intentions,
am I correct, you want to get a structure with 4 qualities?

Then why you do not add for every line you are parsing your 4 elements:
either with 
append data reduce [port disabled vlan name]
or with
append/only data reduce  [port disabled vlan name]
?
mhinson
15-May-2009
[2422x3]
sqlab, where would I store my data so I could retrieve it in the 
right sequence please?

The input presents the data verticaly & I need to export it horizontaly.
Each line I parse will have only one of the values disabled, vlan, 
name, & a range of ports.
when I have parsed the data I know it is for a vlan & the number 
of the vlan & the port... it is only later that I will find the same 
port number associated with the name.
sqlab
15-May-2009
[2425]
I understand, you are looking for a structure where you can later 
reference the qualities?
mhinson
15-May-2009
[2426]
Yes. I neet to have a structure I can enumerate to export my output
symbolicaly:
input
1 3
1 fish
2 3
2 dog

output 
1 3 fish
2 3 dog
sqlab
15-May-2009
[2427]
What is your primary index?
mhinson
15-May-2009
[2428x2]
the index is in 2 parts, like 1/1 1/2 1/3 up to 13/48
I think the structure I want is fairly straight forward, but it seems 
complex to define it without doing all 1800 values manualy.
sqlab
15-May-2009
[2430x2]
So first we need to find a way to define the index with rebol datatypes
is 1x1 ok instead of 1/1 ?
mhinson
15-May-2009
[2432]
I could convert it easily I suppose then convert it back again for 
output
sqlab
15-May-2009
[2433]
Then we could use a structure like
data: [
1x1 [ports disabled vlan etc ...]
1x2 [ ..
2x2 
]

or even
["1/1" [ports disabled vlan
mhinson
15-May-2009
[2434]
So long as I can enumerate them to export the data, preferably in 
order so I dont have to sort them after
sqlab
15-May-2009
[2435x2]
We acces the elements either with 
data/1x1

or with 
data/("2x3")
If you don't add them ordered you will always need a sort run
mhinson
15-May-2009
[2437x2]
I was thinking if I had a data structure like data: [[[vlan 6][vlan 
6]][[][][][]]   of the right nature I could output the data like
for m 1 13 1 [ foreach p [print data/(m)/(p)/vlan]]
sorry I mean
for m 1 13 1 [ for p 1 48 1 [print data/(m)/(p)/vlan]]
sqlab
15-May-2009
[2439x2]
then you would need a different structure
with flat 13 * 48 elements first
and you would get 13 * 48 lines output
maybe I still do not get what you want to do.(
mhinson
15-May-2009
[2441]
My output could be up to 13 * 48 line long, that is right.
sqlab
15-May-2009
[2442]
Always?
mhinson
15-May-2009
[2443]
in practice there will be groups of values that will not need to 
be exported because they contain no information.
sqlab
15-May-2009
[2444]
But you have always 13 * 48 groups and this is your index
  
1/1 
1/2
..
1/48
2/1
..
2/48
..
13/48

is it?
mhinson
15-May-2009
[2445]
yes
sqlab
15-May-2009
[2446x2]
So you first want to generate a table with 13 * 48 elements?
array/initial 13 array/initial 48 none
mhinson
15-May-2009
[2448]
and each of the 13 * 48 elements will have up to 3 different bits 
of information
sqlab
15-May-2009
[2449]
array/initial 13 array/initial 48 array/initial 3 none
mhinson
15-May-2009
[2450]
that looks great!   I will just have to give the 3 bits of data numbers 
instead of names.
sqlab
15-May-2009
[2451x3]
Otherwise make it flat
array/initial 13 * 48 * 3 none

and access it with data/(x * 13 + (y  * 48) + z)
You can acces the your free items of the last group with names
you can use e.g
  alias 'first "portn"
  alias 'second "disabled"
  alias 'third "vlan"
sorry three not free
mhinson
15-May-2009
[2454]
thats a handy trick to make it more readable...
sqlab
15-May-2009
[2455]
or use port: 1 diabled: 2
then /../:port
mhinson
15-May-2009
[2456]
so much choice..   I wonder if that is both the best & the worst 
thing about Rebol.  :-)  Thanks very much for your help & Geomol 
& Graham.

This is a crucial bit of my script & it should start producing the 
output I need very soon..  I have been learning Rebol to solve a 
problem, instead of spending my time to sole the problem manualy. 
But now I am nearly out of time so I a comitted to the scripted aproach.
sqlab
15-May-2009
[2457]
you're welcome

I guess as a beginner you would have reached your goal faster without 
parse with simple loops and finds
mhinson
15-May-2009
[2458]
I heard about Rebol because of parse, & it seems right to learn about 
it.  I am stll very much a noob & appreciate the intensive help I 
get here very much.

I think the only way I could have got more help would have been to 
use a cute girls name as my login. ;-)
sqlab
15-May-2009
[2459x2]
Unfortunately you can infer from the name to the look.)
But I will give you another hint, 
try to use new-line/all with your data
should read  "you cannot  .."  .)
Henrik
15-May-2009
[2461]
mhinson, for your next scripts, maybe you should work a bit more 
on things that are completely unrelated to parse. it helps to get 
away from it a while and then get back to it later.
BrianH
15-May-2009
[2462x4]
ARRAY can take a function as the initial parameter, and that function 
will be called. Try this:
port-proto: make object! [

 vlan: copy []     ;; will hold a number or perhaps a list of numbers 
 e.g. 20 or 3,5,7
	UpState: copy []  ;; none or "disabled"
	name: copy []     ;; any string
]


switch-module: array/initial [13 48] does [make object! port-proto]
That will give you 13x48 unique objects in nested blocks.
>> x: 0
== 0
>> array/initial [2 3] does [x: x + 1]
== [[1 2 3] [4 5 6]]
One interesting thing to note is that because the data in the objects 
is blocks, MAKE will bind/copy the blocks to the new object. This 
is why you don't have to copy the blocks explicitly when you make 
a new object based on the proto.
Steeve
15-May-2009
[2466]
i should use array too now, i didn't noticed those usefull evolutions
Henrik
15-May-2009
[2467]
oh, I didn't know that one.