I've been working on this for TXR Lisp. The next, release 300, will support infix.
The core expression in your example expression will parse as you have written it. Except we have to add ifx:
1> (ifx (if (0 <= x + m && x + m <= n) (prinl 'do-this)))
** expr-1:1: warning: unbound variable x
** expr-1:1: warning: unbound variable m
** expr-1:1: warning: unbound variable x
** expr-1:1: warning: unbound variable m
** expr-1:1: warning: unbound variable n
** expr-1:1: unbound variable x
Though it doesn't work since it's not a complete example with defined variables, we can quote it and expand it to see what the expansion looks like, which answers your question of how you write it one underlying Lisp:
1> (expand '(ifx (if (0 <= x + m && x + m <= n) (prinl 'do-this))))
(if (and (<= 0 (+ x m))
(<= (+ x m) n))
(prinl 'do-this))
The ifx macro deosn't have to be used for every expression. Inside ifx, infix expressions are detected at any nesting depth. You can put it around an entire file:
(ifx
(defstruct user ()
id name)
(defun add (x y) (x + y))
...)
Autodetection of infix add some complexity and overhead to the code walking process that expands macros (not to mention that it's newly introduced) so we wouldn't want to have it globally enabled everywhere, all the time.
It's a compromise; infix syntax in the context of Lisp is just something we can support for a specific benefit in specific use case scenarios. It's mainly for our colleagues who find it a barrier not to be able to use infix.
In this particular infix implementation, a full infix expression not contained inside another infix expression is still parenthesized (because it is a compound form, represented as a list). You can see from the following large exmaple that it still looks like LIsp; it is a compromise.
I took an example FFT routine from the book Numerical Recipes in C and transliterated it, to get a feel for what it's like to write a realistic numerical routine that contains imperative programming "warts" like using assignments to initialize variables and such:
Why? It's a static site generator. He controls the inputs - there's basically no attack surface. I can't think of a situation where lack of memory safety would be less of a problem.
> Also, it's definitely not nearly as easy to implement
I think this is the real reason why there are so many dynamic language implementations. If you want to implement a dynamic language, you just slap a type tag on your runtime objects and boom, your "type system" is done.
Dynamic languages get a lot of expressiveness "for free", whereas having a really expressive static type system requires a lot of work. It's not that hard to get a type system on the level of C, but if the language is interpreted, it's still going to be pretty slow.
I do think there can be benefits to having typing in a scripting language (and not a bolted-on type system like typescript or mypy). It's much easier to work with an FFI if the type system of the scripting language maps closely to the implementation language. It also does make it much easier to optimize the language down the line, if that becomes a priority. Making a fully dynamic language efficient is very, very difficult.
> When I read the article it was very clear, due to the compiler's in-memory graphs, that they needed a GC.
It's actually pretty easy to do something like this with C, just using something like an arena allocator, or honestly, leaking memory. I actually wrote a little allocator yesterday that just dumps memory into a linkedlist, it's not very complicated: http://github.com/danieltuveson/dsalloc/
You allocate wherever you want, and when you're done with the big messy memory graph, you throw it all out at once.
There are obviously a lot of other reasons to choose go over C, though (easier to learn, nicer tooling, memory safety, etc).
I would call that weakly typed since there is no step before your code runs that validates (or even tries to validate) that your program satisfies a "type system". But since the definition of "strong" and "weak" typing has always been vague, I will just say that it is stupidly typed[1], and that I am a pedantic nerd.
Maybe surprising to hear white people saying it, but most black people (or people who grew up in predominantly black neighborhoods) throughout the US have been using it for a long time. I would assume that's a byproduct of The Great Migration.
I’m not a Lisp hater, but there’s a reason people make this criticism. I think most people find the infix version easier to read.
reply