context? error with default function

Notices and updates
Locked
Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

context? error with default function

Post 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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

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

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post by Tim Johnson »

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

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post 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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post 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)))
   ... 

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post 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

Locked