Legal symbol names and generics

Discussion in 'Ruby' started by John Lam, Nov 24, 2005.

  1. John Lam

    John Lam Guest

    ------=_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--
    John Lam, Nov 24, 2005
    #1
    1. Advertising

  2. John Lam

    John Lam Guest

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

    Whoops, that should be:

    channel =3D ChannelFactory<IOutputChannel>("
    http://www.flickr.com/services/soap/").new.CreateChannel<http://www.flickr.=
    com/services/soap/%22%29.CreateChannel>

    -John
    http://www.iunknown.com

    ------=_Part_23868_14854001.1132851731441--
    John Lam, Nov 24, 2005
    #2
    1. Advertising

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

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

    lopex

    John Lam wrote:
    > 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
    >
    Marcin Mielżyński, Nov 24, 2005
    #3
  4. John Lam

    John Lam Guest

    ------=_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--
    John Lam, Nov 24, 2005
    #4
  5. oops...

    I thought You're writing about symbols ;)

    lopex
    Marcin Mielżyński, Nov 24, 2005
    #5
  6. John Lam

    John Lam Guest

    ------=_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--
    John Lam, Nov 24, 2005
    #6
  7. 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

    --
    David A. Black
    David A. Black, Nov 24, 2005
    #7
  8. 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

    --
    David A. Black
    David A. Black, Nov 24, 2005
    #8
  9. John Lam

    John Lam Guest

    ------=_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--
    John Lam, Nov 24, 2005
    #9
  10. John Lam

    ts Guest

    >>>>> "J" == John Lam <> 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
    ts, Nov 24, 2005
    #10
  11. 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

    --
    David A. Black
    David A. Black, Nov 24, 2005
    #11
  12. John Lam

    Guest

    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.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
    , Nov 24, 2005
    #12
  13. John Lam

    John Lam Guest

    ------=_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


    On 11/24/05, ts <> wrote:
    >
    > >>>>> "J" =3D=3D John Lam <> 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
    >
    >


    ------=_Part_24560_23214147.1132854894898--
    John Lam, Nov 24, 2005
    #13
  14. John Lam

    John Lam Guest

    ------=_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
    >
    > --
    > David A. Black
    >
    >
    >


    ------=_Part_24592_704649.1132855139682--
    John Lam, Nov 24, 2005
    #14
  15. John Lam

    John Lam Guest

    ------=_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 <>
    Date: Nov 24, 2005 1:05 PM
    Subject: Re: Legal symbol names and generics
    To: "" <>

    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--
    John Lam, Nov 24, 2005
    #15
  16. John Lam wrote:

    > channel = 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?


    Use a method .fetch for indexers on classes?

    Or use ChannelFactory.specialize(IOutputChannel) or something similar.
    Florian Groß, Nov 24, 2005
    #16
  17. John Lam

    John Lam Guest

    ------=_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


    On 11/24/05, Florian Gro=DF <> wrote:
    >
    > John Lam wrote:
    >
    > > 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?

    >
    > Use a method .fetch for indexers on classes?
    >
    > Or use ChannelFactory.specialize(IOutputChannel) or something similar.
    >
    >
    >


    ------=_Part_25397_31715668.1132859129485--
    John Lam, Nov 24, 2005
    #17
  18. John Lam

    Pit Capitain Guest

    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
    Pit Capitain, Nov 24, 2005
    #18
  19. Pit Capitain wrote:
    > dict = Dictionary[Integer, String].new


    Though of course it should be

    dict = Dictionary[:to_i, :to_str]

    ;)


    Cheers,
    Daniel
    Daniel Schierbeck, Nov 24, 2005
    #19
  20. On 11/24/05, John Lam <> wrote:
    > 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
    Sean O'Halpin, Nov 24, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juergen Berchtel
    Replies:
    1
    Views:
    5,991
    John C. Bollinger
    May 20, 2005
  2. baumann@pan
    Replies:
    1
    Views:
    742
    Richard Bos
    Apr 15, 2005
  3. Soul
    Replies:
    0
    Views:
    519
  4. Jean-Louis Leroy
    Replies:
    4
    Views:
    322
    Bo Persson
    Mar 5, 2009
  5. Song Ma
    Replies:
    2
    Views:
    229
    Charles Oliver Nutter
    Jul 20, 2008
Loading...

Share This Page