Assignment (computer science)
The use of the equals sign =
as an assignment operator has been frequently criticized, due to the conflict with equals as comparison for equality. This results both in confusion by novices in writing code, and confusion even by experienced programmers in reading code. The use of equals for assignment dates back to Heinz Rutishauser‘s language Superplan, designed from 1949 to 1951, and was particularly popularized by Fortran:
A notorious example for a bad idea was the choice of the equal sign to denote assignment. It goes back to Fortran in 1957[a] and has blindly been copied by armies of language designers. Why is it a bad idea? Because it overthrows a century old tradition to let “=” denote a comparison for equality, a predicate which is either true or false. But Fortran made it to mean assignment, the enforcing of equality. In this case, the operands are on unequal footing: The left operand (a variable) is to be made equal to the right operand (an expression). x = y does not mean the same thing as y = x.[19]
— Niklaus Wirth, Good Ideas, Through the Looking Glass
若問面對 ASCII 編碼表︰
現今使用的 ASCII American Standard Code for Information Interchange 美國資訊交換標準代碼,最早發布於一九六七年,是基於拉丁字母的一套電腦編碼系統。然而為什麼需要編碼的呢?由於人類的語言就是大自然中人事物的『符號』,也就是一種編碼。那麼要如何將這些『符號』用『數位計算機』的 與 的序列 來『表達』的呢?假使說沒有一種『約定』,那麼『』是指『自然數‧ 』、『邏輯‧假』還是『沒有錯誤‧代碼』的呢??因此 ASCII 用『八位元』可有二百五十六個『可能編碼』來規定二十六個基本『拉丁字母』 、『阿拉伯數字』、『英文標點符號』和『終端機 ESC 控制碼』,至今一共定義了一百二十八個碼,卻連英語『重音符號』都沒有!!其中『符號‧』的編碼是 ;『符號‧』的編碼是 。
因為『 ASCII 』碼的『美語侷限性』,現今逐漸轉向使用『萬國碼』Unicode 的時代。當然『編碼概念』遠大於此,比方說『音樂的 mp3 編碼』原先的目的是『壓縮聲音檔案大小』,減少儲存所需要的空間,由於播放結果不會『感覺失真』,彷彿『原音重現』 ,以至於反倒『成了標準』!與之對應的『 mp3 解碼播放器』因此也就『大行其道』的了!!無怪乎老子有言︰無名天地之始,有名萬物之母。
─── 摘自《樹莓 λ 者程式探源》
考慮鍵盤 Keyboard 輸入之簡易,你會用什麼符號代表『指定』 assignment 的呢?
Notation
The two most common representations for the copying assignment are equals sign (=
) and colon-equals (:=
). Both forms may semantically denote either an assignment statement or an assignment operator (which also has a value), depending on language and/or usage.
-
variable = expression
Fortran, PL/I, C (and descendants such as C++, Java, etc.), Bourne shell, Python, Go (assignment to pre-declared variables), R, Windows PowerShell, etc. variable := expression
ALGOL (and derivatives), Simula, CPL, BCPL, Pascal[20] (and descendants such as Modula), Mary, PL/M, Ada, Smalltalk, Eiffel,[21][22] Oberon, Dylan,[23] Seed7, Go (shorthand for declaring and defining a variable),[24] Io, AMPL, ML,[25] etc.
Other possibilities include a left arrow or a keyword, though there are other, rarer, variants:
-
variable << expression
Magik variable <- expression
F#, OCaml, R, S variable <<- expression
R assign("variable", expression)
R variable ← expression
APL,[26] Smalltalk variable =: expression
J LET variable = expression
BASIC let variable := expression
XQuery set variable to expression
AppleScript set variable = expression
C shell Set-Variable variable (expression)
Windows PowerShell variable : expression
Macsyma, Maxima, Rebol var variable expression
mIRC scripting language reference-variable :- reference-expression
Simula
Some platforms put the expression on the left and the variable on the right:
-
MOVE expression TO variable
COBOL expression → variable
TI-BASIC, Casio BASIC expression -> variable
BETA, R put expression into variable
LiveCode
Some expression-oriented languages, such as Lisp[27][28] and Tcl, uniformly use prefix (or postfix) syntax for all statements, including assignment.
-
(setf variable expression)
Common Lisp (set! variable expression)
Scheme[29][30][31] set variable expression
Tcl expression variable !
Forth
記號之不足故而擬似,有利的選擇亦有害處!那為何不將『萬象』獨立『編碼』 Encode 『顯示』 Display 的呢??只怕更會迷失於『記』、『用』之思辨矛盾矣!!但想人類日常『語言』、『文字 』中的『同音異字』、『同字異義』可知也。如是方可了 □○ 符號『意義』的『理解』有其表達之『脈絡』,須細心審視分辨才可免紛擾的吧。
舉例來說派生之『鏈接指定』 Chained Assignment
容易誤讀錯解??!!它的『賦值』程序是
最後一項是『值』 Value
。
然後『從左至右』逐項『賦值』
…
。
【※ 派生之 Assignment 語法與語意】
7. Simple statements
……
Assignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects:
assignment_stmt ::= (target_list "=")+ (starred_expression | yield_expression) target_list ::= target ("," target)* [","] target ::= identifier | "(" [target_list] ")" | "[" [target_list] "]" | attributeref | subscription | slicing | "*" target
(See section Primaries for the syntax definitions for attributeref, subscription, and slicing.)
An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right.
Assignment is defined recursively depending on the form of the target (list). When a target is part of a mutable object (an attribute reference, subscription or slicing), the mutable object must ultimately perform the assignment and decide about its validity, and may raise an exception if the assignment is unacceptable. The rules observed by various types and the exceptions raised are given with the definition of the object types (see section The standard type hierarchy).
………
【試解讀】
pi@raspberrypi:~ $ python3 Python 3.4.2 (default, Oct 19 2014, 13:31:11) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> L = [1, 2, 3] >>> i = 2 >>> L[i] 3 >>> i = L[i] = L[L[i]+1] = 1 >>> L [1, 1, 1] >>>