World: r3wp
[Core] Discuss core issues
older newer | first last |
Dirk 21-Dec-2006 [6532] | woot! thx |
Maxim 21-Dec-2006 [6533] | glad I can help :-) |
Dirk 21-Dec-2006 [6534] | should have read strings, not blocks in the reference .... Thanx for you help Maxim. Have to drive home now ... |
Anton 26-Dec-2006 [6535] | Dirk, check out compose/ONLY, eg: >> blk: [1 2 3] compose/only [hello (blk)] == [hello [1 2 3]] |
Anton 28-Dec-2006 [6536x2] | I want to speed up access to a block of objects (unassociated) for a search algorithm. Should I use LIST! or HASH! ? It's a growing list of visited objects, and I'm searching it each time to see if the currently visited object has already been visited. |
It looks like I should use HASH!, as it is designed to make lookup faster. LIST! is designed for faster modifications. | |
Henrik 28-Dec-2006 [6538] | I wonder what the conversion time is between BLOCK!, LIST! and HASH! there must be some kind of penalty there. |
Tomc 29-Dec-2006 [6539] | perhaps the objects could just contain a visited field |
Anton 29-Dec-2006 [6540] | No, I'm searching the system object; I can't modify the objects. |
Tomc 29-Dec-2006 [6541x2] | ah |
what are you keying off of? | |
Anton 29-Dec-2006 [6543] | Search term is a word, but I want to support strings as well. |
Gregg 29-Dec-2006 [6544] | If lookup speed is primary, use hash!, if you're doing a lot of inserts and removes, use list! There is overhead to has items for lookup, but the speedup is enormous on lookups.. |
Maxim 29-Dec-2006 [6545] | also remmember that lists are at their tails after inserts and append... this is usefull, but quite frustrating to discover when you don't know about it. |
Anton 29-Dec-2006 [6546x2] | A quick test looks like using a hash didn't help in my case, the major work must be somewhere else. |
Yes, I am aware of the index position confusion with list!. | |
Geomol 31-Dec-2006 [6548] | Is it possible to turn off: ** Math Error: Math or number overflow ? My gcc compiler here warn me of integer overflow, but I can run the C program, and bits are lost. But that can be ok in some cases, for example to calculate noise. I'm wondering, if I can do that in a fast way with REBOL. Example: 46341 * 46341 will produce an integer overflow. I just want the result with the high order bits lost. |
Robert 31-Dec-2006 [6549] | Good question. I would like to avoid this error as well. A overflow would be OK in most cases. |
Sunanda 31-Dec-2006 [6550] | Youd could bypass it with something like: (1. * 46341 * 46341) // (2 ** 31) |
Robert 31-Dec-2006 [6551x2] | How do you do this when you have a lot of claculation that use user input? |
The user could input very large numbers. | |
Sunanda 31-Dec-2006 [6553] | Not sure -- and of course it probably doesn't meet Geomol's request for a "fast way" |
Gabriele 1-Jan-2007 [6554x2] | >> 46341 * 46341 ** Math Error: Math or number overflow ** Near: 46341 * 46341 >> 46341x1 * 46341x1 == -2147479015x1 |
("hidden feature" of pairs, used by nenad in is mysql protocol handler :) | |
Geomol 1-Jan-2007 [6556] | LOL Wow! That's nice, Gabriele! Also a fine solution, Sunanda! That might be one of the fastest way to do it. Maybe I'll just use RANDOM in my noise generating routine, but if that's not good enough, I'll probably use one of these suggestions. |
Robert 1-Jan-2007 [6557] | Cool. This trick could be used to implement intervall arithmetic. Using a PAIR to store the upper/lower bound of ranges. Than we only need special operator implementations for * / to handle all cases. |
Geomol 1-Jan-2007 [6558] | I was trying to implement this function in REBOL: function IntNoise(32-bit integer: x) x = (x<<13) ^ x; return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0); end IntNoise function Using pair didn't do the job, I guess because of truncating along the way. Sunanda's method works. |
Robert 1-Jan-2007 [6559x2] | Question: I have a block that represents several records (fixed size number of fields). Now I need to extend each record by one column. Inserting a new entry every X entries in the block. IIRC there is a special function to deal with fixed size blocks for such thing. Like remove-each but more generic. |
the simplest way I come up is: FORSKIP series record-size [ APPEND result COPY/PART series APPEND result new-value ] But this copies the series. Is there a nice inplace extension solution? | |
Volker 1-Jan-2007 [6561x2] | parse series[any[ record-size skip p: (p: insert p new-value) :p ]] but that shifts a lot. would use insert clear series result and for speed there is insert/part to avoid all the small temp blocks. |
something inbuild not. | |
Gregg 1-Jan-2007 [6563] | I have a DELIMIT function that will do it, changing the series in place, with the exception of the trailing element. So the final result would look like this: append delimit/skip series new-value record-size new-value The basic idea you want is this: series: skip series size series: head forskip series size + 1 [insert/only series value] My DELIMIT func also works with list! and any-string! types correctly, which simple code above doesn't account for (the +1 part is simplified). |
Geomol 3-Jan-2007 [6564x2] | To move a file, one solution is: write/binary <destination> read/binary <origin> delete <origin> If you leave out the delete, you've got a copying file routine. |
To copy large files, Carl gave some ideas in this blog: http://www.rebol.net/article/0281.html | |
CharlesS 3-Jan-2007 [6566] | Cool thanks |
BrianH 3-Jan-2007 [6567] | If you just need to move a file within the same hard drive, there may be some tricks with renaming or calling external commands that will likely be faster. Be sure to check those out too. |
Anton 9-Jan-2007 [6568] | Given some data which I might load from a file: data: [ [code description] ["CC" "Crazy Cuts"] ["DD" "Dreadful Dingo"] ] I can process it this way: format: data/1 ; get the format block, which is known to be first use format [ foreach blk next data [ ; skip over the format block set format blk if code = "CC" [print description] ] ] with the disadvantage that I set a word ('FORMAT). I could put that in another USE context but then I would have yet another level of nesting in the code. (There is already one level of nesting more than I want.) What I would prefer to write is something like: USE-FOREACH (data/1) (blk) (next data) [ if code = "CC" [print description] ] Therefore, an implementation is called for. Any comments before I begin an implementation ? |
Chris 9-Jan-2007 [6569] | What is the second argument for? -- (blk) |
Gabriele 9-Jan-2007 [6570x2] | Anton, you need a BIND there somewhere :) |
foreach would work as is if it wasn't for the subblocks | |
Anton 9-Jan-2007 [6572x7] | Chris, sorry it's supposed to be unparenthesized, as a word, to have access to the original data. |
Gabriele, you're right. And it's not easy to add. Which is why this is so uncomfortable. | |
This works: | |
data: [ [code description] ["CC" "Crazy Cuts"] ["DD" "Dreadful Dingo"] ] format: data/1 foreach blk next data [ use format compose/only [ set (format) blk if code = "CC" [print description] ] ] | |
I prefer the USE to be on the outside, but it's more code: | |
use format compose/only [ foreach blk next data (compose/only [ set (format) blk if code = "CC" [print description] ]) ] | |
But if packaged nicely.. use-foreach: func [ words [block!] 'word [word! block!] data body /local ][ use words compose/only [ foreach (word) data (compose/only [ set (words) (word) do (body) ]) ] ] use-foreach data/1 blk next data [ if code = "CC" [print description ?? blk] ] | |
Chris 9-Jan-2007 [6579x3] | Some variations: |
If the record blocks are of fixed size, you could do: use-foreach: func [words records body] foreach record records [foreach :words record body] ] | |
Or use join (probably 'ouch' for many records): use-foreach: func [words records body][ foreach record records [ use words join [set words record] body ] ] | |
older newer | first last |