Programmatically access module/filename in Factor?

92 Views Asked by At

The program name specified in command line usage, e.g. "Usage: rot13.factor [OPTIONS]".

Erlang has a macro called ?FILE to access the source code's own filename. Does Factor have something similar?

Rosetta Code

1

There are 1 best solutions below

0
On BEST ANSWER

Factor's command-line vocabulary has a word script which either returns the script name or f when Factor is in interpreted mode.

#! /usr/bin/env factor

USING: namespaces io command-line ;
IN: scriptname

: main ( -- ) script get print ;

MAIN: main

Example:

$ ./scriptname.factor 
Program: ./scriptname.factor

$ factor
( scratchpad ) USING: command-line ;
( scratchpad ) script get .
f