chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SRFI 193 (Command lines) for Chicken


From: Lassi Kortela
Subject: Re: SRFI 193 (Command lines) for Chicken
Date: Sat, 8 Aug 2020 19:20:15 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

Thanks for the hints! Below is a module that works in both 4 and 5.

Should I submit this as an egg?

----------------------------------------------------------------------

(module srfi-193
    (command-line command-name command-args script-file script-directory)

  (import scheme)
  (cond-expand
    (chicken-4
     (import chicken)
     (use files posix))
    (chicken-5
     (import (chicken base) (chicken module) (chicken pathname))
     (import (chicken process-context))))

  ;; Chicken's native parameters: command-line-arguments program-name

  ;;; Fundamental

  (define (script-file)
    (cond-expand
      (chicken-script
       (normalize-pathname
        (let ((file (program-name)))
          (if (absolute-pathname? file) file
              (make-absolute-pathname (current-directory) file)))))
      (else #f)))

  (define command-line
    (make-parameter
     (cond-expand
       ((and csi (not chicken-script)) '(""))
       (else (cons (program-name) (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 (make-pathname (pathname-directory file) "")))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]