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

World: r3wp

[Rebol School] Rebol School

Geomol
20-Jul-2007
[571]
Ah, there's the explanation, a newline can be specified as ^(line)
(for some reason)
PatrickP61
20-Jul-2007
[572]
Ahhhhh
Gregg
20-Jul-2007
[573]
More reference info here: http://www.rebol.com/docs/core23/rebolcore-16.html#section-3.1

And you also have the words CR, LF, and CRLF available.
PatrickP61
26-Jul-2007
[574]
My teachers,  I have an array ( block (of "lines") within a block 
(of values) ) that I would like to convert to a block (of "lines") 
with all values joined with an embedded tab.  What is the best way 
to achieve this?  See example: 


In-array:      [   [   {Col A1}     {Col B1}   ]        <-- I have 
this
                          [   {2}              {3}             ]
                          [   {line "3"}    {col "b"}    ]   ]


Out-block:   [   {Col A1^(tab)Col B1}             <-- I want this 
                         {2^(tab)3}
                         {line "3"^(tab)col "b"}         ]
Rebolek
26-Jul-2007
[575]
>> out-block: copy []
== []

>> foreach line in-array [append out-block rejoin [line/1 "^-" line/2]]
== ["Col A1^-Col B1" "2^-3" {line "3"^-col "b"}]
Anton
26-Jul-2007
[576x2]
in-array: [["Col A1" "Col B1"]["2" "3"][{line "3"} {col "b"}]]

out-block: copy [] 
foreach blk in-array [
	line: copy "" 
	repeat n -1 + length? blk [append append line blk/:n tab]
	if not empty? blk [append line last blk]
	append out-block line
]
new-line/all out-block on
== [
    "Col A1^-Col B1"
    "2^-3"
    {line "3"^-col "b"}
]
PatrickP61
26-Jul-2007
[578]
Anton, what does the new-line/all do.  I gather it inserts newlines 
after each value.  Is that right?
Volker
26-Jul-2007
[579]
it cleans up rebol-listings
PatrickP61
26-Jul-2007
[580]
Forgive me,  how does it do that?
Volker
26-Jul-2007
[581x2]
else all strings would be on one line. only interesting for probing 
rebol-code, does not change the strings itself
there is a hidden markerin values, for newline
PatrickP61
26-Jul-2007
[583]
So if i read you right, then if I didn't do new-line/all, and tried 
to probe Out-block, it would show the entire contents as one large 
string, whereas new-line/all will allow probe to show each value 
as a spearate line.  Right?
Volker
26-Jul-2007
[584x2]
as lots of strings in one line
and with the new-line all strings in own lines
PatrickP61
26-Jul-2007
[586x4]
I see how it works now  -- Thank you Anton and Volker!!
Thank you Reblek  -- didn't see your answer at first!
My teachers, Anton and Rebolek have submitted two answers.  The difference 
between them is that Anton's answer will insert a tab between varying 
numbers of  values per line, where Rebolek will insert a tab in-between 
col 1 and col2 (assuming only 2 columns in the array).  Is that a 
correct interpretation?
Anton, I understand Rebolek answer, but I want to understand your 
answer too.

 I'm wondering about the line: repeat N -1 + length? Blk [append append 
 Line Blk/:N tab]  

does Rebol do the inner append first  (in math expressions) like 
this:  [append ( append Line Blk/:N ) tab]
and then do this for the number of "lines" in the array
N	Out-block
0	[]
1	"Col A1^-Col B1"
2	"Col A1^-Col B1"	"2^-3"
3	"Col A1^-Col B1"	"2^-3"	{line "3"^-col "b"}


I think I see the above progression, but not sure about Blk [append 
Line last Blk]  Is this advancing the starting position within In-array?
Gregg
27-Jul-2007
[590]
...insert a tab between varying numbers of  values per line <versus> 
... insert a tab in-between col 1 and col2
 -- Correct.


On new-line, it's kind of advanced because it doesn't insert a newline 
(CR/LF), but rather a hidden marker between values that REBOL uses 
when molding blocks.
PatrickP61
27-Jul-2007
[591]
Hi Gregg -- Is that primarily for display purposes, or could it be 
used for other things?
Gregg
27-Jul-2007
[592x2]
On "append append", yes. You could also do it like this: "append 
line join blk/:n tab", the difference being that APPEND modifies 
its series argument, and JOIN does not.


REPEAT is 1-based, not zero, Anton is using "-1 + length? blk" rather 
than "(length? blk) - 1" or "subtract length? blk 1". The first of 
those cases requires the paren because "-" is an op! which will be 
evaluated before the length? func, so REBOL would see it like this 
"length? (blk - 1)", which doesn't work.
For display or formatted output. It's *very* useful when generating 
code for example.
PatrickP61
27-Jul-2007
[594]
Sounds like more advanced stuff than I'm understanding right now. 
 I'll read up on the terms. 

When I get REBOL code solution, I'd like to understand how Rebol 
is processing the code.  What it does logically first, and logically 
second... I think I get confused about when Rebol does the evaluations.
Gregg
27-Jul-2007
[595x3]
You shouldn't have to worry about new-line at all. It's actually 
relatively new, so we all lived without it for a long time.
It can be confusing at times, and even once you know what you're 
doing, you sometimes have to think about it a bit. The up-side is 
that you have a great deal of control once you know how to use it.
I should point out that NEW-LINE, as Anton used it, is a handy shortcut 
that takes the place of foreach+print for simple console display.
PatrickP61
27-Jul-2007
[598]
I am looking forward for the Rebol lightbult to go on full power!!! 
 I think it just takes me playing around with rebol more to get there!
[unknown: 9]
27-Jul-2007
[599]
Yes...that will happen.  The best way is to try to teach what you 
know now to someone else.  To Teach is to learn.
Geomol
27-Jul-2007
[600]
Patrick, before I started with REBOL, I had many years of experience 
with many different languages, both as a hobby and professional. 
It wasn't hard for me to grasp new languages, because every new one 
always reminded me of some other language, I already knew. Then I 
came to REBOL, and I could make small scripts after a few days. But 
it took me more than a year to really "get it". And it's just the 
best language, I've ever programmed in. It keeps amaze me after all 
these years, and I constantly find new things, new ways of doing 
things. From your posts here, you're having a very good start, as 
I see it. Just keep hacking on that keyboard, and don't forget to 
have fun!
btiffin
27-Jul-2007
[601]
Patrick; Check out http://www.rebol.org/cgi-bin/cgiwrap/rebol/art-display-article.r?article=lf019t
 It's an experiment in rebol.org hosting public wiki articles.  Plus 
I'm plugging my own work  :)
Vladimir
3-Oct-2007
[602x4]
Well first of all ....Im new here... :) joined yesterday... and I 
have a problem on my hands.....
Here is a piece of code from graphic editor.... I have problems with 
"insert-event-func"
pixel_face: make face [
    size: pixel_size
    edge: none
	color: black
    data: 0
]

...

pane-func: func [face index] [
    index: (index - 1)
    either integer? index [
        if index < ((grid_size/x) * (grid_size/y)) [
        	xx: (index // (grid_size/x)) + 1
        	yy: to-integer ((index / (grid_size/x)) + 1)
            pixel_face/data: index
            pixel_face/offset/y: ((yy - 1) * (pixel_size/y))
            pixel_face/offset/x: ((xx - 1) * (pixel_size/x))
            pixel_face/color: pick paleta sprite-colors/:yy/:xx
            return pixel_face
        ]
    ][
 ;       return to-integer index/y / 20 + 1
    ]
]

key-event: func [face event] [
    if event/type = 'key [
	            switch event/key [
                        up [cursor_y: cursor_y - 1]
	            		down [cursor_y: cursor_y + 1]
                        left [cursor_x: cursor_x - 1]
                        right [cursor_x: cursor_x + 1]

                       ]
           		sprite-colors/:cursor_y/:cursor_x: 2
	            show grid
            ]
    if event/type = 'time [
		? now/time
    	cursor_color: (3 - cursor_color)
   		sprite-colors/:cursor_y/:cursor_x: :cursor_color
        show grid
	]
    event
]
 
insert-event-func :key-event

grid: make face [
    offset: ((screen_size - window_size) / 2)
    size: window_size
    rate: 00:00:05
    color: blue
    effect: [gradient]
    pane: :pane-func
]

view/new grid
do-events
No matter where I put the rate: 1 element I get 24 events in one 
second..... How can I slow this down?
Oldes
3-Oct-2007
[606]
Which events? If from keyboard, you have to filter them in your key-event 
function.
Vladimir
3-Oct-2007
[607x3]
That is what I do in key-event func....:  if event/type = 'time [
		? now/time
    	cursor_color: (3 - cursor_color)
Problem is that events are always happening the same rate... no matter 
what I do....
I tried to put rate:1 in my grid face.... I tried to put it in pixel_face... 
I tried to put it in pane-func...
Oldes
3-Oct-2007
[610]
Here is simplified your problem:
ke: func[f e][ if e/type = 'time [print now/time/precise] e]
insert-event-func :ke
view layout [box with [rate: 10]]


But I cannot help you. I'm not a view guru. It looks you should not 
use insert-event-func if you don't want to get all time events.
Vladimir
3-Oct-2007
[611x2]
:)
yeah... I guess its a mix between insert-event-func and iterated 
pane..... pane is generated every time and my adding rate element 
to it doesn't effect global rate..... thanks for answer!
Oldes
3-Oct-2007
[613]
Use somethink like:

view layout [
	box with [
		rate: 10
		feel: make feel [
			engage: func [f a e] [
				if a = 'time [print now/time/precise]
			]
		]
	]
]
Vladimir
3-Oct-2007
[614x7]
I'm just typing something like that.... :)
I will check if iterated pane is the source of problem....
pane is not a problem...... your code works (as it should) :)
I know it works, but I remember puting insert-event-func there for 
a reason.... If I remember I couldnt get keyboard response from my 
iterated pane somehow.... I'll try it again ....
Thanks for help!
Done it! All I needed was:  system/view/focal-face: grid
I guess I should read docs more :)