[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Working with generic functions
- To: Kenneth Knight <krk@oit.itd.umich.edu>
- Subject: Re: Working with generic functions
- From: moon (David A. Moon)
- Date: Wed, 02 Dec 92 20:47:18 EST
- Cc: info-dylan@cambridge.apple.com
> Date: Wed, 2 Dec 92 13:58:28 EST
> From: Kenneth Knight <krk@oit.itd.umich.edu>
>
> I am writing methods to do some basic combinatorics (permutation, r-permutation
> , combinations, and so on). The problem is that I'd like to access the 'permute'
> function in two ways: 1. as P(n) for permuting an entire set of objects; and,
> 2. as P(n,r) for permuting n objects in r subsets. I have factorial written
> and it works. My problem is that from what I can tell (and what Thomas,
> thank Mark Feeley for a nice embedded version) I can not create two methods
> called 'permute' with different number of parameters. The param-lists are
> not congruent. I would very much like to call both of the functions 'permute'
> but I do not want the aggrivation of having to type (permute 6 6) to find out
> how many permutations are in a 6 objet set. Is there a way I can manage this?
Use keyword arguments.
(define-method permute (n #key (r n)) ...)
(permute 6)
(permute 6 r: 4)
You might want to choose a more mnemonic keyword name than r.