[sage-support] list of functions
Hi again, ... and again sorry if this is a newbie's question: so when I type (in my sage Notebook 3.2.3) a = [i for i in range(2)] a[0] I get 0 (which is fine), now when I type b = [lambda x:i for i in range(2)] b[0](0) I get 1 ... There must be a simple explanation for this but I can't figure it out. What's wrong ? Thanks in advance, (sage is really wonderful :-) - Martin --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Strange behaviour of float()?
Hi everybody, in my Notebook (version 3.2.3) I get the following: sage: a = float(11) sage: a 0.0 sage: var('x') sage: b(x) = float(x1) Traceback (most recent call last): File stdin, line 1, in module File /Users/campos/.sage/sage_notebook/worksheets/admin/4/code/ 204.py, line 8, in module _=var(x);b=symbolic_expression(float(x_sage_const_1 )).function (x) File /Applications/sage/local/lib/python2.5/site-packages/ SQLAlchemy-0.4.6-py2.5.egg/, line 1, in module TypeError: float() argument must be a string or a number ... is this a normal behaviour for float()? And sorry is this is a silly question! -- Martin --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: list of functions
This is caused by the scoping rules for Python's lambdas and list comprehensions. See the question and answer here for an explanation:http://stackoverflow.com/questions/139819/why-results-of-map-and-list... --Mike ...ok, so, a way to write it would be b = [lambda x,u=i:u for i in range(2)] Thanks for the link, that was very helpful. -- Martin --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---