google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.3k stars 209 forks source link

Attribute value based on thread local? #351

Closed ghost closed 3 years ago

ghost commented 3 years ago

My application executes a number of jobs concurrently. I create a new starlark.Thread for each of those jobs.

I want to provide information about the current job through a pre-declared variable so the developer does not need to pass the job through layers of functions. I want to enable something like this:

def example():
     print("The current job is " + job.current.name)

where job is is a pre-declared variable and current is taken from a thread local. This does not work because the Attr method does not have a thread argument. I need to insert a call to get the access the thread:

def example():
     print("The current job is " + job.current().name)

Is there a way to achieve my goal of getting a thread local using dot syntax only?

Is there a forum for asking questions about Starlark, or is this issue tracker the right place?

alandonovan commented 3 years ago

Is there a way to achieve my goal of getting a thread local using dot syntax only?

No. The field selection operation is intended to be an operation on a data structure "at rest", whereas a function call is a computation that takes place within the context of a particular thread. Another implementation of Starlark could have made a different choice, but that's the way this implementation was designed.

(I am not a big believer in the so-called "Uniform Access Principle", which says fields and methods should be interchangeable. I think it's an important pragmatic readability benefit that a field access is just a field access, whereas a function call can do basically anything.)

Is there a forum for asking questions about Starlark, or is this issue tracker the right place?

There is a mailing list here: https://groups.google.com/g/starlark-go but it is very low-traffic.

freb commented 3 years ago

There is also a Starlark channel in the Gopher Slack, but it is also very low-traffic.

ghost commented 3 years ago

Uh oh, the Lua proponents on my team are going to use the () against me. Thankfully, I have correct error positions in my favor!

Thank you for the help.