Programmatically access module/filename in Factor?
-
01-01-2021 - |
문제
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?
해결책
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
제휴하지 않습니다 StackOverflow