[Resolved]: Custom Objects Syntax for Imba 2?

Maybe I’m too lazy, but would it be too weird for Imba2 to have an optional syntax for creating arrays of objects?

Example:

objects users < const
	user: 01
		name: joe
		description: "a great guy"
		hobbies:
			"fishing"
			"running"
	user: 02
		name: jane
		description: "a great gal"
		hobbies:
			"coding",
			"imba"
object admin < let
	name: james
	description: "a cool dude"
	hobbies:
		"jamming",
		"guitar"

I am not quite sure what kind of benefit this is adding? Is it the curly braces that are an issue? I know some people get turned off by it.

It’s already very straightforward to create arrays of objects. I have rewritten your examples in Imba v2 below but most of it should still apply to Imba v1. For a playground see https://scrimba.com/c/cw8RwWuw

const users = [
	{	
		id: 0x1		
		name: "joe"
		description: "a great guy"
		hobbies: [
			"fishing"
			"running"			
		]
	}
	{
		id: 0x2
		name: "jane"
		description: "a great gal"
		hobbies: [
			"coding"
			"imba"
		]
	}	
]

console.log(JSON.stringify(users, null, 2))

let admin =
	name: "james"
	description: "a cool dude"
	hobbies: [
		"jamming",
		"guitar"		
	]

console.log(JSON.stringify(admin, null, 2))

You are right. It wouldn’t be much of an improvement. I just find the braces and brackets uggly against the rest of the imba language.

Usually languages use either indentation or braces for nesting but Imba seems to have to use both to try to be both beautiful and functional.

By the way, you guys are killing it with feedback, examples and updates. You all deserve a raise.

1 Like

One alternative syntax could be something like:

var array = [
	id: 1
	name: 'one'
	-
	id: 2
	name: 'two'
	-
	id: 3
	name: 'three'
]

This would be consistent with how things are separated now:

var x = [
	a: 1
	b
	c: 1
] # results in [{a: 1},b,{c: 1}]

So the - would act the same way as a non-object-key item already does, except it is only used for splitting the objects. Makes sense?

I actually added this now on master. Will use it a little and see how it feels. Right now I’ve made both - and --- work. Maybe we should just support ---?

YES! That looks clean. I will try it out when I get home, but I’m thinking that single dash might be enough for me.

Deployed it in alpha.21 now.

1 Like