Setting block data
[1/7] from: mike::yaunish::home::com at: 21-Nov-2000 18:22
I am trying the following:
info: [
db [
[ detail "detail one" ]
[ detail "detail two" ]
]
]
set-field: func [ apath [path!] v ] [
do [ to-set-path reduce [ :apath 'detail ] :v ]
]
>> set-field 'info/db/1 "newdata"
== "newdata"
>> info
== [
db [
[detail "detail one"]
[detail "detail two"]
]
]
I was hoping to change the value assigned to info/db/1/detail . Does anyone
have any ideas?
Mike Yaunish
[mike--yaunish--home--com]
[2/7] from: mdb:gci at: 22-Nov-2000 16:19
Hello Mike,
An interesting problem, still got me stumped but i managed to come up
with this partial solution:
set-field: func [a v] [do form reduce [to-set-path a v]]
>> info: [db [[detail "detail one"] [detail "detail two"]]]
== [db [[detail "detail one"] [detail "detail two"]]]
>> set-field "info db 1 detail" 444
== [detail 444]
>> set-field "info db 2 detail" 555
== [detail 555]
>> info
== [db [[detail 444] [detail 555]]]
>>
but only seems to work with numbers and not strings ?
I'm very interested to see if you find a solution.
Mike.
===========================================
I am trying the following:
info: [
db [
[ detail "detail one" ]
[ detail "detail two" ]
]
]
set-field: func [ apath [path!] v ] [
do [ to-set-path reduce [ :apath 'detail ] :v ]
]
>> set-field 'info/db/1 "newdata"
== "newdata"
>> info
== [
db [
[detail "detail one"]
[detail "detail two"]
]
]
I was hoping to change the value assigned to info/db/1/detail . Does
anyone
have any ideas?
Mike Yaunish
[mike--yaunish--home--com]
[3/7] from: al:bri:xtra at: 23-Nov-2000 16:04
Mike wrote:
> I was hoping to change the value assigned to info/db/1/detail. Does anyone
have any ideas?
>> info: [
[ db [
[ [ detail "detail one" ]
[ [ detail "detail two" ]
[ ]
[ ]
== [
db [
[detail "detail one"]
[detail "detail two"]
]
]
>> info/db/1/detail: "Changed information"
== [detail "Changed information"]
>> print mold info
[
db [
[detail "Changed information"]
[detail "detail two"]
]
]
I hope that helps!
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
[4/7] from: arolls:bigpond:au at: 28-Nov-2000 20:18
Hello,
REBOL/View 0.10.38.3.1 31-Oct-2000
This is what I just tried (first two lines just the same).
set-field: func [a v] [do form reduce [to-set-path a v]]
info: [db [[detail "detail one"] [detail "detail two"]]]
set-field "info db 1 detail" #"q"
Goodbye console!?!
Other letters or strings give a script error - "hello" has no value,
#"a" has no value, etc.
A bug? Anyone?
--- That was five days ago, this is now (works):
set-field: func [a v] [form reduce [to-set-path a v]]
info: [db [[detail "detail one"] [detail "detail two"]]]
do set-field "info db 1 detail" {"well hello there"}
>> info
== [db [[detail "well hello there"] [detail "detail two"]]]
b: [I am a block]
do set-field "info db 2 detail" {b}
>> info
== [db [[detail "well hello there"] [detail [I am a block]]]]
do set-field "info db 2 1" {'maTete}
>> info
== [db [[detail "well hello there"] [maTete "two"]]]
I couldn't figure out how to 'bind 'info into the function's context,
so the trick is to have 'set-field return what should be done, then
just 'do it.
-Anton.
[5/7] from: al:bri:xtra at: 28-Nov-2000 22:41
Anton wrote:
> This is what I just tried (first two lines just the same).
>
> set-field: func [a v] [do form reduce [to-set-path a v]]
> info: [db [[detail "detail one"] [detail "detail two"]]]
> set-field "info db 1 detail" #"q"
I don't know what you're trying to do, but isn't this simpler?
>> info: [db [[detail "detail one"] [detail "detail two"]]]
== [db [[detail "detail one"] [detail "detail two"]]]
>> print mold info
[db [[detail "detail one"] [detail "detail two"]]]
>> info/db/1/detail: #"q"
== [detail #"q"]
>> index: 2
== 2
>> info/db/:index/detail: #"q"
== [detail #"q"]
>> print mold info
[db [[detail #"q"] [detail #"q"]]]
I hope that helps!
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[6/7] from: arolls:bigpond:au at: 28-Nov-2000 21:30
Andrew,
The point about this bit was, though it didn't improve on
Michael Berrisford's partial solution (23/11 - "Re: Setting Block Data")
to Mike Yaunish's original problem, it does close down my console
session! Please try it as written, and you may see this.
Is it a bug?
I think Mike Y. originally wanted to build the path dynamically,
(I suppose it could be any length path,)
and change the data within a function.
See the bottom of my previous post to see how I tried that.
Anton.
Andrew Martin wrote:
[7/7] from: ingo:2b1 at: 29-Nov-2000 11:37
Hi Anton,
let's step through it:
REBOL/Core 2.4.37.4.2 30-Oct-2000
Copyright 2000 REBOL Technologies. All rights reserved.
>> ; set some values
>> info: [db [[detail "detail one"] [detail "detail two"]]]
== [db [[detail "detail one"] [detail "detail two"]]]
>> a: "info db 1 detail"
== "info db 1 detail"
>> v: #"q"
== #"q"
; now try what happens
>> probe to-set-path a v
info/db/1/detail:
== #"q"
>> reduce [to-set-path a v]
== [info/db/1/detail: #"q"]
>> form reduce [to-set-path a v]
== "info/db/1/detail: q"
>> do form reduce [to-set-path a v]
; here rebol says goodbye, have you spotted the problem ???
Here the last 3 lines again:
>> form reduce [to-set-path a v]
== "info/db/1/detail: q"
>> do form reduce [to-set-path a v]
; !!! form has formed #"q" to just "q", so when the
; is 'DOne in the next line, the path will be set to
; the value returned by the function 'q which happens
; to shutdown the interpreter ...
; A working version would be:
do bind reduce [to-set-path a v] 'info
; 'do can do the block
; 'bind is needed, so that the block is evaluated in the right
; context ....
; And to write the corresponding function set-path is left to the
; reader (meaning, I don't know how to do it best, either ;-)
I hope that clarifies it a bit ...
kind regards,
Ingo
Once upon a time Anton spoketh thus: