I always feel that for lisp-like languages it's just not a good idea to make them statically typed. Their power is derived from macros and the fact that code is data and the other way around. For statically typed languages, they only feel ergonomic to me if they have highly specialized syntax and if they really leverage the type-system (which is often in conflict with macros and runtime flexibility).
Nim is statically typed and has a powerful macro facility: https://nim-lang.org/docs/manual.html#macros https://nim-lang.org/docs/macros.html
BLisp: A Statically Typed Lisp Like Language
41–50 of 51 posts
Re: BLisp: A Statically Typed Lisp Like Language
#42Earlier quoted context omitted.
No problem. I'm interested to hear though why you think unrestricted macros make the type system unsound. Can you explain? The code generated by macros would be type-checked in the scheme I described, and type-unsafe code can't be executed by the macro itself, so it seems safe to me.
That is more of my impression that I have gathered from watching programming languages evolving. Rust is a good example, where they tried hard and the macros still become unsound. Scala is another good example where macros where unsound first and they had a really hard time to make them sound and work with the type-system - they lost a lot of power in the process. Now, that doesn't have to mean that there is some inh…
Which part, the type-checking? Don't we want it to be type-checked?
Re: BLisp: A Statically Typed Lisp Like Language
#43Earlier quoted context omitted.
No problem. I'm interested to hear though why you think unrestricted macros make the type system unsound. Can you explain? The code generated by macros would be type-checked in the scheme I described, and type-unsafe code can't be executed by the macro itself, so it seems safe to me.
That is more of my impression that I have gathered from watching programming languages evolving. Rust is a good example, where they tried hard and the macros still become unsound. Scala is another good example where macros where unsound first and they had a really hard time to make them sound and work with the type-system - they lost a lot of power in the process. Now, that doesn't have to mean that there is some inh…
For my part, my sense is that it would be appropriate for a static lisp to choose completeness over soundness in its type system. Gödel's incompleteness theorem tells us that a static type checker can't be both sound and complete. So you've got to pick one, and there's something about sacrificing liberty for the sake of security that strikes me as being fundamentally un-lispy. All the talk further up about CL-style unhygienic macros seems like a good illustration of the relevant culture. You can't ignore Scheme and Racket, of course, but the longer tradition in Lisp is to say, "We'll give you all the power and all the footguns, and leave it up to you to use them responsibly."
Re: BLisp: A Statically Typed Lisp Like Language
#44Re: BLisp: A Statically Typed Lisp Like Language
#45Is this a lisp? It looks like an ml with s-expressions.
Re: BLisp: A Statically Typed Lisp Like Language
#46Is this a lisp? It looks like an ml with s-expressions.
Lisp isn't necessarily just CL or Scheme. Further, if I recall correctly, ML started out as a lisp that later adopted infix syntax.
Re: BLisp: A Statically Typed Lisp Like Language
#47Earlier quoted context omitted.
Just for completeness, the correct macro would look like this: (defmacro double (x) (let ((temp (gensym)) `(let ((,temp ,x)) (+ temp temp)))) This way, when you write (double (parse-integer (read-line)) it would expand to (let ((#:uniqueName123 (parse-integer (read-line))) (+ #:uniqueName123 #:unique_symbol_123)) This guarantees that that the macro will not accidentally refer to some outside variable, and that it's a…
Surely (defmacro double (x) (let ((temp (gensym)) `(let ((,temp ,x)) (+ ,temp ,temp))))
(declaim (inline double))
(defun double (x) (+ x x))Re: BLisp: A Statically Typed Lisp Like Language
#48I'm now designing macros, but I cannot spend sufficient time to do. Anyway, macros will be implemented in the near future.
This language is being implemented for bare-metal or no_std environments in Rust. This is often called shell. I don't want to control OSes or devices by YAML or unsafe scripting languages.
Re: BLisp: A Statically Typed Lisp Like Language
#49Earlier quoted context omitted.
Oops, yes...
And this thread is why types help :)
(compile nil '(lambda (x) (double x)))
;Compiler warnings :
; In an anonymous lambda form: Undeclared free variable TEMP
; In an anonymous lambda form: Unused lexical variable #:G520
Unfortunately, HN doesn't compile code you add in the comments...Note, this is a warning and not an error because of CL's semantics, as the following is a valid program:
(let ((temp 100))
(double 10))
;returns 200
If you really wanted this effect though, normally you would have to declare that `temp` is a special variable: (declaim (special temp))
(compile 'nil (lambda (x) (double x))
;Compiler warnings :
; In an anonymous lambda form: Unused lexical variable #:G524Re: BLisp: A Statically Typed Lisp Like Language
#50Earlier quoted context omitted.
That is more of my impression that I have gathered from watching programming languages evolving. Rust is a good example, where they tried hard and the macros still become unsound. Scala is another good example where macros where unsound first and they had a really hard time to make them sound and work with the type-system - they lost a lot of power in the process. Now, that doesn't have to mean that there is some inh…
> Well, I would already consider this to be quite a big restriction though. Which part, the type-checking? Don't we want it to be type-checked?