News for hackers. Stuff that matters.
Re:What else are we getting wrong about programming languages? by lisper on Sunday October 30, 2016 @05:49PM (#12832560)
My nomination for what we get wrong over and over again: working under the assumption that there is One True Syntax. There isn't. Different syntaxes are suitable for different needs.

A single language can support multiple syntaxes if the AST is exposed as a first-class construct. This makes it easy to write new syntactic front-ends. Unfortunately, the only language to date that supports this idea is Lisp, which means that this incredibly powerful idea is conflated in most people's minds with lots of irritating silly parentheses. (One of the reasons for this conflation is that once you start adopting this mindset the parens become a lot less silly and irritating, but that's another story.)

I'm currently working on cryptography code, where algebraic syntax is very convenient. Here's an excerpt from some code I'm currently working on:

    (define-method (point-double (ec elliptic-curve a b c q r) x y)
      (bb
       lambda modp(q, (3*x*x + 2*a*x + b)/(2*y))
       x3 modp(q, lambda*lambda - a - 2*x)
       y3 modp(q, lambda*(x-x3)-y)
       (values x3 y3)))
    
    (define-method (point-add (ec elliptic-curve a b c q r) x1 y1 x2 y2)
      (if (and (= x1 x2) (= y1 y2))
        (point-double ec x1 y1)
        (bb
         lambda modp(q, (y1-y2)/(x1-x2))
         x3 modp(q, lambda*lambda-a-x1-x2)
         y3 modp(q, lambda*(x1-x3)-y1)
         (values x3 y3))))
Notice that it looks like Lisp (and it is Lisp) but there's infix code seamlessly embedded. Moreover, the MODP construct automatically converts everything to modular arithmetic operations, so, for example, x/y doesn't actually divide but instead expands into (* x (modular-inverse y p)). But when I code, all I have to do is copy the mathematical formulas more or less verbatim and my compiler takes care of expanding everything out into calculations that use Montgomery reduction or whatever optimizations I want to provide. This approach also has the advantage that I can test the correctness of my protocols completely independently of the correctness of my optimizations.
Re:What else are we getting wrong about programming languages? by err4nt on Sunday October 30, 2016 @05:53PM (#12832588)
Hey thanks for taking the time to write this out. I'm new to programming and learning JavaScript, and what you said about exposing the AST and writing new syntaxes for the same language is really intriguing.

I try to learn about the history of computer science and I try to understand where languages have come from - and one so far I haven't dabbled with any of the Lisp languages at all. If I was a JS learner curious about Lisp - what's the easiest way for me to get started with some experiments?

Re:What else are we getting wrong about programming languages? by lisper on Sunday October 30, 2016 @07:04PM (#12833055)
I started working on a book a while back targeted specifically towards people who already know a little about programming:

https://github.com/rongarret/BWFP

It's nowhere near complete but I'm working on chapter 3 now.

Re:What else are we getting wrong about programming languages? by jbpetersen on Sunday October 30, 2016 @07:26PM (#12833147)
Try checking out https://github.com/maryrosecook/littlelisp. It's a relatively very simple Lisp interpreter written in JS.

http://languagelog.ldc.upenn.edu/myl/ldc/llog/jmc.pdf is another great resource for being introduced to Lisp.

Re:What else are we getting wrong about programming languages? by didibus on Sunday October 30, 2016 @08:30PM (#12833446)
Maybe ClojureScript.
Re:What else are we getting wrong about programming languages? by dnautics on Sunday October 30, 2016 @06:55PM (#12832995)
Julia has AST as a first class object, but I think it does this by secretly running lisp behind the scenes.
Re:What else are we getting wrong about programming languages? by mroll on Sunday October 30, 2016 @06:13PM (#12832702)
tcl is also written directly in the ast. And there is a built in command, expr, for doing infix math
Re:What else are we getting wrong about programming languages? by ljw1001 on Sunday October 30, 2016 @09:09PM (#12833585)
Smalltalk is another language where the AST is fully accessible by application code.