value = dict.get('foo', 'default')
in IronPython. value = dict.get('foo', 'default')
in IronPython.Secondly, saying "it's still .NET" is similar to saying "it's still x64". The F# compiler does a lot of transforms on code that the C# compiler does not. In some cases, this can result in better IL and better JIT'd code. Also, having inlining support at the compiler level can be very handy sometimes.
So you can write code that is optimal from a design point of view (abstractions, etc) and the compiler will turn it into optimal code from a performance point of view.
See http://flyingfrogblog.blogspot.com/2009/07/ocaml-vs-f-burrow... for a much better explanation.
No, it has a different method for failable search. The purpose of `get` is specifically to handle "provide a default value in case the key is not found".
> Or how do you handle that case with that 1 line of code?
dict[key]
[0]: http://docs.python.org/library/collections.html#collections.... [1]: http://docs.python.org/library/stdtypes.html#dict
namespace Org.DictionaryExtensions =
type Dictionary<'T> with
member x.get(key,defaultValue) =
match x.TryGetValue(key) with
| (true,val) -> val
| (false,_) -> defaultValue
There fixed that for you, now you can do, dict.get("foo","defaultvalue") in whatever CLR language you like. :)As for fast and knocking .NET you're not seriously suggesting python are you? Runtime method lookup is not exactly what I think when thinking fast.
Regarding Python speed, I know it's pretty slow, especially the IronPython implementation.
try: value = dict['foo'] except KeyNotFound: value = do_something_interesting() dict['foo'] = value
If you could pass a function in as a default of course this point is moot!
No, but that's not what the example he replied to does.
(setf value (gethash "foo" dict "default"))