About Monkey 2 › Forums › Monkey 2 Programming Help › Playing with first class functions
This topic contains 19 replies, has 5 voices, and was last updated by
nerobot 1 year, 4 months ago.
-
AuthorPosts
-
December 4, 2017 at 3:30 am #12092
GetValue <T>:T ( key:String,value:T=Null )
I quite like this, but I thought your original point was that GetValue should *fail* if ‘key’ can’t be found? I actually like this idea. Perhaps we could have both, eg:
Monkey123Method GetValue:V( key:K )Method GetValue:V( key:K,defaultvalue:V )In this case, it’d be possible to get exactly current behaviour by using ‘GetValue(key,Null)’ but it’d also pick up existing bugs where you expected something to be in a Map but it wasn’t.
December 4, 2017 at 3:49 am #12095Yes, I like what you said in the latest post.
And some changes to docs for these methods where you explain that Null is context specific. Maybe even to create own docs page for Null and place references here from other pages.
What happen if we compare ‘default null’ first class function with keyword Null?
If GetValue ( "test",Null )=Null
Genarally, .Contains () is our big friend.
December 4, 2017 at 5:10 am #12096What happen if we compare ‘default null’ first class function with keyword Null?
The answer is – first class function is null until have no assigned values.
Example app:
Monkey12345678910111213141516171819202122232425Namespace myapp#Import "<std>"Using std..Function Main()Local f:Bool()If f=Null Print "#1: func is null"f+=FuncIf f=Null Print "#2: func is null"f-=FuncIf f=Null Print "#3: func is null"EndFunction Func:Bool()Return TrueEndOutput:
Monkey12#1: func is null#3: func is nullAlso I found that mx2cc allow us to write weird code:
Monkey1f-=Null ' or +=NullIs this Null value will generate anonimous new instance or simple will do nothing?
I think the answer is the second case – do nothing. If we have empty / null f and write f+=Null then f still is null.
December 4, 2017 at 5:43 am #12097Also I found that mx2cc allow us to write weird code:
That *is* pretty weird, but it sort of makes sense (to me). I guess it’s a bit like x+=Null where x is an int. I can live with this wrinkle. All other results are what I’d expect (and what I think people would intuitively expect) anyway.
December 4, 2017 at 5:51 am #12098I tried it just for testing because we talk about Nulls here.
And I can live with that too.
-
AuthorPosts
You must be logged in to reply to this topic.