hi Jason,

> I was a bit surprised to find out just how lazy LazyFamily is:
> 
> sage: f = Family(Zmod(3), lambda i: 2*i)  # This will be lazy by default
> sage: f[2] # I think this should be 1
> 4
> sage: f['spam']  # I think this should fail
> 'spamspam'
> 
> Compare with:
> sage: f = Family([i for i in Zmod(3)], lambda i: 2*i)
> sage: f[2]
> 1
> sage: f['spam']
> KeyError: 'spam'
> 
> I expected that the __getitem__ method for lazy family would
> 
> 1) Check that the value given is (or can be coerced to) a key, and
> 2) If a coercion is necessary, call the function on the coerced item.
> 
> But I guess that not everyone agrees since one of the tests in LazyFamily is
> 
>     sage: f = LazyFamily([3,4,7], lambda i: 2*i)
>     sage: f[5]
>     10
> 
> Perhaps there are arguments about pythonic code and the value of
> duck-typing that I'm not appreciating here.  Or maybe the issue is
> performance.  But can someone say a few words about the rationale for
> this decision?

When calling Family(keys, functions) keys can be pretty anything: lists,
tuple, parent in the category EnumeratedSets() or probably anythng which is
iterable... We didn't assume that x in keys or keys(x) has any meaning. For
example, I think the following is legal:

sage: class toto(object): 
....:    def __iter__(self): 
....:       for i in [1,2,3]: yield i
....: 
sage: bla = toto()
sage: Family(bla, lambda x: x^2)
Lazy family (<lambda>(i))_{i in <__main__.toto object at 0x45f7f10>}

Maybe this is too much permissive. So you are suggesting we should also
require that keys should also implement __contains__. In what concerns
coercion, please remember that a common usage is to lists as keys...

> On a related note, the following *really* looks like a bug to me:
> 
> sage: f = Family(Zmod(3), lambda i: 2*i, lazy=False)
> sage: f
> Lazy family (<lambda>(i))_{i in Ring of integers modulo 3}
> 
> Should we really just silently ignore the intent here, or should
> 
> Family(S, f, lazy=False) always return Family([i for i in S], f)
> 
> (I guess the default for lazy should then be made 'None' so that 'True',
> 'False' and 'None' could all have different behaviors.)

This is clearly a bug ! Thanks for pointing this out.

Cheers,

Florent

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" group.
To post to this group, send email to sage-combinat-de...@googlegroups.com.
To unsubscribe from this group, send email to 
sage-combinat-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sage-combinat-devel?hl=en.

Reply via email to