r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Gabriele
28-Oct-2006
[5910]
alternatively you could create a dummy port handler to let the native 
code do the job for you.
Anton
28-Oct-2006
[5911]
Hmm, both interesting ideas - much more than what I need for now 
- if the code gets any longer it's too unwieldy to be really useful. 
I will add these ideas as possible areas for investigation.
Henrik
31-Oct-2006
[5912]
anyone built a function to find duplicate elements in a block and 
return them in a separate block?
Geomol
31-Oct-2006
[5913x2]
blk: [a b b c b a]
head foreach e unique blk [alter blk e]
== [b b a]
Ups, not separate block. Use copy!
MikeL
31-Oct-2006
[5915]
Henrik.   

Andrew created Tally.r    It wasn't exactly what you asked but maybe 
there's some value there "Tallies up the values in a series,  producing 
a block of [Value Count] pairs"

http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=tally.r
Gregg
1-Nov-2006
[5916]
; Something like this?


    split-unique: func [block [any-block!] /local uniq dupe dest] [
        uniq: copy []
        dupe: copy []
        foreach item block [
            dest: either find/only uniq item [dupe] [uniq]
            append/only dest item
        ]
        reduce [uniq dupe]
    ]
Maxim
1-Nov-2006
[5917x3]
Henrik:  are you talking about intersect ?  (part of rebol core)
>> intersect [1 2 3 4 5] [4 5 6 7 8 9]
== [4 5 6]
just reread your post... you want duplicates in the same block... 
 sorry.
Henrik
1-Nov-2006
[5920]
yes, like:
>> duplicates [1 1 2 2 3 4 5 5 6 7 8]
== [1 2 5]
Maxim
1-Nov-2006
[5921]
you got me into a spin, I rarely do this kind of fun , here is my 
best and shortest solution:

(its also 3 times faster than Geomol's, using his block data ;-)

duplicates: func [serie /local word][

 remove-each word copy serie [same? find serie word find/last serie 
 word] 
]

>> duplicates [a b b c b a]
== [a b b b a]

you can add the 'unique call to clean up the block if you like 
>> unique duplicates  [1 1 2 2 3 4 5 5 6 7 8]
== [1 2 5]
Geomol
1-Nov-2006
[5922]
This one does what you want, I think:
>> blk: [a b b c b a]
>> unique head foreach e unique blk [alter copy blk e]
== [a b]
blk is untouched.
Maxim
1-Nov-2006
[5923x2]
the competition is on  ;-)
the foreach is slow though, when compared to remove-each.
Geomol
1-Nov-2006
[5925x2]
And as a function:

find-dups: func [blk] [unique head foreach e unique blk [alter copy 
blk e]]
Maxim: Henrik didn't ask for speed! ;-)
Maxim
1-Nov-2006
[5927x2]
hehe... but I know he is addicted to it  ;-)  I had found my solution 
when I saw yours...  so I just did a benchmark for the fun of it.
you'll be intrigued to know that the unique call, is VERY slow.  
it was as long as my duplicates itself.
Geomol
1-Nov-2006
[5929]
Funny how the same thing can be done in so different ways with REBOL. 
I think, it's good. Choose the way, you like. Not many languages 
are like that. Again REBOL is much like a spoken language. You can 
say the same thing in lots of ways. Some say it with many words, 
some is short and precise, etc.
Maxim
1-Nov-2006
[5930]
you have seen the old REBOL poetry discussion?  IIRC they where on 
the mailing list... but not sure.
Geomol
1-Nov-2006
[5931]
nope
Maxim
1-Nov-2006
[5932]
some people where amazing.  using only rebol core words and valid 
syntax...
Geomol
1-Nov-2006
[5933]
:-)
Maxim
1-Nov-2006
[5934]
writing subtle lines which often had nice printed results.
Geomol
1-Nov-2006
[5935]
This one? http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-message.r?m=rmlJVXQ
Maxim
1-Nov-2006
[5936]
hehehe... I guess those where part of it...
Gabriele
1-Nov-2006
[5937x4]
>> s: now/precise duplicates-max blk difference now/precise s
== 0:00:02.062
>> s: now/precise duplicates blk difference now/precise s
== 0:00:00.031
>> length? blk
== 10000
duplicates: func [block /local result value] [
    result: make block! 16
    parse sort copy block [

        any [set value skip some value (append result value) | skip]
    ]
    result
]
mine does not need unique either
on a small block the speed is almost the same (mine a little bit 
faster)
Maxim
1-Nov-2006
[5941]
yes parse was the other solution, I was going to explore.
Gabriele
1-Nov-2006
[5942x2]
i wonder if counting each value would be faster, probably not. sort 
being native helps a lot :)
if blk is already sorted then it's even faster (no copy required 
either)
Maxim
1-Nov-2006
[5944]
indeed, in this situation, parse is much more flexible.
Maxim
2-Nov-2006
[5945]
Gabriele, your solution does not support words! 
duplicates [ a b c ] 
** Script Error: Invalid argument: a
** Where: duplicates
Gabriele
2-Nov-2006
[5946]
where's LITERAL when you need it?
[unknown: 5]
2-Nov-2006
[5947]
Does anyone have any information on what strength or methods that 
ENCLOAK uses?  For example, what bit strength etc, algorithm etc,?
Maxim
2-Nov-2006
[5948]
encloak is not an encryptor, its an obfuscator.
[unknown: 5]
2-Nov-2006
[5949]
you mean like an xor type thing?
Maxim
2-Nov-2006
[5950]
I don't know exactly, but I remember reading that its not a real 
encryption system.
[unknown: 5]
2-Nov-2006
[5951x2]
I had just found something via  search it looked like Carl was question 
about it and answered something along the lines of XOR.  Not sure 
if the function has evolved since then or not.
ok Thanks Maxim.
Allen
2-Nov-2006
[5953]
Encloak  -- http://www.rebol.net/cookbook/recipes/0023.html-- Carl 
says


Newer versions of REBOL include "cloaking" functions for encrypting 
and decrypting strings. These functions do not provide full strength 
encryption such as Blowfish, AES, or RSA as found in REBOL/Command, 
nevertheless they can be useful for hiding passwords and other values. 
(That's why we call it cloaking rather than encrypting.)
Maxim
2-Nov-2006
[5954]
so basically, usefull for hidding data from familly and friends, 
but not from your neighbourhood (or company) hacker  ;-)
Gabriele
3-Nov-2006
[5955]
well, the safety of XOR is the safety of the passphrase. if it is 
random and same length as data, then it's the safest possible. :)
Sunanda
3-Nov-2006
[5956]
There are things stronger than encloak in the Library

http://www.rebol.org/cgi-bin/cgiwrap/rebol/search.r?find=encryption
Louis
3-Nov-2006
[5957x2]
Am I correct is assuming that data is more apt to actually be written 
to disk using write/direct than using write with the direct refinement?
with = without
Anton
3-Nov-2006
[5959]
No, /direct just allows control of rebol's memory buffer. Rebol goes 
out to the host filesystem via host OS API calls. The host filesystem 
may still not actually write the data to disk immediately. To be 
sure of an immediate write, you would flush the disk cache, using 
a mechanism provided by the host OS and filesystem. (eg. in WinXP, 
if you disable one of the harddisks, it flushes the cache, then spins 
the disk down. There must be another way to flush the disk, but I 
never learned that.)