unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* help : call function with args
@ 2018-04-03 20:43 amnesia
  2018-04-03 22:40 ` Mark H Weaver
  2018-04-04  7:27 ` tomas
  0 siblings, 2 replies; 9+ messages in thread
From: amnesia @ 2018-04-03 20:43 UTC (permalink / raw)
  To: guile-user

To view the message, please use an HTML compatible email viewer.


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: help : call function with args
@ 2018-04-04  7:43 calcium
  2018-04-04 14:39 ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: calcium @ 2018-04-04  7:43 UTC (permalink / raw)
  To: guile-user

Sorry, I tried to use a disposable email web service, but it didn’t
work, so I just created a email account.


The question was how to do what I intended with this code (sorry I don’t
know how to express this with words) :


(define (f a b c d)

(+ a b c d))


(f 1 (values 2 3) 4)


;;so that I can return multiples args inside a cond or an if statement
calling a function like:


(f 1

(if #t (values 2 3)

(values 4 5))

6)


;;and if this is not possible, which way would be the best to write this
sort of things ?, would it be using internal define so that I only have
to write the different values of the arguments inside the new shortened
function?.



And while I am asking, is there a way to use the default value of an
optional key, but using the key :


(define* (rice #:key (color 'white) (weight 10))

(list color weight))

(define* (lst-of-rice #:key (color 'white) (weight 10))

(list (rice #:color color #:weight weight)

(rice #:color color #:weight weight)))


;;sot that instead of writing in lst-of-rice (color ‘white), write
(color UseSameAsKeyofRice), or something that use the default value of
rice, if no value is given in lst-of-rice, and use the value of
lst-of-rice when we use is key.


Thanks, and sorry for the first email.



^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <1f5de71a-c5aa-b850-023e-96fdd471dab5@disroot.org>]
* Re: help : call function with args
@ 2018-04-05  8:16 calcium
  2018-04-05  8:54 ` Thomas Morley
  0 siblings, 1 reply; 9+ messages in thread
From: calcium @ 2018-04-05  8:16 UTC (permalink / raw)
  To: guile-user

> 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))



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-04-05  9:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-03 20:43 help : call function with args amnesia
2018-04-03 22:40 ` Mark H Weaver
2018-04-04  7:27 ` tomas
  -- strict thread matches above, loose matches on Subject: below --
2018-04-04  7:43 calcium
2018-04-04 14:39 ` tomas
     [not found] <1f5de71a-c5aa-b850-023e-96fdd471dab5@disroot.org>
2018-04-04  8:01 ` calcium
2018-04-05  8:16 calcium
2018-04-05  8:54 ` Thomas Morley
2018-04-05  9:42   ` calcium

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).