JuliaString / InternedStrings.jl

Fully transparent string interning functionality, with proper garbage collection
Other
27 stars 6 forks source link

Workout if I can simplify this with TypedDelegation.jl #2

Closed oxinabox closed 6 years ago

oxinabox commented 6 years ago

I should ask @JeffreySarnoff if he thinks that the code in https://github.com/oxinabox/StringInterning.jl/blob/97792841ca416400180fd2f081c2aaf80e738502/src/operations.jl could be simplified by using TypedDelegation.jl

I feel like it should be able to. But I am not sure the cases like replace that have lots of other arguments are doable. And they are the once that give the most trouble.

JeffreySarnoff commented 6 years ago

What a good question. Yes ... if I add exports that expect some tag-along args in addition to the arg[s] that are structs over|into which one delegates. I will see about that this afternoon.

oxinabox commented 6 years ago

:-D thanks

This is the kinda thing I always think your delegation packages should be good for. And I can never quiet workout if they are.

JeffreySarnoff commented 6 years ago

[ step 1, see that what should work as is does work ] If this works for you, I will move on to step 2.

Your type:

struct InternedString <: AbstractString
    value::String

    InternedString(s) = new(intern!(pool, s))
end

TypedDelegation acts as if it sees your type this way:

struct InternedString
    value::String
end

(the rest of it works as expected, it is just that TypedDelegation does not have to do anything to handle the supertype or the internal constructor)

TypedDelegation actually sees your type more like this:

struct <client_supplies_struct_name>
    <client_supplies_field1_name>::<client_supplies_field1_type>
end

So, to delegate Base.length, you supply the delegate (Base.length), the struct_name (InternedString), the targeted field name (value) and the targeted field's type (String). For length, the result is not rewrapped as an InternedString ... it is used directly.


import Base: length
using TypedDelegation

intern!(pool, s) = s  # so it works without the rest of your code

struct InternedString <: AbstractString
    value::String

    InternedString(s) = new(intern!(pool, s))
end

# delegate Base.length to InternedString
#
@delegate_onefield(InternedString,  value, [length])

test = InternedString("123456578");

println("length(test) is 8+1 .. ", length(test)," .. right?")
JeffreySarnoff commented 6 years ago

The code is showing its age :disappointed: and Julia is showing its rapid advancement :relaxed:.
I think I have to let this implementation go .. even modification to address deprecations is sketchy.

If I ever remake it, your needs will have informed me.

oxinabox commented 6 years ago

Thanks. I look forward to any future Delegation3.jl Resolved in the negative.