World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
BrianH 4-Jun-2007 [526] | Why did I join the community? Because when I joined, REBOL was still pretty new. R2 wasn't there yet - the first alphas for it came a few months after I started playing with the language. Most of the low-level behavior of the language was completely undocumented outside of RT, and they were still trying to position the language as easy to use, easy to learn, high level. It still looked like R1 - Scheme with a different syntax - but it was different. A challenge. So I dug in. I tested every function, everything I could find out. I asked a lot of questions on the mailing list. If they weren't answered, I dug in further and figured it out myself. And I got into a lot of really interesting arguments with the people on the list, testing and probing the language until all of the undocumented stuff became clear. Those early arguments became the low-level documentation of REBOL. And then came the books, and the community got bigger. I started using REBOL at work, even when it wasn't the language I was supposed to be using - code is easier to generate with REBOL than it is to write directly in other languages. More fun too. That's the hook: REBOL is fun. There is a principle I read in a Heinlein essay years ago: The principle of Creative Laziness. He wrote about the guy who invented the automatic pilot, back in World War 2, because piloting back then was a big hassle and he was too lazy to do it. Instead of doing the drudge work he did the more interesting task of figuring out how to automate it. If necessity is the mother of invention, then laziness is its father. Laziness is a virtue. That's what dialecting is all about: Automating the drudge work and wrapping it in a nice little language because it's more fun than doing it manually. More efficient too, a lot of the time. Do you know who REBOL appeals to the most? Engineers, scientists, hackers, analysts, problem solvers. People with opinions, people with enough of a twisted sense of humor, of the world, that they don't want to just sit still and accept the way that they are told the world is - they want to figure it out and remake it if necessary. Interesting people: REBOL's other hook. Welcome to the cool kids' table! |
Maxim 7-Jun-2007 [527] | Brian, you preach the same thing I do... be lazy. its fun and much more productive. |
Will 8-Jun-2007 [528x2] | HELLO, do you have a simple solution, I'd like 'z to stay 10, eg it should be a local in the function z: 10 a: func ['word body][ foreach row [1 2 3][ set word row reduce body ] ] a z [print z] print z |
this works but not in case of path: reduce replace body word 'row is it a bindology or parse job? | |
Gregg 8-Jun-2007 [530] | Look at the source for FOR. If that technique works for you, it will lead you to something like this: z: 10 a: func ['word body /local do-body] [ do-body: func reduce [[throw] word] body foreach row [1 2 3] [do-body row] ] a z [print z] print z |
Will 8-Jun-2007 [531x2] | works! thank you Gregg! ...tryed to look at 'foreach which is native! 8-) |
now the [throw] is just in case there is a catch in body, right? | |
Gabriele 8-Jun-2007 [533] | throw re-throws any return in the body |
Will 8-Jun-2007 [534] | ok thanks! |
Will 14-Jun-2007 [535] | can anybody explain me this please: http://reboot.ch/why.png thank you! |
Maxim 14-Jun-2007 [536x4] | rebol blocks have new-line control after each item in the block. depending on the function being used, these will be lost, kept or generated on the fly. usually anything which goes thru a string type will loose any previous new-line setup. and only ONE new-line can be kept per item. the 'NEW-LINE is the function to control this, if you really need to (its usefull for files in my mileage so far): help new-line |
(for files... what I mean is to control the look of rebol block values when it is dumped into files) | |
note the /skip refinement is indexed starting at 0 (meaning don't skip any items, new-line everyone of them) | |
does this help you? | |
Will 14-Jun-2007 [540] | Perfect! thank you Maxim 8-) |
Maxim 14-Jun-2007 [541] | its fun to have easy questions some times (note: easy is not synonymous to obvious ;-) |
Will 14-Jun-2007 [542] | well, I've spent almost an hour trying to figure out.. next time I'll go stright to the dictionary! |
Maxim 14-Jun-2007 [543x3] | some functions are not names the same as in CS so even that sometimes leads you away from what you'd expect.... in this case the dash in the name prevented me from finding it in google for hours. |
names = named | |
and I knew it existed! | |
Geomol 14-Jun-2007 [546] | It sometimes help to find the right REBOL words by calling help with part of the word. Like: >> ? line >> ? new |
Luis 14-Jul-2007 [547] | . |
PatrickP61 17-Jul-2007 [548] | What is the best way to get an formatted timestamp that matches IBM DB2 in this form: ccyy-mm-dd-hh:mm:ss.nnnnnn I tried this, but I'm stuck on how to extract out the nanoseconds from Now/precise: Timestamp: rejoin [ now/year "-" now/month "-" now/day "-" now/time ".000000" ] Also, if the month or day is less than 2 digits, I need a leading zero -- how can I do this easily? |
Sunanda 17-Jul-2007 [549x2] | To get the seconds: third now/time/precise Use first, second, to get HH MM. Not sure it is nano-second precise! |
This adds leading zeroes to MM or DD -- you could use similar logic: http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=to-iso-8601-date.r | |
Henrik 17-Jul-2007 [551] | precision depends on the OS used, but millisecond precision is displayed always, AFAIK. |
PatrickP61 17-Jul-2007 [552] | I got the following when I did this: rejoin [now/year "-" now/month "-" now/day "-" now/time "." third now/time/precise "000" ] 2007-7-17-13:40:36.36.748000 which is pretty close, except the seconds are repeated again. |
Sunanda 17-Jul-2007 [553] | Try this: rejoin [now/year "-" now/month "-" now/day "-" first now/time "." second now/time "." thir d now/time/precise "000" ] But you may need to add some more trailing zeroes.... a time of 01:02:03.100 would show in REBOL as 1:2:3.1 |
PatrickP61 17-Jul-2007 [554] | That seems to work -- except for adding leading zeroes which can be done via above script -- Thanks Sunanda |
Gregg 17-Jul-2007 [555] | I have a format func that isn't on REBOL.org (yeah, I know...; it requires another func, etc.) if you have to do a lot of formats and don't want to roll them all. Anyway, let me know if you want me to send it Patrick. |
PatrickP61 17-Jul-2007 [556x2] | Sure -- Why not -- I'm learning more and more all the time |
OK -- I'm perplexed as to when does things get evaluated. If I have a variable like Now-TS: to get the formatted time, it will be resolved immediately and return the time. If later, after I wait 1 second, I want to print the new formatted timestamp, it returns the exact same value as before, when I know the time has acutally changed. How do I get the time now to be resolved again? Example code: print now/precise gives 17-Jul-2007/14:35:21.308-5:00 wait 1 print now/precise gives 17-Jul-2007/14:35:22.324-5:00 now/precise is evaluated immediately Now-timestamp: rejoin [ Now/year "-" Now/month "-" Now/day "-" first Now/time "." second Now/time "." third Now/time "000" ] print Now-timestamp gives 2007-7-17-14.35.22.0000 wait 1 print Now-timestamp gives 2007-7-17-14.35.22.0000 the exact same time -- not evaluated immediately Is it this way because Now-timestamp has been assigned and already evaluated -- if so, how do I have it reevaluate it again? | |
BrianH 17-Jul-2007 [558] | Wrap it in a function. now-timestamp: does [rejoin [...]] |
PatrickP61 17-Jul-2007 [559x2] | Ok, so if a variable is unset, then it is evaluated when defined. If it is already defined, then it is not evaluated again unless there is a do or does? Is that right? |
Super -- that worked just great | |
BrianH 17-Jul-2007 [561x4] | DOES is a shortcut for creating a function, DO evaluates its value directly. A variable is not evaluated when assigned - the value is, and then it is assigned to the variable. You don't really "define" variables in REBOL, but the distinction may be more complicated than you need to worry about for now. |
You might consider that the time will march on during the course of your evaluation, so you might want to store it in a local variable, like this: pad0: func [x n [integer!]] [head insert/dup (x: form :x) "0" (n - length? x)] now-timestamp: func [/local n] [n: now/precise rejoin [ pad0 n/1 4 "-" pad0 n/2 2 "-" pad0 n/3 2 "-" pad0 n/4 11 "000" ]] | |
Sorry, that won't work in some cases. Try this instead: now-timestamp: func [/local n s] [ n: now/precise s: n/4/3 s: join either s < 10 ["0"] [""] s: head insert/dup tail s "0" 9 - length? s rejoin [ pad0 n/1 4 "-" pad0 n/2 2 "-" pad0 n/3 2 "-" pad0 n/4/1 2 ":" pad0 n/4/2 2 ":" s ] ] | |
missing an s :( s: join either s < 10 ["0"] [""] s | |
PatrickP61 17-Jul-2007 [565x3] | Thanks Brian. I will play around with it a little more. Just to re-iterate my understanding of rebol assignments A variable is not evaluated when assigned - the value is, and then it is assigned to the variable. You don't really define" variables in REBOL" So at the time of assignment, the text following the : is assigned to the variable but is not evaluated. That is to say the variable is like a pointer to the text string that was typed in. Does that mean that Rebol will not do evaluations until it needs to. For example: In-file: %file_path_name.txt In-text: Read In-file write %out-file-path-name.txt In-text <-- this is where the evaluation occurs to resolve all the above? Is that right? |
Another similar example: In-file: %file_path_name.txt In-text: Read In-file append In-text 'this-is-the-end-of-the-file <-- evaluated because of action word append write %out-file-path-name.txt In-text | |
is that right? | |
BrianH 17-Jul-2007 [568x4] | That's not what I meant. I meant that the expression to the right of the set-word (s:) is evaluated. The result of that evaluation is the value that will be assigned to the word. So, you were right the first time about the evaluation order. |
The word itself is not evaluated though, it is just assigned. The value that the word was assigned is returned from the assignment expression too, so that you can chain assignments or use the value later, like I did in pad0 above. | |
Later on you can either do a full evaluation of the word by stating it directly ( a ) or you can just retrieve its value by using a get-word ( :a ). | |
REBOL variables don't really need to be declared, as such, but you do need to declare function parameters and object fields. Some of the REBOL language look like they are declaring variables, but they really are doing something different. | |
PatrickP61 18-Jul-2007 [572] | Thanks for your patience with me. I'm wrong about the evaluation. It is done at the time of the assignment returing whatever value to the variable. The reason Now-timestamp had identical values, even after waiting 1 second was that it was evaluated once, with a value put into it, then the wait happened, then I simply re-printed the same value as before, because I did not re-do the variable. I think I was making it harder than it really is. I don't understand this statment: Later on you can either do a full evaluation of the word by stating it directly ( a ) or you can just retrieve its value by using a get-word ( :a ) Are you saying that I can simply type Now-timestamp to have it re-evaluated at that time? |
btiffin 18-Jul-2007 [573x3] | Umm, not quite. You're getting into it now. :) Sometimes it helps to think of it this way (but it is actually 'deeper') myprint: print won't work, it tries to evaluate print, but myprint: :print "gets" the value of print and then you can myprint [1 2 3] - again it's deeper than what I just explained. |
a: 23 * 56 when interpreted will compute 23 * 56 then the set-word a: assigns the value 1288 to the variable a. Because it is just a number a and :a are both 1288, you can't really get at the 23 * 56 anymore, that expression has been evaluated and "forgotten", forgotten not really a good word, but the expression 23 * 56 is not around anymore, only the 1288. | |
Patrick; I just looked back a little bit, your question about formatted time-stamps...Chris has donated an awesome date time formatter to the rebol.org repository. Very close to strftime in function. Check out http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=form-date.r | |
older newer | first last |