Questions tagged [free-variable]

31 questions
37
votes
4 answers

What are free variables?

Javascript closure definition says : A "closure" is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression). Can some one explain to me the…
Geek
  • 26,489
  • 43
  • 149
  • 227
23
votes
2 answers

What are Free and Bound variables?

I've been programming for a long time (too long, actually), but I'm really struggling to get a handle on the terms "Free Variables" and "Bound Variables". Most of the "explanations" I've found online start by talking about topics like Lambda…
Roddy
  • 66,617
  • 42
  • 165
  • 277
15
votes
3 answers

Can a pure function have free variables?

For example, a referentially transparent function with no free variables: g op x y = x `op` y A now now a function with the free (from the point-of-view of f) variables op and x: x = 1 op = (+) f y = x `op` y f is also referentially transparent. …
Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
9
votes
3 answers

How can "NameError: free variable 'var' referenced before assignment in enclosing scope" occur in real code?

While I was hanging out in the Python chatroom, someone dropped in and reported the following exception: NameError: free variable 'var' referenced before assignment in enclosing scope I'd never seen that error message before, and the user provided…
Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
6
votes
1 answer

Free variables list of a lambda expression

I was just doing some homework for my upcoming OCaml test and I got into some trouble whatnot. Consider the language of λ-terms defined by the following abstract syntax (where x is a variable): t ::= x | t t | λx. t Write a type term to…
rickmeizter
  • 131
  • 1
  • 7
5
votes
4 answers

Free Variable in Prolog

Can anyone explain the concept of free variables in Prolog. Is it similar to anonymous variables ? Or is there a difference. Also could be great if an example is given to explain.
3
votes
2 answers

Which Vars affect a Clojure function?

How do I programmatically figure out which Vars may affect the results of a function defined in Clojure? Consider this definition of a Clojure function: (def ^:dynamic *increment* 3) (defn f [x] (+ x *increment*)) This is a function of x, but…
Jouni K. Seppänen
  • 43,139
  • 5
  • 71
  • 100
3
votes
1 answer

Destroy type in Julia

I have to destroy some type in Julia which looks like: struct City x::Int y::Int index::Int end and I want a function like destroy(City) that will delete this. Is it possible? Thanks for your answers.
blue rabbit
  • 139
  • 1
  • 13
3
votes
2 answers

Return a list of free(unbound) variables in SML

I've created my own datatypes: datatype typ = Bool | Int | Arrow of typ*typ; (* i.e., Arrow(argType, returnType) *) (* diMLazy expressions *) datatype expr = TrueExpr | FalseExpr | IntExpr of int | VarExpr…
NickBolden
  • 31
  • 2
3
votes
1 answer

`del` statement and free variables

Testing some Python code today I tried the following code: (The following runs on Python 3.2+, although previous versions will raise a SyntaxError when del is used and a variable is referenced in an enclosing scope) def x(): N = 200 def…
GIZ
  • 4,409
  • 1
  • 24
  • 43
2
votes
1 answer

Are variables bounded to free variables still free variables?

I am looking at some questions in my textbook about whether or not the variables are free or bound. I am not sure about these two in particular. First off, I want to make sure I understand the concept of free vs. bound. I am fairly sure this x is a…
2
votes
1 answer

How do I solve this constrained linear programing (LP) problem with one free variable?

I was researching methods to rank forecasts and found this paper, A novel ranking procedure for forecasting approaches using Data Envelopment Analysis, I've been working through the article and setting up my data, but I can't seem to replicate their…
2
votes
2 answers

Will recursively-called variable be free or bound?

I am trying to have a better understanding about free and bound variables. Here is an example code: (define (what-kind-of-var? guess x) (< (abs (- (square guess) x)) 0.001)) I see that bound variables here would be guess and x, and free…
Isaac
  • 273
  • 3
  • 19
2
votes
2 answers

Finding list/map of free variable(s) of a closure in groovy

This is my simple groovy script; def fourtify(String str) { def clsr = { str*4 } return clsr } def c = fourtify("aa") println("binding variables: ${c.getBinding().getVariables()}") ... All I'm trying to do here is being able…
stdout
  • 2,471
  • 2
  • 31
  • 40
2
votes
1 answer

Free variables treated as globals in Python?

In the Execution Model section of the Python 3.7 reference manual I read the following statement: The global statement has the same scope as a name binding operation in the same block. If the nearest enclosing scope for a free variable contains a…
saveturn
  • 23
  • 2
1
2 3