Members of the Forum:

what with resolving, for myself for the time being, the issue of
using the global variable USERFOLDERS in conjunction with PUBLIC
to make it easy to load my own code in a portable fashion, e.g.
I use something like

load 'mycode'

which gets looked up in the first column of PUBLIC_j_ and resolved
to, e.g. '~User/code/mycode.ijs' by the second column, which is
further resolved to a specific path via USERFOLDERS.

Maybe this is too elaborate.

Anyway, re-thinking these issues leads me to look at my code and
notice I load my own "startup.ijs" in addition to my own "config.ijs":
this definitely seems too elaborate as most of startup is, in
fact, configuration routines.

Now that I've pared down startup to only those things I want to
do when I start up that aren't configuration, almost the only code
left is a function I wrote to avoid problems with an endless loop
loading scripts. That is, if I have a script "endlessLoopLoad1.ijs"
which looks like this:

 NB.* endlessLoopLoad1.ijs: demonstrate problem with endless-loop loading.
 load '~User\code\endlessLoopLoad2.ijs'
 smoutput 'Done loading endlessLoopLoad1.ijs.'

and "endlessLoopLoad2.ijs" like this:

 NB.* endlessLoopLoad2.ijs: demonstrate problem with endless-loop loading.
 load '~User\code\endlessLoopLoad1.ijs'
 smoutput 'Done loading endlessLoopLoad2.ijs.'

I get a "stack error" when I try to load one or the other.
Using "require" instead of "load" does not solve the problem.

This is a rare problem but it comes up when I have a lot of
small utility libraries that require functions from each other -
eventually I may inadvertently introduce a loop.

I have a way of dealing with this but it seems rather problematic
and I was wondering if anyone else has come across this problem
and dealt with it more neatly.

My solution is to insert something like the following in a known
troublemaker:

addScriptName2List jpath '~User\code\endlessLoopLoad1.ijs'

where "addScriptName2List" updates the global "LOADED_j_" with the
name of the current script. "LOADED_j_" is the existing global
used to check if a script has already been loaded.

The problem is, it (correctly) only gets updated on completion
of the load and this is too late to prevent the endless loop.

The problem with my fix is that I have to keep the fully-pathed
name of a script inside itself in order to properly update
LOADED. This isn't too onerous - at least it remains fairly
portable given that I define my own USERFOLDERS - but I'm
wondering if anyone else has solved this differently.

Thanks,

Devon
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to