Skip to content

Commit 57c8934

Browse files
authored
Merge pull request #14 from thautwarm/refactor
WIP Refactor: A concise and maintainable implementation
2 parents 94d49da + 8bda2da commit 57c8934

File tree

5 files changed

+824
-315
lines changed

5 files changed

+824
-315
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
name = "JuliaVariables"
22
uuid = "b14d175d-62b4-44ba-8fb7-3064adc8c3ec"
33
authors = ["thautwarm"]
4-
version = "0.1.4"
4+
version = "0.2.0"
55

66
[deps]
7-
LegibleLambdas = "f1f30506-32fe-5131-bd72-7c197988f9e5"
87
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
98
NameResolution = "71a1bf82-56d0-4bbc-8a3c-48b961074391"
109

1110
[compat]
1211
julia = "1"
12+
MLStyle = "^0.3.1"
13+
NameResolution = "^0.1.3"
1314

1415
[extras]
1516
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Specification.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Specification of Julia Scoping Rule
2+
3+
`S` indicates the current scope.
4+
Some terminologies(as well as interfaces provided in NameResolution.jl) :
5+
- `LHS`: left-hide-side
6+
- `RHS`: right-hide-side
7+
- `pseudo scope`: a scope but does not introduce free variables in its parent scope. I don't know how to call it actually, `pseudo scope` is a tentative name.
8+
- `LOCAL`: to mark a symbol as **local**, instead of resolving it automatically
9+
- `GLOBAL`: to mark a symbol as **global**, instead of resolving it automatically
10+
11+
## For Loop
12+
13+
```julia
14+
for i = I, j in J
15+
body
16+
end
17+
```
18+
19+
`i` is LHS in in `S/for1`, `I` is RHS in `S`.
20+
21+
`j` is LHS in `S/for1/for2`, `J` is RHS in `S/for1`.
22+
23+
`body` is RHS in `S/for1/for2`.
24+
25+
26+
## Standalone Assignments
27+
28+
```julia
29+
$f = a
30+
```
31+
32+
If `$f` is a function calling expression, it's treated as `function $f; a end` . See [Function Definition](#Function Definition).
33+
34+
Otherwise, all symbols(except heads of expressions) of `$f` are LHS in `S`, `a` is RHS in `S`.
35+
36+
## Functions
37+
38+
```julia
39+
function f(x::A{T}=default_value) where T
40+
body
41+
end
42+
```
43+
44+
- `f` is LHS in `S`(however the function name should be marked for further analysis, e.g., self recursions).
45+
46+
There's a *pseudo* scope `S/mk-type-params`,
47+
48+
- `T` in `where T` is LHS in `S/mk-type-params`.
49+
50+
The requirement of a symbol in argument type annotations is from the scope `S/mk-type-params`.
51+
52+
Say,
53+
- `T` in `f(x::A{T}=value)` is RHS in `S/mk-type-params`, and
54+
- `A` is RHS in `S/mk-type-params`(though we know `A` is from `S`, pseudo scope doesn't result in free variables).
55+
56+
The function execution has the scope `S/mk-type-params/inner` and,
57+
- `x` is LHS in `S/mk-type-params/inner`,
58+
- `default_value` is RHS in `S/mk-type-params/inner`,
59+
- `body` is RHS in `S/mk-type-params/inner`
60+
61+
62+
Except for
63+
- `Expr(:function, ::Symbol, Expr(:block, _...))` is a declaration
64+
65+
## Let-Bindings
66+
67+
```julia
68+
let a = b
69+
c
70+
end
71+
```
72+
73+
`S/let` is a pseudo scope.
74+
75+
- `b` is RHS in `S`
76+
- `a` is LHS in `S/let`
77+
- `c` is RHS in `S/let`

0 commit comments

Comments
 (0)