-
-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memoize doesn't account for method overrides #1388
Comments
It would probably be easiest to use the number of arguments of the method in the method name. If no arguments are given, everything would use |
That could work. Though, if we do that, then we should also see about raising an error if you try to define one that clashes. memoize def account(number : String)
end
memoize def account(number : Int32)
end |
Memoize has [issues][issues], and I've never really had a use case for memoizing a method that has arguments. See luckyframework/lucky#1388 [issues]: luckyframework/lucky#1396
The best way is to just {{ name = UUID.random.hexstring }}
@__memoized_{{name}} or something like Another way is to keep a counter which just increments with every call to Another way is to define the variable inside a closure and not have to worry about a unique name, but I couldn't figure it out either. |
@NotWearingPants Thanks for the suggestion. I like that idea of just creating a hash and using that as the differentiator. And yeah, the macro system can be quite tricky if you're not used to working with it. Thanks again! |
I ran in to this random issue where I have 2 methods that I wanted to memoize both, but one takes an additional arg that the other doesn't.
If we can figure out how to handle the method overrides, that would be cool, though not at the cost of performance, or massive memory allocation like I'd expect it might lead to. I'm also cool with just raising a compile-time error (if possible) that says you can't memoize the second method because it's already being memoized as
account
The text was updated successfully, but these errors were encountered: