• 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: 27901 end: 28000]

world-name: r3wp

Group: Core ... Discuss core issues [web-public]
Anton:
21-May-2006
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
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
That's a pretty fundamental operation, so we want to fix that in 
place pretty early.
Geomol:
21-May-2006
- 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.)
Joe:
22-May-2006
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
>> 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]
Joe:
22-May-2006
also, f is normally a large standard function that I can not create
Anton:
22-May-2006
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.
Anton:
22-May-2006
What do you mean a large standard function ? example ?
Joe:
22-May-2006
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
Joe:
22-May-2006
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
Joe:
22-May-2006
if is a normal function
 --> i meant "it is a typical function definition
Anton:
22-May-2006
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
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" ...
Anton:
22-May-2006
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"
Joe:
22-May-2006
i imagine this could be a solution using the global context
Ladislav:
22-May-2006
just a moment, testing
Ladislav:
22-May-2006
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
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
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
Ladislav:
22-May-2006
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
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
Joe:
22-May-2006
I get the same error when commenting a: 1 b: 1 line inside f
Joe:
22-May-2006
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
Joe:
22-May-2006
i am preparing the pseudo-code. just a few minutes
Joe:
22-May-2006
template:       to block!  "<html><head><title> title </title></head><body>tag1 
tag2 tag3</body></html>"


blk:            remove-each val load copy template [tag? val]    
?? blk ; == [title tag1 tag2 tag3]

tag3:           "this is a fake value, should not appear"

eval-template: func [
        /local res
][
        res:            copy ""
        title:          "hey"
        tag1:           "this is tag1^/"
        tag2:           "i am tag 2^/"
        ;tag3:          "might not be set^/"
        bind/copy       template 'res
        repend          res template
        res
]
Joe:
22-May-2006
template:       to block!  "<html><head><title> title </title></head><body>tag1 
tag2 tag3</body></html>"


blk:            remove-each val load copy template [tag? val]    
?? blk ; == [title tag1 tag2 tag3]

tag3:           "this is a fake value, should not appear"

eval-template: func [
        /local res
][
        res:            copy ""
        title:          "hey"
        tag1:           "this is tag1^/"
        tag2:           "i am tag 2^/"
        ;tag3:          "might not be set^/"
        bind/copy       unbind blk 'res
        repend          res template
        res
]
Joe:
22-May-2006
The unbind function is very close to what I want. In the previous 
example if the function body does not set the variables a or b it 
prints [none none]. What I want is that if a variable in blk is not 
set then it throws an error
Joe:
22-May-2006
IPls let me know if this example is not clear. What I want is to 
catch the case where tag3 is not set and throw an error This is useful 
where the tags are set in a large function and there are many tags
Joe:
22-May-2006
I want title to be local without defining it in the spec. Eval template 
is a function that might be used for many different templates
Joe:
22-May-2006
IMy understanding is that if you bind a word to the local context 
then it's a local even if it's not defined in the spec but I probably 
have multiple misunderstanding (though I just read the Bindology 
Bible by Ladislav)
Gregg:
22-May-2006
local without defining it in the spec
 -- I don't think that's a good way to think about modeling it.
Joe:
22-May-2006
I see. This is a major limitation. I see the rebol3 has a blog entry 
that "bind expands contexts" How could I approach this with the current 
rebol ?
Anton:
22-May-2006
No, that's right. Contexts cannot be extended with new words (at 
this time).  I would pass a context to your function with the template 
and all the words in it. This context will have to be built at the 
beginning.
Anton:
22-May-2006
Sorry, I mean you eval-template function can create a context on 
the fly with the words in it.
Anton:
22-May-2006
It's not a terribly easy thing to do, but can be done.
Joe:
22-May-2006
Gregg, the GOAL is to be able to have a generic eval-template function 
that can evaluate multiple templates without having to include hundreds 
of locals in eval template. The values are generated dynamically 
with a code-block e.g. eval-template template code-block where code-block 
is [title: func-title "aha" tag1: emit-whatever ...
Anton:
22-May-2006
Eval-template will accept a template string
1) convert to block
2) extract the words
3) create a context with these words
4) unset all words in the context

5) do your code bound to the context   ( do bind your-code the-context 
)
6) handle errors
7) return results
Joe:
22-May-2006
What I've been using in the past is different versions of eval-template 
for each template and I found the typical bug to be when missing 
a local given that the templates are evaluated multiple times
Anton:
22-May-2006
After extracting the words you need to convert them all to set-words 
and put them in a spec block, eg:
spec: copy []
foreach word words [append spec to-set-word word]
append spec none
; now you can create the context using the spec
the-context: context spec
; now unset each word in the context, etc..
Joe:
22-May-2006
Yes anton, I will code it this way. I am worried that unbinding the 
words every time is a performance hit
Ladislav:
22-May-2006
I just thought, that you wanted to have a function accepting and 
processing templates
Joe:
22-May-2006
Yes, my problem is an error handling problem. So far the template 
blocks are global, and I want to have functions that can build the 
templates without actually passing the template as a parameter
Anton:
22-May-2006
Yes, it's a bit confusing jumping straight into it like this.
Gregg:
22-May-2006
I'm only asking because I think you're making this a lot harder than 
it needs to be, but I can't be sure if I don't understand the problem.
Anton:
22-May-2006
Yes, I can't say I find myself needing to do such an operation very 
often. Been a while since I generated html though.
Joe:
22-May-2006
a new attempt. The code that follows works except that I have to 
define the tags as locals, which is a pain when there are lots of 
them
Anton:
22-May-2006
You would have to define a function every time, yes.
Gregg:
22-May-2006
I would still lean towards a higher level solution at some point, 
but this makes more sense to me than messing with bindings.
Gregg:
22-May-2006
Profile it. :-) How many do you *need* to generate, how much data, 
how many tags, etc. There are a lot of variables here (no pun intended).
Frank:
22-May-2006
Clipboard on linux :   ctrl-v  in altme and middle mouse button in 
a text editor, it works for me
Henrik:
22-May-2006
Why can't I find paths in a loadable block?

>> t: [x/y]
== [x/y]
>> type? first t
== path!
>> find t 'x/y
== none
>> find t to-path 'x/y
== none
Anton:
23-May-2006
I think the answer is: "because there is a bug."
Henrik:
23-May-2006
yes, it's very fun especially when you are on a time limit :-)
BrianH:
23-May-2006
When searching in a string type for any string type, the type is 
converted. Same for block types. And path! is a block type.
Anton:
23-May-2006
yes, my initial reply was a bit hasty too.
Ashley:
23-May-2006
Don't know whether this has been discussed / RAMBOed yet, but I think 
a smarter reduce (either a refinement or another word) which could 
handle:

	reduce [now then]

instead of requiring:

	reduce [now 'then]

or

	compose [(now) then]


would make writing dialects a lot easier as unset! is rarely a legitimate 
value within a dialect (i.e. I'd like to reduce blocks before parsing 
and words without a value should just be left as is).
Ashley:
23-May-2006
Something like:

reduce2: make function! [
	block [block!]	"Block to reduce"
	/deep		"Reduce nested blocks"
	/local blk

 "Evaluates a block of expressions, skipping words without a value, 
 and returns a block."
] [
	blk: copy []
	foreach word block [
		either block? word [
			either deep [
				insert/only tail blk reduce2/deep word
			] [insert/only tail blk word]
		] [insert tail blk either value? word [do word] [word]]
	]
	blk
]


>> reduce2 [red x now now/date (1 + 1) [red x now now/date (1 + 1)]]

== [255.0.0 x 24-May-2006/13:12:14+10:00 24-May-2006 2 [red x now 
now/date (1 + 1)]]

>> reduce2/deep [red x now now/date (1 + 1) [red x now now/date (1 
+ 1)]]

== [255.0.0 x 24-May-2006/13:12:26+10:00 24-May-2006 2 [255.0.0 x 
24-May-2006/13:12:26+10:00 24-May-2006 2]]


but as a native! and able to handle funcs with args (e.g. reduce2 
[print "hi"]).
Ashley:
24-May-2006
Here's a different approach to get the result I'm after:

cast: make function! [
	block [block!] "Block to cast"
	words [block!] "Words to convert into literal words"
	/local blk word
	"Casts nominated words within a block into literal words."
] [
	blk: copy []
	repeat i length? block [

  insert/only tail blk either find words pick block i [to lit-word! 
  pick block i] [pick block i]
	]
	blk
]

>> cast [area red button green 'btn blue] [area button]
== ['area red 'button green 'btn blue]
>> reduce cast [area red button green 'btn blue] [area button]
== [area 255.0.0 button 0.255.0 btn 0.0.255]
BrianH:
24-May-2006
Yeah, I get that feeling here a lot too :)
BrianH:
24-May-2006
I was a little surprised that the lit-word didn't turn into a word. 
That could be useful. I'm going to do some experiments to see what 
else reduce/only doesn't do. Should be fun.
Graham:
24-May-2006
'read must 'open a file
JaimeVargas:
24-May-2006
Ashley, but reduce/only doesn't perform according to your  initial 
spec "Evaluates a block of expressions, skipping words without a 
value, and returns a block."
>> reduce/only [now then]
** Script Error: then has no value
Ashley:
24-May-2006
but reduce/only doesn't perform according to your  initial spec
 True, on two counts:

1) It doesn't evaluate expressions (even if parenthesized)

2) You have to predetermine what words to ignore (less of an issue 
for dialects)

I still can't see a simple way of doing the following:

>> reduce [b: button red form now/date]
** Script Error: button has no value
** Near: b: button red form now/date
>> reduce/only [b: button red form now/date] [button]
** Script Error: Invalid argument: form
** Near: form now/date
>> reduce/only [b: button red (form now/date)] [button]
== [b: button 255.0.0 (form now/date)]


although at least the last case gets most of the way there. What 
I'd really like is:

>> reduce/ignore [b: button red form now/date]
== [b: button 255.0.0 "25-May-2006"]
Ashley:
25-May-2006
Not sure I understand, a small example would help. ;)
Gabriele:
25-May-2006
Ashley, the idea is that in parse, when you get to something you 
want to evaluate, you set a marker and use do/next. like in volker's 
example. my compile-rules provided  a way to do this automatically 
:)
Gabriele:
25-May-2006
the problem is that it "breaks" the parse logic, because you cannot 
backtrack a do/next (side effects)
Volker:
25-May-2006
It has its purposes without side-effects. And you can have side-effects 
in the parens too, eg a do/next ;)
Henrik:
30-May-2006
anton has a fix for that
Joe:
30-May-2006
can anybody provide a simple example to explain copy and copy/deep 
behaviour ? thanks
Sunanda:
30-May-2006
a: 1
b: [2]
c: copy []
append c a
append/only c b
probe c

d1: copy c
d2: copy/deep c
append b 99999
probe d1
probe d2
======
d1 ends up with it's second entry the same as b
d2 ends up with it's second entry a c opy of b's original values
Anton:
31-May-2006
Did you get this net-error "Cannot open a dir port in direct mode" 
 ?
Oldes:
31-May-2006
and this one as well: ** User Error: Cannot open a dir port in direct 
mode
Anton:
31-May-2006
Yes, that's right, you would have got the "Cannot open a dir port 
in direct mode" error ?
Gordon:
2-Jun-2006
Hello;
  I'm getting an
   "Internal Error: No more global variable space
     Where: to-word
** Near: to word! :value"


 when i run a program that after reading a file into memory, it then 
 does a character by character parse of the file and writes any words 
 that it finds to a new file.  The code that seems to be causing a 
 problem is this:

    Write/Append OutFileNameFull reduce [to-word WordStr newline]   


It gets through about 1.5 MB before it "runs out of global variable 
space".


Why is it running out of global variable space when there is only 
the one variable (to-word WordStr)?
Gordon:
2-Jun-2006
Thanks but WordStr is a string and I need it to be a word type.
Anton:
4-Jun-2006
This is a frequent stumbling block with beginners - using more words 
than necessary. Words are really good at expressing distinct concepts 
(ie. variables). If you have lots of similar data, then that really 
just calls for a series.
Gabriele:
5-Jun-2006
maybe. we've been discussing a few things. nothing decided yet.
Gabriele:
5-Jun-2006
anton, yes that could be an issue. maybe we could have a soft limit 
or something like that for contexts. but, i don't know if there's 
an hard limit, i'm just assuming there isn't, but i may be wrong.
Graham:
5-Jun-2006
Is this a standard windows dll?
BrianH:
6-Jun-2006
That is the C runtime. There are a few other (older) C runtimes on 
Windows, but that is generally the best one.
JaimeVargas:
14-Jun-2006
Humm. I give up. Has somebody found a solution to the path capture 
problem?

#!/usr/local/bin/rebol -sq
REBOL []
print first system/options/args
Gabriele:
14-Jun-2006
if you encap it, the CD will be the dir where the program was started 
from. when run with a shebang though... not sure if there's a way.
BrianW:
14-Jun-2006
Dumb question: When I'm printing a string, what's the best way to 
show special characters (^/ etcetera) in their special form, rather 
than just expanding them (turning ^/ into an actual newline, for 
example)?
BrianW:
14-Jun-2006
well, I know probe is the way to do it direct to stdout, but I want 
to save the "probe" value to a string
james_nak:
15-Jun-2006
Is there a way to "copy" an object  (already defined)  so the result 
is a distinct object? It's probably something easy but for the life 
of me...
Robert:
16-Jun-2006
This is IMO inconsistent and should be changed:

>> ? for
USAGE:
    FOR 'word start end bump body

DESCRIPTION:
     Repeats a block over a range of values.
     FOR is a function value.

ARGUMENTS:
     word -- Variable to hold current value (Type: word)

     start -- Starting value (Type: number series money time date char)

     end -- Ending value (Type: number series money time date char)

     bump -- Amount to skip each time (Type: number money time char)
     body -- Block to evaluate (Type: block)

(SPECIAL ATTRIBUTES)
     catch
     throw
>> a: 2.0
== 2.0
>> for test 1 a 1 [print test]
** Script Error: for expected end argument of type: integer
** Near: for test 1 a 1
>> number? a
== true


It should be possible to use decimal! as well. The interpreter should 
implicitly convert it to an integer!
Oldes:
17-Jun-2006
so at least such a simple function:
BrianH:
17-Jun-2006
Robert, although 1 and 1.0 are both numbers, they are not the same 
type in REBOL. Sure, they can be converted, but unless you do so 
they aren't. It would be simpler to just rewrite your example to 
this:

>> a: 2.0
== 2.0
>> for test 1.0 a 1 [print test]
1.0
2.0


and not have the type mismatch I was talking about. Unfortunately 
REBOL doesn't have type signiatures that are powerful enough to specify 
that these two parameters need to be the same type, so that constraint 
has to be enforced in the code.
BrianH:
17-Jun-2006
Oldes, a builtin read-thru would require Core to be installed rather 
than just copied somewhere, just like it does with View - view-root 
is set during installation. Still, all of the *-thru functions are 
written in REBOL, so they can be copied and adapted to your purposes 
quite easily.
Volker:
17-Jun-2006
a view-root: what-dir works quite well.
Volker:
17-Jun-2006
and having a %public/alongside my /core-script work quite well for 
me.
Volker:
17-Jun-2006
i like to poitn peoples to install rebol and run a little launch-script 
i send them.
BrianH:
17-Jun-2006
It was supposed to be that global settings were contained in rebol.r 
and user-specific or local settings in user.r, but it never worked 
that way with Core because REBOL only looked for the location of 
those files once for both, rather than once for each, so you couldn't 
put user.r in a user-specific place and keep rebol.r is a global 
place. VIew does it right with version 1.3 though.
Robert:
18-Jun-2006
Has someone a nice function to extract tuples by level? For example:
	1.0.0
	1.1.0
	1.2.0
	2.0.0
	2.1.0


I just need all 1st level tuples, than only the second level tuples 
etc.
Robert:
18-Jun-2006
All tuples that have a specific level set.
Robert:
18-Jun-2006
I'm just playing around with a multiplier pattern like zero? (1.0.0 
* 0.1.1). This works expect for the 3rd level.
Anton:
22-Jun-2006
It does not mold into a loadable string. --> RAMBO.
Rebolek:
22-Jun-2006
well, that's really strange. see this >>
>> load mold to file! "[s-:-a]"
** Syntax Error: Invalid email -- %[s-:-a]
** Near: (line 1) %[s-:-a]
>> load mold to file! "[aas-:-df]"
== ª[s-:-df]
Pekr:
25-Jun-2006
ok, putting date in a string helps ...trying to catch leap year ...
27901 / 6460812345...278279[280] 281282...643644645646647