-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore.lisp
687 lines (569 loc) · 25 KB
/
core.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
;;;; Last modified: 2013-10-15 18:54:49 tkych
;; lisp-dojo/core.lisp
;; Copyright (c) 2013 Takaya OCHIAI <[email protected]>
;; This file is released under the MIT License.
;; For more details, see lisp-dojo/LICENSE
;; TODO:
;; -----
;; * once-only print promotion message
;; * .dojo -> your-solutions/.dojo
;; BUG:
;; ----
;; * ./lisp-dojo check <not-generated-yet-id> => error
;;====================================================================
;; Lisp-Dojo: core
;;====================================================================
(in-package :cl-user)
(defpackage #:lisp-dojo (:use :cl))
(in-package #:lisp-dojo)
;;--------------------------------------------------------------------
;; Utils
;;--------------------------------------------------------------------
(defmacro with-gensyms (syms &body body)
`(let ,(mapcar (lambda (s)
`(,s (gensym ,(concatenate 'string (string s) "-"))))
syms)
,@body))
(defun strip (string)
(string-trim '(#\Newline) string))
;; (substitute-char-to-string #\a "####" "adsfadsf") => "####dsf####dsf"
;; as ppcre:regex-replace-all alternative
(defun substitute-char-to-string (old-char new-string target-string)
(with-output-to-string (s)
(loop
:for start := 0 :then (1+ pos)
:for pos := (position old-char target-string :start start :test #'char=)
:until (null pos)
:do (format s "~A~A" (subseq target-string start pos) new-string)
:finally (princ (subseq target-string start) s))))
(defmacro dispatch-string (keyform &body clauses)
"Same as CASE, except that the test function is #'STRING=."
(with-gensyms (evaled-keyform)
`(let ((,evaled-keyform ,keyform))
(declare (ignorable ,evaled-keyform))
(cond ,@(loop
:for (keys . form) :in clauses
:collect
(cond ((or (eq keys t) (eq keys 'otherwise))
`(t ,@form))
((stringp keys)
`((string= ,keys ,evaled-keyform) ,@form))
((listp keys)
(if (null (cdr keys))
`((string= ,(car keys) ,evaled-keyform)
,@form)
`((or ,@(loop
:for k :in keys
:collect
`(string= ,k ,evaled-keyform)))
,@form)))))))))
(defun generate-rfc3339-date-time-string (&optional (sep #\T))
(multiple-value-bind
(sec min hour date month year day daylight-p zone) (get-decoded-time)
(declare (ignore day daylight-p))
(multiple-value-bind
(zone-hour zone-min) (floor (abs zone))
(setf zone-min (* zone-min 60))
(format nil "~4,'0D-~2,'0D-~2,'0D~A~2,'0D:~2,'0D:~2,'0D~A~2,'0D:~2,'0D"
year month date sep hour min sec
(if (plusp zone) #\- #\+)
zone-hour zone-min))))
(defstruct (<lazy> (:constructor make-lazy)
(:conc-name lazy-))
body
forced-p)
(defmacro be-lazy (&body body)
`(make-lazy :body (lambda () ,@body)
:forced-p nil))
(defun force (object)
(if (typep object '<lazy>)
(if (lazy-forced-p object)
(lazy-body object)
(setf (lazy-forced-p object) t
(lazy-body object) (funcall (lazy-body object))))
object))
(defmacro with-print-downcase-symbols (&body body)
`(let ((*print-case* :downcase))
,@body))
;;--------------------------------------------------------------------
;; Special Variables
;;--------------------------------------------------------------------
(defparameter *practices-directory* "practices")
(defparameter *solutions-directory* "your-solutions")
(defparameter *total-num-practices* 34)
(defparameter *promotion-rate* 10)
(defparameter *belts*
#("white-belt"
"red-belt"
"green-belt"
"orenge-belt"
"yellow-belt"
"blue-belt"
"indigo-belt"
"violet-belt"
"black-belt"
;; secret-dojo
;; "Master-of-Wind"
;; "Master-of-Forest"
;; "Master-of-Fire"
;; "Master-of-Mountain"
;; "Master-of-Shadow"
;; "Master-of-Thunder"
))
(defvar *current-practice* nil)
(defvar *progress* 0)
(defparameter *under-construction-message*
"Sorry, documentation is under construction.")
;;--------------------------------------------------------------------
;; Practices
;;--------------------------------------------------------------------
(defclass <practice> ()
((id :type (integer 0 *) :reader get-id :initarg :id)
(name :type symbol :reader get-name :initarg :name)
(level :type (integer 0 3) :reader get-level :initarg :level)
(problem :type string :reader get-problem :initarg :problem)
(hint :type (or null string) :reader get-hint :initarg :hint)
(test-env :type (or null <lazy>) :reader get-test-env :initarg :test-env)
(test-fn :type <lazy> :reader get-test-fn :initarg :test-fn)
(solutions :type (or null string) :reader get-solutions :initarg :solutions)
(reference :type (or null string) :reader get-reference :initarg :reference)))
(defmacro define-practice (&key id name level problem hint
solutions test-env test reference)
`(setf *current-practice*
(make-instance '<practice>
:id ,id
:name ',name
:level ,level
:problem ,problem
:hint ,hint
:test-env ,(when test-env
`(generate-test-env ,test-env))
:test-fn (generate-test-fn ,@test)
:reference ,reference
:solutions ,solutions)))
;;--------------------------------------------------------------------
;; Eval-Tests
;;--------------------------------------------------------------------
(defmacro =>? (expr want)
(if (and (listp want) (eq (first want) :values))
;; 0. Multiple values case
(with-gensyms (eval-test want-values evaled-values result)
`(be-lazy
(with-print-downcase-symbols
(block ,eval-test
(let* ((,want-values ',(rest want))
(,evaled-values
(handler-case (multiple-value-list ,expr)
(error (condition)
(return-from ,eval-test
(format t "~&[31mFAIL ... ~S =>? ~{~S~^, ~} ... =>[0m [33m~@:(~A~)[0m~%"
',expr ,want-values (type-of condition))))))
(,result (equal ,evaled-values ,want-values)))
(if ,result
(format t "~&[32mPASS ... ~S => ~{~S~^, ~}[0m~%"
',expr ,want-values)
(format t "~&[31mFAIL ... ~S =>? ~{~S~^, ~} ... => ~{~S~^, ~}[0m~%"
',expr ,want-values ,evaled-values))
,result)))))
;; 1. Single value case
(with-gensyms (eval-test evaled result)
`(be-lazy
(with-print-downcase-symbols
(block ,eval-test
(let* ((,evaled
(handler-case ,expr
(error (condition)
(return-from ,eval-test
(format t "~&[31mFAIL ... ~S =>? ~S ... =>[0m [33m~@:(~A~)[0m~%"
',expr ',want (type-of condition))))))
(,result (equal ,evaled ',want)))
(if ,result
(format t "~&[32mPASS ... ~S => ~S[0m~%"
',expr ',want)
(format t "~&[31mFAIL ... ~S =>? ~S ... => ~S[0m~%"
',expr ',want ,evaled))
,result)))))))
(defmacro <=>? (expr want)
(with-gensyms (eval-test want-values evaled-values result)
`(be-lazy
(with-print-downcase-symbols
(block ,eval-test
(let* ((,want-values (multiple-value-list ,want))
(,evaled-values
(handler-case (multiple-value-list ,expr)
(error (condition)
(return-from ,eval-test
(format t "~&[31mFAIL ... ~S =>? ~{~S~^, ~} ... =>[0m [33m~@:(~A~)[0m~%"
',expr ,want-values (type-of condition))))))
(,result (equal ,evaled-values ,want-values)))
(if ,result
(format t "~&[32mPASS ... ~S => ~{~S~^, ~}[0m~%"
',expr ,want-values)
(format t "~&[31mFAIL ... ~S =>? ~{~S~^, ~} ... => ~{~S~^, ~}[0m~%"
',expr ,want-values ,evaled-values))
,result))))))
(defmacro =>error? (expr)
(with-gensyms (errored evaled condition result)
`(be-lazy
(with-print-downcase-symbols
(multiple-value-bind (,evaled ,condition)
(handler-case
(values ,expr NIL)
(error (c) (values ',errored c)))
(let ((,result (equal ,evaled ',errored)))
(if ,result
(format t "~&[32mPASS ... ~S =>[0m [33m~@:(~A~)[0m~%"
',expr (type-of ,condition))
(format t "~&[31mFAIL ... ~S =>?[0m [33mERROR[0m [31m... => ~S[0m~%"
',expr ,evaled))
,result))))))
(defun generate-test-fn (&rest tests)
(be-lazy
(loop
:for test :in tests
:collect (force test) :into result
:finally (return (every #'identity result)))))
(defmacro generate-test-env (exprs)
`(be-lazy
,@exprs
(with-print-downcase-symbols
,@(loop :for expr :in exprs
:collect `(format t "~&ENV ... ~A~%" ',expr)))))
;;--------------------------------------------------------------------
;; Progress
;;--------------------------------------------------------------------
;; 42 (<=> #b101010) ~ {1 3 5}
(defun overcome-practice (id)
(setf *progress* (logior *progress* (ash 2 (1- id)))))
(defun overcamep (id)
(logbitp id *progress*))
(defun get-num-overcame ()
(logcount *progress*))
(defun promotep ()
(zerop (mod (1- (get-num-overcame)) *promotion-rate*)))
(defun get-current-belt ()
(svref *belts* (floor (get-num-overcame) *promotion-rate*)))
;;--------------------------------------------------------------------
;; File I/O
;;--------------------------------------------------------------------
(defun make-practice-filespec (id)
(format nil "~A/~3,'0D.lisp" *practices-directory* id))
(defun make-solution-filespec (id name)
(format nil "~A/~3,'0D-~(~A~).lisp" *solutions-directory* id name))
(defmacro with-quiet-error-output (&body body)
`(let ((*error-output*
(make-two-way-stream (make-concatenated-stream)
(make-broadcast-stream))))
,@body))
;; MEMO: 2013-10-12
;; load's verbose default is the value of *load-verbose*.
;; The initial value of *load-verbose* is implementation-dependent.
;; c.f. CLHS, Function LOAD, Variable *LOAD-VERBOSE*
(defun load-practice (id)
(with-quiet-error-output
(load (make-practice-filespec id) :verbose nil)))
;; for DBG
;; (defun load-practice (id)
;; (load (make-practice-filespec id) :verbose nil))
(defun load-solution (id name)
(with-quiet-error-output
(load (make-solution-filespec id name) :verbose nil)))
(defun read-dot-dojo ()
(if (not (probe-file #p".dojo"))
;; If dot-dojo file is missing, we count progress 0.
;; A new dot-dojo file will generate when function
;; WRITE-DOTO-DOJO is called.
(setf *progress* 0)
(with-open-file (in #p".dojo")
(let ((progress (read in)))
(if (integerp progress)
(setf *progress* progress)
(error "~S is unknown dot-dojo format." progress))))))
;; TODO: once-only print promotion message
;; (defvar *promotion* 0)
;; (defun read-dot-dojo ()
;; (if (not (probe-file #p".dojo"))
;; ;; If dot-dojo file is missing, we count progress 0.
;; ;; A new dot-dojo file will generate when function
;; ;; WRITE-DOTO-DOJO is called.
;; (setf *progress* 0)
;; (with-open-file (in #p".dojo")
;; (aif (integerp (read in))
;; (setf *progress* it)
;; (error "~S is unknown dot-dojo format." it))
;; (aif (integerp (read in))
;; (setf *promotion* it)
;; (error "~S is unknown dot-dojo format." it)))))
(defun write-dot-dojo ()
(with-open-file (out #p".dojo" :direction :output
:if-exists :supersede
:if-does-not-exist :create)
(write *progress* :stream out)))
(defun generate-practice-title (id name level)
(format nil "~D. ~A~A~A" id name
(if (zerop level) "" " ")
(make-string level :initial-element #\*)))
(defun make-solution-file (id)
(load-practice id)
(with-slots (name problem level) *current-practice*
(let ((solution-filespec (make-solution-filespec id name)))
(with-open-file (out solution-filespec
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(format out ";;;; Created: ~A lisp-dojo~%"
(generate-rfc3339-date-time-string #\Space))
(format out "
;;====================================================================
;; ~A
;;====================================================================
;; ~A
;;--------------------------------------------------------------------
;;====================================================================
"
(generate-practice-title id name level)
(substitute-char-to-string #\Newline "
;; " problem))
(format t "New solution file generated: ~A~%" solution-filespec)))))
;;--------------------------------------------------------------------
;; Print
;;--------------------------------------------------------------------
(defparameter *lisp-road*
" __ __ __
_ \\_\\ _\\ \\_/ /_
| | _ ____ _____ _____ |_________|
| | |_| / __ \\ | __ \\ \\_ _\\ _/ /_
| | _ \\ \\ \\_\\ | | \\ | \\ \\ ||___||
| | | | __ \\ \\ | |__/ | | | ||___||
| |______ | | \\ \\_\\ \\ | ___/ / / _ ||___|| __
|________| |_| \\____/ | | / /_/ \\||___||_/ /
|_| \\___/-\\_________/
--- The Road Leads to The Lisp Master")
(defparameter *completion*
"
[1;32m\\o/[0m
[1;32m__ __ __[0m [1;32m|[0m [1;31;1m___[0m
[1;36m _ [0m [1;32m\\_\\ _\\ \\_/ /_[0m [1;37m__[0m[1;32m/[0m[1;37m_[0m[1;32m\\[0m[1;37m__[0m [1;31;1m/ \\[0m
[1;36m| |[0m [1;35m _ [0m [1;33m ____ [0m [1;31m_____[0m [1;32m_____ |_________|[0m [1;37m/ \\[0m [1;31;1m\\___/[0m
[1;36m| |[0m [1;35m|_|[0m [1;33m/ __ \\[0m [1;31m| __ \\ [0m [1;32m\\_ _\\ _/ /_[0m [1;37m/ \\[0m
[1;36m| |[0m [1;35m _ [0m [1;33m\\ \\ \\_\\[0m [1;31m| | \\ |[0m[1;32m \\ \\ ||___||[0m [1;34m/[0m[1;37m\\ /\\ /\\ /[0m[1;34m\\[0m
[1;36m| |[0m [1;35m| |[0m [1;33m__ \\ \\ [0m [1;31m| |__/ |[0m [1;32m| | ||___||[0m [1;34m/[0m [1;37m\\/ \\/ \\/[0m [1;34m\\[0m
[1;36m| |______ [0m [1;35m| |[0m [1;33m\\ \\_\\ \\[0m [1;31m| ___/[0m [1;32m/ / _ ||___|| __[0m [1;34m/ \\[0m
[1;36m|________|[0m [1;35m|_|[0m [1;33m\\____/[0m [1;31m| |[0m [1;32m/ /_/ \\||___||_/ /[0m [1;34m/ \\[0m
[1;31m|_|[0m [1;32m\\___/-\\_________/[0m [1;34m/ \\[0m
--- Genius is a little boy chasing a butterfly up a mountain.
")
(defun print-success-message (id name)
(format t "[1;32mAll Tests Passed -- Challenge next practice in ~A[0m~%"
(make-solution-filespec id name)))
(defun print-fail-message (id name)
(format t "[1;31mSome Tests Failed --- Try again this practice in ~A[0m~%"
(make-solution-filespec id name)))
(defun get-progress-bars ()
(let* ((bar (replace
(make-string *total-num-practices* :initial-element #\_)
(substitute #\* #\1
(substitute #\_ #\0
(nreverse (format nil "~B" *progress*))))))
(len (length bar)))
(loop :for start :from 0 :by 70
:for end := (min len (+ start 70))
:until (< *total-num-practices* start)
:append (list (subseq bar start end)
(with-output-to-string (s)
(loop :for i :from start :below end
:do (multiple-value-bind (f r) (floor (1+ i) 10)
(if (zerop r)
(princ f s)
(princ #\Space s)))))))))
(defun print-progress ()
(format t "~&~@:(~A~): ~D~%"
(get-current-belt) (get-num-overcame))
(format t "~&~{~A~^~%~}" (get-progress-bars)))
;; "Love the lisp you live. Live the lisp you love."
(defparameter *promotion-massage*
#("A cat has nine lisps." ;dummy
"A journey of a thousand miles begins with a single step." ;white-belt
"There is no royal road to learning lisp." ;red-belt
"At the touch of lisp, everyone becomes a poet." ;green-belt
"Thou shouldst eat to lisp; not lisp to eat." ;yellow-belt
"Gravitation can not be held responsible for people falling in lisp." ;orenge-belt
"My lisp didn't please me, so I created my lisp." ;blue-belt
"Lisp willingly becomes what they wish." ;indigo-belt
"What is hell? I maintain that it is the suffering of being unable to lisp." ;violet-belt
"All roads lead to the lisp." ;black-belt
;; secret-dojo
;; http://classics.mit.edu/Tzu/artwar.html, 7.17-19
;; http://www.gutenberg.org/ebooks/132
;; Let your rapidity be that of the wind, your compactness that of the forest.
;; In raiding and plundering be like fire, is immovability like a mountain.
;; Let your plans be dark and impenetrable as night, and when you move, fall like a thunderbolt.
;; "Master-of-Wind"
;; "Master-of-Forest"
;; "Master-of-Fire"
;; "Master-of-Mountain"
;; "Master-of-Shadow"
;; "Master-of-Thunder"
))
(defun get-promotion-message ()
(svref *promotion-massage*
(1+ (floor (get-num-overcame) *promotion-rate*))))
(defparameter *colors*
#(37 ;white
31 ;red
32 ;green
33 ;yellow
34 ;blue
35 ;magenta
36 ;cyan
30 ;black
))
(defun get-current-belt-color ()
(svref *colors* (floor (get-num-overcame) *promotion-rate*)))
(defun print-promotion ()
(format t "[1;~Dm~A[0m~%You get a ~@:(~A~)!~% ~S"
(get-current-belt-color) *lisp-road*
(get-current-belt) (get-promotion-message)))
(defun print-completion ()
(format t "~2&Congratulations! You finally accomplished all practices!!")
(princ *completion*))
;;--------------------------------------------------------------------
;; Main
;;--------------------------------------------------------------------
(defun main (command-arguments)
(destructuring-bind (cmd . args) command-arguments
(if (string= cmd "progress")
(output-progress)
(let ((id (parse-integer (first args))))
(dispatch-string cmd
("check" (check-solution id))
("problem" (output-problem id))
("hint" (output-hint id))
("solutions" (output-solutions id))
("reference" (output-reference id))
("new" (make-solution-file id))
(t
(error "~S is unknown command" cmd)))))))
(defun in-practice-package (id)
(let* ((package-name (format nil "LISP-DOJO-~3,'0D" id))
(package (make-package package-name :use '(:cl))))
(import '(define-practice =>? <=>? =>error?) package)
(setf *package* package)))
(defmacro with-in-practice-package (id &body body)
(with-gensyms (current-package)
`(let ((,current-package *package*))
(unwind-protect
(progn
(in-practice-package ,id)
(load-practice ,id)
,@body)
(setf *package* ,current-package)))))
(defun check-solution (id)
(read-dot-dojo)
(with-in-practice-package id
(with-slots (name test-env test-fn) *current-practice*
(load-solution id name)
(force test-env)
;; Check solution
(if (not (force test-fn))
;; Fail case
(print-fail-message id name)
;; Success case
(progn
;; Update dot dojo
(overcome-practice id)
(write-dot-dojo)
(let ((next-id (1+ id)))
(when (<= next-id *total-num-practices*)
(with-in-practice-package next-id
(let ((next-name (get-name *current-practice*)))
(print-success-message next-id next-name)
;; Make next solution file if does not exist.
(unless (probe-file
(make-solution-filespec next-id next-name))
(make-solution-file next-id))))))
;; !! FIXME: once-only print promotion message
;; Print promotion message if it is solved first time.
(when (promotep)
(print-promotion))
(when (< *total-num-practices* (get-num-overcame))
(print-completion))))
(force-output))))
(defun output-problem (id)
(with-in-practice-package id
(with-slots (name level problem) *current-practice*
(let ((title (generate-practice-title id name level)))
(format t "
~A
~A
~A~2%"
title (make-string (1+ (length title)) :initial-element #\-)
(strip problem))
;; Make solution file if does not exist
(unless (probe-file (make-solution-filespec id name))
(princ " ") ;indent for generate-message
(make-solution-file id))
(format t " Write your solution in ~A~%"
(make-solution-filespec id name))))
(force-output)))
(defun output-hint (id)
(with-in-practice-package id
(princ (strip (or (get-hint *current-practice*)
*under-construction-message*)))
(force-output)))
(defun output-solutions (id)
(with-in-practice-package id
(princ (strip (or (get-solutions *current-practice*)
*under-construction-message*)))
(force-output)))
(defun output-reference (id)
(with-in-practice-package id
(princ (strip (or (get-reference *current-practice*)
*under-construction-message*)))
(force-output)))
(defun output-progress ()
(read-dot-dojo)
(print-progress)
(force-output))
;;--------------------------------------------------------------------
;; Run on the Shell
;;--------------------------------------------------------------------
#|
~~ o < Run!!
~~ _ \/|> __
~ / / \ \ ~~
~~ \ _\ _\ / ~~~
~~~ \_______/ ~~
~~ ~~~ ~~~~~ ~
The Birth of Venus
|#
;; Tested: sbcl, clozure, clisp.
;; Not-Tested: gcl, ecl, cmu, allegro, lispworks.
(defun get-command-line-arguments ()
;; http://www.sbcl.org/manual/#Command_002dline-arguments
#+sbcl (rest sb-ext:*posix-argv*)
;; http://ccl.clozure.com/manual/chapter2.5.html
#+clozure ccl:*unprocessed-command-line-arguments*
;; http://www.clisp.org/impnotes/quickstart.html#script-exec
#+clisp ext:*args*
;; http://cubist.cs.washington.edu/~tanimoto/gcl-si.html#SEC11
#+gcl (rest si:*command-args*)
#+ecl (loop :for i :from 1 :below (si:argc) :collect (si:argv i))
;; http://common-lisp.net/project/cmucl/doc/cmu-user/unix.html
#+cmu (rest extensions:*command-line-words*)
;; http://www.franz.com/support/documentation/9.0/doc/operators/system/command-line-arguments.htm
#+allegro (rest (sys:command-line-arguments))
;; http://www.lispworks.com/documentation/lw61/LW/html/lw-1398.htm#36091
#+lispworks (rest sys:*line-arguments-list*)
#-(or sbcl clozure gcl ecl cmu allegro lispworks clisp)
(error "Sorry, not supported for your CL implementation.~
Current supported CL implementations are:
sbcl, clozure, clisp, gcl, ecl, cmu, allegro, lispworks.")
)
;; for DBG
;; (main (get-command-line-arguments))
(handler-case
(main (get-command-line-arguments))
(error (c) (format t "Unexpected error [~S]" (type-of c))))
#+clozure (ccl:quit)
;;====================================================================