Python syntax in Lisp and Scheme
Christoph (news_chr)
swap at gmx.net
Sat Oct 4 18:42:11 EDT 2003
"Alex Martelli" wrote:
...
> def outer(a) proc do |b| a+=b end end
>
> x = outer(23)
> puts x.call(100) # emits 123
> puts x.call(100) # emits 223
>
> [i.e., I can't think of any way you could just use x(100)
> at the end of such a snippet in Ruby -- perhaps somebody
> more expert of Ruby than I am can confirm or correct...?]
Guy is probably thinking about something like this
---
def outer(sym,a)
Object.instance_eval {
private # define a private method
define_method(sym) {|b| a+=b }
}
end
outer(:x,24)
p x(100) # 124
p x(100) # 224
---
but there is no way to write a ``method returning
method ::outer in Ruby that could be used in the form
----
x = outer(24)
x(100)
----
On the other hand, using []-calling convention
and your original definition, you get - at least
visually - fairly close.
---
def outer(a) proc do |b| a+=b end end
x = outer(23)
puts x[100] # emits 123
puts x[100] # emits 223
---
/Christoph
More information about the Python-list
mailing list