Advertisement
Guest User

Untitled

a guest
Jan 9th, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.98 KB | None | 0 0
  1. // Statements perceded by ## are preprocessor directives. Let directive aliases an identifier to another. Identifier can be anything, from a built-in type or a
  2. // keyword to a custom user storage. Preprocessor directives are evaluated at compile time. Preprocessor directives need to be defined and are available in the root // file scope.
  3. ##let false = true
  4.  
  5. // This is an alias. Aliases are runtime let directives. They are identical to let directives but can be used dynamically with statements. They're block scoped.
  6. alias false = true
  7.  
  8. // This is a simple storage with a few properties and methods attached to it. A storage is basically a data template. A storage with properties and/or methods
  9. // attached to it is called a class. Properties inside of a storage are called member properties Every method and member property in a storage is public by default.
  10. // Function attached to a storage is called a method. Every storage is exported to the global scope unless specified private.
  11. let storage AStorage = {
  12.   let aProperty
  13.   let anotherProperty
  14.   // This is a constant member property which can not be reassigned outside of this storage.
  15.   let const constantProperty
  16.   // This is a private member property that can not be accessed outside of this storage.
  17.   let private privateProperty
  18.   // This is a private constant member property which can only be assigned and reassigned inside of the creator. Const always needs to come after the access modifier // (if present, if not, after let)
  19.   let private const privateConstantProperty
  20.  
  21.   // This is a nested storage. Nested storages are root file scoped but can be only accessed through the parent. Nested storages can access parent's member
  22.   // properties and methods.
  23.   let storage NestedStorage {
  24.  
  25.   }
  26. }
  27.  
  28. // This is a private storage that's not exported to global scope. They're root file scoped.
  29. let private storage PrivateStorage {
  30.  
  31. }
  32.  
  33. // This is a creator. Creators are normal methods defined with fragment functions. Creators are called when the storage they're attached to gets created.
  34. let fn AStorage.creator()() {
  35.  
  36. }
  37.  
  38. //Creator implementation:
  39. let fn creator() {
  40.   return :___creator___
  41. }
  42.  
  43. // This is a global property that's assigned to a new instance of the storage. To create a new instance of a storage, you use create. Create and storage creator
  44. // parentheses are optional (if no parameters are passed to them).
  45. let aStorageInstance = create AStorage() //or: create(AStorage)
  46.  
  47. // This is a normal call on an storage instance. Method calls need to be perceded with :: if method is not defined in the current scope. Parentheses are optional if no parameters are expected.
  48. aStorageInstance::someMethod()
  49.  
  50. // This is a parameterless method attached to a storage. Parameterless methods do not require parentheses. This method is public, inherited and overridable by
  51. // storage's children.
  52. let fn AStorage.someMethod() {
  53.  
  54. }
  55.  
  56. // This is a method attached to a nested storage. They behave identically as normal attached methods.
  57. let fn AStorage.NestedStorage.methodInNestedStorage {
  58.  
  59. }
  60.  
  61. // This is a method with parameters. Methods with parameters require parentheses. Parameters can be used as any other local properties.
  62. let fn AStorage.methodWithParams(let param1, let param2) {
  63.  
  64. }
  65.  
  66. // This is a method with parameters. Method parameters can have default values. Parameters with default values are called default parameters. Default parameters
  67. // behave as normal parameters but need to be at the end of the parameter list. If no value is passed to default parameter, it has the specified default value.
  68. // The value passed to the default parameter has to be of the same type as the default value of the default parameter.
  69. let fn AStorage.methodWithDefaultParams(let param1, let param2 = 1, let param3 = "aString") {
  70.   // This is a method call. The parentheses and this:: are optional.
  71.   this::someMethod()
  72. }
  73.  
  74. // operator() is just a function that returns a fragment. You can override an operator without operator(), just by specifying ___operator___<operator here> and needed // parameters.
  75. let fn operator(==)(let left, let right) {
  76.  
  77. }
  78.  
  79. // This is a fragment. A fragment is like any other identifier but it can be used as an expression. Fragments can contain same characters as normal identifiers.
  80. :fragment
  81.  
  82. // Operator implementation
  83. let fn operator(let operator) {
  84.   return :___operator___ + to_fragment(operator)
  85. }
  86.  
  87. // This is a fragment function. Fragment functions return a fragment and can be used as identifiers. Fragment functions can not be methods.
  88. let fn fragmentFunction() {
  89.   return :aFragment
  90. }
  91.  
  92. // This is the only function call example where you need to use parentheses, even on parameterless functions. Example:
  93. let fn fragmentFunction()fragmentExample { // This compiles into let aFragmentfragmentExample
  94.  
  95. }
  96.  
  97. let fragmentFunction // This compiles to let aFragment
  98.  
  99. // This is a parameterless method which can not be overridden by storage's children due to it being const.
  100. let const fn AStorage.nonOverridableMethod {
  101.  
  102. }
  103.  
  104. // This is a private method. Private methods can only be accessed from inside of the storage. Private methods can not be constant because it doesn't make sense.
  105. let private fn AStorage.privateMethod {
  106.  
  107. }
  108.  
  109. // This is a protected method. Protected methods can only be accessed from inside the storage and the children.
  110. let protected fn AStorage.protectedMethod {
  111.  
  112. }
  113.  
  114. // This is a protected constant method. Protected contant methods can only be accessed from inside the storage and the children but can not be overridden by them.
  115. let protected const fn AStorage.protectedConstantMethod {
  116.  
  117. }
  118.  
  119. // This is a storage that extends another storage. If no other options are passed, it inherits all the data from the parent type - the methods and properties. If
  120. // any method or member property of a child has the same name as one of the parent's, child's member property or method overrides parent's if not const.
  121. let storage ExtendedAStorage = AStorage + {
  122.   let someOtherProperty
  123. }
  124.  
  125. // This is an overridden method. Override needs to be second method modifier. To call accessible methods on the parent, use base.
  126. let override fn ExtendedAStorage.someMethod {
  127.   // This calls parent's implementation of this method. Base behaves like any other method call.
  128.   base()
  129.  
  130.   // This is a method call on the parent. It behaves like any other method call.
  131.   base::someMethodWithParams(1, 1)
  132. }
  133.  
  134. // This is a global method decoupled from any storage. Global methods are called functions .
  135. let fn decoupledMethod {
  136.  
  137. }
  138.  
  139. // This is an extended function. Extended function are very unsafe and disencouraged to use in most cases. This will paste the parent function above everything in
  140. // the child function.  
  141. let fn extendedMethod = decoupledMethod + {
  142.  
  143. }
  144.  
  145. // This is a storage extended inline. This storage behaves like any other extended storage but it is more of an alias because it's identical to it's parent. It's the
  146. // same as using alias.
  147. let storage InlineExtendedAStorage = AStorage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement