Skip to content
HoverCatz edited this page Apr 28, 2024 · 6 revisions

Welcome to NekoLang - a cat-ish programming language

  1. Installation
  2. Usage
  3. Instructions list

NekoLang is both ValueByCopy and ValueByRef. It's up to you to decide what's what.
Any custom Box instance will always be ValueByRef by default, unless you specifically unref it. It will then be deep-cloned and passed as Copy.

Example 1:

// static function to change the 'str' variable
< fun !func(str) >.<
	str < 'Hello ' + str + ' :)' > // Example result: 'Hello Hover :)'
>

owo ref name < 'Hover' > // This makes all usage of 'name' CopyByRef
func(name) // auto ref - will change 'name's value
print(name) // auto ref - will print 'Hello Hover :)'

owo test < 'Testing' >
func(test) // no ref - won't change 'test'
print(test) // no ref - will print 'Testing', not 'Hello Testing :)'

owo abc < 'def' >
func(ref abc) // ref - will change 'abc's value
print(abc) // no need to ref here - will print 'Hello def :)'

Example 2

#catflap :3 // Make this Box the entrypoint box

< box Box1 >.<

	owo name < 'Hover' >

	// Entrypoint into the box Box1.
	// Notice the function's name is the same name as the Box we're inside.
	< fun Box1 >.<
		// change the box variable 'name's value from 'Hover' to 'Catz'
		name < 'Catz' >
		
		func1(ref name) // ref mention - will cause the variable to change

		print(name) // will print 'Hello Func3 :)'
	>

	< fun func(str) >.<
		// Edit the argument's value.
		// If this is a Copy or Ref edit,
		// depends on if ref was used when
		// calling this function.
		str < 'Hello ' + str + ' :)' >
	>

	// No ref argument
	< fun func1(obj) >.<
		obj < 'Func1' > // no ref mentions
		func2(obj) // no ref mentions
	>

	// No ref argument
	< fun func2(obj) >.<
		obj < 'Func2' > // no ref mentions
		func3(obj) // no ref mentions
	>

	// No ref argument
	< fun func3(obj) >.<
		obj < 'Func3' > // no ref mentions
	>

>

Example 3 (box ref):

< box Box1 >.<
	owo name // box variable
	< fun Box1(name) >.<
		this.name < name >
	>
>

< fun !func(obj) >.<
	assert obj is Box1 // Make sure 'obj' is a Box1 instance
	obj.name < 'OwO' > // Change the 'name' variable's value to 'OwO'
>

owo box1 < new Box1('uwu') > // Make new box instance with the name 'uwu'

func(box1) // ValueByRef by default
print(box1.name) // will print the name 'OwO'

func(unref box1) // ValueByCopy (will deep-clone object before calling func)
print(box1.name) // will print the name 'OwO' as the previous func call modified a cloned instance of the box and not the original

Example 4 (box unref):

< box Box1 >.<
	owo name // box variable
	< fun Box1(name) >.<
		this.name < name >
	>
>

< fun !func(obj) >.<
	assert obj is Box1 // Make sure 'obj' is a Box1 instance
	obj.name < 'OwO' > // Change the 'name' variable's value to 'OwO'
>

< fun !clone(unref obj) >.<
	return obj // will return a deep-cloned copy of 'obj'
>

owo box1 < new Box1('uwu') > // Make new box instance with the name 'uwu'
owo box2 < clone(box1) > // clone has unref argument = copy/clone

box2.name < 'OWO' >

print(box1.name) // will print 'uwu'
print(box2.name) // will print 'OWO'
Clone this wiki locally