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

World: r3wp

[Core] Discuss core issues

Oldes
19-Apr-2007
[7625x3]
tm: func [p act [block!] /local t][t: now/time/precise loop p :act 
print now/time/precise - t]

flat-while: func[b][a: copy b while [not tail? a][a: change/part 
a a/1 1] a: head a]

flat-repeat: func[b][a: copy [] repeat i length? b [insert tail a 
pick b i] a]

flat-parse: func [b][a: copy [] parse b r: [any [ p: block! :p into 
r | skip (insert/only tail a first p)]]a]
flat-load: func[b][load form b]
b1: [[1 2 3 4 5][6 7 8 9 0]]
tm 10000 [flat-while b1]  ;== 0:00:00.062
tm 10000 [flat-repeat b1] ;== 0:00:00.063
tm 10000 [flat-parse b1]  ;== 0:00:00.172
tm 10000 [flat-load b1]   ;== 0:00:00.046

b2: head insert/dup copy [] [a b c d] 300
b3: head insert/dup copy [] b2 100

tm 1000 [flat-while b3]  ;== 0:03:03.985
tm 1000 [flat-repeat b3] ;== 0:02:11.125
tm 1000 [flat-parse b3]  ;== 0:02:43.704
tm 1000 [flat-load b3]   ;== 0:00:52.344
but I understand, that the parse can be much more faster if the block 
would hold other values as well, not just another blocks....
Anyway... I'm thinking, that maybe it would be good to find solution 
where I will not need nested block at all.
Terry
19-Apr-2007
[7628]
Hey, I'm playing around with the 'tiny web server' and it has this 
function.. 

send-page: func [data mime] [

        insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
        write-io http-port data length? data
    ] 

now.. when i use it like this.. 
	send-page "test" mime
.. it works fine.. but not this.. 
	out: "test"
	send-page out mime

What's up wit 'dat?
Ladislav
19-Apr-2007
[7629]
:-) your SEND-PAGE is mutating the DATA argument, Terry. Avoid that 
if you don't want to encounter unexpected situations
Henrik
19-Apr-2007
[7630x2]
Ladislav, explain mutate :-)
is this one of the fun things about ports?
Terry
19-Apr-2007
[7632x2]
explain unexpected situations ;)
I just don't get how it's even possible that   out: "test" .. somehow 
different that "test" ??
Ladislav
19-Apr-2007
[7634]
usually when you write:

    out: "test"
    send-page out mime


, you expect, that the OUT string remains to be "test", don't you?
Terry
19-Apr-2007
[7635]
yep
Ladislav
19-Apr-2007
[7636]
then don't change it
Terry
19-Apr-2007
[7637]
I don't want to change it.. it just doesn't work
Ladislav
19-Apr-2007
[7638x2]
OK, here is how:
send-page: func [data mime] [
    data: copy data

    insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
    write-io http-port data length? data
]
Terry
19-Apr-2007
[7640]
oh yeah..
Ladislav
19-Apr-2007
[7641]
this way you can make sure that the original DATA argument remains 
unaffected
Terry
19-Apr-2007
[7642]
hmm, that doesn't work either
Graham
19-Apr-2007
[7643]
try 

insert copy data rejoin ..blah ...
Ladislav
19-Apr-2007
[7644]
:-) it does, you probably made more errors of this kind
Graham
19-Apr-2007
[7645x2]
or, even send-page copy data mime
rather than mutating, we say "altering" :)
Terry
19-Apr-2007
[7647x2]
actually it worked fine the original way.. problem was  i set the 
out: "test" within tiny server's try block
sorry, not try.. in it's ANY[] block
Graham
19-Apr-2007
[7649]
whatever
Ladislav
19-Apr-2007
[7650]
:-)
Terry
19-Apr-2007
[7651x2]
so.. any [ out: "test"    send-page out mime] 
well.. out: "test" is any, isn't it ;)
but thanks for the quick response
Graham
19-Apr-2007
[7653x2]
I like that ... have a  "whatever [ ..  ] "
yes, so send-page never gets executed
Terry
19-Apr-2007
[7655]
hehe
Graham
19-Apr-2007
[7656x2]
send-page also doesn't return anything
you probably meant 

all [ out: "test" blah .. ]
Terry
19-Apr-2007
[7658x2]
here's another question..
if you have a block like so.. 

aaa: [bbb[ccc "string"]]


do the 'words  take up memory?  is there a limit to the number of 
'words in a block?
Sunanda
19-Apr-2007
[7660]
length? first system/words
== 1245
   aaa: [bbb[ccc "string"]]
== [bbb [ccc "string"]]
   length? first system/words
== 1248


Max words is around 8192 (varies by version). Note that 1000 or so 
are taken up when you start.
Terry
19-Apr-2007
[7661]
hmm, so that's not very practical way of storing a large flat DB 
?
Graham
19-Apr-2007
[7662]
Ashley's rebdb is an in memory db
Sunanda
19-Apr-2007
[7663]
That's *unique* words, not total words used

You can have as many aaa's as you like in different contexts; it 
adds only 1 to system/words
Terry
19-Apr-2007
[7664x3]
yeah.. i just need a simple hash table
but i like the  aaa/bbb/ccc  path syntax
a dictionary , for example..   cat ["def of cat" ] dog ["def of dog"]
run out of words real quick
Sunanda
19-Apr-2007
[7667]
But you may need to use strings or some other form of identifier 
-- REBOL words are rationed.
Terry
19-Apr-2007
[7668x2]
yeah
but then you lose the path syntax.
Sunanda
19-Apr-2007
[7670]
Use ordinals, then you can  go up to maximum integer with path syntax:
  database/1/234/4454/655/3

Slight problem there: when you delete things you have to leave empty 
slots or change all numbers.
Terry
19-Apr-2007
[7671]
given they would act as keys.. that would be more than a 'slight' 
problem
Sunanda
19-Apr-2007
[7672]
There's always a design trade-off.

I have various systems where real keys (usually strings) are mapped 
to surrogate keys (usually integers). It's a good compromise in many 
cases.
Terry
19-Apr-2007
[7673]
What is THE best way to store a large hash table in memory  like 
a dictionary, .. and access the data?
Henrik
19-Apr-2007
[7674]
terry, about accessing data, there is a speed issue with doing so 
with using indexes with paths, so data/2 is much slower than second 
data or pick data 2. that should solve at least that aspect.