Live data from Hacker News

The Pyret Programming Language

pyret.org

61–70 of 138 posts

Re: The Pyret Programming Language

#61
post #52

> # this is true > ((1 / 3) * 3) == 1 This is a slippery slope. Early versions of Dart tried to use rational numbers by default, but then it was cancelled because denominator size can grow exponentially. Also, I seriously doubt you can make a language that will correctly resolve checks like this one: sin(pi / 6) == 1 / 2

The Wolfram language successfully resolves it: https://www.wolframalpha.com/input/?i=sin%28pi+%2F+6%29+%3D%...

Yes, I should have written "practical programming language". It definitely possible to resolve many equations like this (though not all of them), but is quite a slow process, which is ok for a math system like Mathematica, but not for a real-life programming language.

Re: The Pyret Programming Language

#62

The ruby comparison is unfair: o = Object.new def o.my_method(x) self.y + x end def o.y 10 end o.my_method(5) == 15 # true method_as_fun = o.my_method # Wrong number of arguments, 0 for 1 The last line is actually doing: method_as_fun = o.my_method() Which should make the error message obvious. Ruby makes this syntax optional for readability purposes, which becomes obvious once you start going through real world ruby…

I think if you put more newlines in your code example (at least two per code-line) it might come through the HN formatting thing better?

Re: The Pyret Programming Language

#63
post #49

Earlier quoted context omitted.

Always requiring whitespace around infix operators is, in my opinion, easier to explain to people than "you can do whatever you want with the whitespace." It's consistent and regular. I don't think it's as much of an issue as you're making it out. Pyret is the result of decades of research in computer science education, helmed by Shriram Krishnamurthi, who was one of the original members of the Racket project (itself…

> Knowing who they are, I would happily assume that they spent plenty of time debating this exact issue of mixing kebab case with infix subtraction, and either decided the benefits were worth the cost or else decided that the cost was practically nonexistent. We don't need to assume when we can search. I did a few minutes of searching and found the following: https://groups.google.com/g/pyret-discuss/c/rPe7gYBLdPs/m/…

It only makes more sense when you do look at the background, so thanks for the link. They're lisp folks. They use kebab-case. I completely get it. It may be the product of decades of research, but it is also the product of default choices and comfort for the people who wrote it. ALL programs have an element of this: I write Rust and you can tell without looking when some tool is written in it -- TOML config? Apache-2.0/MIT dual-licensed? Few such decisions have no downsides, and yet exceptions are rare.

It takes a lot to make a choice for reasons other than your own familiarity. From the linked thread, they clearly agonized over this. Apparently they talked themselves down from the usual Lisp ultra-permissiveness on idents, so good on them -- but it was still explicitly a compromise between their comfort and the aims of the project.

There is an obvious and very good reason why the number of languages that do this can be counted on one hand. The authors know that. It is a problem they decided to accept because it was the default for them, and they "just couldn't give up on how pleasing hyphens in identifiers are to the eye and the shift-finger", and then mitigated it via other whitespace changes. They were content when "Anecdotally, no one in our courses ha[d] complained". I disagree with it. I find it really hard to read. I guess I am used to other languages, but so is everyone who has dabbled in python, likely writing primarily numeric code for their stats/bio/physics courses.

Consider me a student reporting it as a problem. Consider the 2013 thread a student reporting it as a problem as well. How about that?

I'll finish with a quote from Krishnamurthi himself: "Saying 'add spaces around binops' is easy to learn, recognize, and implement."

Does this not speak for itself?

    fun subtract(a, b):
      a-b
    end
    
    >>> The identifier a-b is unbound:        definitions://:3:2-3:5
    
    4 | a-b
    
    It is used but not previously defined.
Edit: I dug up an old thread from the guy @estebank who makes all the amazing Rust error messages, responding to a paper of Krishnamurthi's that argues, true to form, that you shouldn't ever actually "Say 'add spaces around binops'" (https://twitter.com/ekuber/status/1140791186858266624). The paper itself is an interesting read, particularly the interviews where beginners don't have the vocabulary to decipher error messages. But I think Esteban is right.

Re: The Pyret Programming Language

#64

The ruby comparison is unfair: o = Object.new def o.my_method(x) self.y + x end def o.y 10 end o.my_method(5) == 15 # true method_as_fun = o.my_method # Wrong number of arguments, 0 for 1 The last line is actually doing: method_as_fun = o.my_method() Which should make the error message obvious. Ruby makes this syntax optional for readability purposes, which becomes obvious once you start going through real world ruby…

The way to do the last bit in Ruby is:

  method_as_fun = o.method(:my_method)
  method_as_fun.call(5) # 15

Re: The Pyret Programming Language

#65

The ruby comparison is unfair: o = Object.new def o.my_method(x) self.y + x end def o.y 10 end o.my_method(5) == 15 # true method_as_fun = o.my_method # Wrong number of arguments, 0 for 1 The last line is actually doing: method_as_fun = o.my_method() Which should make the error message obvious. Ruby makes this syntax optional for readability purposes, which becomes obvious once you start going through real world ruby…

Yes, that would be:

    method = o.method(:my_method)
    method.call(5)
    # or method[5], or method.(5)
If you really want a "function" that you can call with parens:

   Kernel.define_method(:method_as_fun, &method)
(Definitely don't do that last bit in a real project...)

Re: The Pyret Programming Language

#66

The syntax is pretty much like Python and ruby: “end” to declare end of block statements and colon to start a block statement. But why to use “fun” to declare a function when “def” could be used. The same in other languages: function, func, fun, fn, etc.

python doesn't use end. To be honest, as a python programmemr the syntax looks quite alien.

Re: The Pyret Programming Language

#67

The syntax is pretty much like Python and ruby: “end” to declare end of block statements and colon to start a block statement. But why to use “fun” to declare a function when “def” could be used. The same in other languages: function, func, fun, fn, etc.

Maybe because it should be fun to use? NSI. I prefer fun to fn and func, because it aligns nicely with four spaces a tab formatting.

Re: The Pyret Programming Language

#68
post #49

Earlier quoted context omitted.

> Knowing who they are, I would happily assume that they spent plenty of time debating this exact issue of mixing kebab case with infix subtraction, and either decided the benefits were worth the cost or else decided that the cost was practically nonexistent. We don't need to assume when we can search. I did a few minutes of searching and found the following: https://groups.google.com/g/pyret-discuss/c/rPe7gYBLdPs/m/…

It only makes more sense when you do look at the background, so thanks for the link. They're lisp folks. They use kebab-case. I completely get it. It may be the product of decades of research, but it is also the product of default choices and comfort for the people who wrote it. ALL programs have an element of this: I write Rust and you can tell without looking when some tool is written in it -- TOML config? Apache-2…

That could be fixed by checking the identifier for valid operators and offer: "Did you mean a - b?"

Re: The Pyret Programming Language

#69
post #34

Earlier quoted context omitted.

> Always requiring whitespace around infix operators is, in my opinion, easier to explain to people than "you can do whatever you want with the whitespace." It might be easier to explain, but it also makes the code look ugly. Consider the expressions: a := b + c*d if e > f-g then ... Here the * and - are more tighly bound than the + or >, and I'm using the whitespace to make that obvious.

Beauty lies in the eye of the beholder, ie aesthetics are subjective. For me, using proximity instead of parentheses to signify grouping would raise an eyebrow. I'd make an exception for cases of base*exponent, i think Python has it?

Need to reply to myself for correction since it is to late to edit.

It should say base*exponent.

I think other languages use base^exponent, which would be fine with me too.

Re: The Pyret Programming Language

#70

It seems pretty bad to have kebab-case identifiers in a language that also has an infix subtraction operator -. The only languages I know that allow kebab-case idents are lisps, where subtraction is (- prefix notation). From the examples: lam(actual): num-abs(actual - target) This is a new, even worse kind of "whitespace significance" than indentation. Is it a function called `num-abs` or a variable `num` minus `abs(…

> It seems pretty bad to have kebab-case identifiers in a language that also has an infix subtraction operator -. Indeed. What's wrong with using _ in identifiers?

> Indeed. What's wrong with using _ in identifiers?

Nothing wrong with it. It is usually easier to type '-' though. Use in when naming scripts and files for the same reason. Ergonomics matter IMHO.

Post reply on HN