Forum: Ruby Legal symbol names and generics

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 drjflam (Guest)
on 2005-11-24 17:26
(Received via mailing list)
I've just started thinking about generics in my Ruby <=> CLR bridge.
This is
what I'd love to be able to do:

channel = ChannelFactory<IOutputChannel>("
http://www.flickr.com/services/soap/").CreateChannel

The problem is how to deal with the stuff in angle brackets since < and
>
are not legal inside of Ruby constants. Any thoughts on how to
syntactically
deal with this issue?

Thanks
-John
http://www.iunknown.com
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 drjflam (Guest)
on 2005-11-24 18:03
(Received via mailing list)
Whoops, that should be:

channel = ChannelFactory<IOutputChannel>("
http://www.flickr.com/services/soap/").new.CreateC...

-John
http://www.iunknown.com
B97225f66bb5caac601b12735d430a0d?d=identicon&s=25 lopexx (Guest)
on 2005-11-24 18:11
(Received via mailing list)
it is legal (just use another symbol construction literal):

x = :"< ... >"
p x

lopex
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 drjflam (Guest)
on 2005-11-24 18:15
(Received via mailing list)
Ah, so it is, but if I override Object.const_missing, I still have the
problem with the Ruby interpreting the < and > characters :(

-John
http://www.iunknown.com
B97225f66bb5caac601b12735d430a0d?d=identicon&s=25 lopexx (Guest)
on 2005-11-24 18:19
(Received via mailing list)
oops...

I thought You're writing about symbols ;)

lopex
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 drjflam (Guest)
on 2005-11-24 18:31
(Received via mailing list)
Sorry about the misleading subject :) I just need to figure out a way of
transmitting some "type information" in a constant name - effectively a
form
of name mangling so that I can construct the correct proxy.

Thanks,
-John
http://www.iunknown.com
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 dblack (Guest)
on 2005-11-24 18:35
(Received via mailing list)
Hi --

On Fri, 25 Nov 2005, John Lam wrote:

> Ah, so it is, but if I override Object.const_missing, I still have
> the
> problem with the Ruby interpreting the < and > characters :(

I think constant names with < and > would be so hard to read for
humans that Ruby is right to make them impossible :-)

How would you (or Ruby) interpret:

   class A
   end

   class B<A
   end

or:

   puts "Yes" if Object>String

?

(You can take that as a rhetorical question :-)


David
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 dblack (Guest)
on 2005-11-24 18:35
(Received via mailing list)
Hi --

On Fri, 25 Nov 2005, John Lam wrote:

> Sorry about the misleading subject :) I just need to figure out a
> way of
> transmitting some "type information" in a constant name -
> effectively
> a form of name mangling so that I can construct the correct proxy.

Maybe you should use nested constants (using ::).


David
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 drjflam (Guest)
on 2005-11-24 18:43
(Received via mailing list)
Thanks David, I wasn't really thinking about those corner cases at all
(reveals the tunnel vision that I have right now).

Are there *any* characters that I can use in Ruby to escape the type
information in the constant name?

Thanks
-John
http://www.iunknown.com
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 dblack (Guest)
on 2005-11-24 18:47
(Received via mailing list)
Hi --

On Fri, 25 Nov 2005, John Lam wrote:

> Thanks David, I wasn't really thinking about those corner cases at all
> (reveals the tunnel vision that I have right now).
>
> Are there *any* characters that I can use in Ruby to escape the type
> information in the constant name?

Your original example:

ChannelFactory<IOutputChannel>("
http://www.flickr.com/services/soap/").CreateChannel

looks like it could be:

   ChannelFactory::IOutputChannel.create_channel("http://...")

or just:

   IOutputChannel.new("http://...")

since a class called IOutputChannel presumably is already a "factory"
object.

I suppose you could use underscores to set off parts of names, but
that seems like a solution in search of a problem, and very hard to
read.


David
956f185be9eac1760a2a54e287c4c844?d=identicon&s=25 decoux (Guest)
on 2005-11-24 18:47
(Received via mailing list)
>>>>> "J" == John Lam <drjflam@gmail.com> writes:

J> Are there *any* characters that I can use in Ruby to escape the type
J> information in the constant name?

 What is the type information ?

Guy Decoux
E7559e558ececa67c40f452483b9ac8c?d=identicon&s=25 gwtmp01 (Guest)
on 2005-11-24 18:55
(Received via mailing list)
On Nov 24, 2005, at 12:02 PM, John Lam wrote:

> Whoops, that should be:
>
> channel = ChannelFactory<IOutputChannel>("
> http://www.flickr.com/services/soap/").new.CreateC...
> www.flickr.com/services/soap/%22%29.CreateChannel>

I'm not sure I follow your example relative to the arguments to new
and CreateChannel, but:

If you define a class ChannelFactory and then define ChannelFactory#[]
to return a class, then you can have constructs like:

	Flickr = ChannelFactory["http://www.flickr.com/services/soap"]

	channel = Flickr.new(arg1, arg2, arg3)

or something like that.  The main idea is to have a class that generates
classes and use #[] to help with the syntax.




Gary Wright
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 drjflam (Guest)
on 2005-11-24 18:55
(Received via mailing list)
The type information is a CLR type reference (in this case an interface
name).

This is required since I need to be able to parse the intent of the Ruby
caller and find the appropriate type on the CLR side.

-John
http://www.iunknown.com
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 drjflam (Guest)
on 2005-11-24 18:59
(Received via mailing list)
The problem here is that ChannelFactory is a CLR generic type, which is
specialized at run-time. So I'm really looking for a way to pass type
parameter(s) to the type at construction time. So while I like your
first
example, I'm not sure how I could extend it to cover an arbitrary number
of
type parameters.

Here's a simple example (again with the illegal angle bracket syntax):

dict = Dictionary<int, string>.new

Cheers,
-John
http://www.iunknown.com




Your original example:
93d566cc26b230c553c197c4cd8ac6e4?d=identicon&s=25 pit (Guest)
on 2005-11-24 20:08
(Received via mailing list)
John Lam schrieb:
> The problem here is that ChannelFactory is a CLR generic type, which is
> specialized at run-time. So I'm really looking for a way to pass type
> parameter(s) to the type at construction time. So while I like your first
> example, I'm not sure how I could extend it to cover an arbitrary number of
> type parameters.
>
> Here's a simple example (again with the illegal angle bracket syntax):
>
> dict = Dictionary<int, string>.new

As Gary already suggested, I'd use a [] method:

   def Dictionary.[]( *types )
     # return appropriate class
   end

Then you can call it like

   dict = Dictionary[Integer, String].new

Regards,
Pit
5da4c52f43677f395aff5bde775593c2?d=identicon&s=25 Daniel Schierbeck (dasch)
on 2005-11-24 20:20
(Received via mailing list)
Pit Capitain wrote:
>   dict = Dictionary[Integer, String].new

Though of course it should be

   dict = Dictionary[:to_i, :to_str]

;)


Cheers,
Daniel
This topic is locked and can not be replied to.