On Aug 19, 2011, at 3:51 PM, Andrew Pennebaker wrote:

> The parse-time trick is helpful, but it's not perfect. I'm getting an error:
> 
> Generic word length does not define a method for the source-file class.

Oops, that was a typo on my part. Should be:

<<
USING: accessors io.pathnames namespaces source-files vocabs.loader ; 
file get path>> parent-directory add-vocab-root
>>

Note the "path>>" after file get.

> If you're familiar with Ruby's "require" or Python's "import", they look in 
> the user's current directory, i.e.
> 
> C:\CoolStuff\> python coolstuff.py
> 
> will have Python search in C:\CoolStuff\ for relevant modules.

With "." in .factor-roots, running factor from the command line will have the 
same behavior.

> I hope that your macro does this. I'm trying to import code from 
> scriptedmain.factor into test.factor in such a way that no matter which 
> directory those two files are in, as long as they're in the same directory, 
> factor test.factor would work.
> 
> If this is what the macro does, could Factor do this automatically? I think 
> USE and USING would have to be modified in order for that to work.

That is indeed what the above snippet does, though the imported module 
"scriptedmain" will still need to be placed in 
"scriptedmain/scriptedmain.factor" rather than just "scriptedmain.factor" under 
the script file directory for USING: to find it. The search path is orthogonal 
to USING:/USE:, so you could package the above snippet into a parsing word in 
your .factor-rc:

! in .factor-rc
USING: accessors io.pathnames namespaces source-files vocabs.loader ;

! add a RELATIVE word to the base syntax
IN: syntax
SYNTAX: RELATIVE
    file get path>> parent-directory add-vocab-root ;

You could then use RELATIVE in your script:

! in test.factor
RELATIVE
USING: scriptedmain ;

-Joe

Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to