Some Monkey syntax and language features

Monkey Archive Forums/Monkey Tutorials/Some Monkey syntax and language features

Nobuyuki(Posted 2013) [#1]
Here's a thingy I wrote to show off some of Monkey's syntax to others. As you can see, the pygments parser/lexer for Monkey still needs some work. I forgot who on the forums wrote it, but please check this file for maybe a few bugs that can be fixed!

https://gist.github.com/nobuyukinyuu/7186162


Sammy(Posted 2013) [#2]
A very handy piece of code to have for any beginner, well done Nobuyuki!


RENGAC(Posted 2013) [#3]
Thank you! Very useful for begginers like me!


programmer(Posted 2013) [#4]
Try/Catch/End(End Try)!


Sammy(Posted 2013) [#5]
This bits kinda bonkers that it works though!
		str = "Hello World!"
		str = str[-6 .. -1]
		Print str          'Prints "World"



Difference(Posted 2013) [#6]
This looks wrong, shouldn't New have Self.myVal = t ?
'Generic class
Class MyGeneric<T>
	Field myVal:T
		
	Method New(t:T)
		Self.myVal
	End Method
	
	Method WhatsMyVal:T()
		Return T
	End Method
End Class



Difference(Posted 2013) [#7]
Infact that whole class needs some TLC, this is a working version:

Class MyGeneric<T>
	Field myVal:T
		
	Method New(t:T)
		Self.myVal = t
	End Method
	
	Method WhatsMyVal:T()
		Return myVal
	End Method
End Class



Nobuyuki(Posted 2013) [#8]
you guys are right. Looks like I wasn't paying close enough attention! The gist has been updated.

I'd make an example for the Try block, but unfortunately I can't think of a succinct example to utilize it. Might require making a couple throwable classes.