<dougmacdoug>
is there a concept of a static or const variable on a class or should those just be external primitives?
<SeanTAllen>
static/const as in, "this can't be modified"?
<SeanTAllen>
or some other aspect of how static/const work in various languages dougmacdoug ?
<dougmacdoug>
single execution
<SeanTAllen>
can you clarify "single execution"?
<dougmacdoug>
so I have a class with a lambda member that will be assigned to one of several lambdas at creation.. but the 1 of many lambdas i have as lets inside the same class and it occured to me that those will be held in each instance
<dougmacdoug>
like a static assignment on a java class is only executed once
<dougmacdoug>
and there is only one instance of that static "member"
<SeanTAllen>
im not connecting your two statements together, sorry.
<dougmacdoug>
I think i stumbled across the answer just being to use a primitive as a namespace for those lambdas
<SeanTAllen>
if you have a function foo on a Primitive and foo creates a lambda/object literal, and you call foo more than once, you will get more than one lambda/object literal
<SeanTAllen>
you might already know this, sorry, i'm still not sure what it is you are doing.
<dougmacdoug>
erff.. ok..
<SeanTAllen>
"class with a lambda member that will be assigned to one of several lambdas at creation." <-- that is what i'm definitely unclear on
<SeanTAllen>
do you have a bit if pseudo code?
<SeanTAllen>
it sounds like, you want a singleton? only create this lambda once?
<SeanTAllen>
but use it in multiple places?
<dougmacdoug>
so lets say I have a member type (Foo|Bar) and I have some methods... my member var will never change after creation from foo or bar.. I have methods I want to execute.. I dont want to test for Foo|Bar each time
<dougmacdoug>
so for each method I just call the lambda... I create the appropriate lambda at startup and assign it to a member var say _run.. then in my run method I just call _run()
<dougmacdoug>
but the value that _run is assigned to (that lambda) I need somewhere to store only one instance of it (and there are way more than 2, just using foobar example))
<SeanTAllen>
you lost me again. sorry.
<dougmacdoug>
basically if Foo then _run = RunFoo
<SeanTAllen>
sorry, i can't help because i don't understand what you are describing. your words are not clicking with my brain.
<SeanTAllen>
if you could do some pseudo code with comments, perhaps i could follow along.
<dougmacdoug>
not much in the way of comments but maybe its more clear
<SeanTAllen>
are _runfoo and _runbar supposed to be doing partial application?
<dougmacdoug>
no
<SeanTAllen>
how then would they get the foo or bar?
<dougmacdoug>
just an argument.. but the part that I am concerned with is that I have an instance of _runfoo and _runbar (lambda pointer or whatever pony thinks it is) in every instance of MyClass
<SeanTAllen>
you want 1 instance, across all instances of MyClass ?
<dougmacdoug>
for the pointers to those lambdas yes, then each instance of MyClass has a handle (_run) to whichever is appropriate for that instance
<SeanTAllen>
i'm not sure why you say "pointer to those lambdas"
<SeanTAllen>
so, if you want a single instance of the lambdas
<SeanTAllen>
you need to initialize them outside of the class
<dougmacdoug>
inside an instance of MyClass _runfoo and _runbar must exist as something correct?
<SeanTAllen>
and pass them to each instance of the class when creating it
<SeanTAllen>
further, those lambdas will have to be immutable, otherwise sharing wouldn't be safe, unless of course, you aren't going to be sharing instances of MyClass across actors.
<dougmacdoug>
all immutable.. the point is if those two references _runfoo and _runbar are say 8 bytes each .. and I have 1 million instances, then i have 16M that I didnt need to have
<SeanTAllen>
why do you need a lambda and not a function?
<SeanTAllen>
if the lambda is immutable, then a function on a primitive seems to be all you need.
<dougmacdoug>
how do I assign a primitive function
<dougmacdoug>
i'm using the lambda like a function pointer.. decide once run many
<dougmacdoug>
so I dont have to match inside the run() code.. aka decide many
<SeanTAllen>
so
<SeanTAllen>
you have 1 or more functions that have the same interface but different code that would be executed based on something that you match on at object creation?