Can I see method source code?

F

femto gary

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.
 
J

Jeremy Tregunna

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.
 
R

Robert Klemme

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?

robert
 
R

Robert Klemme

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

<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
 
G

Gene Tani

femto said:
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
 
E

Eric Hodel

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

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.
 
R

Rick DeNatale

<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.

--
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/
 
L

Logan Capaldo

<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".
 
J

Jean-Claude Arbaut

Rick said:
<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 ? ;-) At least the HP48 version can show
source, and it's easy to implement in a "personal" version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top