首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LispWorks程序不会作为应用程序生成。

LispWorks程序不会作为应用程序生成。
EN

Stack Overflow用户
提问于 2014-05-11 01:01:52
回答 1查看 137关注 0票数 0

这是我对Lisp程序的第二次正确尝试,它是Mythender (一个免费分发的桌面RPG)的骰子。不过,它也有几个问题:

  • 加载它时,我会得到一个提示,以确认包的创建。这个文件应该是创建它的吗?
  • 当我试图使用LispWorks应用程序构建器独立构建它时,它会出现一个错误,说明我试图在编译时调用一个CAPI函数,但我不知道它在哪里。
  • 我从一些lisp人员那里得到了负面的评论,我谈到了( null ())部分,它们表示函数没有返回,所以没有必要在堆栈上留下任何东西--这是否正确?有更好的方法吗?

任何一般性建议也将受到欢迎。

代码语言:javascript
复制
(defpackage :mythender (:add-use-defaults t) (:use "CAPI"))
(in-package :mythender)

(defun d6 () (the fixnum (+ 1 (random 6))))

(defun d6s (count)
  (declare (type fixnum count))
  (the list (loop for x from 1 to count collecting (d6))))

(defun d6over (count threshold) 
  (declare (type fixnum count threshold))
  (the fixnum (count-if 
   (lambda (x) (> threshold x)) 
   (d6s count))))

(defvar *storm* 3)
(defvar *thunder* 3)
(defvar *lightning* 0)

(declare (ftype (function) printstate))
(defun printstate ()
  (print *storm*)
  (print *thunder*)
  (print *lightning*)
  (the null ()))

(defun roll () 
  (incf *lightning* (d6over *thunder* 3))
  (incf *thunder* (d6over *storm* 3))
  (the null ()))

(defun damage (threshold)
  (setf *thunder* (d6over *thunder* threshold))
  (the null ()))

(defun doroll (&rest args)
  (roll)
  (update-interface)
  (the null ()))


(define-interface mythender-interface () ()
  (:panes
   (roll-button push-button :data "Roll" :callback #'doroll)
   (damage-button push-button :data "Damage")
   (storm-pane display-pane :title "Storm:" :title-position :left)
   (thunder-pane display-pane :title "Thunder:" :title-position :Left)
   (lightning-pane display-pane :title "Lightning:" :title-position :left))
  (:layouts
   (main-layout column-layout '(storm-pane thunder-pane lightning-pane buttonlayout))
   (buttonlayout row-layout '(roll-button damage-button))))

(defvar *interface*)

(defun update-interface-slot (slotname value)
  (declare (type string slotname) (type fixnum value))
  (setf (display-pane-text (slot-value *interface* slotname)) (write-to-string value))
  (the null ()))

(defun update-interface () 
  (update-interface-slot 'storm-pane *storm*)
  (update-interface-slot 'thunder-pane *thunder*)
  (update-interface-slot 'lightning-pane *lightning*)
  (the null ()))


(defun start () 
  (setf *interface* (make-instance 'mythender-interface))
  (display *interface*)
  (the null (update-interface)))
EN

回答 1

Stack Overflow用户

发布于 2014-05-11 07:46:04

您的构建问题的答案必须等到您告诉我们构建语句和错误消息。

你的最后一个问题:

代码语言:javascript
复制
(declare (ftype (function) printstate))
(defun printstate ()
  (print *storm*)
  (print *thunder*)
  (print *lightning*)
  (the null ()))

众所周知,这是一种功能。没必要声明。这样的声明类型,在普通的Common中只具有向编译器提供优化提示的目的,编译器可能会忽略这些提示。实际上,只有CMUCL (以及诸如SBCL和SCL这样的派生编译器)对声明的类型做了更多的工作。

没有人用Lisp编写这样的代码。最好省略那些类型。记住: Lisp不是一种静态类型的语言。

代码语言:javascript
复制
(defun printstate ()
  (print *storm*)
  (print *thunder*)
  (print *lightning*)
  (values))

使用(values)会导致函数不返回值。这通常是首选的,不返回NIL

如果您希望在运行时以有意义的方式检查类型,那么请使用ASSERTCHECK-TYPE和/或DEFMETHOD

代码语言:javascript
复制
(defun d6s (count)
  (declare (type fixnum count))
  (the list (loop for x from 1 to count collecting (d6))))

只是:

代码语言:javascript
复制
(defmethod d6s ((n integer))
  "Returns a list of n dice rolls."
  (loop repeat n collect (d6)))

不要忘记以人类可读的形式描述函数的语义。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23587872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档