[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Iteration constructs that handle multiple values?

William James

5/4/2015 3:56:00 AM

Barry Margolin wrote:

> >I have been trying to figure out if there are any iteration constructs that
> >can deal with functions that return multiple values correctly.
>
> I think LOOP can do it, by making use of destructuring:
>
> (loop for (values foo bar) = (function-call)
> until (exit-condition)
> do ...)

You "think"? ? ? ? ? ?

Why the hell didn't you test it?

SBCL:

(loop for (values foo bar) = (values 2 3)
until (= 2 foo)
do (print (list foo bar)))

; in: LAMBDA NIL
; (SB-LOOP::LOOP-REALLY-DESETQ (VALUES FOO BAR) (VALUES 2 3))
; --> LET SETQ THE
; ==>
; (CAR #:LOOP-DESETQ-TEMP)
;
; caught WARNING:
; Asserted type LIST conflicts with derived type (VALUES (INTEGER 2 2) &OPTIONAL).
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition

A D- grade for you.

Gauche Scheme:

(define stuff '(6 4 2 0))
(define (function-call) (values (pop! stuff) (pop! stuff)))

(let go ()
(receive (foo bar) (function-call)
(print (list foo bar))
(when (> bar 0) (go))))

===>
(6 4)
(2 0)

--
World's most proficient serial killer is black: Thirty-eight of his victims
were women, three men and one a two-year-old girl.... Das Graces said the more
his victims struggled, the more joy he derived from their deaths.... Police
said das Graces also removed his victim's nails to add to their torture. The
admitted killer insisted he killed only white women and preferred blondes....
www.thepoliticalcesspool.org/jamesedwards/worlds-proficient-serial-killer-black/