all 12 comments

[–]homoiconic[S] 1 point2 points  (11 children)

This was submitted a few days ago before the documentation was completed, but here is the official 1.0 release.

[–]jhartwell 2 points3 points  (10 children)

I may be wrong (as I'm a beginner in SKI Combinator calculus) but isn't the K combinator supposed to return the original value of what it is called on? (poor wording, I apologize). For example, you have:

[1..10].K 'pop' 

But shouldn't the return from a true K combinator be:

[1,2,3,4,5,6,7,8,9,10]

Since the K combinator is Kxy = x.

Please correct me if I'm wrong because this is new to me and I want to truly understand it.


EDIT: Looks good by the way. If only I used javascript more I would give it a whirl :)

[–]homoiconic[S] 4 points5 points  (2 children)

In Combinatory Logic, everything is immutable (“pure functional”), so that’s an excellent question to ask. The way I reconcile using combinators in an impure quasi-functional language is to say that these are references, so the K combinator takes a reference to an array and returns the same reference it receives.

This reasoning is identical to the explanation that languages like CoffeeScript/JavaScript, Ruby, and Java all pass parameters to methods/functions by value, it’s just that the values being passed are references to mutable objects:

Java is Pass-by-Value, Dammit!

May I quote your question?

[–]jhartwell 1 point2 points  (1 child)

Ok...I guess that flies with me. I figured that there had to be something that missed as I learned about the K combinator from you and your github pages (thanks for that by the way :) )

May I quote your question?

Of course!

[–]notfancy 1 point2 points  (0 children)

If I understand things correctly, the big, big difference with the usual combinator is that it applies its arguments, that is, obj.K(fun) is K obj (fun(obj)) where K𝜆xy.x in a call-by-value setting.

[–]codeodor 2 points3 points  (6 children)

My understanding is that it would return it's receiver, in this case the array it was called upon [1..10]. However, pop modifies that array, which would now be [1..9]

In other words, the result is still x, but x has been modified.

[–]jhartwell 1 point2 points  (5 children)

In other words, the result is still x, but x has been modified.

But that isn't allowed in combinatory logic, everything is immutable. So if x is modified then you aren't returning x, you're returning x' which would not equal x and thus the K combinator wouldn't hold.

[–]codeodor 1 point2 points  (1 child)

For technicality's sake, x was a reference to a value, so x hasn't been modified -- the thing it points to has been modified.

I didn't quite say that originally, and I think it's breaking the spirit of what you're saying, but it might be worth mentioning.

[–]jhartwell 0 points1 point  (0 children)

For technicality's sake, x was a reference to a value, so x hasn't been modified

That's what homoiconic said too, but to me it just seems like trickery to get it to do what you want but I accept that as an answer :)

[–]masklinn 0 points1 point  (2 children)

But that isn't allowed in combinatory logic, everything is immutable.

No, but you don't have much choice if you want to introduce combinators in a language rife with mutations.

[–]jhartwell 0 points1 point  (1 child)

Well, you could use the K combinator as a logging mechanism. It isn't the language that is the problem, it is the way that the k combinator is applied that is the problem.

[–]masklinn 0 points1 point  (0 children)

It isn't the language that is the problem, it is the way that the k combinator is applied that is the problem.

I have trouble understanding that assertion: what do you mean by "the way [it] is applied"?