Output functions need an optional argument known as output stream which by default is "output-stream" and can be assigned to another stream where the output has to be sent.
write object key : stream
Example 1:
Lisp
; LISP program for Write
(write "Hello World")
(write "To")
(write "The")
(write "LISP")
(write "World")
Output:
- print, pprint , princ , prin1:
print object stream
print ->>prints with a preceding newline and followed by a space.
pprint object stream
pprint ->>like print except that the trailing space is omitted.
princ object stream
princ ->>like prin1 except that the output has no escape character
prin1 object stream
prin1 ->>returns the item as its value.
Example 2:
Lisp
; LISP program for print
(print "Hello World")
(pprint "To")
(prin1 "The")
(princ "LISP")
Output:
- write to string , print to string:
write-to-string object key stream
prin1-to-string object
princ-to-string object The output character string is returned as object from functions.
- write-char, write-string, write-line:
write-char character stream return character and print output
write-string string stream key :start :end writes the particular substring of string to output
write-line string stream key :start :end same as write-string but succeed with newline
terpri stream
print a new line to the stream
fresh-line stream
print new line if stream is not at start of line.
write-byte integer binary-output-stream
write one byte i.e. the value of integer.
- finish output, force output, clear output:
finish-output & optional output-stream
ensure all output sent is reached to stream and then only return null.
force-output & optional output-stream
return nil without waiting for completion of task and force output start the emptying of buffer
clear-output & optional output-stream
abort any outstanding output operation in progress
- output to a binary stream:
write-byte integer binary-output-stream
write-byte writes one byte, the value of integer. It is an error if integer is not of the type specified as the :element-type argument to open when the stream was created. The value integer is returned.
- output to character streams:
write object &key :stream :escape :radix :base :circle :pretty
:level :length :case :gensym :array :readably
:right-margin :miser-width :lines :pprint-dispatch
same as above the output stream can be specified for other functions like as:
prin1 object &optional output-stream
print object &optional output-stream
pprint object &optional output-stream
princ object &optional output-stream
write-to-string object &key
:escape :radix :base :circle :pretty :level :length :case :gensym :array
prin1-to-string object
princ-to-string object
write-char character &optional output-stream
terpri &optional output-stream
fresh-line &optional output-stream
finish-output &optional output-stream
force-output &optional output-stream
clear-output &optional output-stream
Example 3:
Lisp
; this program inputs a number and divide it by 2
(defun QuadNumber()
(terpri)
;for new line
(princ "Input Number : ")
;print statement "Input Number :"
(setq n1 (read))
;set n1 to input number
(setq quad (/ n1 4.0))
;set n1=n1/4
(princ "The Number: ")
(write n1)
;write n1
(terpri)
;new line
(princ "The Number's fourth part: ")
(write quad)
;write quad=n1/4
)
(QuadNumber) ;
call function DoubleNumber
Output:
Similar Reads
Functions in LISP A function is a set of statements that takes some input, performs some tasks, and produces the result. Through functions, we can split up a huge task into many smaller functions. They also help in avoiding the repetition of code as we can call the same function for different inputs. Defining Functio
3 min read
Mapping Functions in LISP In this article, we will discuss mapping functions in lisp. Mapping functions are applied on the list data structure for combining one or more lists of elements. By using this we can perform mathematical operations and can join the elements. The main advantage of this function is that we can combine
2 min read
Input & Output in LISP Pre-requisites: Introduction to LISP Lisp provides a huge set of facilities for performing input/output. All the input/output operations are performed on streams of several kinds. While reading and writing binary data is possible, the majority of Common Lisp input/output methods read or write charac
9 min read
Lambda Functions in LISP In this article, we will discuss lambda functions in LISP. The Lambda function is used to evaluate a mathematical expression in our program. They are also known as anonymous functions. We can create these functions using lambda expression. Syntax: (lambda (parameters) expression_code) where, The par
1 min read
Perl | List Functions A list in Perl is a collection of scalar values. We can access the elements of a list using indexes. Index starts with 0 (0th index refers to the first element of the list). We use parenthesis and comma operators to construct a list. In Perl, scalar variables start with a $ symbol whereas list varia
4 min read
Returning Values Functions in LISP In the previous article on the LISP function, we have seen the syntax of defining a function and calling the function by passing some arguments. Returning values from a function: In LISP, whatever is the last expression in the body of a function becomes the return value of that function. Example: Le
2 min read