Legal symbol names and generics

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("
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

Whoops, that should be:

channel = ChannelFactory("
http://www.flickr.com/services/soap/").new.CreateChannelhttp://www.flickr.com/services/soap/").CreateChannel

-John

it is legal (just use another symbol construction literal):

x = :"< … >"
p x

lopex

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

-John

oops…

I thought You’re writing about symbols :wink:

lopex

Hi –

On Fri, 25 Nov 2005, John L. wrote:

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

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

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 :slight_smile:

David

Sorry about the misleading subject :slight_smile: 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

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

Hi –

On Fri, 25 Nov 2005, John L. 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("
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

“J” == John L. [email protected] 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

Hi –

On Fri, 25 Nov 2005, John L. wrote:

Sorry about the misleading subject :slight_smile: 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

On Nov 24, 2005, at 12:02 PM, John L. wrote:

Whoops, that should be:

channel = ChannelFactory("
http://www.flickr.com/services/soap/").new.CreateChannel<http://
www.flickr.com/services/soap/").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 W.

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

Your original example:

John L. 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.
# return appropriate class
end

Then you can call it like

dict = Dictionary[Integer, String].new

Regards,
Pit

Pit C. wrote:

dict = Dictionary[Integer, String].new

Though of course it should be

dict = Dictionary[:to_i, :to_str]

:wink:

Cheers,
Daniel

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