Hello all,

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?

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

Thanks,
Jason

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