Running Scheme from the command line

后端 未结 4 2151
青春惊慌失措
青春惊慌失措 2021-01-01 23:01

How do you run Scheme programs from the terminal in linux(ubuntu)? Also how to accept arguments from the command-line in a Scheme program?

Edit: Im using the DrSc

4条回答
  •  迷失自我
    2021-01-01 23:29

    It is not standardized in the R6RS. There is a recommendation SRFI-22, which some interpreters support. If your interpreter does not support SRFI-22 then it depends on your implementation.

    Below is an example from the SRFI. It assumes your interpreter is a binary named scheme-r5rs. Basically it calls a function named main with a single arg that is a list of command line args.

    #! /usr/bin/env scheme-r5rs
    
    (define (main arguments)
      (for-each display-file (cdr arguments))
      0)
    
    (define (display-file filename)
      (call-with-input-file filename
        (lambda (port)
          (let loop ()
        (let ((thing (read-char port)))
          (if (not (eof-object? thing))
              (begin
            (write-char thing)
            (loop))))))))
    

提交回复
热议问题