questions about VID and parse.
[1/6] from: p0665393::magellan::umontreal::ca at: 10-Mar-2002 13:32
Hi all!
Beginner questions...
How can I display the content of a series as "text" in Rebol/View?
ex:
a: ["first" "second"]
I want
first
second
I tried: view layout [text foreach i a [i]], but in this case, first is replaced
by second.
---
Also another question about parse. How to use a string as a pattern?
parse "hello world" ??
I want ["hello" "rld"]
By what should I replace ?? to make this sequence ("wo" in this example)
considered as a whole.
Thanks!
best regards
Stephane
[2/6] from: gscottjones:mchsi at: 10-Mar-2002 13:56
Hello, Stephane,
From: "Bansard Stephane"
> Beginner questions...
> How can I display the content of a series as "text" in Rebol/View?
<<quoted lines omitted: 4>>
> second
> I tried: view layout [text foreach i a [i]], but in this case, first is
replaced
> by second.
I assume that you are wishing to dynamically create text-type labels
depending on the contents of a block series. That is a little trickier than
statically laying them out, as you may have discovered. Here is one way to
do it (liberally commented):
a: ["first" "second"]
;clear a fresh block to receive the dynamic layout information
layout-data: copy []
;loop through the series
foreach datum a [
;append the dialect word "text" to the layout data block
append layout-data [text]
;append the information to be displayed by the text word
append layout-data datum
]
;layout-data now is a block ready to be interpreted by the
;view/vid & layout dialect parser
view layout layout-data
> ---
> Also another question about parse. How to use a string as a pattern?
> parse "hello world" ??
> I want ["hello" "rld"]
> By what should I replace ?? to make this sequence ("wo" in this example)
> considered as a whole.
I am unsure about the answer to the second question. I suspect that this
will require a "rule" but I am unsure how to word the rule (my parse skills
have grown a tad rusty during a resent REBOL programming abscence).
> Thanks!
You are welcome. Hope I assumed correctly on your first question. Don't
hesitate to re-ask if I asumed incorrectly.
--Scott Jones
[3/6] from: p0665393:magellan:umontreal:ca at: 10-Mar-2002 15:33
Bonjour Scott Jones,
Thanks a lot for your fully functional example. This way i can progress!
>[...]
> a: ["first" "second"]
<<quoted lines omitted: 4>>
> ]
> view layout layout-data
So basically, I have to create a block like
[text "item1" text "item2" text "item3], right?
It seems there is not way to write a function to avoid rebuilding a new list.
>[parsing]
> I am unsure about the answer to the second question. I suspect that this
> will require a "rule" but I am unsure how to word the rule (my parse skills
> have grown a tad rusty during a resent REBOL programming abscence).
So... I will try to get some explanations about rules!
Thanks
Stephane
[4/6] from: gscottjones:mchsi at: 10-Mar-2002 16:42
From: "Bansard Stephane"
>...
> Thanks a lot for your fully functional example. This way i can progress!
<<quoted lines omitted: 9>>
> [text "item1" text "item2" text "item3], right?
> It seems there is not way to write a function to avoid rebuilding a new
list.
Hi, Stephane,
Perhaps I have inadvertantly caused some confusion. Perhaps I do not
exactly understand the functionality that you seek. Communications can be
so fragile at times.
As you may well know, /View is REBOL's gui extension. Although /View can be
programmed directly, most prefer to use the dialect extension VID (video
interface dialect). A block of interface description language is presented
to the layout command, which can interpret the block into a form presentable
for the view command. Hence, one frequently will use the following sequence
for a quick layout:
view layout [
text "Hello"
text "Goodbye"
]
The block (bracketed text) is presented to 'layout which then digests the
dialect for use by 'view. Alternatively, some let 'layout process the block
and later present the information to 'view:
lo: layout [
text "Hello"
text "Goodbye"
]
view lo
When you asked your question earlier, I made some assumptions, which is
always very hazardous. I assumed that you were needing a way to present
dynamically generated data in a window as in text-type format (aka a type of
label). My simplisitic method allowed for a block of text values to then be
laid out in a VID dialect block that is then presentable for 'layout.
Does this make sense?
If you simply need to format labels in a window and already know the labels,
I would recommend one of the static methods mentioned herein. However, if
you don't know what the labels are in advance, then consider using some
variation on the theme that I gave in the last email.
Have I caused more confusion?
Regards,
--Scott Jones
[5/6] from: christophe:coussement:mil:be at: 11-Mar-2002 9:51
> Beginner questions...
[Coussement Christophe] welcome ;-))
> Also another question about parse. How to use a string as a pattern?
> parse "hello world" ??
> I want ["hello" "rld"]
> By what should I replace ?? to make this sequence ("wo" in this example)
> considered as a whole.
[Coussement Christophe] try:
>> parse "hello world" none
== ["hello" "world"]
>>
hope it helps !
==christophe
[6/6] from: joel:neely:fedex at: 11-Mar-2002 7:53
Hi, Christophe,
Coussement Christophe wrote:
> > Also another question about parse. How to use a string as a pattern?
> > parse "hello world" ??
<<quoted lines omitted: 5>>
> == ["hello" "world"]
> >>
I interpreted the question as wanting "wo" to be the marker/delimiter
between fragments of the string, instead of whitespace. That could be
done something like this:
marker: "wo"
fragment: ""
collection: []
parse-rule: [
any [
copy fragment to marker (append collection fragment)
marker
]
copy fragment to end (append collection fragment)
]
which gives:
>> parse "hello world" parse-rule
== true
>> collection
== ["hello " "rld"]
only leaving open the issue of the trailing whitespace in "hello ",
but that wasn't stated in the delimiter...
-jn-
--
; sub REBOL {}; sub head ($) {@_[0]}
REBOL []
# despam: func [e] [replace replace/all e ":" "." "#" "@"]
; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"}
print head reverse despam "moc:xedef#yleen:leoj" ;
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted