如何在Lisp中读取用户输入 [英] How to read user input in Lisp

查看:84
本文介绍了如何在Lisp中读取用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Lisp还是陌生的,正在尝试编写一个程序,仅要求用户输入3个数字,然后对它们求和并打印输出.

我已阅读到您可以使用以下功能:

 (defvar a)(setq a(读)) 

要在Lisp中设置变量,但是当我尝试使用LispWorks编译代码时,会出现以下错误:

在读取流#<串联流,Streams =()>

时文件末尾

我觉得这应该相对简单,不知道我要去哪里.

解决方案

我没有使用LispWorks,因此只是一个猜测.

当编译器遍历您的代码时,它到达行(setq a(read)),它尝试读取输入,但是编译时没有输入流,因此会出现错误./p>

编写函数:

 (defvar a)(禁用我的功能()(setq a(读)) 

应该可以.

I'm very new to Lisp and am trying to write a program that simply asks a user to enter 3 numbers and then sums them and prints the output.

I've read that you can you a function like:

(defvar a)

(setq a (read))

To set a variable in Lisp, but when I try to compile my code using LispWorks I get the following error:

End of file while reading stream #<Concatenated Stream, Streams = ()>

I feel like this should be relatively simple and have no idea where I'm going wrong.

解决方案

I've not worked with LispWorks, so it's only a guess.

When compiler traverses your code it gets to the line (setq a (read)), it tries to read input, but there is no input stream while compiling, thus you get an error.

Write a function:

(defvar a)

(defun my-function ()
  (setq a (read))

It should work.

这篇关于如何在Lisp中读取用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆