World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Henrik 22-Apr-2009 [1859x2] | with that line, you need to know about SHOW and HIDE. If you set b/text like that, you need to do a: show b afterwards, or the face won't update. |
HIDE just hides the face (I guess it's not really necessary to know for the above, but there it is). | |
mhinson 22-Apr-2009 [1861] | Thanks, I will try to make myself an example to understand that further. I have another small stumbling block here that I would appreciate some wisdom on please.. ; This works view layout [a1: area (to-pair rejoin ["80x" random 100]) button "ok" [print a1/size]] ; but not this view layout [ box effect [ draw [ line 20x20 (to-pair rejoin ["80x" random 100])]] ] Is this because the dialect is different in one place to the other? I was heading towards using a slider to manipulate stuff on the screen, so this is a first step towards that. |
Henrik 22-Apr-2009 [1862] | I'm not sure, but the draw block should be composed. If you are only calculating the random position once per view, you can COMPOSE/DEEP the layout block or: pos: as-pair 80 random 100 view layout [box effect [draw [line 20x20 pos]]] (untested) |
Anton 22-Apr-2009 [1863] | view layout [ box effect compose/deep [ draw [ line 20x20 (as-pair 80 random 100) ] ] ] |
mhinson 22-Apr-2009 [1864] | Yes, that works a treat, I suppose I could have found that from the documentation within a week. Now I will change the random for a slider. Then I will try to make it show the line every time it moves position. (don't tell me the answer yet please, I only learn when my brain is a bit overheated). Would it be fair to say that Rebol is a linguist's language in that there are a lot of words, phrases & idioms to learn, rather than a smaller number of concepts that apply to everything but in a cryptic way? |
Sunanda 22-Apr-2009 [1865] | I think it's fair to say that VID and VIEW are built on top of the REBOL Core. They are not intimately part of REBOL itself, and may not always have had the same care lavished on them as the core of the language. So they tend to be a bit messier and fragmented. More of a work in progress than an attempt at the state of the art. |
Henrik 22-Apr-2009 [1866x3] | remember that you can have a very different syntax in dialects, so if you are not separating dialects from rebol code, you will be confused, because of seemingly conflicting syntax. |
in fact you may be confused also by the fact that DRAW is an entirely separate dialect from VID. | |
but IMHO, it's not as bad as having to combine HTML/JS/SQL/PHP/CSS in a 20 line code block. | |
mhinson 22-Apr-2009 [1869] | I can't remember being so excited about learning a new thing for ages. It is a great privilege to have access to such well informed teachers as yourselves. I feel like I have stumbled into first class helicopter travel when I only paid for a slow bus. |
[unknown: 5] 22-Apr-2009 [1870] | Nice to see your excitement mhinson. I think here in this REBOL3 world you will find all the expertise you need to master REBOL. |
mhinson 22-Apr-2009 [1871] | Well, I modified the code from draw-controls.r in the script library to get this. It is more complex than I expected, Is it a reasonable way to do this sort of thing please? pos1: 20x20 pos2: 80x0 view layout [ scrn: box rate 0:0:0.1 feel [ engage: func [face action event] [ if action = 'time [ scrn/effect/draw: copy [] append scrn/effect/draw [line pos1 pos2] show scrn ] ] ] effect [ draw [] ] s1: slider [ ss1: to-integer (100 * get-face s1) pos2: (as-pair 80 ss1) ] ] Next step is to work out how to make the thing that moves leave a trail. |
Anton 22-Apr-2009 [1872x4] | view layout [box: box effect [draw [line 20x20 80x20]] slider [box/effect/draw/3/y: to-integer value * 60 + 20 show box]] |
To leave a trail, you could append to the draw block (without setting it to a new block each time, as you've done above), but that would mean your draw block would get very big over time. So a better thing to do is to draw onto an image!, which serves as a cache of your previous draw commands. For this, you can use an IMAGE instead of a BOX, and use the DRAW function to draw permanently onto the image. (The IMAGE style is very similar to BOX, but its 'image facet is set to an image! for us, ready to use.) | |
Oops! No it doesn't ! IMAGE does *not* come initialize its 'image facet with an image! for us! We need to create one for it... | |
view layout [my-image: image (make image! 100x100) slider [draw my-image/image reduce ['line 20x20 as-pair 80 value * 60 + 20] show my-image]] | |
Anton 23-Apr-2009 [1876x3] | Another way to write that is: |
img: make image! 100x100 draw-blk: [line 20x20 80x20] view layout [my-image: image (img) slider [draw-blk/3/y: value * 60 + 20 draw img draw-blk show my-image]] | |
The difference being we are using another word (IMG) to reference the image!, and the draw block (DRAW-BLK) is not created new each time, it is reused. Only the third value in the draw block is modified. That could become significant with large draw blocks. | |
mhinson 23-Apr-2009 [1879] | Thanks Anton, that looks a lot simpler. It is going to take me a while to digest your suggestions fully. I want to understand it well enough to appreciate exactly how this works & where I can read the code to deduce locations of thing like box/effect/draw/3/y for myself. I have been hunting through the documentation but there is such a lot of it that I may have failed to look in the right place. Thanks. |
Anton 23-Apr-2009 [1880x2] | I advise you to review each facet in the face object: print mold first system/standard/face and compare with the slightly larger vid-face: print mold first system/view/vid/vid-face (Note, here FIRST is being used to return just the words of an object!, without their values. If you just probe a face it will fill up your console...) |
Once you find a specific facet you are interested in, you can then probe it to see its value: print mold get in face 'color ; == 200.200.200 and you can do this, of course, with any face you make, such as the BOX above. | |
mhinson 23-Apr-2009 [1882] | Thanks for the extra information. I am slowly piecing it all together. |
mhinson 28-Apr-2009 [1883] | Hi, I have continued to re-read the documentation for REBOL, and appreciating it more as I understand a bit more. Are there any puzzels I could try to write a solution to, in REBOL, that would be good for a beginner please? |
Brock 28-Apr-2009 [1884] | There is a puzzles group, and the corresponding puzzles answers group. However, I don't believe the puzzles are easy. |
mhinson 28-Apr-2009 [1885] | It is hard for me to judge how hard a puzzle might be. I have some ideas of what I want to program for my self, but I get stuck too quick, so I need to exercise my understanding in a context where I can have a good chance of success. |
ChristianE 28-Apr-2009 [1886] | Definitely these puzzles aren't for beginners. But have you already had a look at the cookbook at http://www.rebol.net/cookbook? That might be a good start trying to understand some of the examples there and go on from there ... |
Anton 28-Apr-2009 [1887x2] | Here's how you can get a cross-section of all the VID styles, examining the same facet (TEXT) for all of them: foreach [style face] svv/vid-styles [print [style mold face/text]] As you can see, only a few have TEXT set by default. |
(mhinson, that's for you.) | |
Sunanda 29-Apr-2009 [1889x2] | Here's a puzzle I posed (because I wanted a better answer). The ensuing discussion is excellent: http://www.rebol.org/ml-display-thread.r?m=rmlCHQQ |
And here's another one. In both cases, there were excellent procedural solutions and parse-based solutions. In both cases, the parse-based solutions were much faster: http://www.rebol.org/ml-display-thread.r?m=rmlPCJC | |
mhinson 29-Apr-2009 [1891] | Thanks Sunanda. I will have a go at it without reading any suggestions, then learn what I did wrong :-) If I am not back in a week, send a search party. |
Sunanda 29-Apr-2009 [1892x2] | That's kind of what I did.....First had the operational problem; then solved it with a procedural hack; then asked the experts to impress me. They did! |
Good luck | |
mhinson 29-Apr-2009 [1894] | I have a plan, but I am stuck before that as I can't work out how to reference the value of a variable in a block. aa: 1 bb: 2 cc: [aa bb] print first cc I want it to print 1, but however I arange the brackets I can work out how to do it.. I know this is very basic, sorry. |
Henrik 29-Apr-2009 [1895] | You can do one of two things: aa: 1 bb: 2 cc: reduce [aa bb] print first cc aa: 1 bb: 2 cc: [aa bb] print get first cc |
Maxim 29-Apr-2009 [1896x4] | the get function evaluates a word and returns its value, the reduce function evaluates a block and leaves all the results within the block |
(to complement henrik's example) | |
in rebol, words are both litteral values and references to values. a word can also be unbound, in which case it essentially refers to no value. and dont kid yourself, this isn't as basic as you'd think :-) I still get bit, even fater years of rebol experience :-) | |
oops fater=after... darn I'm really infected by the reichart keyboard syndrome ;-) | |
mhinson 29-Apr-2009 [1900x2] | Thanks, that has bought me back to the position that there is an outside chance I can solve this. What was getting me was that sometimes print reduce cc/1 would return an interger & sometimes a word & I couldn't work out why. storing the integers in the block as suggested cc: reduce [aa bb] makes it work right through my code. :-) Thanks. |
This is my first crack at it... blob: [1 23 25 26 27 26 24 2 13 56 57 58 59 34 23 7] score: copy 0 top-score: copy [0 0] repeat i (length? blob) [if/else ((blob/(i) + 1) = (blob/(i + 1))) [ score: score + 1 if (score > top-score/1) [ top-score: reduce [score i]] ][ score: 0 ] ] probe top-score print rejoin [(blob/((top-score/2) + 1 ) - (top-score/1)) "--" blob/((top-score/2) + 1 )] Reading on I see it being solved with parse.. I will try to understand that now if I can... I also realise my solution would be better if the repeat loop was 1 less than length. However running over the length seems to have no bad consequence in this case. Thanks for the chalange & help. | |
Sunanda 29-Apr-2009 [1902] | It works, and it is more compact than my original -- so lots of bonus points there. It's worth reading on to look at some of the other procedural solutions, and Joel's analysis. That'll give you some good tips on how to solve a problem like this using REBOL's data manipulating tools. The parse solutions then take it to another level :-) |
mhinson 29-Apr-2009 [1903] | I still dont feel up to the parse version of the first puzzel, so I have had a go at the first part of the second puzzel. I think I am a bit confused about where to use var: 0 var: copy 0 I have also got a bit mixed up with the use of global variables which I know is bad. This is the code, which now dosnt seem to work since I put the variable initalisation inside the compress function, and tried to pass the variables to the function.. Dont laugh, but this is about 3 hours work. raw-data: [1 2 3 10 11 99 101 2000 2001 2002 2003 2004] sequence-break: func [count store result][ if/else (count > 1) [ append result to-pair rejoin [store "x" count] count: 1 ][ append result store ] ] compress: func [raw-data][count: 1 store: reduce raw-data/1 result: [] repeat i ((length? raw-data) - 1) [ if/else ((raw-data/(i) + 1) = (raw-data/(i + 1))) [ count: count + 1 ][ sequence-break count store result store: reduce raw-data/(i + 1) ] ] sequence-break count store result ] probe compress raw-data I am happy if my code is functional & easy to maintain at the moment. I will never be an application developer but using small bits of code to increase personal productivity is IMHO a very worthwhile thing to try and do. |
Maxim 29-Apr-2009 [1904x4] | I'll just note that you should use either instead of if/else ... the later is deprecated and slower |
so it would be: either (count > 1) [ | |
you'd use var: 0 since 0 (an integer!) is not a series type of data. | |
I don't have the time right now to debug the whole of it though... ':-/ | |
mhinson 29-Apr-2009 [1908] | Thanks for the tips, so either exactly replaces if/else and I need to initalise series types with var: copy [] but not other types. These tips are great.. I just need to study it more & I shoud find my own bugs (and probably remember them too) Thanks very much |
older newer | first last |