World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
BrianH 21-May-2009 [2765] | I don't get what you want to do. Perhaps some sample data and the desired output? |
mhinson 21-May-2009 [2766] | probe b1 [random3 ["data4"] random1 ["data2"]] probe b1/random1/1 data2 but as I dont know what random1 is I want to enumerate the values from the data structure. |
BrianH 21-May-2009 [2767] | Are you trying to get a specific data* or to enumerate all of random*? |
mhinson 21-May-2009 [2768] | Ah I think I am being a numpty. your structure already returns the data, but I need to be able to print the keys with the associated data. |
BrianH 21-May-2009 [2769x2] | foreach [r d] b1 [print [r d]] |
You can do some formatting in the print statement, but it is that easy. | |
mhinson 21-May-2009 [2771] | I will have different numbers of data elements in different keys, so I also need to keep track of which data is stored where, perhaps I need an array as the data element. |
BrianH 21-May-2009 [2772x3] | Your data already has an array as the data element, except we call them blocks. |
b1: [random3 ["data1" "data2"] random1 ["data3"]] | |
foreach [r d] b1 [print [r mold d]] | |
mhinson 21-May-2009 [2775] | I need to know what type of data I have put in data3. It might be the same type as in data1 or data2, or something different again. any one of maybe 10 types. The actual data will be IP addresses & interface details & remote connection information. |
BrianH 21-May-2009 [2776x3] | You can specify ip addresses directly, as data of the tuple! type. Or you could have the data be doubles of strings and type flags. |
Or if you would have at most one of each type, you could name the potential fields and have the data be name value pairs. | |
*a block of* name value pairs. | |
mhinson 21-May-2009 [2779] | most of my different types will be strings I am expecting. Sometimes there will be up to about 4 of the same type (addresses & secondary addresses mostly) |
BrianH 21-May-2009 [2780x2] | [key [flags ["flag1" "flag2"] ips ["127.0.0.1" "192.168.1.1"]] |
Sorry, missing a last ] | |
mhinson 21-May-2009 [2782] | The pairs idea sounds productive, so it is a highly structured array with named groups? |
BrianH 21-May-2009 [2783x2] | Or you could go positional for the different types of data, instead of including the flags and ips words all of the time. dat: [key [["flag1" "flag2"] ["127.0.0.1" "192.168.1.1"]]] foreach [key val] dat [set [flags ips] val ...] |
Structured data makes things easier. | |
mhinson 21-May-2009 [2785] | Thank you very much for you time & help. I will need a while to digest this & make it work with my existing code. I think this type of structure is going to be the core of most of the data extraction I need to do, so I must get to understand it very well. I have a section that uses an array, but some of the more interesting data manipulation needs to cope with more varied keys. Thanks. |
BrianH 21-May-2009 [2786] | This a pretty standard way for REBOL to do lightweight data structures. Blocks are lighter-weight than objects. Enjoy :) |
RobertS 22-May-2009 [2787] | . |
mhinson 22-May-2009 [2788x2] | Hi, is there an easy way to make this sort of structure work please? data: [bike [wheels [2] owner [john]] pig [legs [4] owner [roger]]] foreach [thing content] data [print [data/:thing/owner "~" data/:thing/wheels "~" data/:thing/legs]] I want the invalid references (e.g. data/bike/legs) to return nothing so the list is printed for both things |
I know I could put "" values in when I create the structure, but I wondered if the was a neater way to do this. | |
Henrik 22-May-2009 [2790x2] | if you wrap a path in ATTEMPT, it will return none. |
when it doesn't exist | |
mhinson 22-May-2009 [2792] | Thanks Henrik. That sounds like what I need. |
Henrik 22-May-2009 [2793] | I like to do things like: any [attempt [this/leads/nowhere] "Unknown"] |
mhinson 22-May-2009 [2794x2] | The task I am trying to accomadate is to output my data as a table. so I think I can adapt your example to return "" Thanks. |
I cant work out how to turn that into a function, because if I do att: func [paf][any [attempt [paf] ""]] att this/leads/nowhere the invalid path returns an error before it can be passed to the function. I bet there is a good answer. I have been looking at using :paf, but that makes it return the invalid path | |
Steeve 22-May-2009 [2796] | lit-path!, it's done for that. |
mhinson 22-May-2009 [2797x3] | so I try to find a way to pass it as that sort of data type? |
Not getting anywhere with this I am afraid. where do I put the lit-path! please? | |
I have been trying this sort of thing att: func [paf[lit-path!]][any [attempt [paf] ""]] but I suspect that is not what Steeve means. | |
Steeve 22-May-2009 [2800] | You suspect well, but you suspect too much. It would be better if you knew all the data types in Rebol and their usages. Currently you're only trying to "guess" how to programm with Rebol, not to learn it. I don't think it's always a good method to "give" the answer directly, especially when they are obvious. It' gives some bad habits to the newcommers. Sorry. |
Graham 22-May-2009 [2801x2] | Steeve is an advocate of the Socratic method |
BTW, I think any [ attempt [paf] "" ] should be any [ attempt [.. ] copy "" ] ... ie. you need a 'copy in there. | |
mhinson 22-May-2009 [2803] | ok, I will continue to read the documentation. I think you are right Steeve, but it is hard to learn with no current programing skills. Perhaps I am just trying to find out how to solve my problems. Some of the data types seem quite straight forward, but some seem to need to be used before I can appreciate what they are exactly.. I try not to ask questions that are too trivial, and never before I have tried to research an answer for myself. You maybe just misunderstand how stupid I am. ;-) |
Graham 22-May-2009 [2804] | There are several good books on REBOL, even one in english |
mhinson 22-May-2009 [2805] | Do you think the web resources are in some way worse than the printed books Graham? |
Steeve 22-May-2009 [2806] | Mhinson, i think we all enjoy to answer to people like you. Especially because you're a nice and psersistent personn. But after some weeks, there are questions, we don't want to see comming from you.anymmore ;-) |
Graham 22-May-2009 [2807] | Books are good because someone here gets to sell your their copy :) |
mhinson 22-May-2009 [2808x2] | If anyone has any good Rebol books in English that they would like to sell in the UK please let me know. Thanks. |
Steeve, I suspect you doubt the time & effort I have been putting into learning Rebol. If you have a clear idea about which sorts of questions I really should be able to answer from my own research it would give me some useful direction to my study I think. It is frustrating thatl I am often trying to guess how to create the structures I want, perhaps if I had a better foundation I would know know better how to learn more directly. | |
Steeve 22-May-2009 [2810] | My advices for a very efficient learning of R2. 1/ Go on Rebol.com and read all the documentation published (it's your bible). 2/ Go on Rebol.org and download all the scripts published. Test thoses you can, read their sources and try to figure how they work and what technics are used. 3/ When you have questions, At first , check on Rebol.org (the mailing list archive) most of the time your answer is there. |
mhinson 22-May-2009 [2811] | Thanks Steeve, I will try not to post here any more unless I am invited. I have enjoyed trying to learn Rebol & will continue, but I do understand that my constant questions are an anoyance, and I dont want to be banned from this very usefull forum. :-( |
Steeve 22-May-2009 [2812] | Sorry it's not what i mean. |
mhinson 22-May-2009 [2813] | Well, I dont want to cause an anoyance with too much noise |
Steeve 22-May-2009 [2814] | you're really wellcome here to post questions |
older newer | first last |