Can I see method source code?

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

No, there are only a few languages I can think of (okay, 2) that allow this: the aforementioned javascript, and Io; Ruby does not.

···

On 06-09-01, at 02:45, femto gary wrote:

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

--
Jeremy Tregunna
jtregunna@blurgle.ca

hi,

···

On 9/1/06, femto gary <femtowin@gmail.com> wrote:

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

http://blog.zenspider.com/archives/2005/02/rubytoruby.html
may be of some use

femto gary wrote:

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

you can search c.l.ruby for all the SCRIPT_LINES__ tricks that people
ahve done

Just out of curiosity: what about Lisp?

  robert

···

On 01.09.2006 09:23, Jeremy Tregunna wrote:

On 06-09-01, at 02:45, femto gary wrote:

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

No, there are only a few languages I can think of (okay, 2) that allow this: the aforementioned javascript, and Io; Ruby does not.

hello all, Can I see method source code,

http://blog.zenspider.com/archives/2005/02/rubytoruby.html

Yup. I made another, much simpler one, using method_added:
http://svn.twifkak.com/jonx/site_ruby/dlm/irb.rb

Only works for methods defined normally, in actual files. Not meta-programming friendly or anything. Just a cheap hack, but great (as the URL implies) for IRB use.

Devin

Lies (provided the method is written in Ruby).

$ ruby -rlib/ruby2ruby.rb -I ../../ruby_to_c/dev/lib/ -e 'puts Object.source(:source)'
def source(method_name = nil)
   RubyToRuby.new.process(parse_tree(method_name))
end

You can find ruby2ruby.rb in the ZenHacks gem.

···

On Sep 1, 2006, at 12:23 AM, Jeremy Tregunna wrote:

On 06-09-01, at 02:45, femto gary wrote:

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

No, there are only a few languages I can think of (okay, 2) that allow this: the aforementioned javascript, and Io; Ruby does not.

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

I don't know of a single lisp implementation that lets you do this, perhaps you could enlighten me?

···

On 06-09-01, at 04:10, Robert Klemme wrote:

On 01.09.2006 09:23, Jeremy Tregunna wrote:

On 06-09-01, at 02:45, femto gary wrote:

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

No, there are only a few languages I can think of (okay, 2) that allow this: the aforementioned javascript, and Io; Ruby does not.

Just out of curiosity: what about Lisp?

--
Jeremy Tregunna
jtregunna@blurgle.ca

<disclaimer>No LISP guru here</disclaimer>

I probably confused lambdas with normal functions:

[1]> (setq f1 (lambda (x) (+ x x)))
#<FUNCTION :LAMBDA (X) (+ X X)>
[2]> (funcall f1 10)
20
[3]> f1
#<FUNCTION :LAMBDA (X) (+ X X)>

So, for a lambda you can - but apparently for functions you can't. Or can you?

Kind regards

  robert

···

On 01.09.2006 11:26, Jeremy Tregunna wrote:

On 06-09-01, at 04:10, Robert Klemme wrote:

On 01.09.2006 09:23, Jeremy Tregunna wrote:

On 06-09-01, at 02:45, femto gary wrote:

hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It's especailly useful when you examine other's code
or dynamic generating func/method.

No, there are only a few languages I can think of (okay, 2) that allow this: the aforementioned javascript, and Io; Ruby does not.

Just out of curiosity: what about Lisp?

I don't know of a single lisp implementation that lets you do this, perhaps you could enlighten me?

I think that it just looks like the source here. The print-name of a
lambda can look pretty much like source code because the internal
representation looks a lot like the source code. But it's not really
the source code.

···

On 9/1/06, Robert Klemme <shortcutter@googlemail.com> wrote:

<disclaimer>No LISP guru here</disclaimer>

I probably confused lambdas with normal functions:

[1]> (setq f1 (lambda (x) (+ x x)))
#<FUNCTION :LAMBDA (X) (+ X X)>
[2]> (funcall f1 10)
20
[3]> f1
#<FUNCTION :LAMBDA (X) (+ X X)>

So, for a lambda you can - but apparently for functions you can't. Or
can you?

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/

<disclaimer>No LISP guru here</disclaimer>

I probably confused lambdas with normal functions:

[1]> (setq f1 (lambda (x) (+ x x)))
#<FUNCTION :LAMBDA (X) (+ X X)>
[2]> (funcall f1 10)
20
[3]> f1
#<FUNCTION :LAMBDA (X) (+ X X)>

So, for a lambda you can - but apparently for functions you can't. Or
can you?

I think that it just looks like the source here. The print-name of a
lambda can look pretty much like source code because the internal
representation looks a lot like the source code. But it's not really
the source code.

Note that this is the same reason Ruby2Ruby doesn't give you the "source code". Of course the OP probably doesn't really care if he gets the source code "character for character".

···

On Sep 2, 2006, at 5:28 PM, Rick DeNatale wrote:

On 9/1/06, Robert Klemme <shortcutter@googlemail.com> wrote:

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/

Rick DeNatale wrote:

···

On 9/1/06, Robert Klemme <shortcutter@googlemail.com> wrote:

<disclaimer>No LISP guru here</disclaimer>

I probably confused lambdas with normal functions:

[1]> (setq f1 (lambda (x) (+ x x)))
#<FUNCTION :LAMBDA (X) (+ X X)>
[2]> (funcall f1 10)
20
[3]> f1
#<FUNCTION :LAMBDA (X) (+ X X)>

So, for a lambda you can - but apparently for functions you can't. Or
can you?

I think that it just looks like the source here. The print-name of a
lambda can look pretty much like source code because the internal
representation looks a lot like the source code. But it's not really
the source code.

And what about Forth ? :wink: At least the HP48 version can show
source, and it's easy to implement in a "personal" version.