Live data from Hacker News

An Opinionated Treatise on Cosmos, a New Programming Language

medium.com

41–50 of 66 posts

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#41

Thanks 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 :-)

To me, a functor is a ML function from modules to modules :)

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#42
post #27
post #26

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…

I should clarify before people respond antagonistically ... as someone who is designing a programming language, I think it's great any time someone is making languages and trying out new ideas. That part is great, if you want to make a functional imperative declarative loosely strongly typed language then hey, go for it. But I think one has a responsibility not to try and sell one's project as something it's not, whi…

I kind of like the style. One shouldn't ever read an opinion piece seriously anyway, he's the author, he's going to be telling you it's great. Of course it's not going to be 200% better, just like it's not the best programming language ever designed.

To me it feels like he's trying to open up the audience a little, if he's enthusiastic enough, perhaps people will go "this guy is so crazy for it, maybe there's something there". I mean it is a tough sell. A semi-functional programming language with optional types based on SWI-Prolog of all things? I bet he hasn't even solved how to deploy and run prolog in a transparent manner yet. This thing is going to be tough to polish.

On a side note: I'm super curious about your programming language, do you have anything on paper yet? I'd love to see even a short blog post of what the language looks like in your mind right now.

I'm working on a language for games as well, sort of, I call it Nancy, or Non-ANSI-C. It's basically C (literally using the Clang compiler) modified to have less inconsistencies, replacing header files with modules, and perhaps a little bit of structure. In my opinion games don't particularily need all the fancy abstract features of C++, they just need the bare metal access C gives, plus easy access to libraries and a good way to interact with an entity system. That last point isn't quite designed in my head yet, but I think it's a critical feature for game development. Every game project has their own entity management system, you either design it yourself, or fight with one someone else designed, they're less trivial to implement then you initially think, and the syntax of the language never cooperates. I think it would be cool if there was a language that was designed specifically to accomodate CES/ES.

(Jay for jumping off-topic to force my opinion onto internet celebrities ;) )

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#43

I was confused by this example: rel p(s, x) if(s = ‘a’) //this is sugar for [(s=’a’ and x=0) or x=2] x = 0 else x = 2 Why does it transform to [(s=’a’ and x=0) or x=2] and not [(s=’a’ and x=0) or (s!=’a’ and x=2)] (or whatever "not equals" is in Cosmos)? In any language I know, "else" means "do this when the guard was _not_ true", and not "nondeterministically maybe do this other thing instead, if you want". Did I si…

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 generate both alternatives.

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#44

I was confused by this example: rel p(s, x) if(s = ‘a’) //this is sugar for [(s=’a’ and x=0) or x=2] x = 0 else x = 2 Why does it transform to [(s=’a’ and x=0) or x=2] and not [(s=’a’ and x=0) or (s!=’a’ and x=2)] (or whatever "not equals" is in Cosmos)? In any language I know, "else" means "do this when the guard was _not_ true", and not "nondeterministically maybe do this other thing instead, if you want". Did I si…

I'm not sure either. But it could be a ruby style and, and a mix between assign and equal operator.

Then

  (s='a' and x=0)
would mean: if s=='a' then set x to 0, but if s != 'a' he would never jump to x=0, since and does stop when the result before is falsy - it is following the logical and behaviour.

The or would prevent the x=2 to be executed when the prior block is true, one true is enough.

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#45

Thanks 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 :-)

Yes, C++ is notorious for abusing the “functor” concept in the way you mention. Compare the Wikipedia article: http://en.wikipedia.org/wiki/Functor

A better way to describe a class that defines the »operator apply« is “function object”, as it is called in Lisp.

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#46

> If you only have a single feature then you only need to learn one thing and it can only go wrong one way. I beg to differ. You can definitely go wrong in more ways with Lua tables because they stand in for modules, arrays, and maps.

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.

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#47
post #43

I was confused by this example: rel p(s, x) if(s = ‘a’) //this is sugar for [(s=’a’ and x=0) or x=2] x = 0 else x = 2 Why does it transform to [(s=’a’ and x=0) or x=2] and not [(s=’a’ and x=0) or (s!=’a’ and x=2)] (or whatever "not equals" is in Cosmos)? In any language I know, "else" means "do this when the guard was _not_ true", and not "nondeterministically maybe do this other thing instead, if you want". Did I si…

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 way of writing:

    s='a'
    x=2
so why "if" at all?

And if we take the second interpretation of if without else, then when there's else - it should also get the !if_condition implicitly.

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#48

A 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.picat-lang.org/) or Ciao (http://ciao-lang.org/) are probably closer matches to Cosmos.

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#49

Thanks 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.

Re: An Opinionated Treatise on Cosmos, a New Programming Language

#50
post #14

l = [1, 2] l = Cons(1, Cons(2, Cons)) Ah, my other car is a cdr. I almost longed for my lisp (scheme) days. I quickly recovered, though..

Sorry you are mistaken, your CARs are numbers. Your other CDR contains Cons. Which may just be a function.

"My other car is a cdr" is an old joke. It is a play upon a kind of humourous bumper sticker ("my other car is a Ferrari") which was popular at one time.
Post reply on HN