0

I'm trying to return (values str ((+ x 3) y)) from the function it resides in.

code snippet:

(if (<my condition>)
    (values str ((+ x 3) y))
    (values str ((+ x 2) y)))

gives error:

(+ X 3) SHOULD BE A LAMBDA EXPRESSION 

but (values str (y (+ x 3))) works fine.

why?

3
  • 1
    Can you add a little more context? What are the values of x and y here? It looks like y is acting like a function. Commented Mar 4, 2014 at 5:40
  • 3
    Can you explain what ((+ x 3) y) does or should do? Commented Mar 4, 2014 at 6:01
  • perhaps (y (+ x 3)) should be literal '(y (+ x 3)) or perhaps missing an operator (* y (+ x 3))? Perhaps you have define the function y? Commented Mar 5, 2014 at 20:42

1 Answer 1

6

The S-expression ((+ x 3) y) cannot be evaluated because the first list element is not funcallable (it should name a function or be a lambda expression).

So, to avoid evaluation, you need to quote it:

(if (<my condition>)
    (values str '((+ x 3) y))
    (values str '((+ x 2) y)))

Then you will return a list of length 2 (containing a list of length 3 and a symbol y) as your second value. If, however, you want to return the values of (+ x 2) and y in the list, you will want to do something like

(values str (list (+ x (if <condition> 3 2)) y))

or maybe return 3 values instead of 2:

(values str
        (+ x (if <condition> 3 2))
        y)

On the other hand, y is a symbol, which, apparently, names a function in your image, so (y (+ x 3)) evaluates fine (it calls function y on the result of adding 3 to x).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.