Page 1 of 1

context? error with default function

Posted: Sat May 17, 2008 2:12 am
by Tim Johnson
I have a context called 'cgi and a default function as in

Code: Select all

(define (cgi:cgi) ;....
  )
Another function in this context executes the following:

Code: Select all

(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

Code: Select all

context expected in function context? : cgi:cgi
Is there a way around this?
thanks
Tim

Posted: Sat May 17, 2008 2:33 am
by rickyboy
Tim,

I'm not an expert, but when I try to mock up some code for this, I get a different error message, namely:

Code: Select all

ERR: string expected in function context? : key
When I quote key in the context? expression, the error message goes away.

Code: Select all

(if (not (context? cgi "key")) (raise "Bad dog!"))
Hope this helps. --Rick

Posted: Sat May 17, 2008 2:45 am
by rickyboy
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.

Posted: Sat May 17, 2008 2:51 am
by Tim Johnson
In my code, the symbol 'key has already been coerced to a string.
Thanks
Tim

Posted: Sat May 17, 2008 2:55 am
by Tim Johnson
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

Posted: Sat May 17, 2008 8:47 am
by cormullion
The manual seems to imply that you have to use a string:
(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:

Code: Select all

(if (not (context? cgi (string key)))
   ... 

Posted: Sat May 17, 2008 12:26 pm
by Lutz
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".

Code: Select all

(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"
> 

Posted: Sat May 17, 2008 6:57 pm
by Tim Johnson
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