# Structures in Snap!

In C/C++ there is a structure data type that contains several properties like this:

struct {
char* name;
int age;
} Person;


Is there a way to create structures in Snap? The best way I can find is to generate more sprites for every instance which is not what I want.

I've played around with using the library JSON blocks to get this sort of object but didn't quite get what I was looking for but maybe you could see if they'd work for you?

To replicate created structs (idk their official name), I think you could make a key-value pair table thing.

Then make a block which creates a new table like that given the property names (is that their official name?)

I think they are officially called keys, but that might be for enumerable (listable, accessible with iteration) properties.

Are these JSON blocks in the "Libraries" menu or somewhere else?

Yep - hidden in the Web Services

It seems like all of these solutions use lists (which kind of defeats the purpose since I was trying to create linked lists in Snap!), but I'll try to use them for some other stuff

[scratchblocks]
([] in front of (list) :: list)
(all but first of (list) :: list)
[/scratchblocks]

Not like that, like lists with nodes that have a property that contains the next node

function node() {
this.value = undefined;
this.next = undefined;
}
//...


@snapenilk is right; what you want is exactly what the IN FRONT OF constructor makes!

For structs (abstract data types, as we Lispians say), we generally just make procedures: a constructor

and selectors

and so on.

And you do that for every single data type?

Every single non-primitive data type that my project needs, yeah. It'll be quicker and easier when we have macros.

Every single non-primitive data type that my project needs, yeah. It'll be quicker and easier when we have macros.

I'm very excited for this. How would macros work in Snap?

Like Lisp macros, basically. I don't know if I'd try for Schemely hygienic macros, but maybe. At least to begin with, I'll just do good old Lisp 1.5 eval-it-twice macros. That is, you evaluate the macro call, and then you evaluate what the macro returns.

We already have half of what macros do, because we have the ability to declare a procedure input to be of an Unevaluated type (Any Unevaluated, Number Unevaluated, Boolean Unevaluated). Now what we need is a way for the macro to report a script which will then be evaluated in the caller's environment.

In Lisp this is really easy to build because a program is just a list, i.e., it's data and you can easily tear it apart and put it together. That's not the case in Snap!, so I need to use something like @pumpkinhead's library to convert between scripts and syntax trees.