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.

Steeve
19-Apr-2009
[1807]
What the need of flags and splitted lines, uh ?
you can't write simple semantic ?
Reading, your example file , you've got these simple rules.

1/ counting the lines
line: [ thru newline (n: n + 1)]


2/ one interface mays contain several lines (infos) and is terminated 
by a line beginning by "!"  
interface: [
	"interface" copy interface* line 
	any [infos | #"!" line break]
]

3/ infos may be description, ip-adrr, ip-tables
infos: [
	  " description " copy desc* line 
	| " ip route " copy route* line
	| "ip address" copy ip-add* line 
]

That''s all folks, just parse the whole file with:
parse/all [any [interface | line]]


Please don't use read/lines or internal flags for such simple rules.
BrianH
20-Apr-2009
[1808]
The problem with that method is managing backtracking. If your lines 
are really separate, you will have to be careful in writing your 
rules to make sure that you don't inadvertantly backtrack to a previous 
line when you don't want to.
Steeve
20-Apr-2009
[1809x2]
No, Backtracking is a wonderfull feature, it's not a problem.

People who get unwanted backtracking, just don't know how to use 
parse correctly.
but imho, it's easy to learn.
BrianH
20-Apr-2009
[1811x2]
Hello, welcome to the "I'm new" group. Let's assume that someone 
who is asking questions about parse here doesn't know parse :)
I find it pretty easy to manage backtracking too, but I used to use 
Icon before REBOL. Most people without a background in backtracking 
parsers or languages tend to have a bit of trouble with backtracking.
mhinson
20-Apr-2009
[1813x2]
Thanks for pointing out the errors.


The lines I want to group together are not all together in the file. 
But for the interface details they are.

IP routes are grouped together under a vrf & the interfaces will 
relate to a particular vrf.

The end of a section might be a "!" or might just be the beginning 
of the next section, or any non space or anything  that does not 
match a pattern.. It depends on the particular section.


I will try to reduce the number of rules I need and get a very clear 
view of what I am trying to achieve. I don't find the semantics of 
this very easy to grasp and I am still struggling to find any documentation 
that makes sense to me.


Sorry to be asking so many questions but I not done any programming 
to speak of since Pascal the mid 1980s so I am sort of like a complete 
idiot as you see.  Thanks for taking the time to suggest how much 
improvement is possible.
another very basic question.
how can I pass a filename from the command line please?


filename: %/c/temp/file.txt works fine, but if I pass the filename 
from the command line it get surrounded by ""

do I have to parse the result to get the filename, or is there a 
simpler way for something so common?
The only reference I could find was here
http://www.rebol.com/docs/sdk/custom.html#section-3


It seems there is a great deal of Rebol documentation, but simple 
questions can be had to find answers to.
BrianH
20-Apr-2009
[1815]
Try passing the string to TO-REBOL-FILE and then that will let you 
specify filenames with local file syntax.
Sunanda
20-Apr-2009
[1816]
assuming the file name is a string in system/options/args
  filename: to-file system/options/args

Though you may want to error trap that -- in case the command line 
is malformed. One way:
   filename: none
  attempt [ filename: to-file system/options/args]
  if none? file-name [print "Bad command line" halt]
BrianH
20-Apr-2009
[1817]
Sunanda, you're showing your Unix or Linux usage there. TO-FILE doesn't 
make sense to use on Windows (note %/c/ in his example).
mhinson
20-Apr-2009
[1818]
Thanks, that worked exactly as I needed, either way, & now it has 
helped me find the documentation for "datatype functions" which I 
am sure I will need more of later.
Sunanda
20-Apr-2009
[1819x2]
Thanks for the correction, Brian.
Mike, REBOL has some built-in help. Sometimes it can jog the memory, 
or point you to a function you never dreamed came as standard .... 
Try these in the console  
   help file
   help "to"
mhinson
20-Apr-2009
[1821]
Thanks Sunanda,  that is very handy, I didnt realise help searched 
like that, I thought you had to give it an exact command.  very good.
Oldes
20-Apr-2009
[1822]
Instead of:
  filename: none
  attempt [ filename: to-file system/options/args]
  if none? file-name [print "Bad command line" halt]
I would use:
if error? try [filename: to-file system/options/args][
	print "Bad command line" halt
]

I really don't like that people use the attemp in cases where they 
expect error. I use own attempt in cases where I don't expect error 
but still want to continue with execution (display and log the error).
Sunanda
21-Apr-2009
[1823]
Help is even better in R3 -- worth getting a copy just for that:
http://www.rebol.com/article/0404.html
mhinson
21-Apr-2009
[1824]
That is very good and usefull thanks.  Is there any way to get help 
on things like 

view layout [ slider ]   please.   I am paticularly keen to find 
how the data is returned from these controls.  something like

view layout [ h2 slider ]   but that dosn't work..  there are hundreds 
of examples of how pretty the vid functions are, but I have failed 
to find much about using the results returned.
Geomol
21-Apr-2009
[1825x3]
view layout [h: h2 "data shows here" slider [h/text: value show h]]
A block after a style is being evaluated, when you operate the style.
The name of the variable holding the data for slider is called value. 
You have to look at docs to figure that out:
http://www.rebol.com/docs/easy-vid.html

Or you can look into the styles yourself, like:
>> layout [s: slider]
>> ? s
mhinson
21-Apr-2009
[1828]
Thanks Geomol, the docs dont seem to explain all the functions of 
the returned object.  Is this detail recorded anywhere please?

The object for slider is value, but value seems to be an object with 
lots of  data & functions in it, how does it return the position 
I cant see how that is to be expected.
Geomol
21-Apr-2009
[1829x3]
value comes from the function do-face. Try:

>> source do-face
Well, it might confuse to talk about do-face. :-) When you create 
a face (style) with an action block, it's set in the face. You can 
see it like this:

>> layout [s: slider [print "hm"]]
>> probe get in s 'action
func [face value][print "hm"]


That function is called, when you operate the style (face). Makes 
sense?
Now I both mention face and style. Styles are used to create faces. 
I guess, the GUI docs are not too clear in all of this.
Henrik
21-Apr-2009
[1832]
The value that s contains is the face object. This is not what you 
need to read out the value. Use GET-FACE s for that.
Geomol
21-Apr-2009
[1833]
mhinson, you can get a more detailed documentation of the face object 
here:
http://www.rebol.com/docs/view-system.html


It document the view system, which you can see as being below VID.
Henrik
21-Apr-2009
[1834x2]
LAYOUT is the VID dialect, which is REBOL's layout engine. When giving 
it a block of words, it produces a tree of objects, that each are 
a face. Each face contains sizes, offsets, colors, texts, event handlers 
and actions to perform when clicking on the face.
The tree of objects is then passed to VIEW, which displays the tree 
of objects as a graphical user interface.
Anton
21-Apr-2009
[1836]
mhinson, if you want to see the SLIDER from which all slider instances 
are derived, then you can do this:

	print mold system/view/vid/vid-styles/slider

(Instead of printing you could write to a file, etc.)

You can easily be overwhelmed with information, however, as faces 
are complex objects.
I usually aim for key facets like:

	print mold svv/vid-styles/slider/init
	print mold svv/vid-styles/slider/feel

etc.
mhinson
21-Apr-2009
[1837]
wow & I thought parse was tricky...

It seems anything more than drawing results on the screen is is undocumented 
at a newbie level. 

I could try to write the documentation myself I suppose, but I still 
havent managed to understand how to find what value is returned from 
these things.
Henrik
21-Apr-2009
[1838x3]
whoa, Anton is showing expert stuff there. it really should not be 
necessary to work with faces at that level. try settling for VIEW, 
LAYOUT, SET-FACE and GET-FACE for now. The next level would be events 
and the FEEL object. Then possibly STYLIZE.
getting a value from a face is easy-peasy:

view layout [field [name: get-face face print name]]
but note that VID is lacking a lot in some areas, and that requires 
expert supervision (like Anton) to extend. it's excellent for smaller 
projects, though.
mhinson
21-Apr-2009
[1841]
ok, thanks. I was sort of hoping to use the GUI for input too, rather 
than just drawing titles & pictures etc.

I know how to do that with slider now, but it seems a bit over the 
top if I have to ask you guys every time I want to use a function.
Henrik
21-Apr-2009
[1842]
there is a replacement GUI system available called RebGUI. If you 
find VID to be lacking what you need, perhaps RebGUI is capable of 
solving your problem. (but I don't use it myself, so I know nothing 
about it).
mhinson
21-Apr-2009
[1843]
I doubt VID is lacking, I am just not able to understand how to use 
it.
Henrik
21-Apr-2009
[1844]
VID is actually famous for its speed with which you can write usable 
GUIs. So it's not hard to learn.
mhinson
21-Apr-2009
[1845]
I suppose I have only spend an hour or two on it & I can work out 
how to make stuff appear on the screen, but not how to get stuff 
from the screen. (except slider).
Henrik
21-Apr-2009
[1846]
I just wrote above a line of code how to do that...
mhinson
21-Apr-2009
[1847]
[shakes head]...  I am sorry, I am just not able to understand how 
I use that line of code to find out for example what information 
is returned from slider for example.  Sorry, I must be making no 
sense to you.  Thanks for your patience.
Sunanda
21-Apr-2009
[1848x3]
This is a good tutorial, with examples of entering values, and the 
script responding to them:
http://www.rebol.org/art-display-article.r?article=pfx654q
Or browse some of the many Q&As on the mailing list:
http://www.rebol.org/ml-topic-index.r?i=view
and:
http://www.rebol.org/ml-topic-index.r?i=vid
Henrik
21-Apr-2009
[1851]
mhinson, have you tried running that line of code? Have you noticed 
that everytime you type something and press enter in the field, the 
contents is printed in the console?
mhinson
21-Apr-2009
[1852]
I have just realised that in your line of code "field" is the name 
of one of the VID functions, so I understand that one now, thanks.
If I use 
view layout [button "Ok" [name: get-face face print name]]  

it just  returns "none", not down or up or true or false or clicked 
etc. 
I tried this
view layout [button "Ok2" [name: value print name]]
and it returns the text on the button
does this mean get-face does not work on button?
could I have predicted this?
If I try to reference a different value like this
view layout [button "Ok2" [name: value/text print name]]

I just get an error & I have to restart the console to close the 
button.
is this where I should be able to interpret 
print mold system/view/vid/vid-styles/button/feel

to know how to ask for the parts of the value?      Thanks very much 
for all the help.  I am back at work now so can mostly only study 
this in the evenings.
Anton
22-Apr-2009
[1853]
A FIELD is a style, just like BUTTON, AREA etc. See the full list 
of available built-in styles like this:

	print mold extract svv/vid-styles 2

Check the ACCESS facet of a style to see what GET-FACE returns.
For BUTTON, it is:

	>> print mold svv/vid-styles/button/access
	make object! [
	    set-face*: func [face value][face/data: value]
	    get-face*: func [face][face/data]
	    clear-face*: func [face][face/data: false]
	    reset-face*: func [face][face/data: false]
	]


You can see that using GET-FACE on a BUTTON just returns face/data. 
Buttons by default don't use their data facet for anything, so it's 
NONE. (You could use the data facet to relate a button to something 
else that the button is associated with.)

Here's an example where a button does GET-FACE on a field.


 view layout [button "get-face field" [probe get-face my-field] my-field: 
 field "hello"]
Henrik
22-Apr-2009
[1854]
mhinson, you've stumbled onto the first limitation. If we take the 
line of code apart, it does the following:

view								; view the created layout

 layout							; create the layout (object tree of FACES) from the 
 VID dialect block
		[						; start of VID dialect block
			button					; the first element, a BUTTON
				"ok"				; the text for BUTTON

    [				; start of the action block for the button. it's evaluated when 
    the button is clicked.

     name: get-face face	; get the value of the button through the buttons 
     GET-FACE accessor
					print name		; print the value (likely none)
				]				; end of action block
		]						; end of layout block


Now when I say limitation, it's because you can't easily check for 
mouse button up, release, mouse movement, etc. The VID dialect directly 
uses a block right after the button description to describe what 
should happen after clicking the button. That's part of the syntax 
and above I wrote it as:

	<face style> <face text> [<action>]


You can specify size, color, edge size, background image and a few 
grahpical effects.


And with it being a dialect, you can leave things out or swap the 
ordering of some parameters.


If you want more advanced control, you need to use the FEEL object, 
but you are definitely not ready for that. :-) Settle for working 
with VID and some layouts like above. VID was designed to be easy 
and very fast to use. If you go beyond VID, you will need a whole 
lot more knowledge on how to do things.
mhinson
22-Apr-2009
[1855]
Thanks for your help again. Trust me to stumble on something ;-) 
I think I am getting there now.  Would this be the right way to identify 
which button was pressed?

view layout [button "ok" [print "button1"] button "ok" [print "button2"]]

I was expecting the buttons to have names other than the text on 
the button. I guess identifying the button by its possition in the 
code is what I will need to do.   Thanks.   I have never done any 
GUI programming before so perhaps I am just in a muddle about how 
it is done in general terms. I was expecting the event that a button 
was pressed to pop up in another part of the code (are they called 
event handlers?) (thus needing to identify which button it was). 
 If Rebol dosn't do it like that I may just be asking the wrong questions.
Henrik
22-Apr-2009
[1856]
I guess identifying the button by its possition in the code is what 
I will need to do.


Not necessary. That is what the set-word! prior to the style name 
is for. You can do that like this:

layout [b: button "Hello!" [print "clicked"]]

'b is now a button face. You can access it like this:

>> get-face b
== none

>> b/text
== "Hello!"

>> b/color
== 44.80.132

>> do-face b none
clicked


From inside the action block, you can also access it by FACE, e.g.:

[get-face face]