context? error with default function

Started by Tim Johnson, May 16, 2008, 07:12:15 PM

Previous topic - Next topic

Tim Johnson

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
Programmer since 1987. Unix environment.

rickyboy

#1
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
(λx. x x) (λx. x x)

rickyboy

#2
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.
(λx. x x) (λx. x x)

Tim Johnson

#3
In my code, the symbol 'key has already been coerced to a string.

Thanks

Tim
Programmer since 1987. Unix environment.

Tim Johnson

#4
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
Programmer since 1987. Unix environment.

cormullion

#5
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)))
   ...

Lutz

#6
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"
>

Tim Johnson

#7
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
Programmer since 1987. Unix environment.