AltME groups: search
Help · search scripts · search articles · search mailing listresults summary
world | hits |
r4wp | 5907 |
r3wp | 58701 |
total: | 64608 |
results window for this page: [start: 32001 end: 32100]
world-name: r3wp
Group: Rebol School ... Rebol School [web-public] | ||
Geomol: 24-Feb-2009 | I can think of a way to do it, but it isn't easy. I have a feeling, REBOL has a problem with random decimals. | |
Geomol: 24-Feb-2009 | You can build a hex value from an integer with TO-HEX. And you can put that hex value into a decimal using struct! | |
Geomol: 24-Feb-2009 | To get the result between some values, you have to use a factor somewhere. | |
Geomol: 24-Feb-2009 | I'm wondering, if this has come up before? I didn't find a random decimal function in the library (rebol.org). Some of the math guys here may have a better way? | |
Henrik: 24-Feb-2009 | how about randoming a big integer and divide by that integer and multiply with your desired max-value? | |
Geomol: 24-Feb-2009 | Yes, that's an easy way, but I'm afraid rounding will lead to the result not being very random (or a limit in possible outcome). It has to be checked at least. | |
Anton: 24-Feb-2009 | Rebol decimal! is 8 bytes and integer! is only 4 bytes. So you would need to make a struct of 2 integer!, then swap its contents with a struct of 1 decimal! | |
Geomol: 24-Feb-2009 | I used float up there, which is 32 bit afaik. What do I write to make a 64 bit decimal struct? | |
Geomol: 24-Feb-2009 | Anton, are you sure, I don't get a 4 byte float? >> d: make struct! [v [float]] none >> d/v >> type? d/v == decimal! >> length? third d == 4 The length of a decimal is 8. | |
Geomol: 24-Feb-2009 | missed a line: >> d/v == 0.0 | |
Geomol: 24-Feb-2009 | :-) I follow you, when you say, you're no longer sure. This is a little used corner of REBOL (for me at least). I think, we have a problem still. random 2 ** 32 seem to never give results above 2 ** 31. | |
Geomol: 24-Feb-2009 | Never returns: >> until [a: random 2 ** 32 a > (2 ** 31)] | |
Anton: 24-Feb-2009 | That would be a problem, yes. | |
Geomol: 24-Feb-2009 | And since we don't have a 16 bit datatype (or maybe we do with a string or other series somehow!?), we have to make 8 times random 256 (and subtract 1). | |
Anton: 24-Feb-2009 | We can substitute the struct of 2 integer!s with a struct of 8 char. Maybe this is useful: >> random 255.255.255.255.255.255.255.255 == 168.97.60.251.15.20.205.31 | |
Geomol: 24-Feb-2009 | Kib asked a simple question about random and decimals. It seems to be a bit of a hazzle to get what we want, and this should be pointed out to Carl for R3, I think. | |
Geomol: 24-Feb-2009 | Kib, I think, the answer is, that REBOL do a lot and then some more, but there are a few holes. | |
kib2: 24-Feb-2009 | Yes, this one and repeating a string are essential to me. I may find other cases too :) | |
Geomol: 24-Feb-2009 | Kib, there might be a good explanation, why there's no random decimal in REBOL. See: http://stackoverflow.com/questions/439115/random-decimal-in-python It's not a trivial problem. | |
Geomol: 24-Feb-2009 | You asked how to make a random number between e.g. pi and -pi. There are a number of ULPs (Unit in the Last Place) between those two numbers. For 64 bit decimals, it's a large number. The possible decimals in computer arithmetic lie closer together around zero than for large numbers. If you had a routine, that would give you any possible 64 bit decimal number between pi and -pi with equal probability, then you would get a lot more numbers close to zero than close to either pi or -pi. The distribution wouldn't be flat (as you would expect). It's much better to choose, how many different values between pi and -pi, you need, and then make a random integer of that number, and do some calc to get the result between pi and -pi. I hope, it makes sense. | |
kib2: 24-Feb-2009 | I came with this, what do you think of it ? (highly criticable) : random-dec: func[i n /local ent dec] [ "generates a decimal : i digits before, n digits after" ent: to-integer random i dec: to-integer random n return to-decimal rejoin [ent "." dec] ] print random-dec 9999 999999 ; 4 digits before 6 after | |
[unknown: 5]: 24-Feb-2009 | You shouldn't need the return statement. The last value will be returned unless a return is found elsewhere. | |
Janko: 24-Feb-2009 | GEomol, yes I need it for nice output ... this is the function I made: format-int: func [ int ] [ a: to-string int d: tail a loop to-integer ((length? a) - 1) / 3 [ d: back back back d insert d "," ] head d ] | |
Henrik: 24-Feb-2009 | Gabriele once wrote a function for this. I can't remember if it's called pad-decimal or form-decimal. | |
Gregg: 24-Feb-2009 | Yes, there are a number of them out there. | |
PatrickP61: 25-Feb-2009 | Simple Question: I want to assign a specific script name to the word RUN and have it execute it whenever I type it into the console. RUN: do %script.r But upon the assignment, it evaluates the expression and executes it. So I tried it in a block as RUN: [do %script.r] but this returns == [do %script.r] I can do this: IT: %script.r and then type DO IT to perform the script, but I want a way to combine the DO and the IT together. Any ideas? | |
kib2: 25-Feb-2009 | Isn't RUN already a native function ? | |
[unknown: 5]: 25-Feb-2009 | I think it was supposed to be a winexecute type of function. | |
Geomol: 25-Feb-2009 | Try source does and you see, DOES simply makes a function. So instead of using DOES, you could also have written: run: func [] [do %script.r] , but of course DOES is easier and shorter in this case. | |
Geomol: 25-Feb-2009 | I use FUNC, DOES and HAS a lot in my scripts. | |
Geomol: 25-Feb-2009 | A little tutorial on HAS, functions and objects. Let's say, I wanted to make a function with a local variable, that works like a counter, so 1 is added to it every time, I call my function. This doesn't work: >> f: has [a] [a: 0 a: a + 1] >> f == 1 >> f == 1 because a has to be defined (given a value and by that a datatype), before I can use it, and I need to use it, when I add 1. So I can use an object: >> o: make object! [a: 0 f: does [a: a + 1]] >> o/f == 1 >> o/f == 2 But there is a trick to do the same thing with HAS and without making an object: >> f: has [a] [a: [0] a/1: a/1 + 1] >> f == 1 >> f == 2 The thing is, that a is giving a block with zero inside the first time. The second time, I call f, a is just the same block (part of memory), and the value inside isn't touched (it is 1 now), so it works. I can see the block inside my function with: >> source f f: func [/local a][a: [2] a/1: a/1 + 1] and we see, a is a block with 2 inside, because I've called my function 2 times. | |
PatrickP61: 25-Feb-2009 | If you used a: [0], doesn't this assign a zero to the block for a? | |
Geomol: 25-Feb-2009 | a: [0] simply mean, a become this block with zero inside, if a isn't already this block. If a already is this same block, this same part of memory, it has no effect. To always make a block with zero inside, you need to use COPY or REDUCE. | |
Geomol: 25-Feb-2009 | This is only within functions. If you write a: [0] at the console prompt, a become a new block with zero inside (you typed a new block, so it isn't the same, and it kinda makes sense). :-) | |
Geomol: 25-Feb-2009 | abc is seen as a word, and it doens't have a value. <abc> is a tag! datatype, like "abc" is a string datatype: >> type? <abc> == tag! | |
Geomol: 25-Feb-2009 | and it also is a series, like strings are series: >> second <abc> == #"b" | |
kib2: 25-Feb-2009 | Geomol: I wasn't aware there was a tag type ! | |
Geomol: 25-Feb-2009 | I've forgot, what a symbol! datatype is!? | |
kib2: 25-Feb-2009 | s there any 'Challenge' channel for submitting a problem ? | |
PatrickP61: 25-Feb-2009 | Another question: How do you setup Rebol code to be performed when a button is pressed? Lets say I want a VID to show a list of websites to open to, and I set the default to HULU. I have the following to setup the correct url: k-prefix: [http://www.] k-suffix: [.com] txt-site: [hulu] url-site: to-url ajoin [k-prefix txt-site k-suffix] | |
PatrickP61: 25-Feb-2009 | OK, that works when I do a browse url-site | |
PatrickP61: 25-Feb-2009 | But when I put it after a button like this: group [ button "Open" browse url-site <-- this code works only if it is done before the VIEW button "Reset" reset button "Cancel" close | |
PatrickP61: 25-Feb-2009 | I tried to replace the browse url-site with browse to-url ajoin [k-prefix txt-site k-suffix] to no avail. Is there a way to "predefine" the code above the VIEW so that when the button is pressed, it will perform the desired task like button "Open" format-and-browse-site <-- where this has been set to do the url-site assignment and browse funtions? | |
PatrickP61: 25-Feb-2009 | Try this: REBOL [] ; Assignments ------------------------------------ k-prefix: [http://www.] k-suffix: [.com] txt-site: [hulu] url-site: to-url ajoin [k-prefix txt-site k-suffix] ; Main-procedure --------------------------------- load-gui view [ title "WebSite Selector" text "Please choose a website you would like to open" panel 2 [ label "URL:" txt-site: field "Hulu" label "WebSites:" area ] group [ button "Open" browse url-site button "Reset" reset button "Cancel" close ] ] | |
Henrik: 25-Feb-2009 | As I said, you need a DO block (I think you missed that). Then you create a function to create the URL-SITE url. Then you use that as input with BROWSE and that will work. | |
PatrickP61: 25-Feb-2009 | Thanks Henrik, I'll give it a try | |
PatrickP61: 25-Feb-2009 | I get a ***GUI Error: Cannot parse the GUI dialect But if I type browse eval-url-site at the console, it works -- What am I missing? | |
PeterWood: 26-Feb-2009 | To achieve what I think you want you need to make input-file a function!: container: make object! [ infile: none input-file: make function! [] [read join infile ".txt"] ] | |
Geomol: 26-Feb-2009 | Or use DOES again: input-file: does [read join infile ".txt"] When stuff is evaluated can be a bit difficult to figure out. The more you use and learn about REBOL, the more clear it will become. | |
kib2: 26-Feb-2009 | I named my script "ooo.r" and I have a "user.r" file inside that directory too. | |
kib2: 26-Feb-2009 | I'm mising something here : #!/usr/bin/rebol -q REBOL [ Title: "Tests with oo programming" Date: 26-Feb-2009 Author: "Kib" File: "ooo1.r" Purpose: "nothing interesting" ] son: make object! [ parent: none name: "object b" get-parent: does [print parent] ] mother: make object! [ name: "object a" son-instance: make son [parent: self] ] pony-mum: make mother [] print ["object name: " pony-mum/name] print ["instance name: " pony-mum/son-instance/name] print ["instance name:(other method) " pony-mum/son-instance/get-parent] What's wrong with the last call ? | |
kib2: 26-Feb-2009 | Graham : as i'm inside mother, self refers to a mother no ? | |
Graham: 26-Feb-2009 | mother: make object! [ name: "object a" myparent: self son-instance: make son [ parent: myparent ]] | |
kib2: 26-Feb-2009 | >>it looks like you're inside son-instance I don't understand why, sorry. I'm inside mother (I mean, when I write it "son-instance", but maybe it's a bad Python habit). mother: make object! [ name: "object a" son-instance: make son [parent: self] ] | |
Graham: 26-Feb-2009 | you're creating a new object son-instance so self now refers to son-instance | |
kib2: 26-Feb-2009 | Is there any lib somewhere to encode or decode a file to utf-8 ? | |
kib2: 27-Feb-2009 | Anton: hi! thanks a lot: what's the meaning of the parenthesis here ? | |
Anton: 27-Feb-2009 | So SELF will be evaluated before the second CONTEXT has a chance to see it. | |
Anton: 27-Feb-2009 | But, if you're curious, you can always have a look yourself, using PROBE, eg: mother: context [son: context compose probe [parent: (self)]] mother: context [son: context probe compose [parent: (self)]] | |
kib2: 2-Mar-2009 | Is it possible to draw something (lines, arrows, curves, etc) on top of buttons in a GUI app ? | |
kib2: 2-Mar-2009 | Geomol: yes with the mouse; in fact if you click on a number, i should draw all possible bridges (lines) coming from it. | |
kib2: 2-Mar-2009 | Ok, thanks for the hints : I think I have to study VID events a little more than what I've already done. | |
PatrickP61: 2-Mar-2009 | I have a question on same? Do the following: a: "apple" b: to-string 'apple same? a b == false Why is that, they are both strings of the same length and datatype, just not created in the same way? | |
kib2: 2-Mar-2009 | Good question : i really don't know. Moreover, a == b returns true. | |
PatrickP61: 2-Mar-2009 | I tried this too: a: "apple" b: "apple same? a b == false Does same? mean that it is the same object, not that the contents are the same? | |
kib2: 2-Mar-2009 | Henrik: do you mean their location (via a pointer) ? | |
Henrik: 2-Mar-2009 | >> a: "boo" == "boo" >> b: reduce [a copy a] == ["boo" "boo"] >> same? b/1 a == true >> same? b/2 a == false | |
kib2: 2-Mar-2009 | ok, it's clearer now. But how do you explain this ? a: "apple" b: to-string a same? a b ; --> returns false Does that mean that to-string makes just a copy of a, and so does not point to the same location ? | |
PatrickP61: 2-Mar-2009 | This link seems a little confusing to me http://www.rebol.com/r3/docs/functions/same-q.html At first, it seems like it is comparing the values of two objects, but if you read further, it says they must reference the same objectS | |
Henrik: 2-Mar-2009 | AS-STRING is useful to represent a binary as a string. There is a similar AS-BINARY function for converting strings to binaries. | |
kib2: 4-Mar-2009 | Hi, is there any REBOL version running on a PocketPC 2002 version ? | |
BrianH: 4-Mar-2009 | Core 2.5.0.15.5 for WinCE 2.0 Handheld PC works on PocketPC 2002, but is not onscreen-keyboard aware - the onscreen keyboard obscures the command line, so you better have a builtin or bluetooth keyboard, or perfect typing. As with all R2 WinCE releases, there is no support for the clipboard, program command line, file associations, or background operation. This makes it almost unusable, even on a machine with a hardware keyboard. I was the one who requested the build, and there hasn't been a WinCE build since. | |
BrianH: 4-Mar-2009 | Wait for R3 - the layout model should be flexible enough that you can provide a completely different UI layout for mobile use. | |
BrianH: 4-Mar-2009 | You couldn't extend the memory of a HP Journada 820 with sticks, or at all. You could extend the storage, but not the working RAM. | |
kib2: 4-Mar-2009 | Yes, same for me here with a Packard Bell. But I suspect R3 won't run on these obsolete plateforms. | |
kib2: 4-Mar-2009 | I took the contents from a REBOL tutorial I've found "REBOL Essentials". Now, I think it could be better, ie there's nothing on arguments. | |
Henrik: 5-Mar-2009 | ? native! is a good one. | |
Henrik: 5-Mar-2009 | since you have created the sheet manually (if I'm correct), I would create a block with the words in the sheet in the order as shown on the sheet and then do something like: foreach word words [ print [word type? get word] ] | |
kib2: 5-Mar-2009 | Yes, that's a better way I think | |
Henrik: 5-Mar-2009 | that simplifies things a bit | |
kib2: 5-Mar-2009 | hum... I've made some rules in my OO calc sheet to set some styles (ie color a line on two), and if I had native/mezzanines it will break all. I've to find an issue.: maybe add a column for that. | |
Henrik: 5-Mar-2009 | Actually there are also action! types, which are related to natives. Perhaps one-letter identification in a separate column: N = Native, A = Action, F = Function, M = Modifies Input, etc. | |
Henrik: 5-Mar-2009 | it's probably a good idea to keep separate sheets for R2 and R3, since some functions have moved from mezzanine to native and vice versa in R3. | |
Geomol: 5-Mar-2009 | I'm wondering, if it's important for a newbie to the language to distinguish between natives, actions and functions. Wouldn't it just confure more? | |
kib2: 5-Mar-2009 | CheatSheet Updated to v1.2 . Geomol: that makes sense to me, but sure that may be confusing. But it's not a problem on this sheet, just don't take the second column into account. | |
kib2: 5-Mar-2009 | Is it possible to draw something inside an over function (in a GUI app) ? | |
Geomol: 5-Mar-2009 | view layout [box 400x400 effect [draw [line]] feel [engage: func [f a e] [if a = 'over [append f/effect/draw e/offset show f]]]] Try paint with the mouse. | |
Geomol: 5-Mar-2009 | Ups, was that a one-line paint program? ;-P | |
Geomol: 5-Mar-2009 | There's a lot of REBOL One-liners here, you might find amusing: http://www.rebol.com/oneliners.html | |
kib2: 5-Mar-2009 | Geomol: thanks, that will be a lot more complicated for my case. | |
kib2: 5-Mar-2009 | that does not work...even the print message does not appear. An idea ? monlayout: [ origin 0x0 space 0x0 across ; --- define a new button (style) style p image %vide.png style node image %but.png effect [draw [line]] feel [ engage: func [f a e /local x y island] [ if a = 'over [ print "over" x: round/down e/x / 40 + 1 y: round/down e/y / 40 + 1 island: game/:x/:y if island/ways <> none [ foreach v island/ways [ append f/effect/draw to-pair [x y] to-pair [v/x v/y] show f ] ] ] ] ] ] | |
Geomol: 5-Mar-2009 | The effect isn't attached to a style. You have style definitions, and then effect. | |
Geomol: 5-Mar-2009 | yes, but it's just a definition. Where is your buttons? :-) | |
Geomol: 5-Mar-2009 | This works here: myl: [style node image logo.gif effect [draw [line]] feel [engage: func [f a e] [if a = 'over [append f/effect/draw e/offset show f]]]] append myl [node "my node"] view layout myl | |
Geomol: 5-Mar-2009 | You have a simple bug somewhere, I guess. :-) | |
PatrickP61: 6-Mar-2009 | Quest to all: What is the easiest / best way to convert a file path to a dir path? Example FILE-PATH: request-file ; assigns a specific file path == %/C/Documents and Settings/Owner/filename.txt How can I assign a variable like FILE-DIR: to become the directory of FILE-PATH i.e. %/C/Documents and Settings/Owner/ Ideas? | |
kib2: 7-Mar-2009 | Geomol: sorry for the delay, it was lunch time for me. It's the first langage where i see no operator priority (maybe with Lisp, but it's because of its notation). Thanks, and that may explain why I wasn't able to draw something correctly in a GUI app. | |
BrianH: 7-Mar-2009 | Having only a single level of operator precedence was done to make it faster to program in REBOL. It makes it easier to remember the precedence rules when reading or writing REBOL, something that anyone with experience in most programming languages can tell you is tricky at times. Having fewer language rules to remember makes the language less distracting from the programming process. Though it is also faster to run, as it makes DO simpler (and even moreso in R3). | |
kib2: 8-Mar-2009 | BrianH: this seems a right approach to me, it makes sense. | |
PatrickP61: 10-Mar-2009 | Question to all How can I get the results of a PRINT to load into a block? ie File-list-blk: LIST-DIR |
32001 / 64608 | 1 | 2 | 3 | 4 | 5 | ... | 319 | 320 | [321] | 322 | 323 | ... | 643 | 644 | 645 | 646 | 647 |