Hash functions within a context do not see context members

Started by Tim Johnson, March 24, 2010, 06:34:16 PM

Previous topic - Next topic

Tim Johnson

I have a solution, but don't fully understand the issue:

I've set up a typehandler/callback using a hash with functions as in

(define typeHandler:typeHandler)
(typeHandler "text"
    (fn (fl val ndxs DS DSndx)
        (letn((ndx (ndxs 0))(ele (fl ndx))
                (attrs(set-attr (list "value" val)(ele 2 1))))
         (setf (DS DSndx ndx 2 1) attrs)
         DS)))

Even though the code above is lexically within a context, the functions defined as members of

the hash do not recognize members of the outer context.

To elaborate, I have to pass the context member DS as the fourth argument to the

(typeHandler "test") lambda and the context member current-DS-index (DSndx)

as the fifth argument.

I can live with that, but I'd welcome comments or whether or not I may be missing

something.

thanks

tim
Programmer since 1987. Unix environment.

Lutz

No sure what you mean. In the following smaller example you can see 'outer-var' recognized:


(define typeHandler:typeHandler)

(set 'outer-var 999)

(typeHandler "text" (fn (x y z) (println x  ":" y ":" z ":" outer-var)))

((typeHandler "text") 1 2 3)

1:2:3:999


and the following with the code inside a context FOO will also work:


(define typeHandler:typeHandler)

(context 'FOO)

(set 'outer-var 999)

(typeHandler "text" (fn (x y z) (println x  ":" y ":" z ":" outer-var)))

(context MAIN)

((typeHandler "text") 1 2 3)

1:2:3:999

Tim Johnson

Quote from: "Lutz"No sure what you mean. In the following smaller example you can see 'outer-var' recognized:

Note that I placed the define for 'typeHander inside of the context.

I moved the define outside of the context and now the hash functions have context scope. I.E. It appears

that the context members are now visible to the type handler functions.

Thanks for the example. That showed me what to do.



cheers

tim
Programmer since 1987. Unix environment.