mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	This is a very big change. If FunC has `.methods()` and `~methods()`, Tolk has only dot, one and only way to call a `.method()`. A method may mutate an object, or may not. It's a behavioral and semantic difference from FunC. - `cs.loadInt(32)` modifies a slice and returns an integer - `b.storeInt(x, 32)` modifies a builder - `b = b.storeInt()` also works, since it not only modifies, but returns - chained methods also work, they return `self` - everything works exactly as expected, similar to JS - no runtime overhead, exactly same Fift instructions - custom methods are created with ease - tilda `~` does not exist in Tolk at all
		
			
				
	
	
		
			38 lines
		
	
	
	
		
			1,003 B
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
	
		
			1,003 B
		
	
	
	
		
			Text
		
	
	
	
	
	
| // A part of standard library for Tolk
 | |
| tolk 0.6
 | |
| 
 | |
| /**
 | |
|     Lisp-style lists are nested 2-elements tuples: `(1, (2, (3, null)))` represents list `[1, 2, 3]`.
 | |
|     Elements of a list can be of different types.
 | |
|     Empty list is conventionally represented as TVM `null` value.
 | |
|  */
 | |
| 
 | |
| @pure
 | |
| fun createEmptyList(): tuple
 | |
|     asm "PUSHNULL";
 | |
| 
 | |
| /// Adds an element to the beginning of lisp-style list.
 | |
| /// Note, that it does not mutate the list: instead, it returns a new one (it's a lisp pattern).
 | |
| @pure
 | |
| fun listPrepend<X>(head: X, tail: tuple): tuple
 | |
|     asm "CONS";
 | |
| 
 | |
| /// Extracts the head and the tail of lisp-style list.
 | |
| @pure
 | |
| fun listSplit<X>(list: tuple): (X, tuple)
 | |
|     asm "UNCONS";
 | |
| 
 | |
| /// Extracts the tail and the head of lisp-style list.
 | |
| @pure
 | |
| fun listNext<X>(mutate self: tuple): X
 | |
|     asm( -> 1 0) "UNCONS";
 | |
| 
 | |
| /// Returns the head of lisp-style list.
 | |
| @pure
 | |
| fun listGetHead<X>(list: tuple): X
 | |
|     asm "CAR";
 | |
| 
 | |
| /// Returns the tail of lisp-style list.
 | |
| @pure
 | |
| fun listGetTail(list: tuple): tuple
 | |
|     asm "CDR";
 |