Live data from Hacker News

An Opinionated Treatise on Cosmos, a New Programming Language

medium.com

61–66 of 66 posts

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

#61
post #18

Prolog is neat. There is probably a Prolog embedded in some of the C++ type checkers. The problem is that the world at large is often in a flux and can't be conveniently described in terms of static relationships, which makes Prolog programming at large challenging to do (or you augment Prolog with features that make it more or less imperative).

> The problem is that the world at large is often in a flux and can't be conveniently described in terms of static relationships

Apparently there was work in the late '90's on accounting for this without `assert` / `retract`-style messiness: https://en.wikipedia.org/wiki/Transaction_logic.

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

#63

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…

https://en.wikipedia.org/wiki/Lazy_evaluation#Control_struct...

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

#64

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…

Because then what if:

    rel q(y)
     y = true
     y = false
    
    rel p(s, x)
     if(s = ‘a’)
      x = 0
     else
      x = 2
    
    rel main()
     k = q()
     if(k)
      s = 'a'
     else
      s != 'a'
     p(s,x)
     println(x)
Actually, I'd like to know what Cosmos would resolve this to as things stand. Is it just going to decide that | x = 0, | x = 2? Also can I throw probabilities into this code?

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

#65

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…

Because then what if: rel q(y) y = true y = false rel p(s, x) if(s = ‘a’) x = 0 else x = 2 rel main() k = q() if(k) s = 'a' else s != 'a' p(s,x) println(x) Actually, I'd like to know what Cosmos would resolve this to as things stand. Is it just going to decide that | x = 0, | x = 2? Also can I throw probabilities into this code?

One property of Cosmos is that there is no boolean type and relations are themselves booleans (q() would be false in this case). Hence, the code would be rather like this:

  rel q()
   true
   false
  ...
  rel main()
   if(q())
    ...
Indeed, having an 'else' that negates the condition would get tough for complicated conditions. Negation-by-failure and soft-cut ('choose') have their own problems in certain circumstances.

Yeah, it's going to decide that | x = 0 | x = 2 (there is no CLP for strings).

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

#66
I wrote quite a lot of TurboProlog code for a while some 25 years ago. I always wondered why there were no syntax sugar for nested 'or' Horn clauses.

Now it's fixed. Cool. So is the rest of Cosmos syntax sugar, cool, kudos.

I guess some OO would be a nice addition. And, that's the thing of the day: an efficient JS transpiler and a decent IDE with a stepping debugger. That's asking a lot. I know.

Post reply on HN