对象___不适用 [英] The object ___ is not applicable

查看:45
本文介绍了对象___不适用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在写一些东西,它紧接在第一个元素之后的第三个元素中.但是由于;对象(a b c d e f g)不适用",我无法测试逻辑.代码在下面,原子?检查是否为列表,listful定义为空列表.

Hi I'm writing something that grabs every third element after the first element. However I can't test the logic due to ";The object (a b c d e f g) is not applicable." The code is below, atom? checks if it's a list, listful is defined as an empty list.

(DEFINE (threes var)
    (if(atom? var)
        ((newline) (DISPLAY "Bad input")  ))
    (APPEND(listful (CAR var)))
    (if(> 3 (length var))
        (threes (cdddr(listful)))
        (listful))
)

有人可以给我一些提示吗?这是我在Scheme环境中调用方法的方式.

Can anyone give me some tips? Here is how I'm calling the method in the Scheme environment.


>(threes (list1))
>(threes '(A B C D E F))

推荐答案

if只能具有一个表达式,而只能具有一个表达式.如果需要多个,则必须使用begin括起表达式序列-用()包围表达式将不起作用,这会导致报告错误,因为Scheme将()解释为函数应用程序.这将是正确的语法:

An if can only have one expression as the consequent, and one as the alternative. If you need more than one you have to use a begin to enclose the sequence of expressions - surrounding the expressions with () won't work, and that's causing the error reported, because Scheme interprets () as function application. This would be the correct syntax:

(define (threes var)
  (if (atom? var)
      (begin
        (newline)
        (display "Bad input")))
  (append (listful (car var)))
  (if (> 3 (length var))
      (begin
        (threes (cdddr (listful)))
        (listful))))

…但是,这不太可能起作用.在过去几天里,您想做的事情已经问了几次,特别是在此处是我自己以前的回答:

… However, that's unlikely to work. What you want to do has been asked a couple of times in the last days, in particular here is my own previous answer:

(define (threes lst)
  (cond ((or (null? lst) (null? (cdr lst))) lst)
        ((null? (cdr (cdr lst))) (list (car lst)))
        (else (cons (car lst)
                    (threes (cdr (cdr (cdr lst))))))))

例如:

(threes '(a b c d e f g h i j k l m n o p))
=> '(a d g j m p)

请参见原创问题寻求其他解决问题的方法,并附有详细说明.

See the original question for other ways to solve the problem, with detailed explanations.

这篇关于对象___不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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