문제

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

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top