Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Determine whether a variable is a local or global variable #89

Open
kennyjwilli opened this issue Jan 26, 2020 · 1 comment
Open

Determine whether a variable is a local or global variable #89

kennyjwilli opened this issue Jan 26, 2020 · 1 comment

Comments

@kennyjwilli
Copy link
Contributor

The WITH function is quite useful. I'd be interested in a way to determine if a variable used in a formula is a local variable (i.e., defined using WITH) or a global variable (i.e., expected to be passed in when the formula function is called).

For example, take this formula "WITH(a, 1, a + b)". a would be a local variable and b would be a global variable.

Thinking the best way to do this for now is to use the ast, collecting local variables defined with WITH.

@DeLaGuardo
Copy link
Contributor

axel-f already track global variables used in formulas. you can get it from metadata attached to compiled function.

(require '[axel-f.excel :as af])

(def formula "WITH(a, 1, a + b)")

(meta (af/compile formula))
;; => {:free-variables (("b")) ...}

We are using it in production to reconstruct data schema required by the formula.

Right now this list is not considered for public usage because the data stored here requires extra knowledge and it's form might change in the future.

Current data structure can be read as a path of keys and * symbol. For example (("foo" "*" "bar") ("foo" "*" "baz")) means the context must be a map:

{"foo" [{"bar" 'some-value} ...]}

Tracking of local variables (created by WITH) is possible but can not be very helpful here because WITH can shadow out globals:

a + WITH(a, 1, a + c)

a in this formula is global and local at the same time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants