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

World: r3wp

[Core] Discuss core issues

Anton
21-May-2006
[4570x2]
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
[4610x5]
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
(or unbound, in my version of the function)
It looks, that we don't know what exactly you want to accomplish, 
and it is a bit hard to guess. Could you be more specific?
Joe
22-May-2006
[4615x5]
I am using linux and the clipboard doesn't worked so I typed the 
code
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
        a: 1 b: 1
        probe reduce res
]
f blk
** Script Error: self has no value
** Where: f
** Near: self
>>
I get the same error when commenting a: 1 b: 1 line inside f
Ladislav, thank your help. I wanted to ask you about this via the 
mailing list and I did send the message earlier this morning but 
the mailing list is down. Please bear with me and I will provide 
the details. I think the solution you provided is exactly what I 
was looking for but I might be missing some detail. I am studying 
your code right now and will be more specific in a few minutes