前缀运算符有两种类型:tilde前缀运算符和bang前缀运算符。颚化符前缀运算符以颚化符“~”开头,bang前缀运算符以bang“!”开头。主要区别在于,在应用波浪号前缀运算符时,忽略了波浪号字符。
颚化符前缀运算符
以波浪号为前缀的运算符以波浪号“~”开头,后跟以下内容之一:
波浪号前缀运算符也可以构建为任意数量波浪号的列表:
~~, ~~~, ~~~~, ~~~~~, ...
应用运算符时,必须省略波浪形,除非它是波浪形蛇。
âââââââââââââââ¦âââââââââââââ¦âââââââââââââââââââââââââââ
â declaration â usage â remark â
â ââââââââââââââ¬âââââââââââââ¬âââââââââââââââââââââââââââ£
â ~~ â ~~ â â
â ~~~ â ~~~ â â
â ~~~~~~~~~ â ~~~~~~~~~ â or any number of tildes â
â ~+ â + â â
â ~+. â +. â â
â ~- â - â â
â ~-. â -. â â
â ~% â % â â
â ~%% â %% â â
â ~& â & â â
â ~&& â && â â
âââââââââââââââ©âââââââââââââ©âââââââââââââââââââââââââââ
Bang前缀运算符
带bang前缀的运算符以bang“!”开头后跟以下字符的任意组合:
此规则的例外是“!=”。前缀运算符不能以此组合开头。
ââââââââââââââââ¦âââââââââââââââ
â declaration â usage â
â âââââââââââââââ¬âââââââââââââââ£
â !! â !! â
â !% â !% â
â !& â !& â
â !* â !* â
â !+ â !+ â
â !. â !. â
â !/ â !/ â
â !< â !< â
â !> â !> â
â !@ â !@ â
â !^ â !^ â
â !| â !| â
â !~ â !~ â
â !? â !? â
â !@=@> â !@=@> â
â !!!/<=>@!!!* â !!!/<=>@!!!* â
ââââââââââââââââ©âââââââââââââââ
type SomeString = SomeString of string
let ( ~~ ) (SomeString s) = "~~ " + s
let ( ~~~ ) (SomeString s) = "~~~ " + s
let ( ~~~~~~~~~ ) (SomeString s) = "~~~~~~~~~ " + s
let ( ~+ ) (SomeString s) = "~+ " + s
let ( ~+. ) (SomeString s) = "~+. " + s
let ( ~- ) (SomeString s) = "~- " + s
let ( ~-. ) (SomeString s) = "~-. " + s
let ( ~% ) (SomeString s) = "~% " + s
let ( ~%% ) (SomeString s) = "~%% " + s
let ( ~& ) (SomeString s) = "~& " + s
let ( ~&& ) (SomeString s) = "~&& " + s
let x = SomeString "tilde"
printf "%s\n" (~~ x) // ~~ tilde
printf "%s\n" (~~~ x) // ~~~ tilde
printf "%s\n" (~~~~~~~~~ x) // ~~~~~~~~~ tilde
printf "%s\n" (+ x) // ~+ tilde
printf "%s\n" (+. x) // ~+. tilde
printf "%s\n" (- x) // ~- tilde
printf "%s\n" (-. x) // ~-. tilde
printf "%s\n" (% x) // ~% tilde
printf "%s\n" (%% x) // ~%% tilde
printf "%s\n" (& x) // ~& tilde
printf "%s\n" (&& x) // ~&& tilde
type SomeString = SomeString of string
let ( !! ) (SomeString s) = "!! " + s
let ( !% ) (SomeString s) = "!% " + s
let ( !& ) (SomeString s) = "!& " + s
let ( !* ) (SomeString s) = "!* " + s
let ( !+ ) (SomeString s) = "!+ " + s
let ( !. ) (SomeString s) = "!. " + s
let ( !/ ) (SomeString s) = "!/ " + s
let ( !< ) (SomeString s) = "!< " + s
let ( !> ) (SomeString s) = "!> " + s
let ( !@ ) (SomeString s) = "!@ " + s
let ( !^ ) (SomeString s) = "!^ " + s
let ( !| ) (SomeString s) = "!| " + s
let ( !~ ) (SomeString s) = "!~ " + s
let ( !? ) (SomeString s) = "!? " + s
let ( !@=@> ) (SomeString s) = "@=@> " + s
let ( !!!/<=>@!!!* ) (SomeString s) = "!!!/<=>@!!!* " + s
//let ( != ) (SomeString s) = "!= " + s // prefix != is not allowed
//let ( !=@@ ) (SomeString s) = "!= " + s // prefix != is not allowed
let y = SomeString "bang"
printf "%s\n" (!! y) // !! bang
printf "%s\n" (!% y) // !% bang
printf "%s\n" (!& y) // !& bang
printf "%s\n" (!* y) // !* bang
printf "%s\n" (!+ y) // !+ bang
printf "%s\n" (!. y) // !. bang
printf "%s\n" (!/ y) // !/ bang
printf "%s\n" (!< y) // !< bang
printf "%s\n" (!> y) // !> bang
printf "%s\n" (!@ y) // !@ bang
printf "%s\n" (!^ y) // !^ bang
printf "%s\n" (!| y) // !| bang
printf "%s\n" (!~ y) // !~ bang
printf "%s\n" (!? y) // !? bang
printf "%s\n" (!@=@> y) // !@=@> bang
printf "%s\n" (!!!/<=>@!!!* y) // !!!/<=>@!!!* bang