Forum OpenACS Q&A: Re: Problems defining procs

Collapse
Posted by Andrew Piskorski on
In other words, I need to dynamically define this proc. But this doesn't work.

You left out perhaps the single most important piece of information: Where are you trying to do this proc definition?

Each thread in Tcl - and in AOLserver - gets its own Tcl interpreter. If you define your proc in a *.tcl page, it will of course get (re)created every single time that page runs, and will always be available while that page is running. Try that and see that it works.

Next, to reduce the innefficiency of recreating the proc on every page load, you should instead try to define your proc in a library at AOLserver startup time, which automatically makes it available to all threads. Whether that is feasible for you depends on why you're trying to dynamically define your proc in the first place. You have a full Tcl interpretor available at AOLserver startup time and can do arbitrary programming, but naturally many of APIs you would use in a connection thread don't make sense to use during server startup and will fail if you call them then.

Collapse
Posted by ultra newb on
I stated several times that I put this proc definition in a "blah-procs" file in a tcl folder. In other words, I put it in a file that is supposed to "auto-run" when the system starts.
Collapse
Posted by Andrew Piskorski on
I stated several times that I put this proc definition in a "blah-procs" file in a tcl folder.

Which is not a way to "dynamically define this proc".

Collapse
Posted by ultra newb on
What's the correct way to do it? (current way seems to be working now)
Collapse
Posted by Jim Lynch on
so the proc has to return a list... that's not a problem, a list is a string. I'm really, really skeptical when you say the proc has to be dynamic; there's a database you can use, are the values you need to return in the database?
Collapse
Posted by ultra newb on
No, the values are in a backend system I wrote in another programming language (a server). These values change from time to time. I'd like to avoid having to change values in the openacs system (front end) when the values on the backend change. I thought the best and cleanest approach was to make a dynamic proc (the memoized approach one person recommended works also).

At any rate, everything is working fine now. The problem (as someone pointed out) was accessing a system proc when there wasn't a connection.