在LispWorks中进行编程12:创建对话框

  • 6

在LispWorks中进行编程12:创建对话框

Category:UI界面编写 Tags : 

创建对话框

在本课中,您将学习如何使用Lisp创建Macintosh或Windows界面功能,如窗口和对话框。

执行此操作的过程都在名为CAPI的LispWorks库中提供,其名称以capi开头

显示消息:capi:display-message

要显示消息,请使用  capidisplay-message  过程。接下来是格式字符串和参数列表,就像格式一样。例如:

(capi:display-message “The sum of ~a and ~a is ~a.” 3 4 (+ 3 4))

将显示:

提示输入字符串:capi:prompt-for-string

这要求用户输入一个字符串。例如:

(capi:prompt-for-string “Think of an animal:”)

将显示:

并将返回您键入的字符串。

提示一个数字:capi:提示号码

以类似的方式:

(capi:prompt-for-number “How many legs does it have:”)

将显示:

并返回您输入的号码。

询问是或否:capi:提示确认

程序  capiprompt-for-confirmation询问问题,并让用户回答是或否:

(capi:prompt-for-confirmation “Are you hungry?”)

这显示:

如果用户单击是,则过程返回T(true)。如果用户单击否,则返回Nil(false)。

给用户一个选择:capi:prompt-with-list和capi:prompt-for-items-from-list

最后,函数capiprompt-with-list获取列表和消息,并让用户选择其中一个项目。例如:

(capi:prompt-with-list

‘(“red” “blue” “green” “pink”)

“What’s your favourite colour?”)

将显示:

并返回您选择的项目的值。

程序  capiprompt-for-items-from-list是相同的,除了它允许您选择任意数量的项目,并返回您选择的项目列表。

一个故事写作程序

最后,这是一个将所有这些程序放在一起的故事编写程序:

(defun story ()

(let ((name (capi:prompt-for-string “What is your name:”))

(food (capi:prompt-for-string “What is your favourite food:”))

(colour (capi:prompt-with-list

‘(“red” “blue” “green” “pink”)

“What’s your favourite colour?”)))

(capi:display-message

“There once was a witch called ~a who liked ~a.

One day ~a found some ~a ~a and ate so much that she died. The end.”

name food name colour food)))

运行故事程序评估:

(story)

因为没有参数。

演习

1.尝试改进程序以编写更长的故事,并使用capiprompt-for-confirmation  和if语句在故事中添加分支; 例如:

(capi:prompt-for-confirmation “Should the witch die at the end?”)


6 Comments

Judd_Trump_01

Judd_Trump_01

8月 25, 2021at 2:11 下午

顶!

陆 志广

10月 31, 2018at 10:25 上午

网站要一直办下去,要有一个良性循环的方式,单靠我一个人的努力是不够的。

陆 志广

10月 31, 2018at 10:24 上午

已修复,网站时区忘了设置了,有问题及时提出评论。

HZ-陈创修

10月 31, 2018at 12:11 上午

网站的评论时间显示的不正确,现在是北京时间
8:10

HZ-陈创修

10月 31, 2018at 12:11 上午

好的cl网站,要一直办下去

HZ-陈创修

10月 30, 2018at 11:59 下午

simply and practical examples for learning Common Lisp

Leave a Reply

搜索

分类目录

公 告

本网站学习论坛:

www.zhlisp.com

lisp中文学习源码:

https://github.com/zhlisp/

欢迎大家来到本站,请积极评论发言;

加QQ群学习交流。