diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-08-05 12:20:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-05 12:20:40 +0100 |
| commit | 05aee9e5d10b3a224a75ac15302adc64b029057a (patch) | |
| tree | 7e0fb19eff51572192a8684cc7f503da21f83eda | |
| parent | b7551a4c5b9171e92f99bd7c733e4176bfcaba88 (diff) | |
| parent | 60aa771d39fb5ee8d49a78555786a53ab1e194ff (diff) | |
| download | perlweeklychallenge-club-05aee9e5d10b3a224a75ac15302adc64b029057a.tar.gz perlweeklychallenge-club-05aee9e5d10b3a224a75ac15302adc64b029057a.tar.bz2 perlweeklychallenge-club-05aee9e5d10b3a224a75ac15302adc64b029057a.zip | |
Merge pull request #2040 from jeongoon/ch-072
add a solution of common-lisp for task 2
| -rw-r--r-- | challenge-072/jeongoon/common-lisp/ch-2.lsp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-072/jeongoon/common-lisp/ch-2.lsp b/challenge-072/jeongoon/common-lisp/ch-2.lsp new file mode 100644 index 0000000000..c1e960d8fd --- /dev/null +++ b/challenge-072/jeongoon/common-lisp/ch-2.lsp @@ -0,0 +1,51 @@ +;; Ref: +;; http://www.gigamonkeys.com/book/files-and-file-io.html +;; http://cl-cookbook.sourceforge.net/files.html#open +;; http://www.ai.sri.com/pkarp/loop.html + +(defun get-command-line () + (or + #+CLISP *args* + #+SBCL *posix-argv* + #+LISPWORKS system:*line-arguments-list* + #+CMU extensions:*command-line-words* + nil)) + +(defparameter *cmdline* (get-command-line)) + +(defun print-usage () + (format t "Usage: sbcl --script ch-2.lsp <file-path> <from> <to>~%" (car *cmdline*))) + +(when (not (= (length *cmdline*) 4)) ;; not 3 + (format t "Wrong Number of arguments got ~d: not 3~%" (length *cmdline*)) + (print-usage) + (quit)) + +(defparameter *file-path* (nth 1 *cmdline*)) +(defparameter *from* (parse-integer (nth 2 *cmdline*))) +(defparameter *to* (parse-integer (nth 3 *cmdline*))) + +(when (not (probe-file *file-path*)) + (format t "Could not read the file ~a~%" *file-path*) + (quit)) + +(when (not (and (numberp *from*) (numberp *to*))) + (format t "given numbers are not in the range: from ~a, to ~a" *from* *to*) + (quit)) + +(format t "[INF] File: ~a: from: ~d to: ~d~%" *file-path* *from* *to*) + +(with-open-file + (in *file-path* :if-does-not-exist nil) ;; return nil instead of error + (loop for line = (read-line in nil) + for cnt from 1 ;; cool auto counter + + while line do ;; I don't know whay parenthesis is not used here. + ;; look like a macro for something + (progn + (when (and (<= *from* cnt) (<= cnt *to*)) + (format t "~a~%" line)) + (when (= cnt *to*) + (format t "[INF] Done.~%") + (return "[done]")) + (setq cnt (+ 1 cnt))))) |
