Forum OpenACS Development: Re: uplevel with passed variables

Posted by Samer Abukhait on
Suppose that many pages are doing some processes based on 2 (or more) attributes of a passed object.

All Pages accept a parameter object_id and based on the object's attributes it processes something..

My procedure aims to check if the logged member has the right permission on the passed object and set's the object's attributes in the calling page script.

Since many pages share this concept I wanted to modularize it in a procedure.

I tried your suggestion on calling uplevel without passing object_id to the procedure and it doesn't work.

Posted by Benjamin Bytheway on
Why cannot this be done by setting and returning an array of the attributes? The method you've currently described is really an abuse of upvar/uplevel, and should be avoided.

It creates the situation where procs are making assumptions about the callers variable space.  Relying on procs to setup variables for you creates code that is difficult to maintain.  Variables are used that pop up out of nowhere, with no indication who actually set them in the first place.

Upvar and Uplevel have been abused in this project, mainly, I think, to work around shortcomings of tcl that have since been improved/corrected in 8.x.

For proper use of Upvar and Uplevel, see Rob Mayoff's guidelines:

Posted by Andrew Piskorski on
Incidentally, there is never any good reason to abuse upvar, as using it correctly is exceedingly easy, and I would hope, usually obvious. Using uplevel well is perhaps less straightforward and thus, ugly usage more forgivable.

Rob's guidelines above are very good, thanks for that reminder.