runlisp.c, eval.lisp, etc.: Add new `-p' option to `princ' expressions.
[runlisp] / runlisp.1.in
... / ...
CommitLineData
1.\" -*-nroff-*-
2.\"
3.\" Manual for `runlisp'
4.\"
5.\" (c) 2020 Mark Wooding
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of Runlisp, a tool for invoking Common Lisp scripts.
11.\"
12.\" Runlisp is free software: you can redistribute it and/or modify it
13.\" under the terms of the GNU General Public License as published by the
14.\" Free Software Foundation; either version 3 of the License, or (at your
15.\" option) any later version.
16.\"
17.\" Runlisp is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.\" for more details.
21.\"
22.\" You should have received a copy of the GNU General Public License
23.\" along with Runlisp. If not, see <https://www.gnu.org/licenses/>.
24.
25.ie t \{\
26. ds o \(bu
27. if \n(.g \{\
28. fam P
29. ev an-1
30. fam P
31. ev
32. \}
33.\}
34.el \{\
35. ds o o
36.\}
37.
38.de hP
39.IP
40\h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
41..
42.ds .. \&.\|.\|.
43.
44.\"--------------------------------------------------------------------------
45.TH runlisp 1 "2 August 2020" "Mark Wooding"
46.SH NAME
47runlisp \- run Common Lisp programs as scripts
48.
49.\"--------------------------------------------------------------------------
50.SH SYNOPSIS
51.
52.B runlisp
53.RI [ options ]
54.RB [ \-\- ]
55.I script
56.RI [ arguments
57\*(..]
58.br
59.B runlisp
60.RI [ options ]
61.RB [ \-d
62.IR form ]
63.RB [ \-e
64.IR form ]
65.RB [ \-l
66.IR file ]
67.RB [ \-p
68.IR form ]
69.if !t \{\
70.br
71 \c
72.\}
73.RB [ \-\- ]
74.RI [ arguments
75\*(..]
76.PP
77where
78.I options
79is
80.br
81 \c
82.RB [ \-CDEnqv ]
83.RB [ +DEn ]
84.RB [ \-L
85.IB sys , sys , \fR\*(..]
86.if !t \{\
87.br
88 \c
89.\}
90.RB [ \-c
91.IR conf ]
92.RB [ \-o
93.RI [ sect \c
94.BR : ] \c
95.IB var = \c
96.IR value ]
97.
98.\"--------------------------------------------------------------------------
99.SH DESCRIPTION
100.
101The
102.B runlisp
103program has two main functions.
104.hP 1.
105It can be used in a script's
106.RB ` #! '
107line to run a Common Lisp script.
108.hP 2.
109It can be used in build scripts
110to invoke a Common Lisp system,
111e.g., to build a standalone program.
112.
113.SS "Options"
114Options are read from the command line, as usual,
115but also (by default) from the script's second line,
116following a
117.RB ` @RUNLISP: '
118marker: see
119.B Operation
120below for the details.
121.
122.PP
123The options accepted are as follows.
124.
125.TP
126.BR "\-h" ", " "\-\-help"
127Write a synopsis of
128.BR query-runlisp-config 's
129command-line syntax
130and a description of the command-line options
131to standard output
132and immediately exit with status 0.
133.
134.TP
135.BR "\-V" ", " "\-\-version"
136Write
137.BR query-runlisp-config 's
138version number
139to standard output
140and immediately exit with status 0.
141.
142.TP
143.BR "\-D" ", " "\-\-vanilla-image"
144Don't check for a custom Lisp image.
145Usually,
146.B runlisp
147tries to start Lisp systems using a custom image,
148so that they'll start more quickly;
149the
150.RB ` \-D '
151option forces the use of the default `vanilla' image
152provided with the system.
153There's not usually any good reason to prefer the vanilla image,
154except for performance comparisons, or debugging
155.B runlisp
156itself.
157Negate with
158.B +D
159or
160.BR \-\-no-vanilla-image .
161.
162.TP
163.BR "\-E" ", " "\-\-command-line-only"
164Don't read embedded options from the
165second line of the
166.I script
167file.
168Negate with
169.B +E
170or
171.BR \-\-no-command-line-only .
172This has no effect in eval mode.
173which is set at compile time.
174.
175.TP
176.BI "\-L" "\fR, " "\-\-accept-lisp=" sys , sys ,\fR\*(..
177Use one of the named Lisp systems.
178Each
179.I sys
180must name a supported Lisp system;
181the names are separated by a comma
182.RB ` , '
183and/or one or more whitespace characters.
184This option may be given more than once:
185the effect is the same as a single option
186listing all of the systems named, in the same order.
187If a system is named more than once,
188a warning is issued (at verbosity level 1 or higher),
189and all but the first occurrence is ignored.
190.
191.TP
192.BI "\-c" "\fR, " "\-\-config-file=" conf
193Read configuration from
194.IR conf .
195If
196.I conf
197is a directory, then all of the files within
198whose names end with
199.RB ` .conf ',
200are loaded, in ascending lexicographical order;
201otherwise,
202.I conf
203is opened as a file.
204All of the files are expected to be as described in
205.BR runlisp.conf (5).
206.
207.TP
208.BI "\-d" "\fR, " "\-\-dump-expression=" expr
209Evaluate the expression(s)
210.I expr
211and print the resulting value(s)
212to standard output
213(with
214.B *print-escape*
215true, as if by
216.BR prin1 ).
217If a form produces multiple values,
218they are printed on a single line,
219separated by a single space character;
220if a form produces no values at all,
221then nothing is printed \(en not even a newline character.
222This option causes
223.B runlisp
224to execute in
225.I eval
226mode.
227See also
228.RB ` \-p ',
229which prints with
230.B *print-escape*
231false.
232.
233.TP
234.BI "\-e" "\fR, " "\-\-evaluate-expression=" expr
235Evaluate the expression(s)
236.I expr
237and discard the resulting values.
238This option causes
239.B runlisp
240to execute in
241.I eval
242mode.
243.
244.TP
245.BI "\-l" "\fR, " "\-\-load-file=" file
246Read and evaluate forms from the
247.IR file .
248This option causes
249.B runlisp
250to execute in
251.I eval
252mode.
253.
254.TP
255.BR "\-n" ", " "\-\-dry-run"
256Don't actually start the Lisp environment.
257This may be helpful for the curious,
258in conjunction with
259.RB ` \-v '
260to increase the verbosity.
261Negate with
262.B +n
263or
264.BR "\-\-no-dry-run" .
265.
266.TP
267.BI "\-o" "\fR, " "\-\-set-option=\fR[" sect :\fR] var = value
268Assign
269.I value
270to the variable
271.I var
272in configuration section
273.IR sect ,
274or
275.B @CONFIG
276if no section is specified.
277The value is unexpandable,
278and overrides any similarly named setting
279from the configuration file(s).
280.
281.TP
282.BI "\-p" "\fR, " "\-\-print-expression=" expr
283Evaluate the expression(s)
284.I expr
285and print the resulting value(s)
286to standard output
287(with
288.B *print-escape*
289false, as if by
290.BR princ ).
291If a form produces multiple values,
292they are printed on a single line,
293separated by a single space character;
294if a form produces no values at all,
295then nothing is printed \(en not even a newline character.
296This option causes
297.B runlisp
298to execute in
299.I eval
300mode.
301See also
302.RB ` \-d ',
303which prints with
304.B *print-escape*
305true.
306.
307.TP
308.BR "\-q" ", " "\-\-quiet"
309Don't print warning messages.
310This option may be repeated:
311each use reduces verbosity by one step,
312counteracting one
313.RB ` \-v '
314option.
315The default verbosity level is 1,
316which prints only warning measages.
317.
318.TP
319.BR "\-v" ", " "\-\-verbose"
320Print informational or debugging messages.
321This option may be repeated:
322each use increases verbosity by one step,
323counteracting one
324.RB ` \-q '
325option.
326The default verbosity level is 1,
327which prints only warning measages.
328Higher verbosity levels print informational and debugging messages.
329.
330.PP
331The
332.RB ` \-d ',
333.RB ` \-e ',
334.RB ` \-l ',
335and
336.RB ` \-p '
337options may only be given on the command-line itself,
338not following a
339.RB `@ RUNLISP: '
340marker in a script.
341These options may be given multiple times:
342they will be processed in the order given.
343If any of these options is given, then no
344.I script
345name will be parsed;
346instead, use
347.RB ` \-l '
348to load code from files.
349The
350.IR arguments ,
351ppif any,
352are still made available to the evaluated forms and loaded files.
353.
354.SS "Operation"
355The
356.B runlisp
357program behaves as follows.
358.
359.hP 1.
360The first thing it does is parse its command line.
361Options must precede positional arguments,
362though the boundary may be marked explicitly using
363.RB ` \-\- '
364if desired.
365If the command line contains any of
366.RB ` \-d ',
367.RB ` \-e ',
368.RB ` \-l ',
369or
370.RB ` \-p ',
371then
372.B runlisp
373treats all of its positional arguments as
374.I arguments
375to provide to the given forms and files,
376and runs in
377.I eval
378mode;
379otherwise, the first positional argument becomes the
380.I script
381name, the remaining ones become
382.IR arguments ,
383and
384.B runlisp
385runs in
386.I script
387mode.
388.hP 2.
389In
390.I script
391mode,
392.B runlisp
393reads the second line of the script file,
394and checks to see if it contains the string
395.RB ` @RUNLISP: '.
396If so, then the following text is parsed
397for
398.IR "embedded options" ,
399as follows.
400.RS
401.PP
402The text is split into words
403separated by sequences of whitespace characters.
404Whitespace,
405and other special characters,
406can be included in a word by
407.I quoting
408or
409.IR escaping .
410Text between single quotes
411.BR ' \*(.. '
412is included literally, without any further interpretation;
413text between double quotes
414.BR """" \*(.. """"
415is treated literally,
416except that escaping can still be used
417to escape (e.g.) double quotes and the escape character itself.
418Outside of single quotes, a backslash
419.RB ` \e '
420causes the following character to be included in a word
421regardless of its usual meaning.
422(None of this allows a newline character
423to be included in a word:
424this is simply not possible.)
425A word which is
426.RB ` \-\- '
427before processing quoting and escaping
428marks the end of embedded options.
429As a concession to Emacs users,
430if the sequence
431.RB ` \-*\- '
432appears at the start of a word
433before processing quoting and escaping,
434then everything up to and including the next occurrence of
435.RB ` \-*\- '
436is ignored.
437.PP
438The resulting list of words
439is processed as if it held further command-line options.
440Currently, only
441.RB ` \-D '
442and
443.RB ` \-L '
444options are permitted in embedded option lists:
445.RB ` \-h '
446and
447.RB ` \-v '
448are clearly only useful in interactive use;
449setting
450.RB ` \-q '
451or
452.RB ` \-v '
453would just be annoying;
454setting
455.RB ` \-c '
456or
457.RB ` \-o '
458would override the user's command-line settings;
459it's clearly too late to set
460.RB ` \-E ';
461and
462.B runlisp
463is now committed to
464.I script
465mode, so it's too late for
466.RB ` \-d ',
467.RB ` \-e ',
468.RB ` \-l ',
469and
470.RB ` \-p '
471too.
472.PP
473(This feature allows scripts to provide options even if they use
474.BR env (1)
475to find
476.B runlisp
477on the
478.BR PATH ,
479or to provide more than one option,
480since many operating systems pass the text following
481the interpreter name on a
482.RB ` #! '
483line as a single argument, without further splitting it at spaces.)
484.RE
485.
486.hP 3.
487If no
488.RB ` \-c '
489options were given,
490then the default configuration files are read:
491the system configuration from
492.B @etcdir@/runlisp.conf
493and
494.BR @etcdir@/runlisp.d/*.conf ,
495and the user configuration from
496.B ~/.runlisp.conf
497and/or
498.BR ~/.config/runlisp.conf :
499see
500.RB runlisp.conf (5)
501for the details.
502.
503.hP 4.
504The list of
505.I "acceptable Lisp implementations"
506is determined.
507If any
508.RB ` \-L '
509options have been found,
510then the list of acceptable implementations
511consists of all of the implementations mentioned in
512.RB ` \-L '
513options
514in any of the places
515.B runlisp
516looked for options,
517in the order of their first occurrence.
518(If an implementation is named more than once,
519then
520.B runlisp
521prints a warning to stderr
522and ignores all but the first occurrence.)
523If no
524.RB ` \-L '
525option is given, then
526.B runlisp
527uses a default list,
528which consists of all of the Lisp implementations
529defined in its configuration,
530in the order in which they were defined.
531.
532.hP 5.
533The list of
534.I "preferred Lisp implementations"
535is determined.
536If the environment variable
537.B RUNLISP_PREFER
538is set,
539then its value should be a list of names of Lisp implementations
540separated by a comma and/or one or more whitespace characters.
541Otherwise, if there is a setting for the variable
542.B prefer
543in the
544.B @CONFIG
545configuration section,
546then its (expanded) value should be a list of Lisp implementations,
547in the same way.
548Otherwise, the list of preferred implementations is empty.
549.
550.hP 6.
551If
552.B runlisp
553is running in
554.I eval
555mode, then a new command line is built,
556which invokes an internal script,
557instructing it to evaluate and print the requested expressions,
558and load the requested files.
559.
560.hP 7.
561Acceptable Lisp implementations are tried in turn.
562First, the preferred implementations
563which are also listed as acceptable implementations
564are tried, in the order in which they appear
565in the preferred implementations list;
566then, the remaining acceptable implementations are tried
567in the order in which they appear
568in the acceptable implementations list.
569.RS
570.PP
571A Lisp implementation is defined by a configuration section
572which defines a variable
573.BR run-script .
574The name of the configuration section
575is the name of the Lisp implementation,
576as used in the acceptable and preferred lists described above.
577.hP (a)
578The variable
579.B image-file
580is looked up in the configuration section.
581If a value is found, then
582.B runlisp
583looks up and expands
584.BR image-path ,
585and checks to see if a file exists with the resulting name.
586If so, it sets the variable
587.B @image
588to
589.B t
590in the configuration section.
591.hP (b)
592The variable
593.B run-script
594is expanded and word-split.
595The
596.I script
597(an internal script, in
598.I eval
599mode)
600and
601.IR argument s
602are appended, and
603the entire list is passed to the
604.BR execvp (3)
605function.
606If that succeeds, the Lisp implementation runs;
607if it fails with
608.B ENOENT
609then other Lisp systems are tried;
610if it fails with some other error, then
611.B runlisp
612reports an error message to stderr
613and exits unsuccessfully
614(with code 127).
615If the
616.RB ` \-n '
617option was given, then
618.B runlisp
619just simulates the behaviour of
620.BR execvp (3),
621printing messages to stderr
622if the verbosity level is sufficiently high,
623and exits.
624.
625.SS "Script environment"
626Many Lisp implementations don't provide a satisfactory environment
627for scripts to run in.
628The actual task of invoking a Lisp implementation
629is left to configuration,
630but the basic configuration supplied with
631.B runlisp
632ensures the following facts about their environment.
633.hP \*o
634The keyword
635.B :runlisp-script
636is added to the
637.B *features*
638list if
639.B runlisp
640is running in
641.I script
642mode.
643.hP \*o
644Most Lisp systems support a user initialization file
645which they load before entering the REPL;
646some also have a system initialization file.
647The
648.B runlisp
649program arranges
650.I not
651to read these files,
652so that the Lisp environment is reasonably predictable,
653and to avoid slowing down script startup
654with things which are convenient for use in an interactive session,
655but can't be relied upon by a script anyway.
656.hP \*o
657The Unix standard input, standard output, and standard error files
658are available through the Lisp
659.BR *standard-input* ,
660.BR *standard-output* ,
661and
662.BR *error-output*
663streams, respectively.
664.hP \*o
665Both
666.B *compile-verbose*
667and
668.B *load-verbose*
669are set to nil.
670On CMU\ CL,
671.B ext:*require-verbose*
672is also nil.
673Alas, this is insufficient to muffle noise while loading add-on systems
674on some implementations.
675.hP \*o
676If an error is signalled, and not caught by user code,
677then the process will print a message to stderr
678and exit with a nonzero status.
679The reported message may be a long, ugly backtrace,
680or a terse error report.
681If no error is signalled but not caught,
682then the process will exit with status 0.
683.hP \*o
684The initial package is
685.BR COMMON-LISP-USER ,
686which has no symbols `present' (i.e., imported or interned).
687.hP \*o
688The
689.B asdf
690and
691.B uiop
692systems are already loaded.
693Further systems can be loaded using
694.B asdf:load-system
695as usual.
696The script name
697(which is only meaningful if
698.B runlisp
699is in
700.I script
701mode, obviously)
702and arguments are available through the
703.B uiop:argv0
704function and
705.B uiop:*command-line-arguments*
706variable, respectively.
707.
708.\"--------------------------------------------------------------------------
709.
710.SH BUGS
711.hP \*o
712Loading ASDF systems is irritatingly noisy
713with some Lisp implementations.
714Suggestions for how to improve this are welcome.
715.hP \*o
716More Lisp implementations should be supported.
717I've supported the ones I have installed.
718I'm not willing to put a great deal of effort into supporting
719non-free Lisp implementations;
720but help supporting free Lisps is much appreciated.
721.hP \*o
722The protocol for passing the script name through to
723.B uiop
724(specifically, through the
725.B __CL_ARGV0
726environment variable)
727is terribly fragile,
728but supporting
729.B uiop
730is obviously a better approach than introducing a
731.BR runlisp -specific
732interface to the same information.
733I don't know how to fix this:
734suggestions are welcome.
735.
736.SH SEE ALSO
737.BR dump-runlisp-image (1),
738.BR query-runlisp-config (1),
739.BR runlisp.conf (5).
740.
741.SH AUTHOR
742Mark Wooding, <mdw@distorted.org.uk>
743.
744.\"----- That's all, folks --------------------------------------------------