Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Two different unrelated adjectives: it's an advanced language, and a purely functional language


This is about https://news.ycombinator.com/item?id=7475631

You asked a year ago:

>You say it's used all the time -- so how about you give an example of a "lazy" solution to a problem in, say, C?

but I was just reading that old thread now, so replying here.

short-circuit evaluation would be an example in C, because the programmer can ask the compiler to do something, but at run-time it won't do it if the results aren't necessary - it just won't execute despite the programmer explicitly writing those instructions.

e.g. in the condition if (is_prime(a) && is_something_hard_to_compute(a)) then even though you're calling the function is_something_hard_to_compute() about a, at run-time if it's not necessary for the result, then purely out of laziness it won't get called. (i.e. if the first test returns false.)

this meets the condition you asked about.

reference: http://en.wikipedia.org/wiki/Short-circuit_evaluation




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: