You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: _drafts/2025-02-14-symbolic-of-what.md
+60-5
Original file line number
Diff line number
Diff line change
@@ -236,11 +236,9 @@ Let us contemplate the following situation.
236
236
237
237
(defng [z] (inc z))
238
238
(defnh [x] (g x))
239
-
```
240
239
241
240
(nsns1
242
-
(:use[big.deal.namespace :as ns2 :only[g]])
243
-
(:import[System String])) ; unnecessary in real life because this import is done automatically
241
+
(:require [big.deal.namespace :as ns2])) ; unnecessary in real life because this import is done automatically
244
242
245
243
(defnf [x y z] [z y x])
246
244
```
@@ -250,8 +248,8 @@ Now consider the situation where we have read the following code and are evaluat
250
248
```Clojure
251
249
(fn* [x]
252
250
(let* [y 7]
253
-
(f (ns2/g ^System.Int64 y)
254
-
(String/ToUpper ^String x)
251
+
(f (ns2/g Int64/MaxValue y)
252
+
(String/.ToUpper x)
255
253
(big.deal.namespace/h7))))
256
254
```
257
255
(Note: the parser would see `fn*` instead of `fn` -- the latter is macro that expands to the former. Similarly for `let*.)
@@ -265,5 +263,62 @@ We need to interpret each symbol in that form:
265
263
f x y ns2/g big.deal.namespace/h System.Int64 String String/ToUpper
266
264
```
267
265
266
+
`x` and `y` are easy. They do not have a namespace, so the first step is look to see if they are currently bound in the lexical scope.
267
+
They are, so they resolve to local bindings expressions.
268
+
269
+
`f` also does not have namespace. However, it not bound in the current lexical scope.
270
+
It does not have a namespace, so it does not refer to directly or indirectly (via an alias) to a namespace.
271
+
The remaining option is that it has a mapping in the current namespace. It does, to a `Var` and that is what we use.
272
+
273
+
`ns2/g` is a bit more complicated. It has a namespace, so it won't be a local. We need to determine what namespace `ns2` stands for.
274
+
The `NamespaceFor` method is used:
275
+
276
+
```F#
277
+
static member NamespaceFor(inns: Namespace, sym: Symbol) : Namespace =
278
+
//note, presumes non-nil sym.ns
279
+
// first check against currentNS' aliases...
280
+
let nsSym = Symbol.intern (sym.Namespace)
281
+
282
+
match inns.lookupAlias (nsSym) with
283
+
| null -> Namespace.find (nsSym)
284
+
| _ as ns -> ns
285
+
```
286
+
287
+
In this context, the current namespace is `ns1` and `ns1` is an alias for `big.deal.namespace`. So we look up `g` in `big.deal.namspace`, finding a `Var`.
288
+
289
+
Next up is `Int64/MaxValue`. It does have a namespace, so it won't be a local.
290
+
When we call `NamespaceFor` on `Int64`, no namespace is found. (`null` is returned.)
291
+
If you were to try to find a type `Int64`, you would fail. There is a type named `System.Int64`.
292
+
Fortunately, all namespaces are set up with a mappings from unqualified names of types to their types.
293
+
Thus, there is a mapping from `Int64` to `System.Int64` in the `ns1` namespace.
294
+
When we have something of the form `Type/Member`, we look for the `Member` in as a property or field in that type.
295
+
In this case, there is a property `MaxValue` in `System.Int64`, so we turn this into a static method call node.
268
296
297
+
`String/.ToUpper` is similar. In this case, because this symbol appears in the functional position of function invocation,
298
+
given that `String` maps to `System.String`, we look for methods also. Beacause the name starts with a period, we look for an instance method, and find one.
0 commit comments