• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

AltME groups: search

Help · search scripts · search articles · search mailing list

results summary

worldhits
r4wp5907
r3wp58701
total:64608

results window for this page: [start: 39601 end: 39700]

world-name: r3wp

Group: Core ... Discuss core issues [web-public]
Dockimbel:
24-Mar-2009
I'm a guy with principles and respecting the work done by other is 
one of them. I like playing by the rules.
Oldes:
24-Mar-2009
As I'm reviewing my old code, where I see a lot of rejoins where 
the first arg of block is always binary... what do you think about 
something like:
abin: func[block][append copy first block next block]
where the speed gain is:
>> tm 1000000 [abin [#{00} "a"]]
0:00:01.609
>> tm 1000000 [rejoin [#{00} "a"]]
0:00:02.938
Oldes:
24-Mar-2009
maybe not such a big gain.. as I must use:
abin: func[block][append copy first block reduce next block]
which has result 0:00:02.078... but anyway.. every ms counts:)
Oldes:
24-Mar-2009
mazbe it's strange that works:
>> make string! reduce ["a" "b"]
== "ab"
but not:
>> to binary! reduce [#{00} "a"]
** Script Error: Invalid argument: #{00}
** Near: to binary! reduce [#{00} "a"]
Oldes:
24-Mar-2009
abin: func[

 "faster binary creation of a block where the first arg is already 
 binary!"
	block
][
	head insert tail copy first block: reduce block next block
]
;to be able have code like:
abin [to-binary #"^(00)" "a" "b"]
BrianH:
24-Mar-2009
Oldes, a faster way (in R2) is this:
abin: func[

 "faster binary creation of a block where the first arg is already 
 binary!"
	block
][
	head insert copy #{} reduce block
]
BrianH:
24-Mar-2009
bjoin, since it is a binary version of ajoin.
BrianH:
24-Mar-2009
bjoin [#"^(00)" "a" "b"]
Gregg:
24-Mar-2009
What do you see as the arguments to both have = and == in REBOL?


There are times when you care about strict equality, and times when 
you don't. And it's a balancing act between usability, strictness, 
and risk; similar to the choice of making a language case sensitive 
or not.
Gregg:
24-Mar-2009
It's tricky, too, because sometimes you'll want to add something 
that you think will make things easier, but it really causes more 
problems in the grand scheme of things. TO-STRING versus FORM is 
a good example. I would like to see REBOL minimize the number of 
things that differ only in very subtle ways (which are often not 
explicitly documented).
Geomol:
24-Mar-2009
Let's look at this example. I have two words, iss and str, that represent 
some value, and they're some datatype. This is charasteristics of 
them:

>> series? iss
== true
>> series? str
== true
>> first iss
== #"a"
>> first str
== #"a"
>> length? iss
== 3
>> length? str
== 3
>> pick str 2
== #"b"
>> pick iss 2
== #"b"
>> str/3
== #"c"
>> iss/3
== #"c"

They seem quite alike. Are they equal?

>> str = iss
== false

Nope! Why not?

>> str
== "abc"
>> iss
== #abc


Again, I see little point in having both equal and strict-equal, 
when there's so little difference between them. If there were more 
differences between them, it would be good arguments to me for having 
both.
[unknown: 5]:
24-Mar-2009
But if we didn't have strict-equal then how would we know when a 
variable is a pointer?
[unknown: 5]:
24-Mar-2009
;consider:

>> a: "123"
== "123"
>> b: a
== "123"
>> b
== "123"
>> a
== "123"
>> append a "4"
== "1234"
>> b
== "1234"
>> a == b
== true
[unknown: 5]:
24-Mar-2009
Obviously, a and b are pointers to the same memory address that  
holds the string.
Geomol:
24-Mar-2009
You don't check, if they point to the same mem area with strict-equal, 
you use same? (or =?) for that:

>> a: "abc"
== "abc"
>> b: "abc"
== "abc"
>> a == b
== true
>> a =? b
== false


So it's not obvious, they point to same memory address, just because 
a == check returns true.
Geomol:
24-Mar-2009
Something funny. (We had a long discussion about this in R3-alpha.):

>> 0.3 - 0.2 - 0.1 = 0.0
== false

This is also false in e.g. the C language.
BrianH:
24-Mar-2009
It's a floating point thing - 0.1 can't be represented exactly in 
IEE754 floats.
BrianH:
24-Mar-2009
Or you could use fixnums: integer! and a scale.
Geomol:
24-Mar-2009
But Python is also a bit strange, it seems. From Python prompt:

>>> 0.1 + 0.1
0.20000000000000001
>>> 0.1 + 0.1 == 0.2
True
>>> 0.1 + 0.1 + 0.1
0.30000000000000004
>>> 0.1 + 0.1 + 0.1 == 0.3
False
Graham:
24-Mar-2009
anyone remember where the parse demos showed a calculator dialect 
?
Graham:
24-Mar-2009
saves me a few mins writing my own !
Pekr:
26-Mar-2009
I was trying to help new guy on ML, and just would like to ask - 
why is there a difference in evaluation when printing a block, and 
printing first block?

>> colors: [red green blue]
== [red green blue]
>> print colors
255.0.0 0.255.0 0.0.255
>> print first colors
red

so 'first does not reduce the value, while print itself does?
PeterWood:
26-Mar-2009
>> a: 1

== 1

>> type? a

== integer!

>> type? 'a
== word!

>> b: [a
]
== [a
]
>> type? first b

== word!

>> print a

1

>> print first b

a

>> print 'a

a
Sunanda:
26-Mar-2009
Help says print does an evaluate (presumably a reduce) if the value 
to print is a block....So it is documented behavior:
  http://www.rebol.com/docs/words/wprint.html
TomBon:
27-Mar-2009
trouble with double caret afer forming a string from block.

print y: form [KBE RKH CSCD IDJ MNOV LCAPB CWCO ^DJA]
KBE RKH CSCD IDJ MNOV LCAPB CWCO ^^DJA

how can I avoid the double caret?

form, mold or composing the string via foreach etc. doesn't work 
here.
TomBon:
27-Mar-2009
sorry I mean a probe... -> probe y: form  [KBE RKH CSCD IDJ MNOV 
LCAPB CWCO ^DJA]
Chris:
27-Mar-2009
Any time the string is displayed literally (such as at the console, 
or mold/save) will you see the double caret.  Internally it's a single 
caret.
Steeve:
27-Mar-2009
As chris states, there is a difference between how rebol show some 
chars and how they are kept internally
Chris:
27-Mar-2009
But there's no way other than a rewrite to get 'probe to display 
a single caret.
Steeve:
27-Mar-2009
same behavior with tab, newline,...
a tab is showed as "^-" but internally it's only one char!
TomBon:
27-Mar-2009
ahh I see. I need this string to compose a url and get a error. thought 
by 'probe the second phantom caret was the failure.
TomBon:
27-Mar-2009
looks like rebol doesn't accept the caret with a url
TomBon:
27-Mar-2009
yes, made a string and then to-url. this helps if the caret is hex-encoded 
 %E5
Dockimbel:
28-Mar-2009
So, a typo in a user input string could result in returning a wrong 
time! value without throwing an error. Looks like a bug or at least, 
a flaw IMO.
Sunanda:
28-Mar-2009
REBOL has always had a policy of "normalising" times with >59  minutes. 
Even without the to-time and string:
>> 1:111:11
== 2:51:11
Sunanda:
28-Mar-2009
I think you may have a typo........My example was 1:0:5000 (two colons). 
I see identical behavior in R2 and R3
Chris:
30-Mar-2009
>> blk: [a b c d e]
== [a b c d e]
>> foo: [bar 5]
== [bar 5]
>> path blk foo/bar
>> blk
== [a b c d]
>> foo/bar: 1
== 1
>> path blk foo/bar
>> blk             
== []
>> foo
== [bar 1]
Anton:
30-Mar-2009
The primary example use was in functions, to return the contents 
of a variable and also free the variable. eg, this:

	add-one: func [value][1 +  also value value: none]

replaces older code such as this:

	add-one: func [value][1 + first reduce [value value: none]]
Geomol:
30-Mar-2009
Is that a good example? Why would you set value to none, if it's 
a number? It doesn't matter.
Steeve:
30-Mar-2009
use cases: 
1/ swaping a with b
a: also b a: b
2/ in a function, returning a value after cleaning local vars
func [x /local tmp][
	tmp: a * 2
	also tmp tmp: none
]
Steeve:
30-Mar-2009
error with swaping
a: also b b: a
Geomol:
30-Mar-2009
Hm, a SWAP command could be a good idea, maybe. Or just do:
set [a b] reduce [b a]


About freeing local variables, why would you do that? Don't you call 
your function several times? You give garbage collector more to do 
this way. If it's often the case, that locals should be freed, then 
maybe we need a new function type, that does that?


(I'm asking all this, because I never understood the reason for having 
ALSO.)
Geomol:
30-Mar-2009
When I think about it, much of this is based on assumption how memory 
is handled in REBOL. We don't really know, because it's not documented. 
When is it good to free a local, and when not? There may be something 
wrong, if this should be handled by the programmer (also when it's 
not documented).
Geomol:
30-Mar-2009
If I have a simple local in a language like C, I wouldn't allocate 
and free it every time, I call my function.
Geomol:
30-Mar-2009
A local in C is just a value stored in some memory. I guess, it's 
the same in REBOL? Again we don't really know.
Geomol:
30-Mar-2009
REBOL must have a look-up table for the known words in the context, 
but after that it should just end up at a memory address.
[unknown: 5]:
30-Mar-2009
I use also function a lot.
[unknown: 5]:
30-Mar-2009
John, I haven't done a lot of performance checking but I know the 
clear-locals function is working to free memory.
Steeve:
30-Mar-2009
it's a differrent use case when dealing with series.
even in R3 you need to clear the series
eFishAnt:
30-Mar-2009
so, if I am on a M$ network, what is the best way to reach a \\blah\blah\blah\file.blah?
eFishAnt:
30-Mar-2009
wow, thanks Paul.  I think I freaked momenarily.  If I have to do 
it through Windoze I figure I could do a call (as a backup plan)
eFishAnt:
30-Mar-2009
A link to where Gab answered this, and yes, your example looks correct, 
http://www.rebol.org/ml-display-thread.r?m=rmlJZJQ
Geomol:
30-Mar-2009
Is this a bug?

>> first [:a/b]
== :a/b
>> type? first [:a/b]
== path!

Shouldn't it be get-path! ?
Henrik:
30-Mar-2009
R3 responds get-path!, so it might be a bug
Geomol:
30-Mar-2009
I think, you are right! Just a bit confusing, what :a/b mean then. 
It doesn't give an error.
Geomol:
30-Mar-2009
Maybe a combined get-word! and path! ?
[unknown: 5]:
30-Mar-2009
It isn't a path either
Henrik:
30-Mar-2009
I think it's being interpreted as a get-word! with a refinement:

>> type? :a/b
** Script Error: a has no value
** Where: halt-view
** Near: type? :a/b
>> type? :a /b
** Script Error: a has no value
** Where: halt-view
** Near: type? :a /b
>>
Henrik:
30-Mar-2009
and inside the block, it can be interpreted as a path. basically 
get-path! is a good idea. :-)
[unknown: 5]:
30-Mar-2009
>> as-lit-word? first [:a/b]
== false
>> as-lit-word? first [:a]
== true
[unknown: 5]:
30-Mar-2009
Tells me if an item acts as a lit-word.
[unknown: 5]:
30-Mar-2009
I could test the value with the as-lit-word? function to determine 
if I want to set the word to a value.
Dockimbel:
30-Mar-2009
It seems that there's no specific semantic rule in R2 for a get-word! 
as first item of a path! value. So, it's just treated as word!.

>> a: [b 123]
== [b 123]
>> :a/b
== 123
>> a/b
== 123
Henrik:
31-Mar-2009
I think it was to get rid of 'my-port. ALSO is useful when returning, 
so you don't need to assign another word for results that would otherwise 
be temporary. I use ALSO in a couple of places here.
Geomol:
31-Mar-2009
What happens, where you call process-port? Don't you have a variable 
there?
Henrik:
31-Mar-2009
It does really untie a small knot there and I've bumped into that 
quite often. It was discussed heavily a year ago in the r3-alpha 
world and Carl wanted it in. I remember the discussion was mostly 
what to name it. :-)
Geomol:
31-Mar-2009
Maybe if I see a bit larger program, that use ALSO!?
Geomol:
31-Mar-2009
I learned a program structure more than 20 years ago called "program 
95%". It's a structure, you use 95% of the time when programming 
COBOL (and probably also in most other langauges). Maybe the need 
for ALSO is related to how we structure our programs?
Henrik:
31-Mar-2009
I'm not sure it is. For the port example above, there's no way to 
return without ALSO or assigning a temporary variable. If you are 
using it inside another function, like process-port, it will only 
reduce overhead, not create more.
Geomol:
31-Mar-2009
What is the overhead for calling a function compared to not call 
it? And by having the close down in a function mean, it may not be 
on the same level as the open, which may be seen as bad programming 
style.
Henrik:
31-Mar-2009
no, you may exactly _not_ have 'my-port. you may be doing a test 
on the port which does not require an extra word.
Geomol:
31-Mar-2009
So you don't really need to copy the port? It's just for a test, 
like:

port: open ....
while [port] [
....
]
close port
Oldes:
31-Mar-2009
Geomol: I wonder why you have a problem with 'also now. It was discussed 
on 10-Aug-2007 on r3-alpha in new-functions group - and you were 
one of the people who were in this discussion
Geomol:
31-Mar-2009
Yes, I then said, I didn't see the need for it, but I suggested a 
good name. Now 1.5 years later, I still don't use it. I'm asking, 
if people use it, because if I see good use of it, I hope to use 
it myself.
Izkata:
31-Mar-2009
I've used it in a couple places, almost always having to do with 
ports - it is much nicer than spanning 3 lines for the same thing
[unknown: 5]:
31-Mar-2009
John, consider if you have a local variable in a function.  Then 
calling also can clear that local variable.  This is what I use 'ALSO 
for the most and why it is way cool.
[unknown: 5]:
31-Mar-2009
Yes to save resources.  For example, what if I just read an MP3 file 
into a word? I want to free that word so that it no longer is allocated 
to that data.
Geomol:
31-Mar-2009
If you want to load more MP3s, it would be a good idea to reuse the 
same memory area. An example:

>> f: func [/local blk] [blk: []]   
>> a: f
== []
>> insert a 42
== []
>> a
== [42]
>> source f
f: func [/local blk][blk: [42]]
>> clear a
== []
>> source f
f: func [/local blk][blk: []]


You see, A and BLK inside F points to the same memory. Next time 
you call F, you can put some more stuff in BLK (read another MP3).

If you want to be able to completely remove BLK, I would do that 
using an object. Build the MP3 player as an object, instead of just 
a function. Makes sense?
Geomol:
31-Mar-2009
You still have to set the MP3 data returned from your function to 
none to release the memory (making the garbage collector to work). 
I would handle this situation either by making a refinement to my 
function or (probably better) creating the whole thing as an object.
[unknown: 5]:
31-Mar-2009
I gotta run for a bit but will be back in about an hour or sooner.
Geomol:
31-Mar-2009
Using ALSO returns some data. If your code look like this:

mp3-data: load-mp3-function


and that load-mp3-function ends with an ALSO, setting the local var 
to none, you still have a full copy in mp3-data. Actually you end 
up having 2 copies for some time, until the garbage collector frees 
the local version. Later in your code, you need to set mp3-data to 
none to free to memory (which the garbage collector does). Now, is 
this how you use ALSO and why you need it?
Izkata:
31-Mar-2009
but, like before, say that happened in a function
Geomol:
31-Mar-2009
>> f: has [q] [q: [] append q "kdfjkd" also q q: none]
>> a: f
== ["kdfjkd"]
>> a
== ["kdfjkd"]
>> source f

f: func [/local q][q: ["kdfjkd"] append q "kdfjkd" also q q: none]
Geomol:
31-Mar-2009
Is this expected behaviour?

>> f: func [/local q][q: "blahblahblahblahblah" also q q: none]
>> a: f
== "blahblahblahblahblah"
>> source f
f: func [/local q][q: "blahblahblahblahblah" also q q: none]
>> insert a "hmm"
== "blahblahblahblahblah"
>> source f
f: func [/local q][q: "hmmblahblahblahblahblah" also q q: none]
>> a: none
== none
>> source f
f: func [/local q][q: "hmmblahblahblahblahblah" also q q: none]
Geomol:
31-Mar-2009
Izkata, you got a point with your Pread. But it's not a secure function, 
because it may crash. Let me see, how I would make such a function...
[unknown: 5]:
31-Mar-2009
>> a: f: has [q][q: "blahblahblahblahblah" also q q: none]
>> a
== "blahblahblahblahblah"
[unknown: 5]:
31-Mar-2009
>> f
== "blahblahblahblahblah"
>> a: f
== "blahblahblahblahblah"
>> source f
f: func [/local q][q: "blahblahblahblahblah" also q q: none]
Geomol:
31-Mar-2009
You can see, it doesn't this way:

>> f: func [/local q][q: "blahblahblahblahblah" also q q: none]
>> a: f
== "blahblahblahblahblah"
>> insert a "more blahblahblahblah"
== "blahblahblahblahblah"
>> source f

f: func [/local q][q: "more blahblahblahblahblahblahblahblahblah" 
also q q: none]

Look at the source of f. Notice the "more blahblah...."
[unknown: 5]:
31-Mar-2009
a: f: has [q][q: copy "blahblahblahblahblah" also q q: none]
TomBon:
31-Mar-2009
unfortunatly the same story...
does anybody knows why a replace on the second and third also
changes the first letter?  ^JKSE = %5E/KSE and  ^IKSE = %5E-KSE
but ^MERV = %5EMERV and therefore okay.

	probe load replace/all  mold "^MERV" #^ "%5E"
	probe load replace/all  mold "^JKSE" #^ "%5E"
	probe load replace/all  mold "^IKSE" #^ "%5E"

any advise is highly appreciated...
tom
Geomol:
31-Mar-2009
Paul, in your last example with copy, the q memory is released, and 
the string after copy remains. So this actually is a version with 
something gained. Now I have to think, if I would do it this way.
Izkata:
31-Mar-2009
Well, ^I is a control-i.. and in vim, that inserts a tab.  ^- is 
the tab character in Rebol
Geomol:
31-Mar-2009
Anyway, I can now see, how you use ALSO with ports. By using a function 
approach, you choose to copy the data out to some further external 
computation. And it's up to the user of the function to free the 
data, when finished. I would take an object approach and store the 
data in the object. Then external computation can work on the data 
in the object. I feel, it's confusing using ALSO, but maybe it's 
just me.
Geomol:
31-Mar-2009
Where I see a potential problem with ALSO, is if you in a function 
load a local var with a huge amount of data, say 1GB. And then to 
release that data ends your function with:
also copy local-data local-data: none


At that moment between the two arguments to ALSO, you have 2 GB of 
data allocated. The first 1 GB is freed, when the garbage collector 
comes to it.
Izkata:
31-Mar-2009
Geomol: [Izkata, about the timeout. It seems here, that when the 
open/binary returns, the data is immediately available, so the timeout 
has no effect. I'm on OS X, maybe it's different under windows?]

I'm on Ubuntu  ;)  but yeah, now that I think about it, that's true. 
 Originally it was written differently, and the error appeared to 
be on the copy.  I added it when mininova was timing out on certain 
requests due to high load - it seemed to make a difference then, 
but I don't know if it was coincidence or not.
Izkata:
31-Mar-2009
If you're thinking I'm making a torrrent client in Rebol, not yet 
 ;)
Graham:
31-Mar-2009
networking is not a strong point
Anton:
31-Mar-2009
Geomol, your last "potential problem with ALSO" is not exclusive 
to ALSO. It's a potential problem anywhere COPY is abused by a programmer 
not knowing what's going on.

The way to return the large amount of data and to release the local 
from it is of course like this:

	also local-data local-data: none
Anton:
31-Mar-2009
In the load-mp3-data function above, a large binary series is loaded 
and contents set to refer to it. The ALSO line returns the binary 
series and unsets CONTENTS so that it no longer refers to the binary 
series. The usage code below the function definition takes the return 
value (the binary series) and sets DATA to it.

So effectively the variable referencing the binary series has been 
switched with another one.
Anton:
31-Mar-2009
Which is a good thing to do, because now the function does not maintain 
a reference to the large binary series after it has been called.
39601 / 6460812345...395396[397] 398399...643644645646647