TGViewer
TON Dev News TON Dev News @tondev_news · 41.1K subscribers
Post #185 4.43K

Forwarded from TOLK lang

Tolk v0.8: preparation for structures

A new version of Tolk was released several days ago. We're starting a way to eventually implement structures with auto packing to/from cells. This will take several steps (each publicly released), it's the first one.

✅ Notable changes in Tolk v0.8:
1. Syntax tensorVar.0 and tupleVar.0, both for reading and writing
2. Allow cellslice, etc. to be valid identifiers

PR on GitHub with detailed info.

Using syntax `tensorVar.{i}` and `tupleVar.{i}`, you can access tensors/tuples by indices without unpacking them.

It works for tensors:

var t = (5, someSlice, someBuilder); // 3 stack slots
t.0 // 5
t.0 = 10; // t is now (10, ...)
t.0 += 1; // t is now (11, ...)
increment(mutate t.0); // t is now (12, ...)
t.0.increment(); // t is now (13, ...)

t.1 // slice
t.100500 // compilation error


It works for tuples (does asm INDEX/SETINDEX under the hood):

var t = [5, someSlice, someBuilder]; // 1 tuple on a stack with 3 items
t.0 // "0 INDEX", reads 5
t.0 = 10; // "0 SETINDEX", t is now [10, ...]
t.0 += 1; // "0 INDEX" to read 10, "0 SETINDEX" to write 11
increment(mutate t.0); // also, the same way
t.0.increment(); // also, the same way

t.1 // "1 INDEX", it's slice
t.100500 // compilation error


It works for nesting var.{i}.{j}. It works for nested tensors, nested tuples, tuples nested into tensors. It works for mutate. It works for globals.

Why is this essential?

In the future, we'll have structures, declared like this:

struct User {
id: int;
name: slice;
}


Structures will be stored like tensors on a stack:

var u: User = { id: 5, name: "" };
// u is actually 2 slots on a stack, the same as
var u: (int, slice) = (5, "");

fun getUser(): User { ... }
// on a stack, the same as
fun getUser(): (int, slice) { ... }


It means, that `obj.{field}` is exactly the same as `tensorVar.{i}`:

var u: User = ...; // u: (int, slice) = ...
u.id; // u.0
u.id = 10; // u.0 = 10


Same goes for nested objects:

struct Storage {
lastUpdated: int;
owner: User;
}

s.lastUpdated // s.0
s.owner.id // s.1.0


So, implementing indexed access for tensors/tuples covering all scenarios is a direct step towards structures.
  • 👍 15
  • 🔥 8
  • ❤ 1
More from @tondev_news
  1. Jun 15, 2026🤑GRAM is live! The ticker, logo and name are changing. Everything else stays the same. Sa…
  2. Jun 11, 2026Bot API 10.1 📝 Markup Revolution This update introduces native text styling tools to enab…
  3. Jun 10, 2026TON Connect v3. TON Connect has received a major update with gasless transactions, connect…
  4. Jun 4, 2026MTONGA / MGRAMGA: the next step is clear: 30% extra on any top-up at @dtontech_bot / dton.…
  5. Jun 1, 2026🪙 Toncoin Name Change — Community Vote TON has changed substantially in recent months. Te…
  6. May 18, 2026🧠 AI devs asked for this — and we delivered. 🤖 Bots can now talk to other bots on Telegr…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →