On Jun 18, 10:30 am, tvn <[email protected]> wrote:
> in particular sage's id()  gives different results (memory) address  for the
> below examples whereas python's id() gives the same  (expected)

Sage uses a shell that is different from python's (sage uses IPython),
and keeps a history. So while in python the memory cells used in the
previously line are immediately released and ready for reuse, they are
not in Sage. Compare

>>> [id(lambda x:x),id(lambda x:x+1)]
[47227954829624, 47227954829624]

vs.

sage: [id(lambda x:x),id(lambda x:x+1)]
[150535416, 150535416]

(the list is pre-allocated and the ints fit right in, so the lambda
construct can be deleted as soon as its ID is determined, after which
the same memory cells can be reused for the next lambda construct).
There is no fancy reuse happening in either:

sage: L=[lambda x:x, lambda x:x]
sage: [id(l) for l in L]
[150480248, 150535056]

>>> L=[lambda x:x, lambda x:x]
>>> [id(l) for l in L]
[47191758731816, 47191758730976]

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to