Tom
Tom

Reputation: 673

scheme - function "if"

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.

Upvotes: 1

Views: 178

Answers (2)

drysdam
drysdam

Reputation: 8637

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).

Upvotes: 3

Justin Ethier
Justin Ethier

Reputation: 134275

Just use begin - for example:

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

Upvotes: 5

Related Questions