I have a context called 'cgi and a default function as in
(define (cgi:cgi) ;....
)
Another function in this context executes the following:
(if (not (context? cgi key))
(raise (append "key: ['" key "] not previously set")))
Where 'raise is another function in the context.
And I get the following error message
context expected in function context? : cgi:cgi
Is there a way around this?
thanks
Tim
Tim,
I'm not an expert, but when I try to mock up some code for this, I get a different error message, namely:
ERR: string expected in function context? : key
When I quote key in the context? expression, the error message goes away.
(if (not (context? cgi "key")) (raise "Bad dog!"))
Hope this helps. --Rick
Oh yes, now I'm getting your error message, Tim. (I had mocked up the functions incorrectly before.)
The good news is that the solution in my last message (expressing "key" as a string constant) still solves the problem.
In my code, the symbol 'key has already been coerced to a string.
Thanks
Tim
You know what? I think there may be a side effect causing this,
and since my wife just informed me that it was my turn to make
dinner, I'm going to abandon this 'til tomorrow. :-)
thanks
and stay tuned
tim
The manual seems to imply that you have to use a string:
Quote
(context? exp str-sym)
[this] syntax checks for the existence of a symbol in a context. The symbol is specified by its name string in str-sym.
Perhaps you can't supply a symbol for evaluation here. Or perhaps you have to coerce it to a string here rather than elsewhere:
(if (not (context? cgi (string key)))
...
Refer to 'cgi' with 'MAIN:cgi'. The function 'cgi:foo' thinks you are referring to 'cig:cgi', because 'cgi' is define as a local symbol in the context 'cgi'. When you say 'MAIN:cgi' you make clear you mean the context cgi. The local symbol 'sgi' is not a context but a lambda function returning "hello".
(context 'cgi)
(set 'var 123)
(define (cgi:cgi) "hello")
(define (foo key)
(if (context? MAIN:cgi key)
(append key " does exist")
"does not exit"))
(context MAIN)
> (cgi:foo "var")
"var does exist"
> (cgi:foo "bar")
"does not exit"
>
Thanks Lutz, I'm afraid I wouldn't have thought of that myself.
Can we then say that any context is part of the 'MAIN context?
Tim