4 ms·
Okay. I was testing it in C# where it does short circuit, and functions aren't called until the conditions require them to be called. This is also how the Kerne
by Sanddancer 11y ago
Okay. I was testing it in C# where it does short circuit, and functions aren't called until the conditions require them to be called. This is also how the Kernel language seems to operate. I have...misgivings about javascript's pre-evaluation of functions.
- cyphar 11y agoC does the same thing. I didn't know C# followed the functional train all the way to lazy evaluation of arguments. But given the fact that C# isn't purely functional, that seems like a bad design decision.
- tyoverby 11y agoC# does not have lazy argument evaluation. Arguments are fully evaluated for each call.
- cyphar 11y agoYeah, I thought as much. Haskell and (some?) LISPs are the only languages I can think that actually advertise this (but there's probably others). C# isn't purely functional, so lazy argument evaluation would be a very wonky feature.
- qwertyuiop924 11y agoOnly functional lisps, and those are few and far between.
- Sanddancer 11y agoI had just realized that prior to coming back here. The example given would evaluate. I could probably do the same with some operator overloading to emulate lazy evaluation, but it would be a bit more complicated.
- dsp1234 11y agoI'm pretty sure the specification for C# disallows any instance where the arguments to a function are not evaluated at the time the function is called aka lazy evaluation. This, of course, is the whole point of the statement 'try doing this in your language' that the klisp website makes. In other words, it's not possible to create an 'and' function in C# (or JavaScript) that does not evaluate it's arguments before executing. You can certainly hard code that type of logic in your code (using && in both languages), but a generic function with a signature of and(a, b) is out of reach. As a specific example, imagine B is a function that evaluates to a list of all even whole numbers and A is always false. C#/JavaScript/etc will never complete, whereas klisp (and other languages with lazy evaluation) will have no problem returning false immediately.
- dsp1234 11y agoUnfortunately, you are also wrong about C#[0]. http://csharppad.com/gist/0408e33984025e970013 http://csharppad.com/gist/0408e33984025e970013 This behavior is defined (in the C# 5.0 specification document) at section 5.1.4 "Value Parameters"[0]. "A value parameter comes into existence upon invocation of the function member (method, instance constructor, accessor, or operator) or anonymous function to which the parameter belongs, and is initialized with the value of the argument given in the invocation." [0] - https://www.microsoft.com/en-us/download/details.aspx?id=7029 https://www.microsoft.com/en-us/download/details.aspx?id=702...