Re: Default values

2015-02-21 Thread Jeremy Heiler
On 2/21/15 4:57 AM, Cecil Westerhof wrote: I want to work with default values. For this I use: [& nr] This gives the value null to nr. So far so good. But I want to propagate the value, because I want to fill the default at a higher level. ​I have: (defn test-lucky-numbers

Re: Default values

2015-02-21 Thread Cecil Westerhof
problem is that the function also accepts two parameters. (I understood optional parameters wrongly.) I should probably go back to my first option of a multi-arity function. Would a be possibly to define a value that is only known in the local source file? > On Sat Feb 21 2015 at 9:58:00 AM Cec

Re: Default values

2015-02-21 Thread Ulises
o use apply, e.g.: user=> (defn foo [& stuff] stuff) #'user/foo user=> (defn bar [& things] (apply foo things)) #'user/bar user=> (bar 1 2 3) (1 2 3) On Sat Feb 21 2015 at 9:58:00 AM Cecil Westerhof wrote: > I want to work with default values. For this I use: >

Default values

2015-02-21 Thread Cecil Westerhof
I want to work with default values. For this I use: [& nr] This gives the value null to nr. So far so good. But I want to propagate the value, because I want to fill the default at a higher level. ​I have: (defn test-lucky-numbers-all "Test all lucky number pe

Re: defrecord with default values

2010-09-07 Thread anthonyghr
Awesome! Thanks so much! Anthony On Sep 7, 2:10 am, Meikel Brandmeyer wrote: > Hi, > > first of all we should start with the form we finally want to have: > > (defrecord Foo [a b c]) > > (defn make-Foo >   [& {:keys [a b c] :or {a :x c :z}}] >   (Foo. a b c)) > > ; Use as: (make-Foo :b :f) => (

Re: defrecord with default values

2010-09-06 Thread Meikel Brandmeyer
Hi, first of all we should start with the form we finally want to have: (defrecord Foo [a b c]) (defn make-Foo [& {:keys [a b c] :or {a :x c :z}}] (Foo. a b c)) ; Use as: (make-Foo :b :f) => (Foo. :x :f :z) The only annoying part is the boilerplate of defining make-Foo. What we would like

defrecord with default values

2010-09-06 Thread anthonyghr
Disclamer: I'm a Clojure noob, so bad code follows... I have been putzing around with implementing a Simple Temporal Network (a graph structure for scheduling problems) in Clojure. In the process, I wanted to generate records that had default values. I ran into this blog post by cemerick

Re: Default values for fields of a defrecord?

2010-08-27 Thread Stuart Sierra
No, constructor functions are the correct way to accomplish this. -S On Aug 27, 5:16 pm, Darren Austin wrote: > Hi folks, > > Is there a way to specify default values for the fields of a > defrecord?  Or barring that, is there a way to override or augment the > constructor

Default values for fields of a defrecord?

2010-08-27 Thread Darren Austin
Hi folks, Is there a way to specify default values for the fields of a defrecord? Or barring that, is there a way to override or augment the constructor for the record? That is, if I have: (defrecord Foo [a b c d e f g]) I want to be able to create a new Foo with: (Foo.) and have default

Re: Maps with functions for default values

2010-07-12 Thread Steve Purcell
On 12 Jul 2010, at 16:13, aria42 wrote: > Is there a way to set up a map so that there is a default function > which depending on the key returns a value if one is not present in > the map. I can obviously write this with a deftype and have it > implement Associative, Seqable, etc. so it behaves l

Maps with functions for default values

2010-07-12 Thread aria42
Is there a way to set up a map so that there is a default function which depending on the key returns a value if one is not present in the map. I can obviously write this with a deftype and have it implement Associative, Seqable, etc. so it behaves like a built-in map, but just wondering if there w

Re: more constructors (to support default values) for deftype?

2010-01-29 Thread Rich Hickey
On Fri, Jan 22, 2010 at 5:41 PM, Raoul Duke wrote: > hi, > > if i have (deftype map-db [next-id id-to-item-map]) i have to then do > (map-db 0 {}) any time i want to make a new one. it would be nice to > be able to add a function in my deftype so i could use (map-db) to get > the same effect. > >

more constructors (to support default values) for deftype?

2010-01-22 Thread Raoul Duke
hi, if i have (deftype map-db [next-id id-to-item-map]) i have to then do (map-db 0 {}) any time i want to make a new one. it would be nice to be able to add a function in my deftype so i could use (map-db) to get the same effect. ? -- You received this message because you are subscribed to the

Re: hashmap default values

2009-04-27 Thread Meikel Brandmeyer
Hi Mark, Am 27.04.2009 um 23:42 schrieb Mark Volkmann: Is there something in core or contrib that supports creating a map where gets on undefined keys return a specified default value? For example, I'd like to create a hashmap where the default value for missing keys is zero. You can specify

hashmap default values

2009-04-27 Thread Mark Volkmann
Is there something in core or contrib that supports creating a map where gets on undefined keys return a specified default value? For example, I'd like to create a hashmap where the default value for missing keys is zero. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~--