Skip to content

Instantly share code, notes, and snippets.

@indraniel
Created July 17, 2017 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indraniel/7ddde0804280465a4e92f890dbbf348c to your computer and use it in GitHub Desktop.
Save indraniel/7ddde0804280465a4e92f890dbbf348c to your computer and use it in GitHub Desktop.
An example file reading script with chicken scheme
#!/usr/bin/env csi -ss
;; An example file reading script with chicken scheme
(use extras)
(define (read-it file)
(let ((fh (open-input-file file)))
(let loop((c (read-line fh)))
(if (eof-object? c)
(close-input-port fh)
(begin
(print c)
(loop (read-line fh)))))))
(define (main args)
(define file (if (null? args) '() (car args)))
(if (null? file)
(display "Please supply a file name to read!\n")
(read-it file)))
@markjfisher
Copy link

markjfisher commented Sep 14, 2021

A chicken 5 version on linux (env -S)

#!/usr/bin/env -S csi -ss

;; An example file reading script with chicken scheme

(import scheme (chicken io))

(define (read-it file)
  (let ([fh (open-input-file file)])
    (let loop ([c (read-line fh)])
      (if (eof-object? c)
          (close-input-port fh)
          (begin
            (print c)
            (loop (read-line fh)))))))

(define (main args)
  (let ([file (if (null? args) '() (car args))])
    (if (null? file)
        (display "Please supply a file name to read!\n")
        (read-it file))))

@indraniel
Copy link
Author

@markjfisher : A belated thank you for the chicken 5 update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment