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

World: r3wp

[Core] Discuss core issues

Geomol
21-May-2006
[4563]
Ah, maybe not. E.g. #"a" = 97 is true. #"A" = 97 is false. I suppose, 
this is the best behaviour.
Anton
21-May-2006
[4564x3]
Yes, char! is more close to integer....
Note:
>> "x" == "X"
== false
That's the more strict-equal, which turns off the case-insensitive 
equality of strings.
Volker
21-May-2006
[4567x2]
I would expect chars to compare like strings, but maybe that breaks 
things now.
mixing case/no-case comparisons can give surprises, and till now 
i nevernoticed that extra rules. good to know.
Anton
21-May-2006
[4569x3]
Better to keep the simple behaviour we have now with char equality, 
I think.
Anyone processing strings from different code-pages would be driven 
crazy by case-insensitive char compare.
Look at this ticket, "'select with a char! is not consistent":
http://www.rebol.net/cgi-bin/rambo.r?id=4046&
Volker
21-May-2006
[4572]
its not about simple, its about expected. a char is a char is no-case 
by default evrywhere, "=", 'parse, 'find, to-char - no wait.
Anton
21-May-2006
[4573]
(parse converts chars to strings internally..)
Volker
21-May-2006
[4574]
I dont look into the internallies all the time ;) On some occasions 
i am lazy and expect similar things to work similar.
Anton
21-May-2006
[4575x3]
But you could be right. At least there is scope for moving the simple 
equality test to strict-equal ==
Well, now is the time to lobby for such changes in Rebol 3.
That's a pretty fundamental operation, so we want to fix that in 
place pretty early.
Volker
21-May-2006
[4578x2]
Agreed.
What is the best way to distingisch text/binary files? list of suffixes 
for "is text, everything else binary", "is binary, evwerything else 
text"? Other ideas?
Geomol
21-May-2006
[4580]
- Read a part of the file. If every byte is ASCII (or 8-bit), it's 
text, else it's binary. This is only a good guess, of course!

- Many types of files have some header information right at the start 
of the file. Make a list of those headers. (I think, this is the 
way, many datatypes works in Amiga OS.)
Volker
21-May-2006
[4581]
Good ideas.
Geomol
21-May-2006
[4582]
You can also study the UNIX command: file
http://unixhelp.ed.ac.uk/CGI/man-cgi?file
You can probably find source for this command somewhere.
Anton
21-May-2006
[4583]
Gosh, the name of that unix command is really disturbing.
Joe
22-May-2006
[4584]
Hi,

I am a bit confused with bind and context

e.g.

blk: [a b] a: 1 b: 2
f: func [/local res][ 
res: bind/copy 'blk res 
probe reduce res
]

>> f
== [1 2]

Here my understanding would be that a and b are not
set in that context and the result is an error.

Apart for understanding the current behaviour, what I
want to accomplish is the behaviour that results in an
error.

I have a program where I set a lot of variables within
a function but I don't want to set all of them as
local, because it's repetitive and I sometimes miss a
few so I'd like declare them as local using a block
with all the variable names. 

Also, when I reduce the block I should get an error if
some of the variables have not been set independently
of whether any of these variables is set in the global
context.

Any ideas how to accomplish this ?
Anton
22-May-2006
[4585x4]
yep, hang on.
>> a: 1 b: 2
== 2
>> vars: [a b]
== [a b]

>> f: func compose [/local res (vars)][bind vars 'res reduce vars]
>> f
== [none none]

>> f: func compose [/local res (vars)][bind vars 'res a: 100 reduce 
vars]
>> f
== [100 none]
The vars block is composed into the function when it is created, 
but after that, vars is independant of the function, so it will be 
up to you to ensure they are consistent.
But I am wondering for what purpose you need this functionality.
Joe
22-May-2006
[4589x2]
but I want the vars to be unset! not none! so that it throws an error
also, f is normally a large standard function that I can not create
Anton
22-May-2006
[4591x3]
Function locals are set to none for you every time they are called.
They used to be left unset! but after a discussion years ago it was 
decided that it was more handy to set them to none.
What do you mean a large standard function ? example ?
Joe
22-May-2006
[4594x3]
I am using this for message composition, templates, etc.. So imagine 
you have a template: "<html><head> title </head><body> body </body></html>" 
but with many more tags and then you have a large funtction emit-page 
that generates many tags and when you generate the page you want 
to make sure that you've generated all the tags and if you missed 
some then you get an error
I think the above explains the problem domain. Imagine pages with 
lots of tags and that you don't want to clutter the emit-page function 
with lots of template variables neither want to compose the function 
given that if is a normal function where you do have other normal 
local variables. I am looking for ideas on how to approach this
if is a normal function
 --> i meant "it is a typical function definition
Anton
22-May-2006
[4597]
So you want an expanding block of name value pairs to be checked 
by a function.

Something like: [title "Product X website" introduction "Product 
X is a new way to..." cost 25.90]
Joe
22-May-2006
[4598x4]
I want the easiest possible approach i.e. you create an html file 
and define the tags like in the example above template:
and then you collect with a function the list of tags that you've 
created and then in a function you go and define dynamically all 
those tags as variables i.e. title: func-title "xyz" ...
I want to use the power of bind and contexts to make sure this works
going to lunch. talk to u later thanks
Anton
22-May-2006
[4602x2]
Or wait... you want a context to keep all your template variables 
in:
	template: context [title: introduction: cost: none]
then unset all the variable in the template:
	unset bind next first template template

Your function references words in the template and receives an error 
for the first one which is unset.
	f: func [template][do bind [?? title] template]
	f template
	** Script Error: title has no value
	** Where: ??
	** Near: mold name: get name
but works fine when they have values:
	template/title: "hello"
	f template
	; ==> title: "hello"
That should give you some ideas.
Ladislav
22-May-2006
[4604]
how about an UNBIND function as follows:
Joe
22-May-2006
[4605x2]
what is the syntax of unbind ? is it costly to execute ? I would 
use it unbind the block of variables before creating the template
i imagine this could be a solution using the global context
Ladislav
22-May-2006
[4607x2]
just a moment, testing
unbind: func [
	{unbind words}
	[catch]
	words [word! block!]
	/local word result object
] [
	if word? words [words: reduce [words]]
	result: copy []
	unless parse words [
		any [set word word! (insert tail result to set-word! word)]
	] [throw make error! "unexpected data"]
	exclude result [self:]
	insert tail result none
	object: make object! result
	either find result first [self:] [first object] [
		exclude first object [self]
	] 
]

blk: [a b]
a: 1 b: 2
f: func [/local res][ 
	res: bind/copy unbind blk 'res 
	probe reduce res
]
f blk
Joe
22-May-2006
[4609]
I get script error: self has no value and I get the same error if 
I set a and b after bind in function f
Ladislav
22-May-2006
[4610x3]
show me your code, please
(the code producing the "self has no value" error)
Here my understanding would be that a and b are not
set in that context 
and the result is an error.

 - right, neither 'a nor 'b exists in the function context, therefore 
 they remained global