[#16611] lambda, ->, haskell, and so on — Dave Thomas <dave@...>

This is one of those e-mails that I know from the start to be futile, =20=

148 messages 2008/05/01
[#16661] Re: lambda, ->, haskell, and so on — Paul Brannan <pbrannan@...> 2008/05/05

On Thu, May 01, 2008 at 12:26:47PM +0900, Dave Thomas wrote:

[#16662] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/05

Hi --

[#16663] Re: lambda, ->, haskell, and so on — ts <decoux@...> 2008/05/05

David A. Black wrote:

[#16664] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/05

Hi --

[#16682] Re: lambda, ->, haskell, and so on — ara howard <ara.t.howard@...> 2008/05/08

[#16684] Re: lambda, ->, haskell, and so on — Michael Neumann <mneumann@...> 2008/05/08

ara howard wrote:

[#16687] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/08

Hi --

[#16691] Re: lambda, ->, haskell, and so on — "ara.t.howard" <ara.t.howard@...> 2008/05/08

[#16692] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/08

Hi --

[#16695] Re: lambda, ->, haskell, and so on — "ara.t.howard" <ara.t.howard@...> 2008/05/08

[#16705] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/11

Not to throw the whole thread into a tizzy again, but why again is:

[#16708] Re: lambda, ->, haskell, and so on — Nobuyoshi Nakada <nobu@...> 2008/05/11

Hi,

[#16720] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/11

Hi,

[#16721] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/12

Hi --

[#16722] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16723] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/12

[#16724] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16726] Re: lambda, ->, haskell, and so on — Nathan Weizenbaum <nex342@...> 2008/05/12

What about "fn" or "fun", for "function"?

[#16728] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16731] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/12

[#16732] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16759] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/13

Hi --

[#16766] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/14

Hi,

[#16784] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/18

Hi --

[#16795] Re: lambda, ->, haskell, and so on — Nate_Wiger@... 2008/05/19

On Wed, 14 May 2008, David A. Black wrote:

[#16797] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/19

Hi,

[#16798] Re: lambda, ->, haskell, and so on — "Christopher Gill" <gilltots@...> 2008/05/19

how about an uppercase lambda (instead of the usual lowercase one)

[#16802] Re: lambda, ->, haskell, and so on — "Suraj N. Kurapati" <sunaku@...> 2008/05/20

Christopher Gill wrote:

[#16843] Re: lambda, ->, haskell, and so on — "Suraj N. Kurapati" <sunaku@...> 2008/05/22

Suraj N. Kurapati wrote:

[#16846] Re: lambda, ->, haskell, and so on — "Berger, Daniel" <Daniel.Berger@...> 2008/05/22

=20

[#16854] Re: lambda, ->, haskell, and so on — "=?ISO-8859-2?Q?Rados=B3aw_Bu=B3at?=" <radek.bulat@...> 2008/05/22

T24gVGh1LCBNYXkgMjIsIDIwMDggYXQgNTozNyBQTSwgQmVyZ2VyLCBEYW5pZWwgPERhbmllbC5C

[#16857] Re: lambda, ->, haskell, and so on — "Jeremy McAnally" <jeremymcanally@...> 2008/05/23

RXZlbiB0aG91Z2ggSSBzZWUgdGhlIHVzZWZ1bG5lc3MsIHRoYXQncyBqdXN0IHVnbHkuCgotLUpl

[#16874] Re: lambda, ->, haskell, and so on — Nate_Wiger@... 2008/05/23

"Jeremy McAnally" <jeremymcanally@gmail.com> wrote on 05/22/2008 05:35:01=20

[#16875] Re: lambda, ->, haskell, and so on — "Nikolai Weibull" <now@...> 2008/05/23

2008/5/23 <Nate_Wiger@playstation.sony.com>:

[#16886] lambda with normal block syntax — "Eric Mahurin" <eric.mahurin@...>

This patch is an independent but related one to my previous one. It can be

64 messages 2008/05/25
[#16895] Re: [PATCH] lambda with normal block syntax — Nobuyoshi Nakada <nobu@...> 2008/05/26

Hi,

[#16900] Re: [PATCH] lambda with normal block syntax — "Eric Mahurin" <eric.mahurin@...> 2008/05/26

On Sun, May 25, 2008 at 8:19 PM, Nobuyoshi Nakada <nobu@ruby-lang.org>

[#16901] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16902] Re: [PATCH] lambda with normal block syntax — "Suraj N. Kurapati" <sunaku@...> 2008/05/26

Hi,

[#16903] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16904] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16905] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16907] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16912] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16920] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

If I may, here are two entries from the ChangeLog file:

[#16922] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16927] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

Dave Thomas wrote:

[#16928] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16929] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

Dave Thomas wrote:

[#16931] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/27

[#16946] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/27

Dave Thomas wrote:

[#16947] Re: [PATCH] lambda with normal block syntax — James Gray <james@...> 2008/05/27

On May 27, 2008, at 12:33 PM, David Flanagan wrote:

[#16949] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/27

James Gray wrote:

docstrings (Was Re: Uniform RDoc markup)

From: "Rocky Bernstein" <rocky.bernstein@...>
Date: 2008-05-05 11:07:02 UTC
List: ruby-core #16657
Speaking of Ruby and documentation, I'd like to put in a suggestion for
document strings. Emacs Lisp and Python both have it.  And in both is a
really good thing and made heavy use of it. It means at run time one can get
very specific documentation information.

I leave open where and how this information is tagged. In both Emacs Lisp
and Python this is a string that appears after the method "signature".
However
it is also possible that something could be done to use the comment before
the method definition, the same as rdoc currently uses.

Finally, I'd like to put in a plug for Paul Brannan's work in ruby-internal
for getting method signatures dynamically.
Paul Brannan to me
show details Apr 29 (6 days ago)
Reply
On Tue, Apr 29, 2008 at 11:44:37AM -0400, Rocky Bernstein wrote:
> Some things though relating to method signatures. First, in contrast to
what
> the nodewrap documentation <http://rubystuff.org/nodewrap/> seems to
> suggest, adding:
>     require 'methodsig'
> is what worked for me. Is this correct, or am I doing something wrong?

Yes, that's correct, and I've fixed the webpage.

> Also, methods implemented in C give an error when trying to get the
> signature:
>   NoMethodError: undefined method `argument_names' for #<Node::CFUNC
> cfnc=-1209864880, argc=-1>

Good catch.  I'm not surprised by this at all.

I've entered a bug:

http://rubyforge.org/tracker/index.php?func=detail&aid=19854&group_id=313&atid=1268

> Attached is a patch that add an "impl" instance variable to the signature
> which right now can be :cfunc or nil if not a C function. I'm not sure
what
> other possibilities there are but no doubt there may be other interesting
> kinds of method implementations. For example, perhaps a "compiled" method
of
> YARV might be an interesting thing to note here.

Thank you for the patch.  It needs unit tests and a few fixes before I
can commit.  Do you want to do this or should I add it to my todo list?
I've put my comments below.

BTW, all my nodewrap development is now going toward ruby-internal on
github, so this patch should really be against
lib/internal/method/signature.rb rather than lib/methodsig.rb.

> Another problem I've noticed is that classtree gives an error:
> Object.classtree
> ArgumentError: cyclic include detected
>     from ./classtree.rb:20:in `real_superclass'
>     from ./classtree.rb:20:in `classtree'
>     from ./classtree.rb:22:in `classtree'
>     from ./classtree.rb:25:in `classtree'
>     from (irb):2

Hmm, I wonder when this broke.  This is why unit tests are important. :)

http://rubyforge.org/tracker/index.php?func=detail&aid=19853&group_id=313&atid=1268

> Unless this is a known problem that you care to elucidate on, I'll
probably
> look at this some other day.
>
> As before, thanks for the great work.

Thanks for your feedback!

> cvs diff -u
> cvs diff: Diffing .
> Index: methodsig.rb
> ===================================================================
> RCS file: /var/cvs/nodewrap/nodewrap/lib/methodsig.rb,v
> retrieving revision 1.19
> diff -u -r1.19 methodsig.rb
> --- methodsig.rb      19 Feb 2008 03:40:41 -0000      1.19
> +++ methodsig.rb      29 Apr 2008 15:13:57 -0000
> @@ -53,7 +53,11 @@
>    # Return the names of the arguments this method takes, in the order in
>    # which they appear in the argument list.
>    def argument_names
> -    return self.body.argument_names
> +    if @impl == :cfunc
> +      return ['argc']

This isn't right.  The cfunc still has argument names; we just don't
know what they are.  For a method that takes 3 args argument_names()
should return an array with 3 elements, even if those elements are just
'arg1', 'arg2,' and 'arg3'.

Also, using 'if' like this isn't OO-style.  It's better to make use of
polymorphism instead.  I think this can be done implementing
Node::CFUNC#local_vars, Node::CFUNC#argument_names, and the like.

> +    else
> +      return self.body.argument_names
> +   end
>    end
>
>    def args_node
> @@ -83,28 +87,32 @@
>    # Return a hash mapping each argument name to a description of that
>    # argument.
>    def arguments
> -    names = self.argument_names()
> -    block_arg = self.block_arg()
> -
>      args = {}
> -    names.each do |name|
> -      args[name] = Argument.new(name, nil, nil, false, false)
> -    end
> +    if @impl == :cfunc
> +      args['argc'] = self.body.argc

All members of the args hash should be of type Argument.

> +    else
> +      names = self.argument_names()
> +      block_arg = self.block_arg()
> +
> +      names.each do |name|
> +        args[name] = Argument.new(name, nil, nil, false, false)
> +      end
>
> -    # Optional args
> -    args_node = args_node()
> -    set_optional_args(args, args_node, names)
> +      # Optional args
> +      args_node = args_node()
> +      set_optional_args(args, args_node, names)
>

Cfunc never has optional args (as your code correctly handles),

> -    # Rest arg
> -    if self.rest_arg then
> -      rest_name = names[rest_arg]
> -      args[rest_name] = Argument.new(rest_name, nil, nil, true, false)
> -    end
> +      # Rest arg
> +      if self.rest_arg then
> +        rest_name = names[rest_arg]
> +        args[rest_name] = Argument.new(rest_name, nil, nil, true, false)
> +      end

But it can have a single rest arg in some cases:

irb(main):006:0> method(:puts).body
=> #<Node::CFUNC cfnc=47601960251488, argc=-1>

> -    # Block arg
> -    if block_arg then
> -      block_name = names[block_arg]
> -      args[block_name] = Argument.new(block_name, nil, nil, false, true)
> +      # Block arg
> +      if block_arg then
> +        block_name = names[block_arg]
> +        args[block_name] = Argument.new(block_name, nil, nil, false,
true)
> +      end
>      end

CFUNC should never have an explicit block arg (again, your code is
correct).

>
>      return args
> @@ -112,17 +120,19 @@
>
>    # An abstraction for a method signature.
>    class Signature
> -    attr_reader :origin_class, :name, :arg_names, :args
> +    attr_reader :origin_class, :name, :arg_names, :args, :impl
>
> -    def initialize(origin_class, name, arg_names, args)
> +    def initialize(origin_class, name, arg_names, args, impl=nil)
>        @origin_class = origin_class
>        @name = name
>        @arg_names = arg_names
>        @args = args
> +      @impl = impl
>      end
>
>      def to_s
> -      return "#{@origin_class}\##{@name}(#{param_list})"
> +      impl = :cfunc == @impl ? ' C function' : ''
> +      return "#{@origin_class}\##{@name}(#{param_list})#{impl}"
>      end
>
>      def param_list
> @@ -155,13 +165,21 @@
>  class Method
>    include MethodSig
>
> +  def initialize
> +    @impl = nil
> +  end
> +
>    # Return a String representing the method's signature.
>    def signature
> +    if self.body.respond_to?(:nd_type) and 'CFUNC' ==
self.body.nd_type.name
> +      @impl = :cfunc
> +    end
>      return Signature.new(
>          attached_class(),
>          method_oid().to_s,
>          argument_names(),
> -        arguments())
> +        arguments(),
> +        @impl)
>    end
>  end
>
> @@ -170,11 +188,15 @@
>
>    # Return a String representing the method's signature.
>    def signature
> +    if self.body.respond_to?(:nd_type) and 'CFUNC' ==
self.body.nd_type.name
> +      @impl = :cfunc
> +    end
>      return Signature.new(
>          origin_class(),
>          method_oid().to_s,
>          argument_names(),
> -        arguments())
> +        arguments(),
> +        @impl)
>    end
>  end
>
> @@ -386,5 +408,6 @@
>
>    def foo(foo, bar=[1,2], *args, &block); end
>    puts method(:foo).signature
> +  puts method(:caller).signature
>  end

 Reply
Forward

On Mon, May 5, 2008 at 2:55 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

>
> On May 4, 2008, at 13:37 , Phil Hagelberg wrote:
>
>  "Jeremy McAnally" <jeremymcanally@gmail.com> writes:
> >
> >  Would there be any resistance to making the markup of the RDoc
> > > throughout the core code more consistent?
> > >
> >
> > I would be very much in favour of seeing stronger conventions applied
> > throughout the Ruby community in the standard library, in gems, and
> > elsewhere. That's one of the things I miss from writing Emacs Lisp; it
> > has very specific guidelines[1]
> >
>
> I guess Phil brings up a good point... emacs lisp doco is a breeze to
> read.
>
> I don't mind any work making rdoc more consistent, but I'll resist any
> efforts to make it so damn structured. Do we really need to have an h4 tag
> for the parameters, options, returns, examples sections??? Let's leave
> javadoc to the java ppl and do something cleaner and clearer.
>
>
>

In This Thread

Prev Next