Thursday, May 21, 2020

Why is get(dict,value,default) evaluated eagerly?

I have always believed that, in get(X,y,z), z would be evaluated only
when dictionary X does not contain key y. Today, to my surprise, I have
discovered that it is not the case:

fun! Loop()
call Loop()
endf

let H = { 'a': 1 }

if has_key(H, 'a') || Loop() " Fine, this is evaluated lazily
endif

echo (get(H, 'a') != 0) ? "" : Loop() " Fine, lazy

" But, endless recursion here:
echo get(H, 'a', Loop())

What is the rationale for this behaviour?

Thanks,
Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ra68ro%241f42%241%40ciao.gmane.io.

No comments: