lisp错误:应该是lambda表达式 [英] lisp error: should be lambda expression

查看:108
本文介绍了lisp错误:应该是lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己在学习口齿不清,我不知道为什么会出现此错误. 如果有人可以帮助我,那就太好了:)

I'm learning lisp by myself and I can´t figure out why am I getting this error. If somebody could help me that would be great :)

这是我遇到错误的情况:

This is the condition where I'm getting the error:

(cond ((equal c1 caracter) (push caracter pilatemp))
    ((or (equal c2 caracter) (equal c3 caracter) (equal c4 caracter) (equal c5 caracter) (equal c6 caracter))
        ((loop
            (setf t1 (jerarquia(caracter)))
            (setf t2 (jerarquia(first pilatemp)))
            if((or (= t1 t2) (> t1 t2)) (return))
            (push (pop pilatemp) piladef))
        (push caracter pilatemp)
            ))
    ((equal c7 caracter) ((loop
                    if((equal (first pila) c1) (return))
                    (push (pop pilatemp) piladef))
                (pop pilatemp)))
    (T (push caracter piladef))
)

这是"jerarquia"功能:

And here is the "jerarquia" function:

(defun jerarquia(x)
(setf c1 ")")
(setf c2 "+")
(setf c3 "-")
(setf c4 "^")
(setf c5 "*")
(setf c6 "/")
(setf c7 "(")
(cond ((equal c1 x) 5)
    ((equal c4 x) 4)
    ((equal c5 x) 3)
    ((equal c2 x) 2)
    ((equal c7 x) 1)
    (T 0)))

这是我遇到的错误:

*** - SYSTEM::%EXPAND-FORM:
(LOOP (SETF T1 (JERARQUIA (CARACTER)))
  (SETF T2 (JERARQUIA (FIRST PILATEMP))) IF
  ((OR (= T1 T2) (> T1 T2)) (RETURN)) (PUSH (POP PILATEMP) PILADEF))
should be lambda expression

推荐答案

很明显,您对如何将SExpressions组合在一起以创建有效的Common Lisp程序感到困惑.这对于初学者来说很常见.让我为您简要介绍一下.

It's clear that you are quite confused about how SExpressions are put together to create valid Common Lisp programs. That's common for a beginner. Let me take a stab at giving you a very brief introduction.

最简单的是原子.像Alpha,+,12,-23.4;那四个分别是两个符号,两个数字.加号是一个符号,就像alpha一样.

The simplest thing are atoms. Things like Alpha, +, 12, -23.4; those four are respectively two symbols, two numbers. The plus sign is a symbol, just like alpha.

接下来最简单的事情是函数调用,即调用一个函数.例如:(+1 2).该示例中的功能是加法,并且与符号+关联.

The next simplest thing are function calls, i.e. invoking a function. For example: (+ 1 2). The function in that example is addition, and it's associated with the symbol +.

函数调用在所有编程语言中都是常见的.通常,他们从左到右自底向上进行评估.因此,(F(G 1 2)(H 3 5))将调用G,然后是H,然后是F.如果他们想做其他事情,他们会引入语法,例如if语句,循环等.

Function calls are common in all programming languages. And typically they evaluate them left to right bottom up. So (F (G 1 2) (H 3 5)) will call G, then H, then F. If they want to do something else they introduce syntax, like if statements, loops, etc. etc.

这给我们带来了下一件事情,一件聪明的事情.在Lisp中,所有语法都像函数调用一样乍一看.因此,您得到的内容如下:(if(< a b)(f a)(f b)).不会从下而上进行评估,而是自上而下进行评估,以便可以根据第一种形式来决定应该对F进行两次调用中的哪一次.

Which brings us t the next thing, a clever thing. In Lisp all the syntax appears at first blush just like a function call. So you get things like: (if (< a b) (f a) (f b)). Which is not evaluated bottom up, but top down so that it can decided based on the first form which of the two calls on F it should make.

这些自上而下的形式有两种形式,特殊形式和宏,但是对于初学者来说并不重要.使用这些形式代替您在其他语言中找到的语法.评估人员/编译人员浏览列表中的第一项,以确定它是简单的函数调用还是语法.

These top-down forms come in two flavors, special forms and macros, but for a beginner that's not important. These forms are used instead of the syntax you find in other languages. The evaluator/compilers glance at the first term in the list to decide if it's a simple function call or a bit of syntax.

这让我们解释了您在帖子中观察到的错误.评估者(或编译器)看到了((loop ...)...),其中的第一个术语是(loop ...).那使评估者感到困惑.它期望看到一个符号.当然,错误消息是完全不透明的,但这是因为事情比我要说明的要微妙得多.对于没关系的初学者.

Which lets us explain the error you observed in your posting. The evaluator (or compiler) saw ((loop ...) ...), and the first term in that is (loop ...). That bewildered the evaluator. It expects to see a symbol. Of course the error message is entirely opaque, but that's because things are a bit more subtle than I'm making them out to be. For a beginner that doesn't matter.

表单(cond ...)是表单的另一个示例,它不是简单的函数调用,而是更像语法.当它扫视为第一个元素时,即cond,它知道期望(cond(??? ...)(??? ...)...等...)是用来决定是否应运行该分支机构的表格...

The form (cond ...) is another example of a form this isn't a simple function call, but is instead more like syntax. The when it glanced as the first element, i.e. cond, it knew to expect (cond (??? ...) (??? ...) ...etc...) where the ??? are forms it will used to decide if it should run that branch's ...

您的代码还有许多其他问题.我建议您使用Lisp REPL并以较小的块进行试验.循环中断. ((OR(...)"也遇到了相同的问题,即第一种形式不是符号.看起来您的调用字符串包含单个字符字符",而不是字符串,虽然俗气但可以忍受.

There are numerous other problems with your code. I'd recommend that you get a lisp REPL and experiment with things in much smaller pieces. The loops are broken. The "((OR (..." suffers the same problem of the first form not being a symbol. It appears that your calling strings that contain a single character "characters" rather than strings, that's tacky but tolerable.

这篇关于lisp错误:应该是lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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