[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SRFI 193 (Command lines) for Chicken
From: |
Kon Lovett |
Subject: |
Re: SRFI 193 (Command lines) for Chicken |
Date: |
Sat, 8 Aug 2020 06:57:51 -0700 |
i will take a stab at some of these
> On Aug 8, 2020, at 5:14 AM, Lassi Kortela <lassi@lassi.io> wrote:
>
> Hello,
>
> SRFI 193 is in the last-call period before finalization. Here is an
> implementation for Chicken. I'd like to publish it as an egg. The API
> is trivial enough that if you like it, you may want it in core.
>
> The code works as is, but has the following issues:
>
> - It's Chicken 5 only. Could it be easily backported to 4?
yes
>
> - It checks for the magic string "csi" to figure out whether running
> in csi or in a standalone program compiled using csc. The check is
> dodgy; what would be a proper way to do it?
csi adds feature identifiers at runtime:
(http://wiki.call-cc.org/man/5/Module%20(chicken%20platform)#features)
csi always
chicken-script when -ss, -sx, -s, -script
otherwise not the interpreter
(cond-expand
(chicken-script (main (command-line-arguments)) )
(csi (display “run it yourself”) (newline) )
(else (main (command-line-arguments)) ) )
>
> - Pathname handling is not cross-platform. It uses `string-append`
> with "/" to build pathnames, and feeds the result to
> `normalize-pathname` to resolve relative pathnames into absolute.
> How does one get the host platform's directory separator, and would
> there be cleaner ways to write the pathname parts in general?
(make-pathname "foo" “") => "foo/“
(make-pathname "foo” “bar") => “foo/bar“
- while (chicken pathname) knows the separator, it does not export ;-)
>
> Thanks to anyone who can spare a moment to help a noob :)
>
> ;;; ----------------------------------------------------------------------
>
> (module srfi-193
> (command-line command-name command-args script-file script-directory)
>
> (cond-expand
> (chicken-5
> (import scheme (chicken base) (chicken module) (chicken pathname)
> (rename (only (chicken process-context)
> current-directory
> argv command-line-arguments program-name)
> (argv chicken/argv)
> (command-line-arguments chicken/command-line-arguments)
> (program-name chicken/program-name)))))
>
> ;;; Fundamental
>
> ;; csi -script => "filename.scm"
> ;; csi repl => #t
> ;; exe from csc => #f
> (define interpreted
> (let ((arg0 (car (chicken/argv))))
> (and (equal? "csi" (pathname-file arg0))
> (if (equal? "csi" (chicken/program-name)) #t
> (chicken/program-name)))))
>
> (define (script-file)
> (and (string? interpreted)
> (normalize-pathname
> (string-append (current-directory) "/" interpreted))))
>
> (define command-line
> (make-parameter (if (eqv? #t interpreted) '("")
> (cons (or (script-file) (chicken/program-name))
> (chicken/command-line-arguments)))))
>
> ;;; Derived
>
> (define (command-name)
> (let ((file (car (command-line))))
> (and (not (equal? "" file))
> (pathname-file file))))
>
> (define (command-args)
> (cdr (command-line)))
>
> (define (script-directory)
> (let ((file (script-file)))
> (and file (string-append (pathname-directory file) "/")))))
>