1

I have a :get route with easy-routes that, when hit, runs one function (quick-test). The function quick-test returns two values. Both are strings.

(easy-routes:defroute test-file ("/test-file" :method :get) (&get filename)
  (quick-test filename))

However, when the form is sent to "/test-file", only one line is visible in the dom.

I then tried using multiple value bind. But the result is the same.

(easy-routes:defroute test-file ("/test-file" :method :get) (&get filename)
  (multiple-value-bind (a b) (quick-test filename)
    (values (format nil "~a" a)
        (format nil "~a" b))))

My goal is to be able to run quick test and see all returned values on the dom.

Is there a way to do that?

For completeness, here is the form:

<form id="form" action="/test-file" method="get">
    <input type="text" name="filename" placeholder="type the filename"/>
    <input type="submit" value="Send"/>
  </form>

Vinn
  • 1,030
  • 5
  • 13

1 Answers1

2

Values can return more values, but if your function expects some expression, it takes only the first returned value and discards the rest. For example, floor returns two values, but + takes only the first:

> (floor 5 2)
2
1

> (+ 2 (floor 5 2))
4

This question can also help you: values function in Common Lisp

Defroute probably does the same and takes only the first value.

You can fix your route for example like this:

(easy-routes:defroute test-file ("/test-file" :method :get) (&get filename)
  (multiple-value-bind (a b) (quick-test filename)
    (format nil "~a, ~a" a b)))
Martin Půda
  • 7,353
  • 2
  • 6
  • 13
  • Interesting. You raised a great point here. It seems defroute also only recognises one format function. Putting them into one solved the issue. Thanks – Vinn Feb 11 '23 at 02:01
  • It isn't really defroute but Hunchentoot. It expects one value to return to the browser. Usually, we would render templates here, instead of `format`. – Ehvince Feb 11 '23 at 08:42
  • @Ehvince - good point. In this particular case the front end will be Nextjs. At the moment, im not sure how to allow for common lisp to pass the information to next for rendering – Vinn Feb 11 '23 at 09:31
  • It's the same: Nextjs asynchronously requests the webserver at a given route. The route is handled by Hunchentoot / easy-routes. You probably want the server to return JSON, and not a simple string or HTML. Nextjs does the rendering into the DOM. – Ehvince Feb 12 '23 at 21:19