tag:blogger.com,1999:blog-5135517.post110237221137889596..comments2023-11-05T03:54:44.710-08:00Comments on Making it stick.: Programming and SpreadsheetsPatrick Loganhttp://www.blogger.com/profile/02088461489050417591noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5135517.post-1102583481456626292004-12-09T01:11:00.000-08:002004-12-09T01:11:00.000-08:00How about using lambdas for expressions. The you a...How about using lambdas for expressions. The you are using the language.<br /><br />For instance <br /><br />class spreadsheet(dict):<br /> def __getitem__(self,val):<br /> if callable(super(spreadsheet,self).__getitem__(val)) :<br /> return super(spreadsheet,self).__getitem__(val) (self)<br /> else:<br /> return super(spreadsheet,self).__getitem__(val)<br /><br /># Excuse the formatting I couldn't get it too look right ;-)<br />Then <br />>>> s = spreadsheet()<br />>>> s['a1'] = 4<br />>>> s['a2'] = 2<br />>>> s['a3'] = lambda self: self['a1'] + self['a2']<br /><br />>>> s['a3]<br />6<br />>>> s['a4'] = lambda self: self['a3'] * 10<br />60<br /><br />Yep heaps of stuff is missing ;-)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5135517.post-1102519689516551382004-12-08T07:28:00.000-08:002004-12-08T07:28:00.000-08:00Jim Weirich responded to this post and tackled it ...Jim Weirich responded to this post and tackled it in Ruby. It's a pity there is no referer or trackback on this page. URL (can't figure out how to make it a link):<br /><br />http://onestepback.org/index.cgi/Tech/Ruby/SlowingDownCalculations.rdocAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5135517.post-1102461432655456892004-12-07T15:17:00.000-08:002004-12-07T15:17:00.000-08:00You can use that same technique (ss cell: 1@1) in ...You can use that same technique (ss cell: 1@1) in Python. That's what I do in SQLObject.sqlbuilder to construct queries; you can override all the operators (as of Python 2.1) to return arbitrary objects. Except the boolean operators (and, or, not), which is a bit annoying. I still find it kind of hacky, since it involves these magic objects, that are kind of value and kind of not. But one of the advantages of this over eval() is that you can mix in known constants, even when they are stored in a variable. And you could potentially mix in other late-bound values and expressions, though both in Python and Smalltalk you'd have to wrap them in a closure. (Which is prettier in Smalltalk)<br /><br />When I think of spreadsheets I usually think about it in terms of naked objects -- variables and arrays made visually manifest, and thus much more accessible. But this aspect is important too... it's more the mathematical notion: the use of "=" to mean "is equal to", not "is equal to?" or "make equal to". Prolog-ish, even if the implementations tend to be constrained so that they can be implemented in an imperative way.Ian Bickinghttps://www.blogger.com/profile/10921115783730718101noreply@blogger.comtag:blogger.com,1999:blog-5135517.post-1102442376446706732004-12-07T09:59:00.000-08:002004-12-07T09:59:00.000-08:00One of my favorite spreadsheets is Levoy's "Spread...One of my favorite spreadsheets is Levoy's "Spreadsheets for Images", http://graphics.stanford.edu/projects/spreadsheets/<br /><br />Bit backwards: he essentially put Tcl (+ image stuff) in a spreadsheet. But a neat example nonetheless of a alternative user interface.<br /><br /><A HREF="http://www.blogger.com/r?http%3A%2F%2Fwww.machinelake.com">gavin</A>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5135517.post-1102437205706022862004-12-07T08:33:00.000-08:002004-12-07T08:33:00.000-08:00> ss cell: 1@2 value: (ss cell: 1@1) * 6.
Don't y...> ss cell: 1@2 value: (ss cell: 1@1) * 6.<br /><br />Don't you rather want:<br />ss cell: 1@2 value: [(ss cell: 1@1) * 6]<br /><br />?<br /><br />Add cell value caching and invalidation after change ...<br /><br /><br />Matthias ErnstAnonymousnoreply@blogger.com