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

World: r3wp

[Rebol School] Rebol School

BrianH
9-Feb-2011
[3383]
No SET-MODES at all yet.
PatrickP61
9-Feb-2011
[3384x3]
Any idea on what I'm doing wrong with R2 for this code:

		set-modes system/ports/input [binary: true]
		string: ""
		until [
			char: input
;			print char-x: to-char char
			if not char = 13 [
				prin "-" prin char-x: to-char char
				append string char-x
				]
			char = 13 ; <enter>
			]
		set-modes system/ports/input [binary: false]
		head string
		print "string: " string

Typing in the following gives me this:
-1-2-3string:      

I was hoping for
-1-2-3string: "123"
Typing in      123<enter>
dinner calls -- will check back later
Sunanda
9-Feb-2011
[3387x2]
Might be that last print statement.......I think you mean:
    	print ["string: " string]
or perhaps:
    	print ["string: " mold string]
PatrickP61
9-Feb-2011
[3389]
Dohhhhh! That is right!!  Thank you Sunanda
PatrickP61
11-Feb-2011
[3390x3]
I am plaqued by a simple problem.  In R2-core, I keep on getting 
a Security Check prompt when attempting to read a file.

I am able to avoid security check prompts with R3-core by setting 
SECURE [DEBUG ALLOW] in %rebol.r
But I am not able to do this with R2-core. 


What is the proper way to use the SECURE [FILE ALLOW] option so that 
I am not continually prompted all the time?
I've tried it in my rebol.r file but it still asks me for this.
Another annoyance -- I am not sure why, but R2-core seems to require 
two REBOL [] headers for %rebol.r and %user.r -- Is anyone else seeing 
this as well?
Windows XP  R2.7.8
GrahamC
11-Feb-2011
[3393]
secure none
Awi
11-Feb-2011
[3394x4]
Is it possible to get the value of variable number of occurences 
while parsing block?
Foe example, I have the following 

block1: [cancel "res-1" "res-2" "res-3"]	; the number of strings 
following 'cancel might be 1, 2, 3...
>> parse block1 ['cancel set res-numbers some string!]
== true
>> res-numbers
== "res-1"
Is there a way I can get all three strings? Thank you very much!
BrianH
11-Feb-2011
[3398x5]
>> parse block1 ['cancel copy res-numbers [some string!]]
== true
>> res-numbers
== ["res-1" "res-2" "res-3"]
>> parse block1 ['cancel copy res-numbers some string!] res-numbers
== ["res-1" "res-2" "res-3"]
>> parse block1 ['cancel return res-numbers some string!]
== ["res-1" "res-2" "res-3"]
These are all R3 though.
>> parse block1 ['cancel return some string!]
== ["res-1" "res-2" "res-3"]
The ones with COPY work in R2 as well.
Don't use this one (from above):
>> parse block1 ['cancel return res-numbers some string!]
== ["res-1" "res-2" "res-3"]
It is matching the previously copied res-numbers as a rule :(
Awi
12-Feb-2011
[3403]
Thanks Brian! I'm still working with R2. I thought COPY was only 
for parsing string, my bad I didn't even try it. Thanks again.
Awi
14-Feb-2011
[3404]
Is it possible to get the current context name in Rebol?

I'm trying to write a log function (write log data to file, like 
nlog or log4net in .net world), surely it will be nice if I could 
also write the current function being logged.
Example:

log: func [to-log] [write/append/lines %log.txt reform [now current-context/parent-context/name 
to-log]
plus: func [a b] [log reform ["adding" a "to" b] a + b]
>> plus 1 1
== 2
>> read %log.txt
== "14-Feb-2011/23:35:04+7:00 plus adding 1 to 1^/"


What I'm asking if whether such a thing like current-context and 
it's parent context exist, and how to get them. Thanks!
Henrik
14-Feb-2011
[3405]
I'm not sure if you can. The closest analogy is BIND?, I believe.
Sunanda
14-Feb-2011
[3406]
You can, sort of, by cheating and generating an error.....The error 
object usually contains the current context name, but not the parent's
     plus: func [a b /local name][
        name:  get in disarm try [0 / 0 ] 'where   ;; cheat
        print name

        log reform ["adding" a "to" b "in" name]  ;; and add name explicitly 
        to log function call
        a + b
         ]
Maxim
14-Feb-2011
[3407x2]
sunanda, that is a hell of a nice cheat!  never thought of that one.
pity it can't be made into a function  :-)
Gabriele
15-Feb-2011
[3409]
that is not the current context, rather, the current "function name". 
(and Max... I think I posted that a long time ago ;) I was using 
it in my profiler)


Awi, the thing is that functions don't have names. Also, by "context" 
in REBOL we mean something closer to what other languages call "frame", 
however REBOL has no concept of a "current frame" or of a "parent 
frame". R3 though has (had?) a STACK function that will probably 
give you want you want.
BrianH
15-Feb-2011
[3410x2]
You can get the name of the word that the function was called through 
in the current call stack. This isn't *the* name of the function, 
but it's *a* name of the function. Note: "pity it can't be made into 
a function  :-)" This is because if you put that trick in a function, 
then *that* function is the function that will be referenced.
R3's STACK returns information about the entire call stack, though 
the 'debug security setting would put some limits on it. SECURE is 
disabled in recent builds so we don't know what the limits are; we 
could try older versions to find out what those limits used to be. 
Also, see http://issue.cc/r3/885for a bug in STACK.
Awi
17-Feb-2011
[3412]
Thank you guys, I can never learn enough of Rebol.
WuJian
7-Mar-2011
[3413]
>> a: "1.  "  ;here's  a space
== "1.  "   
>> layout [text a]
>> a 
== "1."
Ladislav
7-Mar-2011
[3414x2]
That looks more like a quirk of the function, than as something one 
should explain to the beginners.
The function looks like trying to be "cleverer" than the user.
WuJian
7-Mar-2011
[3416]
I feel  that 'a should not be modified?
Oldes
7-Mar-2011
[3417x3]
probe select system/view/vid/vid-styles 'text
...
if all [not flag-face? self as-is string? text] [trim/lines text]
...
Just don't know how one should set the flag as-is... I'm not using 
view many years
Googled....
>> a: "1. " layout [text as-is a] a
== "1. "
WuJian
7-Mar-2011
[3420x2]
Ok
[trim/lines text]   or [trim/lines copy text]  ?
Henrik
7-Mar-2011
[3422]
the latter one, if you don't want the original string modified.
Janko
7-Mar-2011
[3423x2]
0MQ binding.. that is awesome! Does/will this work for R2 also maybe? 
:)
ups .. wrong chanel
Awi
9-Mar-2011
[3425]
VID question (R2): Is it possible to get the cursor position in the 
scroll-line event? I wanted to use the scroll to zoom in (like in 
google maps), and to zoom in to the right area, I needed the cursor 
position. Thanks for the help.
Rebolek
9-Mar-2011
[3426]
You can get cursor position using CARET-TO-OFFSET
Awi
9-Mar-2011
[3427]
Unluckily the face I am using is a plain panel, so no text there. 
I just tried PRINT CARET-TO-OFFSET pnl-map "", and it returns none.
BrianH
9-Mar-2011
[3428]
That's the mouse pointer, not the cursor (sorry, terminology isn't 
very portable to REBOL).
Gregg
9-Mar-2011
[3429]
You probably need to remember the offset from the last 'move event, 
since the scroll-line uses the event offset parameter itself.
Maxim
9-Mar-2011
[3430x2]
yes, you need to hack the event engine a little bit.   


As gregg says, you need to have a memory of the last move event to 
get its position  and store it (you can do this with an event-handler). 
 glayout and GLASS do this for handling scrollwheel events.


what I also do is find the top-level face which is under the mouse-cursor 
and fire off my own events from the scroll-wheel instead of relying 
on a text field.

again, you can trap the scroll-wheel events in the event handler.


if you want to have a ready-made solution, download glayout.r from 
rebol.org  and look at the hacked WAKE-EVENT function.


it already does all of this and wraps it up by adding new function 
you can add to your face/feel  object in order to handle scroll-wheels.
the wake-event function needs a few other functions which are all 
in the glayout module, but it should be easy to keep just what you 
need and run that before the rest of your script.
Awi
10-Mar-2011
[3432]
Thanks for the help, I am still digging around, will let you know 
the result. I will have to translate all that to RebGui though.