Arc Forumnew | comments | leaders | submitlogin
2 points by absz 6019 days ago | link | parent

Your problem is that tcp-connect returns multiple values; not a list, but multiple values. What you need to do is extract the two values into a list, and return them. This can be done via mzscheme's call-with-values procedure, takes two functions; the first is called with no arguments, and generates multiple values; the second is called on all of the values. Thus, you want, if memory serves, the entirely untested

  (xdef 'tcp-connect
        (lambda (host port . rest)
          (call-with-values
            (lambda () (apply tcp-connect host port rest))
            list)))
Give that a shot, and see if it works.

I never knew that mzscheme had multiple return values… learn something new every day, I guess!



1 point by bOR_ 6019 days ago | link

It works! (with the occasional error message)

  arc> (= inout cons)
  #<primitive:cons>
  arc> (= inout (tcp-connect "avendar.com" 9999))
  (#<input-port> #<output-port>)

   
  arc> (read (car inout))
  Avendar
  arc> (read (car inout))
  created
  arc> (read (car inout))
  by
  arc> (read (car inout))
  Matt
  arc> (read (car inout))
  Wallace
  arc> (read (car inout))
  (unquote Thane)
  arc> (read (car inout))
  Williams

-----

1 point by almkglor 6019 days ago | link

Why do you assign 'cons to 'inout?

Anyway I suggest you push it on Anarki^^

-----

1 point by bOR_ 6018 days ago | link

Why? because there isn't that much in lisp/scheme/arc that comes naturally to me :).

Not sure about how to go about pushing something on something else. Never been in an environment where we worked with cvs or git or anything. Solitary scientists :)

-----

1 point by almkglor 6019 days ago | link

Might be better:

  (xdef 'tcp-connect
        (lambda (host port . rest)
          (call-with-values
            (lambda () (apply tcp-connect host port rest))
            (lambda (x y)
              (cons x (cons y 'nil))))))

-----

1 point by absz 6018 days ago | link

Ouch, I hadn't thought of that. But I just tested this, and it appears that ac.scm runs the translation step after the xdefed functions return, so we get a valid Arc list back. Saved by the bell, so to speak :)

-----