Asciidots详解

· · 个人记录

又是一个神仙天图

实际上

Asciidots长得和Befunge差不多

/#$<.
*-[+]
\#1/

但

为什么多出了[]?

这个语言相当于一个管道系统,每点水都是一个入水口,到一个地方,这些复杂的水经过处理出去了

开始讲语言吧

在Asciidots中,用.作为“入水口”,&作为“出水口”

每个点一开始有一个方向,ID和值,一开始都是0,这些之后再谈

注释是``后跟着的一些东西

却说我们需要一些“管道”让“水”流,于是便有了

- 左右联通
| 上下联通
/和\ 一个非常像平面镜的东西,例如
/-
|
它是沟通的
同时,还有
 |
-/-
 |
+ 十字路口,不改变方向

练习1

/-&         `` This is where the program ends!
|
\-\ /-\
  | | |
/-/ | \-\
\---/   |
        |
        \-. `` Here's where the program starts

讲讲方向键

<>^v

分别代表四个方向

只要不是逆流,这些水都会变为顺着箭头方向走

.-<-&

这一段代码可以通过(逆向不受影响)

当然,还有括号等

( 只要有水朝左冲过来,就会被影响为往右冲,就像一个蹦床

) 一样的道理

* 只要有水冲进来,就会朝另三个方向冲出去

就像(一个比喻)

 v
<*>
 v

练习2

  /-\ /-& `` End
  | | |
  \-+-v
    | | /-\
(-<-/ | | |
  |   \-<-/
  \-\
    |
    .    `` Start

说说之前所说的ID和数字

ID可以区分每个点,而数字便是这股水的一个信息

一般上,用@变ID,用#变数字

比如

.-@7-#2-&

值有覆盖性,就像

.-#1#2-&

此时水的信息为2

练习3

.-#7-#0-@278-#17-#8-@4-#0-@99-#1-#13-&

当然,与外界的交流是必须的

用$输出

比如,一股水流进了$,

如果接下来的符号是#

就将打印它的值并回车

如果是"或'

就表明接下来是字符串

按方向一个一个输出,到结束后输出回车

当然,你可以用$_取消输出回车

和$a#输出对应的ASCII字符

?是输入

外界将输入一个整数值,这个?将变成那个值

比如

.-#?-&

读入了3就表示

.-#3-&

练习4

.-$"Hey!"-$_"Here we go : "-#?-$#-&

这里有一个非常像变压器的字符

~ 只要在上(下)方等待的数字不为0,那么水平方向上的水将会往下(上)流 在竖直方向的水中,只要在经过~时加上!,效果将恰恰相反

练习5

  /-$"The value is not equal to zero"
  |
.-~-$"The value is equal to zero"
  |
  ?
  #
  |
  .

啊!谈到计算了!

计算是用[]或{}包起来的

比如

 |
[/]-a
 |
 b

假设从右边来的数为a,从下(上)来的数为b,则这里将往上(下)返回b/a

类似的道理,以下是计算一览表,一些返回bool型的将会变为1和0

+ - * / %   基本运算
^ 指数
& 和
o 或
x 异或
> 大于
G 大等于
< 小于
L 小等于
= 相等
! 不等
a-{/}-
   |
   b

{}类似,只是它是计算a/b并水平弹出

练习6

`` Simple subtraction:
``   (3 - 2 = 1)

   #
   $
   |
  [-]-2#-.
   |
   3
   #
   |
   .

.-#?-{+}-$#
      |
.-#?--/

过滤水?

: 删除经过它的值为0的水
; 同理,但过滤的是非0数

如果在它们前面加上@,就表示用id为过滤项

当然,函数什么的也有

用%$定义函数

用一个非正式字符表示

函数以自己的字符开始,以自己的字符(绕了一圈)或走不下去(结束程序)结束

函数就像一个传送带,将水按同样的方向、ID和值进去后按函数最后绕到原字符的方向冲出

练习7

%$A

#  /-)
$  |
\>-A
 \-3#-.

A-\
\-/

当然,还有库支持,这里不允与解释

Libraries
Dots supports libraries! A library is a program that defines a character (usually a letter).

Using Libraries
A library can be imported by starting a line with %!, followed with the file name, followed with a single space and then the character that the library defines.

By default, all copies of the character to lead to the same (singleton) library code. This can cause some unexpected behavior if the library returns an old dot, since that old dot will come out of the char that it came from.

Here’s an example of importing the standard for_in_range library (located in the libs folder) as the character f:

%!for_in_range.dots f
The way to use a library varies. Inputs and outputs of the library are through the alias character.

For the for_in_range library, the inputs are defined as follows:

The dot coming from the left side sets the starting value of the counter
The dot coming from the right sets the end value of the Counter
And the outputs are as follows:

A dot for each number within the range defined by the inputs is output from the top
When the loop is complete (the end value has been reached), a dot is output from the bottom
Here is an example of outputting all the numbers between 1 and 100 to the console, then stopping the program:

%!for_in_range.dots f

         #
         $
         |
.-*-#1---f-\
  \-#100-+-/
         |
         &
Creating Libraries
Each library defined a character that will act as a warp to & from the library.

That can be done like so:

%$X `` X could be replaced with a different character, if so desired
It is recommended that you create warps for different sids of the char. Just look at the example code for the val_to_addr.dots library:

%^X
%$AB

B-X-A


A-*----@{+}-#0-B
  |      |
  \------/
Location of Library Source Files
The source files for libraries are searched for in the following directories (in order):

The directory of the asciidots file being interpreted
The implementation’s dots/libs/ directory
The implementation’s libs/ directory (for backwards compatibility)
Interpretation
Each tick, the dots will travel along the lines until they hit a charter that acts as a function of multiple dots (i.e. an operation character or a ~ character). The dot will stop if it goes on a path that it has already traversed in the same tick

Due to the fact that dots may be moving backwards down a line, if a number or system value (e.g. ?) is seen without a preceding @ or #, it will be ignored, along with any @ or # immediately thereafter

好了,基本上就是这样了

尝试解决一下开头代码的翻译吧