Hi Vincent, On Thu, 6 Jan 2022 10:12:37 +0100 Vincent Aguiléra <vincent.aguil...@advizia.fr> wrote:
> I'm a new (and so far happy ;-) Chicken Scheme user. Welcome! > I'm facing a problem with port-position. The doc states that > port-position "returns the current position of PORT as two values: row > and column number". > > So this function should return a pair of values (whatever column > number means). But in the tests I've made so far only the row number > seems to be returned (tested on the default input port, on file ports > and on string ports). Not really a pair, but actually two values (as produced by the `values' procedure). CHICKEN provides some binding forms to support multiple values (e.g., define-values, let-values, receive etc). In CHICKEN they are in the chicken.base module [0]. See also SRFIs 8 [1] and 11 [2], for more detailed information. [0] http://wiki.call-cc.org/man/5/Module%20(chicken%20base)#other-binding-forms [1] https://srfi.schemers.org/srfi-8/srfi-8.html [2] https://srfi.schemers.org/srfi-11/srfi-11.html > Below are a code snippet and the corresponding csi output. > > Hope this list is appropriate for this kind of message! Definitely! > Thanks in advance for your help > > Vince > > ============= > (with-input-from-string "ab\ncd\nef" > (lambda () > (port-for-each > (lambda (c) > (print c ': (port-position))) > read-char))) > ============== > CHICKEN > (c) 2008-2021, The CHICKEN Team > (c) 2000-2007, Felix L. Winkelmann > Version 5.3.0 (rev e31bbee5) > linux-unix-gnu-x86-64 [ 64bit dload ptables ] > > Type ,? for help. > ; loading test.scm ... > ; loading /usr/local/lib/chicken/11/chicken.port.import.so ... > a:1 > b:1 > > :2 > c:2 > d:2 > > :3 > e:3 > f:3 That happens because `print' is not aware of multiple values and only prints the first one. You can try the following on csi: #;1> (port-position) 2 0 ; 2 values #;2> (print (values 1 2)) 1 #;3> (print (let-values (((x y) (values 1 2))) (cons x y))) (1 . 2) I hope this helps. All the best. Mario -- http://parenteses.org/mario