Solved sbcl: retrieving the script name

Suppose I have a file named 1.sb with this content:
Code:
#!/usr/local/bin/sbcl --script

(prin1 sb-ext:*posix-argv*) (terpri)
If I invoke it as 1.sb a b c I get this output:
Code:
("/usr/local/bin/sbcl" "a" "b" "c")
How do I get the name of the script file itself (1.sb)?

(I got no takers on stackoverflow for this question.)
 
Never done anything with LISP so I'm just shooting in the dark. But you're printing the whole ARGV array and the first value of that array is the name of the script. As I don't know LISP I have no idea how to address a single, indexed, value from an array.

I'm also suspecting the --script option basically causes an exec(1) which results in the sbcl executable taking over execution (and ends up being the process' $0).
 
It turns out that for sbcl, a correct (at least as far as I can tell) lightweight solution would be as in this script:
Code:
#!/usr/local/bin/sbcl --script

(prin1 (apply #'concatenate 'string
         (remove-if #'null
           (list (pathname-name *load-truename*)
                 (when (pathname-type *load-truename*)
                   ".")
                 (pathname-type *load-truename*))))) (terpri)
(I have given credit to user tobik for the *load-truename* suggestion when posting this solution to stackoverflow.)
 
Back
Top