It is cute, but you can't design a language for toy problems or you run into problems with bigger software. I kind of stopped reading here: "Since it is declarative code, update returns a new world w2 instead of merely modifying w1. The funny thing is, just by doing this our code becomes 200% better. For example, you can now modify the code to store all world states in a list!" Uh huh. Try doing that with a nontrivia…
An Opinionated Treatise on Cosmos, a New Programming Language
51–60 of 66 posts
Re: An Opinionated Treatise on Cosmos, a New Programming Language
#52Thanks for the replies. A few comments: 1. I might have gotten a bit carried away when writing some parts of the article. 2. "Functors" are the same as functors from Prolog. Note that Prolog lists are functors too. They also may enable the language to have an 'Option' type like in some functional languages.
He, great article. I like the language already. Also liked the "it's the best, obviously" attitude. Minor nitpick: what if (s="a") x=2 translates into? s="a" and x=2 or (s="a" and x=2) or (s!="a") ? Because your example with if .. else .. seems to indicate the first one and that's weird.
(s="a" and x=2) or true
There is an implicit else.Re: An Opinionated Treatise on Cosmos, a New Programming Language
#53Earlier quoted context omitted.
You're thinking imperatively. It is not "do this" but "generate the set of possible solutions". The "soft cut" part I'm presuming is similar to Prolog, where a "cut" indicates that once you've gotten past it, you can't backtrack (roughly - my knowledge of Prolog is rather limited) to try other arms - so "choose" is forced down one path by the guard, and then not allowed to also evaluate the other arm, while "if" can…
I am somewhat familiar with declarative programming and Prolog and still don't get it. The problem is there even without else. if (s='a') x=2 Should it be (s='a') and (x=2) or ((s='a') and (x=2)) or (s!='a') Because IMHO it should be the second one (it's also basicaly the logical definition of implication, which IMHO should be consistent with "if"). The first interpretation of if without else just give you another wa…
A better set of keywords to describe the logic might be "when ... allow". Because there is an implication here, it's just in reverse.
Because the relation finds all possible solutions that meet the relationship, this code really reads "when s is the letter a, allow x to be 0, and call that a solution. Otherwise, any pairing where x is 2 is a solution."
So if you were to call p(s, 0), you would find that you only get one solution, where s must be 'a'. From an imperative-ish POV, that "sets" (constrains) s to 'a'.
OP is using if, combined with the notions that you take only the first of all relation solutions, and that you treat the rightmost relation member as an output, to achieve an imperative-like behavior in a non-deterministic logic language. Which is mentioned in the paragraph following the example.
Re: An Opinionated Treatise on Cosmos, a New Programming Language
#54It looks like Oz [1] declarative variables could help implement a lot of this stuff. Essentially, its variables are pointers that can be assigned to only once. As such you can pass an unbound variable to a function and have it bound to produce a result. You can also do "unification" between two variables, meaning that it will try to make the two variables equal to each other. Typically, one or both of the two variabl…
I was also lost at functor...
But I get your point. Oz is a nice language which suffers from poor marketing and lack of support. It's a really lovely language though. It's the closest take I've seen so far of enabling expressibility by using a small number of orthogonal primitives. That's basically all the "multi-paradigm" talk is about.
If someone is interested to seriously hack on Oz, I think Peter Van Roy [1] would be interested, esp. if you can pitch it as a research project somehow (easier to get funding). I can make introductions if necessary.
Re: An Opinionated Treatise on Cosmos, a New Programming Language
#55Earlier quoted context omitted.
He, great article. I like the language already. Also liked the "it's the best, obviously" attitude. Minor nitpick: what if (s="a") x=2 translates into? s="a" and x=2 or (s="a" and x=2) or (s!="a") ? Because your example with if .. else .. seems to indicate the first one and that's weird.
That would get translated into (s="a" and x=2) or true There is an implicit else.
I would think if would work better if it was transformed into implication.
if (p)
q
would be (p => q)
and if p
q
else
r
would be (p=>q) and (~p => r)
Anyway, not my language.Re: An Opinionated Treatise on Cosmos, a New Programming Language
#56Earlier quoted context omitted.
Well, I've been writing Lua code for a few years now and I think that the ways you can go right with Table usage far outweigh any liabilities that newcomers to the language will suffer as they learn to do powerful things with the simple features. As long as you know what modules, arrays, or maps are, and what uses they can provide, then you can't really screw things up too much with the Lua table. But of course, that…
I don't disagree with any of that. I just think that combining concepts doesn't necessarily reduce the number of ways things can go wrong (even if, as you say, it increases the number of things that can go right as well). For an extreme case of what I mean, consider Church numerals.
I would warrant that there must be something to them, or else we wouldn't be discussing them as persistent features of a social phenomenon, which is something I think we all take for granted about software language: it is entirely social.
Whereas your extreme case is mathematically derived, our social habits occur because of decisions.
Re: An Opinionated Treatise on Cosmos, a New Programming Language
#57Thanks for the replies. A few comments: 1. I might have gotten a bit carried away when writing some parts of the article. 2. "Functors" are the same as functors from Prolog. Note that Prolog lists are functors too. They also may enable the language to have an 'Option' type like in some functional languages.
Stylistic quibbles aside, I have some reservations about the choices you've made in diverging from Prolog.
Your use of 'functor' seems to be different from Prolog's. You are therefore adding a forth or fifth meaning to the term, will have to compete with those already given by of Carnap, Quine, category theory, and OCaml. You are, thus, further muddying the sense of an already over-loaded term (http://pinealservo.com/posts/2014-10-22-ManyFunctionsOfFunct...). You seem to use 'functor' to refer to labeled tuples, or positional records. Prolog 'functors' are rather the atoms used to label such structures, e.g., `p(a)` and `p(a,b)` are different compounds with the same functor, 'p'. As a matter of fact, Prolog's compound structures do also serve as labeled tuples, but that is only a symptom of Prolog's explicit evaluation and homoiconicity. In fact, Prolog functors are "function like" in that we can call a functor on arguments, thereby instantiating a predicate. Your "functors" seem to be inert, and I think it would keep things much clearer if you just called them "records" or something. 'Functor' makes sense in the context of Prolog, where labeled compounds can be both data structures and propositions/propositional functions; for in that case, the atom used for labeling also serves a role akin to the string 'sin' in the function `sin(x)`.
This brings me to my other reservation: one of Prolog's real strengths, in my estimation, is the combination of explicit evaluation, unification, and homoiconicity. That combination gives us many higher order behaviors for free and facilitates meta programming. Thus, explicit evaluation and data-as-code means the compound `p(a)` can be mapped over a list, giving us partial application of `p(a,X)`. We also get the equivalence of first-class functions, allowing predicates to be passed as arguments to other predicates. We are also permitted remarkably deep reflection, including unification-matching on predicates and arbitrary data structures: e.g., I can do `p(X,q(r,S)) = p(2+2, Y)` to get the assignments `X = 2+2, Y = q(r,S)` and then `Sum is X * 2`, to get `Sum = 8`, and `S` will still be free until bound to something later.
This is why we differentiate the unification operator `=/2` from the arithmetic evaluation operator `is/2` and various equality operators. Contrary to your assertion, `X = 1+2` works very well, allowing me to do `X =.. [F|Args]` to get the assignments `F = +, Args = [1,2]`, so I can choose to multiply the arguments instead (e.g., `Y =.. [*|Args], Product is Y` getting `Product = 2`), inspect he functor (in this case, `+`), or simply pattern match to get the values in X (`2+Y = X` yielding the assignment `Y = 2`).
As a Prolog user, I have to say, I wouldn't dream of giving up this flexibility just to save the trouble of writing commas for explicit conjunctions and gain the (dubious) convenience of an operator that conflates assignment and equality.
Lastly, as an SWI-Prolog user, it is disingenuous to ask "where is list.map or string.concat?", as I'm sure you are well aware that both of those predicates (and many more besides) are supplied in the standard library. SWI, great as it is, still wants for features, but basic operations like those are well provided for.
So, there's some criticism from an inexpert enthusiast. Truly, I am inspired by your effort and look forward to trying out your language!
Re: An Opinionated Treatise on Cosmos, a New Programming Language
#58A fun paper, but it neglected to explain its means of modularization. I had to read the language implementation to discover the 'require' keyword used to import functions. Projects like Mercury ( http://mercurylang.org/ ) are also covering similar space.
Michael Hendrix described Mercury as Haskell + Prolog, which is accurate, I think, and an indication that Mercury is pretty far removed from what Cosmos is trying to do. (I'm more interested in Mercury). Cosmos looks like it wants to be a multi-paradigm scripting language, whereas Mercury is aiming for logical purity (no cuts), strong and static typing, and high speed (...for a Prolog). I think Picat ( http://www.pic…
Michael Hendrick: https://www.youtube.com/watch?v=G_eYTctGZw8
Re: An Opinionated Treatise on Cosmos, a New Programming Language
#59Thanks for the replies. A few comments: 1. I might have gotten a bit carried away when writing some parts of the article. 2. "Functors" are the same as functors from Prolog. Note that Prolog lists are functors too. They also may enable the language to have an 'Option' type like in some functional languages.
1. Please keep getting carried away 2. I completely didn't understand how a functor can make a list. Note, to me, a functor is a C++ class that overrides operator(). I loved how your writeup allowed me to understand Cosmos concepts _without_ learning Prolog, so an introduction to functors (maybe a later blog post?) would be warmly appreciated :-)