Legal symbol names and generics

J

John Lam

------=_Part_23522_21841397.1132849399348
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I've just started thinking about generics in my Ruby <=3D> CLR bridge. This=
is
what I'd love to be able to do:

channel =3D 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 syntacticall=
y
deal with this issue?

Thanks
-John
http://www.iunknown.com

------=_Part_23522_21841397.1132849399348--
 
M

Marcin Mielżyński

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

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

lopex
 
J

John Lam

------=_Part_24004_31749685.1132852497918
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: base64
Content-Disposition: inline

QWgsIHNvIGl0IGlzLCBidXQgaWYgSSBvdmVycmlkZSBPYmplY3QuY29uc3RfbWlzc2luZywgSSBz
dGlsbCBoYXZlIHRoZQpwcm9ibGVtIHdpdGggdGhlIFJ1YnkgaW50ZXJwcmV0aW5nIHRoZSA8IGFu
ZCA+IGNoYXJhY3RlcnMgOigKCi1Kb2huCmh0dHA6Ly93d3cuaXVua25vd24uY29tCgoKCgpPbiAx
MS8yNC8wNSwgTWFyY2luIE1pZWy/efFza2kgPGxvcGV4eEBhdXRvZ3JhZi5wbD4gd3JvdGU6Cj4K
PiBpdCBpcyBsZWdhbCAoanVzdCB1c2UgYW5vdGhlciBzeW1ib2wgY29uc3RydWN0aW9uIGxpdGVy
YWwpOgo+Cj4geCA9IDoiPCAuLi4gPiIKPiBwIHgKPgo+IGxvcGV4Cj4K
------=_Part_24004_31749685.1132852497918--
 
J

John Lam

------=_Part_24124_21146761.1132853325776
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: base64
Content-Disposition: inline

U29ycnkgYWJvdXQgdGhlIG1pc2xlYWRpbmcgc3ViamVjdCA6KSBJIGp1c3QgbmVlZCB0byBmaWd1
cmUgb3V0IGEgd2F5IG9mCnRyYW5zbWl0dGluZyBzb21lICJ0eXBlIGluZm9ybWF0aW9uIiBpbiBh
IGNvbnN0YW50IG5hbWUgLSBlZmZlY3RpdmVseSBhIGZvcm0Kb2YgbmFtZSBtYW5nbGluZyBzbyB0
aGF0IEkgY2FuIGNvbnN0cnVjdCB0aGUgY29ycmVjdCBwcm94eS4KClRoYW5rcywKLUpvaG4KaHR0
cDovL3d3dy5pdW5rbm93bi5jb20KCgpPbiAxMS8yNC8wNSwgTWFyY2luIE1pZWy/efFza2kgPGxv
cGV4eEBhdXRvZ3JhZi5wbD4gd3JvdGU6Cj4KPiBvb3BzLi4uCj4KPiBJIHRob3VnaHQgWW91J3Jl
IHdyaXRpbmcgYWJvdXQgc3ltYm9scyA7KQo+Cj4gbG9wZXgKPgo+Cg==
------=_Part_24124_21146761.1132853325776--
 
D

David A. Black

Hi --

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
 
D

David A. Black

Hi --

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
 
J

John Lam

------=_Part_24352_5011535.1132853971481
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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

------=_Part_24352_5011535.1132853971481--
 
T

ts

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
 
D

David A. Black

Hi --

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
 
G

gwtmp01

Whoops, that should be:

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

John Lam

------=_Part_24560_23214147.1132854894898
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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


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

------=_Part_24560_23214147.1132854894898--
 
J

John Lam

------=_Part_24592_704649.1132855139682
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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 =3D Dictionary<int, string>.new

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




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

------=_Part_24592_704649.1132855139682--
 
J

John Lam

------=_Part_25012_11994629.1132856963505
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Whoops forgot to reply-all on this one.

---------- Forwarded message ----------
From: John Lam <[email protected]>
Date: Nov 24, 2005 1:05 PM
Subject: Re: Legal symbol names and generics
To: "(e-mail address removed)" <[email protected]>

Thanks, Gary! ... I like this idea.

So rewriting my original example (which I now realize has the constructor
parameter in the wrong place) [1]

channel =3D ChannelFactory[IOutputChannel].new('
http://www.flickr.com/services/soap/').CreateChannel<http://www.flickr.com/=
services/soap/%27%29.CreateChannel>

This does, however clash with static indexers in the CLR since I would like
to preserve the [] indexer semantics in the bridge ... thoughts?

Thanks!
-John
http://www.iunknown.com


[1] It should have read:

channel =3D ChannelFactory<IOutputChannel>.new('
http://www.flickr.com/services/soap').CreateChanel<http://www.flickr.com/se=
rvices/soap%27%29.CreateChanel>

------=_Part_25012_11994629.1132856963505--
 
J

John Lam

------=_Part_25397_31715668.1132859129485
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Yes - this is by far the most straightforward way of making this happen.
While I don't like "magic method names" like .specialize(), I really don't
think there's a way of hacking type information into Ruby's syntax :( And I
need to preserve using [] as well ...

I'll see what I can't do to hack these ideas into the rewrite of my bridge.

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


John said:
channel =3D ChannelFactory[IOutputChannel].new('
http://www.flickr.com/services/soap/').CreateChannel< http://www.flickr.com/services/soap/').CreateChannel>

This does, however clash with static indexers in the CLR since I would like
to preserve the [] indexer semantics in the bridge ... thoughts?

Use a method .fetch for indexers on classes?

Or use ChannelFactory.specialize(IOutputChannel) or something similar.

------=_Part_25397_31715668.1132859129485--
 
P

Pit Capitain

John said:
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
 
S

Sean O'Halpin

Yes - this is by far the most straightforward way of making this happen.
While I don't like "magic method names" like .specialize(), I really don'= t
think there's a way of hacking type information into Ruby's syntax :( And= I
need to preserve using [] as well ...

I'll see what I can't do to hack these ideas into the rewrite of my bridg= e.

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

You could use a factory method - method names and constants are disjoint.
For example,

def ChannelFactory(type_info)
ChannelFactory.specialise(type_info)
end

channel =3D ChannelFactory(IOutputChannel).new

Regards,

Sean
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top