LISP-输入和输出

常见的LISP提供许多输入输出功能。我们已经使用了format函数和print函数进行输出。在本节中,我们将研究LISP中提供的一些最常用的输入输出功能。

输入功能

下表提供了LISP最常用的输入功能-

Sr.No.

Function & Description

1

read & optional input-stream eof-error-p eof-value recursive-p

It reads in the printed representation of a Lisp object from input-stream, builds a corresponding Lisp object, and returns the object.

2

read-preserving-whitespace & optional in-stream eof-error-p eof-value recursive-p

It is used in some specialized situations where it is desirable to determine precisely what character terminated the extended token.

3

read-line & optional input-stream eof-error-p eof-value recursive-p

It reads in a line of text terminated by a newline.

4

read-char & optional input-stream eof-error-p eof-value recursive-p

It takes one character from input-stream and returns it as a character object.

5

unread-char character & optional input-stream

It puts the character most recently read from the input-stream, onto the front of input-stream.

6

peek-char & optional peek-type input-stream eof-error-p eof-value recursive-p

It returns the next character to be read from input-stream, without actually removing it from the input stream.

7

listen & optional input-stream

The predicate listen is true if there is a character immediately available from input-stream, and is false if not.

8

read-char-no-hang & optional input-stream eof-error-p eof-value recursive-p

It is similar to read-char, but if it does not get a character, it does not wait for a character, but returns nil immediately.

9

clear-input & optional input-stream

It clears any buffered input associated with input-stream.

10

read-from-string string & optional eof-error-p eof-value & key :start :end :preserve-whitespace

It takes the characters of the string successively and builds a LISP object and returns the object. It also returns the index of the first character in the string not read, or the length of the string (or, length +1), as the case may be.

11

parse-integer string & key :start :end :radix :junk-allowed

It examines the substring of string delimited by :start and :end (default to the beginning and end of the string). It skips over whitespace characters and then attempts to parse an integer.

12

read-byte binary-input-stream & optional eof-error-p eof-value

It reads one byte from the binary-input-stream and returns it in the form of an integer.

从键盘读取输入

读取函数用于从键盘获取输入。可能没有任何论据。

例如,考虑代码片段-

假设用户从STDIN输入中输入10.2,它将返回,

read函数从输入流中读取字符,并通过解析为Lisp对象的表示来解释它们。

创建一个名为main.lisp的新源代码文件,并在其中键入以下代码-

当您执行代码时,它返回以下结果-

创建一个名为main.lisp的新源代码文件,然后在其中键入以下代码。

当您执行代码时,它返回以下结果-

输出功能

LISP中的所有输出函数都使用一个称为output-stream的可选参数,将输出发送到该参数。如果未提及或为nil,则output-stream默认为变量* standard-output *的值。

下表提供了LISP最常用的输出功能-

Sr.No.

Function and Description

1

write object & key :stream :escape :radix :base :circle :pretty :level :length :case :gensym :array

write object & key :stream :escape :radix :base :circle :pretty :level :length :case :gensym :array :readably :right-margin :miser-width :lines :pprint-dispatch

Both write the object to the output stream specified by :stream, which defaults to the value of *standard-output*. Other values default to the corresponding global variables set for printing.

2

prin1 object & optional output-stream

print object & optional output-stream

pprint object & optional output-stream

princ object & optional output-stream

All these functions outputs the printed representation of object to output-stream. However, the following differences are there −

prin1 returns the object as its value.

print prints the object with a preceding newline and followed by a space. It returns object.

pprint is just like print except that the trailing space is omitted.

princ is just like prin1 except that the output has no escape character

3

write-to-string object & key :escape :radix :base :circle :pretty :level :length :case :gensym :array

write-to-string object & key :escape :radix :base :circle :pretty :level :length :case :gensym :array :readably :right-margin :miser-width :lines :pprint-dispatch

prin1-to-string object

princ-to-string object

The object is effectively printed and the output characters are made into a string, which is returned.

4

write-char character & optional output-stream

It outputs the character to output-stream, and returns character.

5

write-string string & optional output-stream & key :start :end

It writes the characters of the specified substring of string to the output-stream.

6

write-line string & optional output-stream & key :start :end

It works the same way as write-string, but outputs a newline afterwards.

7

terpri & optional output-stream

It outputs a newline to output-stream.

8

fresh-line & optional output-stream

it outputs a newline only if the stream is not already at the start of a line.

9

finish-output & optional output-stream

force-output & optional output-stream

clear-output & optional output-stream

The function finish-output attempts to ensure that all output sent to output-stream has reached its destination, and only then returns nil.

The function force-output initiates the emptying of any internal buffers but returns nil without waiting for completion or acknowledgment.

The function clear-output attempts to abort any outstanding output operation in progress in order to allow as little output as possible to continue to the destination.

10

write-byte integer binary-output-stream

It writes one byte, the value of the integer.

创建一个名为main.lisp的新源代码文件,然后在其中键入以下代码。

当您执行代码时,它返回以下结果-

格式化输出

函数格式用于生成格式正确的文本。它具有以下语法-

哪里,

目标是标准输出

控制字符串保存要输出的字符和打印指令。

格式指令由波浪号(〜),用逗号分隔的可选前缀参数,可选冒号(:)和符号(@)修饰符以及指示此指令类型的单个字符。

前缀参数通常是整数,用可选的带符号十进制数表示。

下表简要介绍了常用指令-

Sr.No.

Directive & Description

1

~A

Is followed by ASCII arguments.

2

~S

Is followed by S-expressions.

3

~D

For decimal arguments.

4

~B

For binary arguments.

5

~O

For octal arguments.

6

~X

For hexadecimal arguments.

7

~C

For character arguments.

8

~F

For Fixed-format floating-point arguments.

9

~E

Exponential floating-point arguments.

10

~$

Dollar and floating point arguments.

11

~%

A new line is printed.

12

~*

Next argument is ignored.

13

~?

Indirection. The next argument must be a string, and the one after it a list.

让我们重写计算圆面积的程序-

创建一个名为main.lisp的新源代码文件,然后在其中键入以下代码。

当您执行代码时,它返回以下结果-

lisp princ详解_LISP-输入和输出相关推荐

  1. Siri详解之输入系统和活跃本体(转)

    Siri详解之输入系统和活跃本体(转) 文 / 张俊林 Siri是iPhone 4S内置的智能语音识别系统,吸引了许多用户的关注.本文将从技术层面详解Siri,主要讲述输入系统和活跃本体两部分内容. ...

  2. c 语言的输出函数cout,详解C++ cout格式化输出完全攻略

    写算法题的时候突然发现自己忘记基本的C++:cout格式化输出了,赶紧拉出以前的C++学习笔记重新看一看. 部分内容来自教程:C语言中文网(一个很棒的网站) 有时希望按照一定的格式进行输出,如按十六进 ...

  3. [pytorch]yolov3.cfg参数详解(每层输出及route、yolo、shortcut层详解)

    文章目录 Backbone(Darknet53) 第一次下采样(to 208) 第二次下采样(to 104) 第三次下采样(to 52) 第四次下采样(to 26) 第五次下采样(to 13) YOL ...

  4. python 多数据输出到txt_详解python读取和输出到txt

    读取txt的数据和把数据保存到txt中是经常要用到的,下面我就总结一下. 读txt文件 python常用的读取文件函数有三种read().readline().readlines() 以读取上述txt ...

  5. iostat命令详解_对iostat输出结果的理解

    前言: 日常工作中,线上服务会出现各种奇奇怪怪的问题,每次出现问题都是根据现象猜测出现问题的原因,比如请求响应慢了,就排查整个请求的逻辑,每一步花了多少时间,分析半天终于发现是某一步慢了以后,在分析为 ...

  6. JS常用的输出内容的方式详解(5种输出方式)

    1.alert("要输出的内容"); ->在浏览器中弹出一个对话框,然后把要输出的内容展示出来 ->alert都是把要输出的内容首先转换为字符串然后在输出的 2.doc ...

  7. python文件输入符_python基础入门详解(文件输入/输出 内建类型 字典操作使用方法)...

    一.变量和表达式 >>> 1 + 1 2 >>> print 'hello world' hello world >>> x = 1 >&g ...

  8. keras train_on_batch详解(train_on_batch的输出输入详解,train_on_batch多GPU训练详解,自定义学习率调整策略)

    利用 train_on_batch 精细管理训练过程 大部分使用 keras 的同学使用 fit() 或者 fit_generator() 进行模型训练, 这两个 api 对于刚接触深度学习的同学非常 ...

  9. python循环控制语句将数值转化成字符串_python基础入门详解(文件输入/输出内建类型字典操作使用方法)...

    f=open("foo.txt") line=f.readline() while line: print line, line=f.readline() #读取一行,包括换行符' ...

  10. python输入输出流详解_输入输出流的概念

    Java中的文件复制相较Python而言,涉及到输入输出流的概念,实现中会调用很多对象,复杂很多,在此以文件复制进行简单总结. 这里是一个简单的处理代码: import java.io.*; publ ...

最新文章

  1. 一个UI布局框架,以最少的代码实现UI设置及布局控制
  2. python调用shell命令之三慷慨法
  3. avenue在科研文章中的意思
  4. Javascript - ExtJs - 组件 - 分页
  5. 2、C#基础 - Visual Studio 的版本选择和下载
  6. Javascript 第七天 笔记
  7. Finalize,Dispose,SuppressFinalize
  8. zabbix 监控项自动发现过滤_Zabbix使用javascript+jsonpath预处理动态生成监控项
  9. 2018-2019-2 网络对抗技术 20165322 Exp9 Web安全基础
  10. Axure手机原型图总结
  11. Opencv drawContours函数用于绘制和填充
  12. selectpicker 动态加载数据
  13. Aziz 的 UiPath 工具面试经验
  14. 实用的电脑绘图软件——亿图图示
  15. 01-初识sketch-sketch优势
  16. fishhook-动态修改MachO文件
  17. 小康qq小助手 v1.0 官网
  18. c语言常量2l是什么,2017年计算机二级c语言题库
  19. 【学习笔记】min-height、max-height、line-height
  20. docx批量转换成html,Batch DOCX to HTML Converter(批量docx转换HTML工具)

热门文章

  1. 有趣的JavaScript数组
  2. Ubuntu中安装网易云音乐(可以直接打开的最简单的方法)
  3. 【Docker】 命令速查
  4. Unity移动端使用 Handheld.PlayFullScreenMovie播放视频参数
  5. winform窗体最大化、最小化、还原
  6. springboot修改默认端口号,启动端口号
  7. 群之脉PHP面试,面试问Redis集群,被虐的不行了......
  8. 公安交管网服务器维护,交管网总是维护
  9. java p39课后答案_面向对象程序设计(JAVA)答案
  10. nodejs-基础:路由基础