drjflam
November 24, 2005, 5:26pm
1
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
drjflam
November 24, 2005, 6:03pm
2
drjflam
November 24, 2005, 6:11pm
3
it is legal (just use another symbol construction literal):
x = :"< … >"
p x
lopex
drjflam
November 24, 2005, 6:15pm
4
Ah, so it is, but if I override Object.const_missing, I still have the
problem with the Ruby interpreting the < and > characters
-John
drjflam
November 24, 2005, 6:19pm
5
oops…
I thought You’re writing about symbols
lopex
drjflam
November 24, 2005, 6:35pm
6
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
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
drjflam
November 24, 2005, 6:31pm
7
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
drjflam
November 24, 2005, 6:43pm
8
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
drjflam
November 24, 2005, 6:47pm
9
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
drjflam
November 24, 2005, 6:47pm
10
“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
drjflam
November 24, 2005, 6:35pm
11
Hi –
On Fri, 25 Nov 2005, John L. 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
drjflam
November 24, 2005, 6:55pm
12
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.
drjflam
November 24, 2005, 6:59pm
13
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:
drjflam
November 24, 2005, 8:08pm
14
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
drjflam
November 24, 2005, 8:20pm
15
Pit C. wrote:
dict = Dictionary[Integer, String].new
Though of course it should be
dict = Dictionary[:to_i, :to_str]
Cheers,
Daniel
drjflam
November 24, 2005, 6:55pm
16
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