unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* (define* (((f a) b) c) ...)
@ 2011-03-13 15:49 Dan Gildea
  2011-03-15  8:37 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Gildea @ 2011-03-13 15:49 UTC (permalink / raw)
  To: guile-user

In guile 2.0, I need to use "define*" to define second-order functions
such as:

(define* ((f a) b) 
   ...)

But define* doesn't work for higher-order functions, or for more
complicated definitions of second-order functions, such as:

(define* (((f a) b) c) 
   ...)

(define* ((f #:optional a) b) 
   ...)

These forms are very common in the scmutils mechanics functions.
Is there any way around this, other than using lambda, as in:

(define* ((f a) b) 
   (lambda (c) 
     ...))

(define* (f #:optional a) 
   (lambda (b) 
     ...))

?



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

* Re: (define* (((f a) b) c) ...)
  2011-03-13 15:49 (define* (((f a) b) c) ...) Dan Gildea
@ 2011-03-15  8:37 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2011-03-15  8:37 UTC (permalink / raw)
  To: Dan Gildea; +Cc: guile-user

Hi,

Dan Gildea <gildea@cs.rochester.edu> writes:

> In guile 2.0, I need to use "define*" to define second-order functions
> such as:
>
> (define* ((f a) b) ...)

You should use (ice-9 curried-definitions) for this (see NEWS), and...

> But define* doesn't work for higher-order functions, or for more
> complicated definitions of second-order functions, such as:
>
> (define* (((f a) b) c) ...)
>
> (define* ((f #:optional a) b) ...)

it also works for optional/keyword arguments:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (use-modules(ice-9 curried-definitions))
scheme@(guile-user)> (define* ((f #:optional a) b) (list a b))
scheme@(guile-user)> ((f) 2)
$2 = (#f 2)
scheme@(guile-user)> ((f 1) 2)
$3 = (1 2)
--8<---------------cut here---------------end--------------->8---

Hope this helps,
Ludo’.



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

end of thread, other threads:[~2011-03-15  8:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-13 15:49 (define* (((f a) b) c) ...) Dan Gildea
2011-03-15  8:37 ` Ludovic Courtès

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