【发布时间】:2014-04-21 01:41:06
【问题描述】:
我发现 this page 解释了一些 gimp 函数不会始终如一地返回值,因此我实现了一个 do while 循环以确保函数在使用 car 之前返回对。尽管如此,我还是收到了错误Error: ( : 1) car: argument 1 must be: pair,但我不确定这怎么可能,因为它应该继续运行该函数,直到它返回一对。
(define (script-fu-scratchpad drawable)
(let* ((imgHeight 0)
(imgWidth)
(bpp)
(pixel))
(set! imgHeight (gimp-drawable-height drawable))
(do ()
[(pair? imgHeight)]
(set! imgHeight (gimp-drawable-height drawable)))
(set! imgHeight (car imgHeight))
(set! imgWidth (gimp-drawable-width drawable))
(do ()
[(pair? imgWidth)]
(set! imgWidth (gimp-drawable-width drawable)))
(set! imgWidth (car imgWidth))
(set! bpp (gimp-drawable-bpp drawable))
(do ()
[(pair? bpp)]
(set! bpp (gimp-drawable-bpp drawable)))
(set! bpp (car bpp))
(display bpp) (newline)
(set! pixel (cons-array bpp 'byte))
(aset pixel 0 150)
(aset pixel 1 150)
(aset pixel 2 150)
(aset pixel 3 0)
(gimp-drawable-set-pixel drawable (/ imgHeight 2) (/ imgWidth 2) bpp pixel)
(gimp-context-set-background '(100 100 100))
(define county 0)
(define countx 0)
(do ()
[(= countx imgWidth)]
(do ()
[(= county imgHeight)]
(gimp-drawable-set-pixel drawable county countx bpp pixel)
(set! county (+ county 1)))
(set! countx (+ countx 1)))))
针对 GoZoner,我对其进行了编辑并收到以下错误:Error: (:1) car: argument 1 must be: pair
(define
(script-fu-scratchpad drawable)
(let*
(
(imgHeight 0)
(imgWidth 0)
(bpp 0)
(pixel 0)
)
(set! imgHeight (gimp-drawable-height drawable))
(set! imgWidth (gimp-drawable-width drawable))
(set! bpp (gimp-drawable-bpp drawable))
(do ()
[(pair? bpp)]
(set! bpp (gimp-drawable-bpp drawable))
)
(set! bpp (car bpp))
(display bpp) (newline)
(set! pixel (cons-array bpp 'byte))
(aset pixel 0 150)
(aset pixel 1 150)
(aset pixel 2 150)
(aset pixel 3 0)
(gimp-drawable-set-pixel drawable (/ imgHeight 2) (/ imgWidth 2) bpp pixel)
(gimp-context-set-background '(100 100 100))
(define county 0)
(define countx 0)
(do ()
[(= countx imgWidth)]
(do ()
[(= county imgHeight)]
(gimp-drawable-set-pixel drawable county countx bpp pixel)
(set! county (+ county 1))
)
(set! countx (+ countx 1))
)
)
)
【问题讨论】:
-
在谷歌搜索时我读到
while是 Script-fu 中唯一的循环结构。那么do是什么? -
@uselpa 您找到的信息似乎已过时。 SIOD 没有
do,但是 gimp 现在使用的是 TinyScheme,这是一个更完整的 Scheme 实现。 -
这是我不喜欢别人做的事情,即使是我也不喜欢,但它就是这样:如果你想学习 scheme 或 lisp,好吧,继续。但是,如果您尝试在 GIMP 脚本或插件中完成任务,也许您应该尝试使用 Python。作为一种更高级别的命令式语言,您会发现向 GIMP“下达命令”要容易得多,而不必担心诸如如何检查列表长度或如何从列表中检索特定项目之类的次要语言细节。跨度>
-
@jsbueno 我在 90 年代学习了我的第一门编程语言,很容易同意你的看法,但这只是因为 Python 是一种熟悉的 Algol 方言。如果你还不知道一种方言,LISP 和 ALGOL 一样容易学习。在 Python 中,这个 SO 条目应该是
TypeError: 'int' object has no attribute '__getitem__'或者可能是IndexError: list index out of range并在末尾附加“为什么”。 -
前段时间我对 Gimp 的 Python 做了介绍,但结果证明它比 TinyScheme 的 Script-fu 涉及更多。另外,由于某种原因,我找不到Scheme 有一个
while,实际上只有一个do。我不知道 TinyScheme 有一个do而 Scheme 有一个while。