• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

PatrickP61
2-May-2013
[1902x2]
It just repeats what i've entered
forever [do ask "? "]  will work on some rebol commands like HELP 
or PRINT "HI" but not "Q" or "QUIT"

which is why I tried to state the condition to break out of the loop
Gregg
2-May-2013
[1904]
So if you type "quit" (no quotes) after running that, it doesn't 
quit REBOL?
PatrickP61
2-May-2013
[1905x2]
right
it is like the word is not being evaluated
Gregg
2-May-2013
[1907]
What version of REBOL, and what OS? It works as expected here on 
Win7.
PatrickP61
2-May-2013
[1908]
r3 111 vista
Andreas
2-May-2013
[1909]
Was just askin about R3 vs R2 :/ I fear you hit a known bug in R3.
Gregg
2-May-2013
[1910x2]
Ah, R3. Let me try.
Indeed. I now see your behavior.
PatrickP61
2-May-2013
[1912]
thanks Andreas,  that explains it
Andreas
2-May-2013
[1913]
(http://issue.cc/r3/851-- that's the bug, just in case.)
PatrickP61
2-May-2013
[1914]
Just FYI: workaround the bug:

forever	[
	do script: ask	[~ " REBOL COMMAND? "]	; do the entered command
	if script = "q"		[break]
	if script = "quit"	[break]	
	]
Gregg
2-May-2013
[1915x3]
So, coming back to the original question... :-) Rather than doing 
"script =" for every command, you could say "if find ["quit" "q"] 
cmd [break]", so it's easier to check multiple commands, aliases, 
etc. e.g., what about HALT?
So I would still hold the result of ASK in a temp var, rather than 
DOing it directly and relying on the bug's behavior.
i.e., get the command, check if it's special and, if not, DO it.
PatrickP61
2-May-2013
[1918]
Yes, that would work better
Endo
4-May-2013
[1919]
May be we should create a "R3 School" and rename this group to "R2 
School"?

So we do not have to ask for version for every question asked in 
this group. What do you think?
Gregg
4-May-2013
[1920]
I think this group is fine. Otherwise we may have fragmentation about 
general questions.
PatrickP61
7-May-2013
[1921]
In R3, I want to be able to request a specific directory quickly 
and easily.  The easiest way I've found is to use REQUEST-FILE since 
it allows the user to quickly "navigate to" the desired directory. 
 Thing is, it requires the user to pick an existing file , even though 
I don't care about the file itself.  In most cases, this is fine 
since the user can pick any one of the files, but in cases where 
a directory is empty of a file, I have a problem.  

example code:

request-file/file to-file join "/" second parse what-dir "/"   <-- 
I use this to default the directory at the highest level is   ie 
 %/c  

Is there a better way to do this in R3?
Endo
7-May-2013
[1922]
There is also request-dir I think.
PatrickP61
7-May-2013
[1923]
I'm using 2.100.111 and no REQUEST-DIR, unless it was added in a 
later version
Cyphre
7-May-2013
[1924]
In Saphirion's build we have REQUEST-DIR already added.
james_nak
7-May-2013
[1925]
I tried request-file in the android build, it didn't crash but nothing 
showed up. Not that I needed it - I was just curious.
Cyphre
7-May-2013
[1926x4]
The android version doesn't have thesee calls implemented yet (AFAIK 
android doesn't have any "default OS" requesters for that so we need 
to do it ourself or reuse custom code)
But in Windows version this works.
It's even in the lates public source release here: http://development.saphirion.com/downloads/
so if anyone have time to make pull-request?
(check the OS_Request_Dir() function in src\os\win32\host-lib.c as 
a base for the feature)
PatrickP61
7-May-2013
[1930x5]
Thanks Cyphre, I've just downloaded from Saphirion -- Looks exciting!
I am trying to troubleshoot a peculiarity in   R3    2.101.0 from 
Saphirion

>> print type? what-dir

file!				<-- Ok, it's a file, even if has an end slash instead of 
a specific file path
>> print type? request-dir	; select any directory
file!				<-- Ok, Same thing


So it stands to reason that passing the value returned by WHAT-DIR 
and by REQUEST-DIR  will be FILE!
So here is my code that is giving me some trouble:

file-list:	[]

read-dir:	func	[
	dir	[file!	]
	] [
	foreach file read dir [
		file: either dir = %./ [file] [dir/:file]
		append file-list file
		if dir? file [
			read-dir file
	]	]	]

inp-dir: request-dir/path	what-dir 

unless inp-dir [ask	">>> No directory selected, cannot proceed  (Enter)" 
 quit ]
cd :inp-dir


read-dir inp-dir		; <-- does not work as expected, must use cd and 
what-dir instead
;read-dir what-dir
new-line/all file-list on
print mold file-list
If you comment out the READ-DIR INP-DIR and uncomment the next line, 
it works fine!

What am I missing?  Another bug?
I'ts getting late, see you tomorrow!
GrahamC
7-May-2013
[1935x2]
what happens when you probe inp-dir after the request?
have you done 'load-gui before you run the script?
Andreas
8-May-2013
[1937x4]
Patrick, simple fix: if you expect INP-DIR do be a file refering 
to a directory, sanitise it through DIRIZE: `read-dir dirize inp-dir`.
The underlying problem indeed is related to a bug in R3. Both directories 
and files are represented by file! in R3. R3 uses a heuristic that 
a trailing slash discernes file file!s from directory file!s. Now 
when you pass a file! without a trailing slash but which actually 
refers to a directory to READ, READ crashes. (Bug#1675)
The simplest demonstration of that bug: read %.
Now if REQUEST-DIR returns a file! without a trailing slash, passing 
that returned value directly to READ will trigger this bug.
PatrickP61
8-May-2013
[1941]
Back again.  Thank you Andreas,


I had realized that FILE! was used for both directory and files, 
but I didn't realize that REQUEST-DIR was NOT sending it back as 
a directory, but as a file (without trailing slash).  I was able 
to confirm by adding a print of WHAT-DIR and INP-DIR and compare, 
as per your comments.

I did not know about DIRIZE


Using READ DIRIZE INP-DIR does fix the problem -- though I wonder 
if REQUEST-DIR should return it with a trailing slash?

Thanks again to all!
Andreas
8-May-2013
[1942]
Yep, I think REQUEST-DIR should return a dirized file!.
PatrickP61
8-May-2013
[1943]
Hey all, I'm having such a good time learning again!


I've got some code to generate a print ruler, but I think it could 
be cleaned up a lot more.   

If some of you have a quick moment, could you take a quick look and 
advise me on how to shorten this code.

ruler1: copy ruler2: ""
idx: 0
loop 110 [
	idx: idx + 1
	append ruler1 "_"
	append ruler2 last-digit: last to-string idx
	if last-digit = #"5" [
		clear back tail ruler1
		append ruler1 "+"
		]	
	if last-digit = #"0" [
		either idx < 99 [clear back back tail ruler1]
			[clear back back back tail ruler1]
		append ruler1 to-string idx
		]
	]
replace/all ruler2 "0" "_"
print ruler1
print ruler2



____+___10____+___20____+___30____+___40____+___50____+___60____+___70____+___80____+___90____+__100____+__110

123456789_123456789_123456789_123456789_123456789_ 123456789_123456789_ 
123456789_123456789_ 123456789_123456789_
GrahamC
8-May-2013
[1944]
Try ++ idx instead of idx: idx + 1
PatrickP61
8-May-2013
[1945x2]
I don't like the BACK BACK ... etc, depening upon the length of IDX 
which is what I want to print out 

Can I do something like LENGTH? IDX and use that number to "back 
up the series"?
I'll give ++ idx a try
GrahamC
8-May-2013
[1947x2]
copy/part tail form idx -1 will give you the last number
shouldn't use mutually exclusive serial if statements
PatrickP61
8-May-2013
[1949]
You mean instead of LAST-DIGIT: LAST TO-STRING IDX
GrahamC
8-May-2013
[1950]
yes
PatrickP61
8-May-2013
[1951]
Should I use FIND instead?