REBOL newbie - have been unable to get some particulars
I've search all over for answers to these items: 1) Change field or area faces font size after the initial layout is on display. Would like to switch between normal and large fonts via a checkbox. 2) How does one use find/any or find/case to search for whole words? My searches return partial words. i.e if I search for Ruth, it will also return Truth. (In AutoHotkey I used RegExMatch with no problem). 3) How can a program set the picked items in text-lists? I've tried tlist/picked: ["Test"] and it selects that item but does strange things afterwards. I need to restore the last picked items from two lists on script startup. Thanks for any help you all can provide.
posted by: Michael Todd 25-Nov-2018/21:39:56-8:00
I can help with one little piece: R E B O L [ Title: "Font change test" Purpose: {Change a font at run time.} ] CHANGE-FONTSIZE: does [ either CHECKBOX/data [ TESTTEXT/font/size: 12 show TESTTEXT set-face TESTRESULT "Small text" ] [ TESTTEXT/font/size: 20 show TESTTEXT set-face TESTRESULT "Large text" ] ] view center-face layout [ across banner "Font change test" return TESTTEXT: text "Change the size of this text" font [size: 20] return TESTRESULT: info 200 return label 100 "Larger text" CHECKBOX: check 20x20 [CHANGE-FONTSIZE] return bar 600 return button "Quit" [quit] button "Debug" [halt] ]
posted by: Steven White 26-Nov-2018/10:42:39-8:00
...and perhaps with another... R E B O L [ Title: "Text-list setter" Purpose: {Show how to pre-set the picked item of a text-list} ] LIST-DATA: [ "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December" ] INITIAL-PICK: "September" SHOW-PICKED: does [ either TLIST/picked [ set-face TPICKED TLIST/picked ] [ set-face TPICKED "Nothing" ;; does not work if nothing picked, BTW. ] ] MAIN-WINDOW: layout [ across banner "Set picked value of text list" return TLIST: text-list 100x200 data LIST-DATA return TPICKED: info 100 return button "Picked?" [SHOW-PICKED] button "Quit" [quit] button "Debug" [halt] ] TLIST/picked: INITIAL-PICK view center-face MAIN-WINDOW
posted by: Steven White 26-Nov-2018/11:13:49-8:00
Regarding question 2, I am hoping the Parsing Masters will have a solution. I would suspect that searching for "whole words" means that your target string would have one or more spaces before it and a space or some punctuation after it. If not, you could get most of them by constructing a search string by joining a blank, your target string, and another blank, and searching for that. But I would love to see a parsing solution because I am trying to build up a personal collection of parsing solutions in the hope that one day I can understand parsing.
posted by: Steven White 26-Nov-2018/11:29:16-8:00
On Q2: you likely are going to have to use PARSE for this. FIND is fairly crude in this regard. Before we get to parsing, we need a definition of what delimits a word. I'm going to use an amalgam of Regex's definition of space and punctuation: space: charset "^/^- " punct: charset "!^"#$%&''()*+,-.//:;<=>?@[]^^`{|}~" Then define a character as something that is not that: chars: complement delims: union space punct Now we just to parse our content until we find our given word: find-word: func [text [string!] word [string!] /local mark][ parse/all text [ any delims ; leading space/punctuation any [ mark: word [delims | end] (return mark) ; we have our word bound by space, we're done here | some chars some delims ; skips a match and then further space ] end skip ; force return FALSE from PARSE ] ] Note that as we're not vetting the whole word, you can match words that include space and punctuation: find-word "the quick brown fox" "quick brown"
posted by: Chris 26-Nov-2018/14:07:58-8:00
Couple of duplicate values in that PUNCT definition, doesn't change the functionality of the above: punct: charset {!"#$%&'()*+,-./:;<=>?@[]^^`{|}~}
posted by: Chris 26-Nov-2018/14:13:52-8:00
Steve, thanks very much. That solves some of those issues. your text font size fix works for field and area facets but I'm using area-scroller which incorporates a synced scroll bar. For that facet, setting the text size doesn't work. :-( I will just let the user click the checkbox, save the font choice to a config.r file and restart the program. No biggie. I use AutoHotkey and it's very tied into all the bells and whistles in Windows.
posted by: Michael Todd 26-Nov-2018/15:08:12-8:00
> SHOW-PICKED: does [ > either TLIST/picked [ > set-face TPICKED TLIST/picked > ] [ > set-face TPICKED "Nothing" > ] > ] It's worth mentioning that when you have code redundancy like this, Rebol is better than most languages at letting you cut that down...since most operations can move into most slots. First, factoring out the EITHER: SHOW-PICKED: does [ set-face TPICKED either TLIST/picked [TLIST/picked "Nothing"] ] Then, you can use ANY to take the first "truthy" thing, removing the redundancy of TLIST/picked: SHOW-PICKED: does [ set-face TPICKED any [TLIST/picked "Nothing"] ] Ren-C takes these ideas further, such as with conditional AND/OR/ANY that infixedly does this, taking a BLOCK! of code on the right hand side and an expression on the left: SHOW-PICKED: does [ set-face TPICKED (TLIST/picked or ["Nothing"]) ] It opens up a lot of ground, since OR completes its left hand side. To combine that with a point on PARSE factoring: data: "aaabbbaaa" a-rule: [some "a"] b-rule: [some "b"] parse data [a-rule b-rule a-rule] or [ fail "The ABA parse rule did not succeed" ] I think this is worth emphasizing to any new users, because to my mind the brevity and elimination of redundancy, without sacrificing clarity is one of the key "joys".
posted by: Fork 26-Nov-2018/15:26:53-8:00
Unfortunately posts in this forum cannot be edited, but that first code example should have read: set-face TPICKED either TLIST/picked [TLIST/picked] ["Nothing"]
posted by: Fork 26-Nov-2018/15:28:08-8:00
Not to divert this to a different topic, but here... http://www.rebol.com/article/0374.html Is an article by Carl that mentions using REBOL like other languages. "Many programmers use REBOL like they're writing in C or BASIC. I can spot it in an instant; they did not bother to learn the fundamental concepts of the REBOL language." I'm sure I am one of those, but I'm not sure I ever have seen those fundamental concepts explained. I just started using REBOL because I knew there was genius in there somewhere, because of who created it (I used to have an Amiga 1000). I hoped that if I beat my head on it long enough I would understand.
posted by: Steven White 27-Nov-2018/10:37:14-8:00
Carl, I've noticed that many simple functions like substring are not built in but are accomplished pretty easily for seasoned Rebolers. AutoHotkey has all the bells and whistles for MS Windows, window manipulation, tooltips, system tray menus, string functions, etc. all readily accessible. So, I'm very spoiled by that. I too see something special about REBOL and am rewriting the basic shell of a large AutoHotkey app in it, for learning purposes. But, some of the tricks that have to be done with scrollers (sliders) for Area faces and text-lists are just taking a lot of research and trial and error.
posted by: Michael Todd 27-Nov-2018/11:03:02-8:00
Okay, in AutoHotkey, I have an app with two listboxes. Click the first list, it generates the items for the second list and display text in an edit window based on the combination of those two clicked items. When I exit the program, it saves the two clicked items so when restarting, the program select both of the items which runs the code to redisplay that text. I have had no luck doing this in REBOL. I have tried the following: the-book/picked: "A" the-chapter/picked: "1" ;get the text for A1 set-face text found or the-book/picked: ["A"] the-chapter/picked: ["1"] show the-book show the-chapter or set-face the-book "A" set-face the-chapter "1" show the-book show the-chapter Sometimes, it will highlight the items, sometimes not, sometimes, I get 2 or three items highlighted??? Is there a way to set these Text-Lists on startup? I am liking REBOL but sure am spinning my wheels on what should be simple stuff.
posted by: Michael Todd 27-Nov-2018/11:16:01-8:00
Is this the general idea you are working on? R E B O L [ Title: "Bookmarker" Purpose: {Demo for setting and remembering bookmarks.} ] CHAPTERS: [ "Book 1 Title" [ "Book 1 Chapter 1" "Book 1 Chapter 2" "Book 1 Chapter 3" "Book 1 Chapter 4" ] "Book 2 Title" [ "Book 2 Chapter 1" "Book 2 Chapter 2" "Book 2 Chapter 3" "Book 2 Chapter 4" ] "Book 3 Title" [ "Book 3 Chapter 1" "Book 3 Chapter 2" "Book 3 Chapter 3" "Book 3 Chapter 4" ] ] LOAD-CHAPTERS: does [ MAIN-CHAP/data: select CHAPTERS MAIN-BOOK/picked show MAIN-CHAP ] LOAD-TEXT: does [ alert rejoin [ "Text loaded for " MAIN-CHAP/picked ] ] view center-face layout [ across banner "Bookmarker" return MAIN-BOOK: text-list 200x500 data (extract CHAPTERS 2) [LOAD-CHAPTERS] MAIN-CHAP: text-list 200x500 [LOAD-TEXT] MAIN-TEXT: area 500x500 return button "Quit" [quit] button "Debug" [halt] ]
posted by: Steven White 27-Nov-2018/13:04:55-8:00
> Carl, Note that Carl does not read this forum (at least, not to my knowledge--he may read it and just not respond, though I'd doubt it). He returned to full-time engineering work, and so further development of Rebol has fallen to others. > I am liking REBOL but sure am spinning my > wheels on what should be simple stuff. Given Carl's absence, Rebol2 has not been developed for many years...and has limited support. So if you're finding bugs in the GUI, they will not be fixed. The Red project does have a GUI, and it is actively developed. They seem to be attending to reported issues. And you'll probably get quicker support on their gitter chat room for any questions: https://gitter.im/red/help https://www.red-lang.org/p/about.html (I have a large set of criticisms of Red at a language level--but they are largely aiming for Rebol2 compatibility. So you're no worse off, in some sense.) You also might try asking questions on StackOverflow; at one point, people were following the rebol/rebol2/red tags and answering GUI questions pretty quickly there: https://stackoverflow.com/questions/tagged/rebol2
posted by: Fork 27-Nov-2018/13:18:38-8:00
Thanks Steven, I will check that out tonight. Thanks Fork for the info on Rebol 2 vs Red.
posted by: Michael Todd 27-Nov-2018/15:57:09-8:00
I keep a little web site of beginner stuff that I find useful. I hesitate to show it off excessively because I don't want to poison the minds of the youth. However, with the above example of using the REBOL syntax to tighten up code, plus another example I obtained some time ago, I made a little article on the topic of speaking REBOL the way she should be spoken. It is here: http://cobolrebol.com/pages/documentation/RefactoringLooseCode.html I hope I haven't said anything I oughtn't.
posted by: Steven White 27-Nov-2018/18:06:33-8:00
Steven and Fork, I have add a zip file containing the Rebol script that started this discussion. It is on one of my Blog pages: http://s355751075.onlinehome.us/rebol-scripting-language/ If you get a change to check it out, let me know. My most pressing problem is while I can reopen the program to the last chosen text, I cannot set the two Text-Lists properly. The user has to repick those item each time. This is what I've accomplished since last Saturday. The script calls slider.r which contains area-scroller and tooltip code.
posted by: Michael Todd 27-Nov-2018/22:33:20-8:00
Fun project. A useful tool for discussing religion at family holiday parties. I hope you did not have to type the entire Bible by hand into a text file. Anyway, I did not read your program in detail but it looks to me like the solution is to load the config.r program, parse book-chapter to get the previous "picked" values from the two text lists, and then set them right before the last line of the program, before "view gui." As I recall, there also is something you have to do when you load text into an area. Where you have "set-face verses txt" I think you also have to codes "verses/line-list: none" for some reason that I can't remember. I ran across it somewhere and did make a note of it here: http://cobolrebol.com/pages/documentation/VIDforCOBOL.html#section-9.19
posted by: Steven White 28-Nov-2018/9:54:19-8:00
Steven, I added the-book/picked: bk right before the first view statement and I had originally created the Chapters text-list as numeric but changed it to string. Between those two changes, the program now comes up with the proper item in each list highlighted. Thanks very much for your help. If you have need of some Windows utilities, check the other apps on my blog as they were all written in AutoHotkey. Mike
posted by: Michael Todd 28-Nov-2018/11:05:40-8:00
|