2 - GiacomoZheng/gm GitHub Wiki

点击前往中文部分

In previous page, we sort everything defined in gm into two types, "class" and "sample" (or "instance"). While in this page, we'll consider it from another aspect.

pointer

(REMARK: I use pointer here but it has the totally different meaning with the pointer in C.)

In many other (programming) languages, they use the = to be the definition symbol, meaning assign the value (or address) of the right to the quantity of the left. In gm we can also define something like a: = 1, it means that, all the as show up in this level (For the mathematicians, you can ignore it if you don't care it) can be replaced by 1 (the full name of 1, indeed).

Pointers are the definitions with criterion attaching something equal, like,

@gm.h.s
a: = 1,
b: b = 1, ; may not be a directly assignment
c:
(
	; ... may be some other criterions
	= 1
),
d:
(
	; ...
	1 = d
)
■

All of the above are directly defined as a pointer, or I should say that, just define a pointer.

With the help of package definition, we can define a function with a pointer return value, as

@gm.h.s,
f(4): = 5,
g(∀x: ∈ set): = ∅
■

where f(4) is a pointer, point the location of 5. Meanwhile, the f here is a location.

location

(REMARK: I tried to use the address here but I also changed back. The location here has nothing to do with the memory. Do not confuse it with the address in C)

Locations are the definitions except the pointers, simply speaking. For every pointer, it point to a certain location.

@gm,
a: ∈ ◉,
b: = a,
c: = b,
■

where, a is a location, b,c are pointers, both point to a.

In fact, the compile part would replace all the pointer into its location.

There are two ways to comprehend the relation between pointers and locations:

  1. The pointers and locations are disjoint, and every pointer point to a location. Or
  2. The locations are just the pointers who points to them self.

You can pick the one you prefer to comprehend it. In fact, the first one the CS's comprehension and the second way is the Math's comprehension.

Remark

  • Refer to the macro definition of C, as the pointers can do the same thing with it. While, as far as I know, the macro definition of C only acts in a single file.

Page Up | Home | Page Down


在上一页中,我们将在gm中定义的所有内容分类为两种类型,类和实例。而在本文中,我们将从另一个角度来考虑这个问题。

指向

许多其他(编程)语言使用"="作为定义符号,意思是将右边的值(或地址)赋给左边的量。

gm中,我们也可以定义类似于a: = 1这样的语句,表示在这个level中出现的所有a(对于数学家来说,如果你不关心它,你可以忽略它)可以被替换为“1”(事实上是它的全名)。

指向是附带了相等条件的定义,例如,

@gm.h.s,
a: = 1,
b: b = 1,; 不一定是直接赋值
c:
(
	; ... 可能是其他一些条件
	= 1,
),
d:
(
	; ...
	1 = d
)

以上都是单纯的定义指向,或者说,只定义一个指向。

借助于package definition,我们可以定义一个带有指向返回值的函数,如

@gm.h.s,
f(4): = 5,
g(∀x: ∈ set): = ∅

其中,f(4)是指向,指向5的位置。同时,这里的f是一个位置。

位置

位置是除指向之外的定义,简单来说说。对于每个指向,它指向一个特定的位置。如

@gm,
a: ∈ ◉,
b: = a,
c: = b
■

其中,a是一个位置,b,c是指向,都指向a。事实上,(未来的)编译部分将把所有指向替换到它的位置。

有两种方法可以理解指针位置之间的关系:

  1. 指针和位置是互斥的,每个指针都指向一个位置。或者
  2. 位置就是那些指向它自身的指针。

你可以选择一个你更愿意理解的。事实上,第一个是计算机学家的理解方式,第二个是数学家的理解方式。

  • 可以参考C中的宏定义,指向和它做了同样的事情。然而,据我所知,C的宏定义只能在当前文件中工作。

上页 | 首页 | 下页

⚠️ **GitHub.com Fallback** ⚠️