[REBOL] Re: why doesn't this work?
From: jkinraid:clear at: 15-Mar-2001 15:50
Hi Jeff,
> write %params.txt {param1: false}
> params: make object! to-block read %params.txt
>
> returns: ** Script Error: false is not defined in this
> context.
> ** Where: param1: false
>
> this does work:
> params: make object! [param1: false]
>
> -- as you'd expect
>
> and this works too:
>
> write %params.txt {param1: "text"}
> params: make object! to-block read %params.txt
>
> And that's what's baffling me.
>
> I'd like to store parameters in a file outside of my
> code. I'd like to use an object inside the code to
> hold the parameters. If I create the object inside
> the code - then read the parameter file stored on disk
> and over-write any values in the default parameter
> object, it allows the user to overwrite only some
> parameters.
>
> So - why is a boolean value not ok in this context?
> Any clues anyone?
When you do a to-block on a string, the resulting block isn't bound to
any context.
>> do to-block "{abcd}"
== "abcd"
>> do to-block "true"
** Script Error: true is not defined in this context
** Near: true
A string doesn't need to be bound to a context, so it works fine.
However, a word needs a context, and there isn't one. Let's make one.
another-context: make object! [true: "not false"]
blk: to-block "true"
do bind blk in another-context 'true
== "not false"
; blk is bound to a context where the value of true is the string
; "not false"
>> do blk
== "not false"
>> :blk
== [true]
; Now change blk to use the global context
>> do bind blk 'true
== true
The load function will automatically convert your string into a block,
*and* bind it to the global context.
>> do load "true"
== true
>> params: make object! load {param1: false}
>> params/param1
== false
Julian Kinraid