Asciidots詳解

Asciidots詳解

來自專欄編程語言專欄

又是一個神仙天圖


實際上

Asciidots長得和Befunge差不多

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

為什麼多出了[]?


這個語言相當於一個管道系統,每點水都是一個入水口,到一個地方,這些複雜的水經過處理出去了


開始講語言吧

在Asciidots中,用.作為「入水口」,&作為「出水口」

每個點一開始有一個方向,ID和值,一開始都是0,這些之後再談

注釋是``後跟著的一些東西

卻說我們需要一些「管道」讓「水」流,於是便有了

- 左右聯通

| 上下聯通

/和 一個非常像平面鏡的東西,例如

/- |

它是溝通的 同時,還有

| -/- |

+ 十字路口,不改變方向

練習1

/-& `` This is where the program ends! | - /- | | | /-/ | - ---/ | | -. `` Heres 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

好了,基本上就是這樣了

嘗試解決一下開頭代碼的翻譯吧


推薦閱讀:

西語語法丨前置詞CON的用法
研究表明,學習外語和音樂能讓大腦變得更靈光
初級日語之換個角度學習日語複合詞
淺思錄 | 為什麼人工智慧時代我們更需要學外語

TAG:科技 | 語言學習 |