site/contents/learn-operators.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
----- content-type: "page" title: "Learn: Operators" ----- {@ _defs_.md || 0 @} Every min program needs _operators_ to: * Manipulate elements on the stack * Perform operations on data * Provide side effects (read/print to standard input/output/files, etc.) There are two types of operators: _symbols_ and _sigils_. _Symbols_ are the most common type of operator. A min symbol is a single word that is either provided by one of the predefined min {#link-page||reference||modules#} like `dup` or `.` or defined by the user. User-defined symbols must: * Start with a letter or an underscore (\_). * Contain zero or more letters, numbers and/or any of the following characters: `/ ! ? + * . _ -` It is possible to define symbols using the {#link-operator||lang||define#} symbol. The following min program defines a new symbol called square that duplicates the first element on the stack and multiplies the two elements: (dup *) "square" define Besides symbols, min provides a set of predefined _sigils_ for commonly-used symbols. For example, the previous definition could be rewritten as follows using sigils: (dup *) :square A sigil like `:` can be prepended to a single-word string instead of using the corresponding symbol. Essentially, sigils are nothing more than syntactic sugar. Currently min provides the following sigils: + : Alias for {#link-operator||lang||module#}. ~ : Alias for {#link-operator||lang||delete#}. ' : Alias for {#link-operator||lang||quote#}. \: : Alias for {#link-operator||lang||define#}. ^ : Alias for {#link-operator||lang||call#}. @ : Alias for {#link-operator||lang||bind#}. > : Alias for {#link-operator||lang||save-symbol#}. < : Alias for {#link-operator||lang||load-symbol#}. = : Alias for {#link-operator||lang||quote-bind#}. \# : Alias for {#link-operator||lang||quote-define#}. / : Alias for {#link-operator||seq||dget#}. % : Alias for {#link-operator||seq||dset#}. ? : Alias for {#link-operator||seq||dhas?#}. ! : Alias for {#link-operator||sys||system#}. & : Alias for {#link-operator||sys||run#}. $ : Alias for {#link-operator||sys||get-env#}. {#link-learn||quotations||Quotations#} |