guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help : call function with args


From: Thomas Morley
Subject: Re: help : call function with args
Date: Thu, 5 Apr 2018 10:54:16 +0200

2018-04-05 10:16 GMT+02:00 calcium <address@hidden>:
>> I think you'll find it easier to reason first about an f
>> which takes as many args as your conditionals produce, so
>> you won't be struggling to splice your "bunch of values"
>> into a bigger argument list.
>
> yes, thank you tomas,
> i stopped trying to return multiples values, and instead call the
> functions with the right numbers of args, and using the cond statement
> to change the values of args.
>
> (define (f a b c d)
>   (+ a b c d))
>
> (let ((a 1)
>       (b #f)
>       (c #f)
>       (d 10))
>   (cond (#t (set! b 2)
>             (set! c 3))
>         (else
>          (set! b 6)
>          (set! c 10)))
>   (f a b c d))
>

Not sure what you aim at.
Though, above seems to be easier with:

(define (f . rest) (apply + rest))

(f)
-> 0
(f 1 2 3)
-> 6
(f 1 2 3 4 5 6 7 8 9 10)
-> 55

Cheers,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]