newLISP Fan Club

Forum => newLISP in the real world => Topic started by: Tim Johnson on March 24, 2010, 06:34:16 PM

Title: Hash functions within a context do not see context members
Post by: Tim Johnson on March 24, 2010, 06:34:16 PM
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
Title: Re: Hash functions within a context do not see context members
Post by: Lutz on March 25, 2010, 04:41:25 AM
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
Title: Re: Hash functions within a context do not see context members
Post by: Tim Johnson on March 25, 2010, 08:40:58 AM
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