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

World: r3wp

[Core] Discuss core issues

Anton
30-Apr-2006
[4263x10]
It doesn't look as simple operation as I thought...
That's weird. When you insert the function body into another block 
for binding it doesn't work. These two examples are not producing 
the same result:
>> ctx-A: context [a: 60]
>> my-func: func [][a: 5]
>> bind second :my-func ctx-A
== [a: 5]
>> ?? ctx-A
ctx-A: make object! [
    a: 60
]
>> my-func
== 5
>> ?? ctx-A
ctx-A: make object! [
    a: 5
]
>> ctx-A: context [a: 60]
>> my-func: func [][a: 5]
>> blk: [] append blk second :my-func
== [a: 5]
>> bind blk ctx-A
== [a: 5]
>> ?? ctx-A
ctx-A: make object! [
    a: 60
]
>> my-func
== 5
>> ?? ctx-A
ctx-A: make object! [
    a: 60
]
Insert copies the words into the block unbound from their original 
context.
Ok, so we can do this instead:
foreach func funcs [bind second :func ctx-A]
No reason for that not to work.
Yes, that works:
>> ctx-A: context [a: none]
>> f1: does [a: 1]
>> f2: does [a: 2]
>> foreach func reduce [:f1 :f2][bind second :func ctx-A]
== [a: 2]
>> ?? ctx-A
ctx-A: make object! [
    a: none
]
>> f1
== 1
>> ?? ctx-A
ctx-A: make object! [
    a: 1
]
>> f2
== 2
>> ?? ctx-A
ctx-A: make object! [
    a: 2
]
Robert
30-Apr-2006
[4273x3]
This stuff is always really tricky.
Ok, thanks a lot. That's stuff I'm really going nuts by. I think 
I will collect all kind of examples and publish them.
A BIND how-to, that not only explains what's going on but shows examples, 
examples, examples is what we need.
BrianH
30-Apr-2006
[4276]
Ladislav's Bindology article might help. I think it's on rebol.org...
Robert
30-Apr-2006
[4277x2]
His article is good, but only for gurus to follow.
Nothing for people getting into first touch with BIND.
BrianH
30-Apr-2006
[4279x3]
I actually think that your best bet here is to pass the context you 
will be saving to the saving function as a parameter, like your original 
example  storage/save-record context-to-save  or if you really want 
to delegate you can assign the function as a member of context-to-save 
and call it like  context-to-save/save-record context-to-save , but 
then you are changing the context you are saving wih saving overhead. 
REBOL does direct delegation by default, rather than mixin delegation 
like Delphi, because REBOL doesn't pass the object reference as a 
hidden parameter like object-oriented languages do. Rebinding your 
function body every time would be time-consuming and either non-recursion-safe 
(bind) or consume a lot of memory (bind/copy) - just passing the 
context as a parameter would be quicker.
Also, you could have some conflict with names in both the storage 
context and context-to-save that could cause the block you are rebinding 
to accidently lose its meaning in unexpected ways.
Not that learning about bind wouldn't be fun...
Robert
1-May-2006
[4282]
I might fall back to the parameter solution. My goal is, that with 
BIND the code becomes much more natural to read and maintain. Because 
teh storage context needs some knowledge about the context to save, 
as I'm using a dynamic field-mapping method. Hence I only need to 
alter the context-to-save (add / remove words) and the storage context 
can handle it automatically. I have to deal with scheme evolution 
and versioning.
BrianH
1-May-2006
[4283x2]
In that case, try the stub functions to hide the parameter passing. 
It will use less space, be more efficient and safer.
Logically though, you do have an object that is providing the storage 
infrastructure and is acting on other objects. The objects aren't 
storing themselves and their storage isn't their primary function. 
They are delegating that function to another object. So, other than 
the data that the storage engine needs, you don't really need to 
be distributing the code for storage throughout the data to be stored, 
unless these objects need per-object-specific serialization and versioning 
algorithms.


All the dynamic context manipulations cal be done by your storage 
engine working on the objects to be stored as data - they really 
are anyways.
Robert
1-May-2006
[4285x2]
Ok, I have tested some ways. The bind solution is nice but has the 
disadvantage, that I can't handle more than one currenct storage-context.
So, back to setting the storage-context and than all functions work 
on this context.
Ladislav
1-May-2006
[4287x2]
Anton: "
>> ctx-A: context [a: 60]
>> my-func: func [][a: 5]
>> blk: [] append blk second :my-func
== [a: 5]
>> bind blk ctx-A
== [a: 5]
>> ?? ctx-A
ctx-A: make object! [
    a: 60
]
>> my-func
== 5
>> ?? ctx-A
ctx-A: make object! [
    a: 60
]


 - you would have to change it to:

ctx-A: context [a: 60]
my-func: 
 func [][a: 5]
blk: [] append/only blk second :my-func
bind blk ctx-A
?? 
 ctx-A
my-func ; == 5
?? ctx-A
:-)
Anton
2-May-2006
[4289]
Ah yes, that would leave the block as is, instead of "unwrapping" 
it, which surprisingly unbinds the words.
Gabriele
2-May-2006
[4290x2]
unwrapping does not unbind; unwrapping copies.
that is, b: [] append b block   and b: copy block   are basically 
the same thing
Anton
2-May-2006
[4292]
Oh ok. So more specifically, the insert copies the words, but not 
their binding.
Ladislav
2-May-2006
[4293x2]
insert copies words *and* their binding of course
your problem is, that if you do 

    bind copy block 'context

the original BLOCK will stay unaffected
Anton
2-May-2006
[4295]
Ah of course! What am I thinking.!  So yes, as Gabriele said, my 
confusion was in not understanding that the words were copied.
Henrik
6-May-2006
[4296]
does make-dir/deep not work on FTP sites?
Anton
7-May-2006
[4297x2]
No, and it caused me grief. But there is help at hand !  I patched 
make-dir to support FTP.
Use the first definition, second one still has issues.
http://home.wilddsl.net.au/anton/rebol/patch/make-dir-patch.r
Henrik
7-May-2006
[4299x2]
I think it works. Thanks.
is this patch submitted to RAMBO?
Anton
7-May-2006
[4301]
No.  I think I didn't think I still wanted to think about it, perhaps 
finding a better way as the second function is attempting to do.
Gabriele
8-May-2006
[4302]
i think there are issues with ftp as a url path is not guaranteed 
to match the file system path
Sunanda
8-May-2006
[4303]
A URL path is _supposed_ to map to the file system path _if_ the 
scheme is ftp://
/
 has no assumed hierachical meaning in other URL schemes.
Hence the confusion at times.

I think REBOL is playing safe in not assuming the mapping. And, given 
how badly many FTP clients are written, that is probably for the 
best.
Louis
8-May-2006
[4304]
How can I change the smtp port to 26?
Graham
8-May-2006
[4305]
install the protocol on port 26
Louis
8-May-2006
[4306]
How?  :>)
Graham
8-May-2006
[4307]
http://www.rebol.com/docs/core23/rebolcore-13.html- on how to use 
the port specification directly.
Louis
8-May-2006
[4308x2]
I don't find what you are referring to.  I've tried this:

system/schemes/smtp/port-id: 26


But either that is incorrect or else something else is the problem.
This doesn't work either:

smtp: open/lines tcp://bible-way.org:26
Graham
8-May-2006
[4310x3]
It should do.
then you can query the smtp directly.
Try 

insert smtp "HELO Louis-here"
probe copy smtp
and you should see a response
or not ...