World: r4wp
[Rebol School] REBOL School
older newer | first last |
Cyphre 7-May-2013 [1927x3] | 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 [1951x2] | Should I use FIND instead? |
How can I use the LENGTH? of IDX as a way to CLEAR those last positions. ie IDX is 110, length is 3 then clear the last 3 characters from the ruler1 series and replace with to-string idx | |
GrahamC 8-May-2013 [1953] | try ? clear skip tail series -3 |
PatrickP61 8-May-2013 [1954] | Thanks Graham, I'm getting an error with ++ idx, help ++ indicates incrementing a 'word, but I'm not understaning it I'll try your suggestions |
GrahamC 8-May-2013 [1955] | >> idx: 1 == 1 >> ++ idx == 1 >> idx == 2 |
PatrickP61 8-May-2013 [1956] | :-D Oh my gosh, i couldn't get copy/part tail form idx - 1 working because I thought it was IDX subtract 1. Ooops, you meant -1 as part of copy/part!!!! |
Bo 8-May-2013 [1957x2] | >> help copy USAGE: COPY value /part range /deep So, copy/part takes two parameters: (1) the start index, and (2) the range If you rewrite the copy/part like I did below, it is much easier to see how it is split up: copy/part tail form idx ;parameter 1 -1 ;parameter 2 |
I'm not saying to use that format for writing your scripts, but as a visual aide, it may help. Also, you could make it kind of lisp-y like this: copy/part (tail form idx) (-1) | |
PatrickP61 8-May-2013 [1959] | Yes, thank you Bo, I like the lisp-y version!!! |
Bo 8-May-2013 [1960] | I sometimes do that when I am trying to debug a lot of nested statements, because if you use parens, Rebol will let you know that it didn't receive something it was expecting instead of just pulling the output from the next nested statement. |
PatrickP61 8-May-2013 [1961] | I've found that it is very easy to nest inside of statements, but hard to remember what goes where!!! I like your suggestion! :-D |
Bo 8-May-2013 [1962x2] | Actually, the first method I posted above is easier to understand for a lot of nested statements. Compare this real line of script from one of my programs. The way I normally write it: browse probe rejoin copy [http://www.respectech.com/log/show-invoice.cgi?user= username "&pass=" password "&submit=" replace/all client "&" "%26" "&invno=" invnum either amtdue [rejoin ["¬ice=1&amtdue=" to-decimal amtdue "&daysdue=" daysdue]][copy ""]] Lisp-y: browse (probe (rejoin (copy [http://www.respectech.com/log/show-invoice.cgi?user= username "&pass=" password "&submit=" (replace/all (client) ("&") ("%26")) "&invno=" invnum (either amtdue [rejoin ["¬ice=1&amtdue=" (to-decimal amtdue) "&daysdue=" daysdue]][copy ""])]))) Heirarchical (takes a lot more space, but is easier to follow -- however, doesn't have the parameter enforcement of parens): browse probe rejoin copy [ http://www.respectech.com/log/show-invoice.cgi?user= username "&pass=" password "&submit=" replace/all client "&" "%26" "&invno=" invnum either amtdue [ rejoin [ "¬ice=1&amtdue=" to-decimal amtdue "&daysdue=" daysdue ] ] [ copy "" ] ] |
I'm glad we don't have to use the Lisp method or the heirarchical method, but it is nice that we can, especially when we are starting out. I usually only use the heirarchical method when I am trying to understand and visualize someone else's really complex scripting. I'll use the Lisp method when I am getting an error that I have narrowed down to a small snippet of code, and I can't figure out why the error is occurring. I also throw in a lot of 'probe statements to see what's really going on. | |
Ladislav 9-May-2013 [1964x3] | Patrick, clear back tail ruler1 append ruler1 "+" actually is change back tail ruler1 #"+" |
Similarly, either idx < 99 [clear back back tail ruler1] [clear back back back tail ruler1] append ruler1 to-string idx can be written as change skip either idx < 99 [-2] [-3] to-string idx | |
err, I lost a part of the expression: change skip tail ruler1 either idx < 99 [-2] [-3] to-string idx | |
Gregg 9-May-2013 [1967x2] | Patrick, rather than building up the strings bit by bit, consider how you might do it if you think of them as a buffer you're modifying. e.g., start with something like this: ruler1: copy "" insert/dup ruler1 "_" 110 forskip ruler1 5 [change skip ruler1 -1 "+"] or this ruler1: head insert/dup copy "" "____+" 22 |
Sometimes things aren't clearer when you reduce them, but sometimes it can work well. | |
PatrickP61 9-May-2013 [1969x2] | Thank you Bo, Ladislav, and Gregg -- I'll use all your suggestions :-) |
Thanks to all that helped. Learning all the time. I think I have the code pretty tight now! A lot better than my first attempt. Final solution: ruler-len: 80 ruler-1: head insert/dup (copy "") "----+----." to-integer (ruler-len + 9 / 10) ruler-1: head clear (skip ruler-1 ruler-len) ; trim excess r1: skip head ruler-1 9 ; adv to pos 10 forskip r1 10 [ adj: ((length? idx: to-string (index? r1)) - 1) change skip r1 (-1 * adj) idx ] ruler-1: head r1 ; r1 is at tail ruler-2: head insert/dup (copy "") "123456789." to-integer (ruler-len + 9 / 10) ruler-2: head clear (skip ruler-2 ruler-len) ; trim excess print-ruler: does [print ruler-1 print ruler-2] | |
Ladislav 10-May-2013 [1971x3] | My notes: * it is absolutely unnecessary to set RULER-1 three times to the same value thus, I normally do: ruler-1: copy "" insert/dup ruler-1 "----+----." to-integer (ruler-len + 9 / 10) clear (skip ruler-1 ruler-len) ; trim excess .... ; for the same reason it is unnecessary to do: ; ruler-1: head r1 |
... and for the same reason I would do r1: skip ruler-1 9 ; HEAD unnecessary | |
The same note applies to RULER-2 | |
Bo 11-May-2013 [1974] | When Carl had me write my first Rebol script, his goal was to see if I understood how scripting in Rebol is different than most other languages. One of the helpful things he told me was that if you see patterns in your scripts, then you are likely not scripting as efficiently as possible. |
Henrik 11-May-2013 [1975] | Bo, that's a great quote. |
Reichart 12-May-2013 [1976] | LOL, I was just posting a rant on FB that can be summed up as "if you do it over and over again, make a BLOODY shortcut". |
older newer | first last |