开发者

scheme - function "if"

开发者 https://www.devze.com 2023-02-27 01:54 出处:网络
In the next code (if (exp1) (Do1) (Do2)) (Do1) is happening when exp1 is 开发者_如何学编程true. My problem that I want to do two things if the condition is true. meaning - I want to add a link to l

In the next code

(if (exp1)
    (Do1)
    (Do2))

(Do1) is happening when exp1 is 开发者_如何学编程true. My problem that I want to do two things if the condition is true. meaning - I want to add a link to list, and also call the function again.

so Do1 in my program is:
           ((cons (car hello) list1)
            (Myfunction (cdr data) list1))

and It give me the next problem:

procedure application: expected procedure, given: ((439043 Mylist)); arguments were: ()

How can I do it?

Thank you.


Just use begin - for example:

(begin
       (cons (car hello) list1)
       (Myfunction (cdr data) list1))


You can use (begin) to put a bunch of statements into one combination. However, I don't think that's what you want here. What is the effect of (cons (car hello) list1)? Nothing. (cons) returns a list, it doesn't alter any of its arguments.

So in fact, I think you want do1 to be (Myfunction (cdr data) (cons (car hello) list1))

That's just a single statement and can go in the consequent of your (if) without using a (begin).

0

精彩评论

暂无评论...
验证码 换一张
取 消