Home New Trending Search
About Privacy Terms
#
#LexicalScoping
Posts tagged #LexicalScoping on Bluesky
> Lexical Scoping refers to when the location of a function's definition determines which variables you have access to. On the other hand, Dynamic Scoping uses the location of the function's invocation to determine which variables are available.

```racket title=dyn-scope.rkt
#lang smol/dyn-scope-is-bad

(defvar y 2)
(deffun (times-2 x)
    (* y x))

(let ([y 3])
  (times-2 2))
(times-2 2)
```

Evaluation:

```racket
6
4
```

Well, this is bad.

<References>
<ReferenceLink href="https://youtu.be/b1MvKYHCdno?si=O6qEgfY2QtH_HtqG&t=2330">Programming Languages Lectures</ReferenceLink>
<ReferenceLink href="https://www.plai.org/3/2/PLAI%20Version%203.2.2%20printing.pdf"><KB>Ctrl+f</KB> for 'dynamic scope'</ReferenceLink>
</References>

> Lexical Scoping refers to when the location of a function's definition determines which variables you have access to. On the other hand, Dynamic Scoping uses the location of the function's invocation to determine which variables are available. ```racket title=dyn-scope.rkt #lang smol/dyn-scope-is-bad (defvar y 2) (deffun (times-2 x) (* y x)) (let ([y 3]) (times-2 2)) (times-2 2) ``` Evaluation: ```racket 6 4 ``` Well, this is bad. <References> <ReferenceLink href="https://youtu.be/b1MvKYHCdno?si=O6qEgfY2QtH_HtqG&t=2330">Programming Languages Lectures</ReferenceLink> <ReferenceLink href="https://www.plai.org/3/2/PLAI%20Version%203.2.2%20printing.pdf"><KB>Ctrl+f</KB> for 'dynamic scope'</ReferenceLink> </References>

Which brought me to write about Dynamic Scoping, too :)

#Racket #Lisp #ProgrammingLanguages #LexicalScoping

0 0 1 0