4 ms·
Of course if you'd use Lisp in the first place you could make a new syntax to input those things in the visually safest manner without waiting for a language re
by cracauer 7y ago
Of course if you'd use Lisp in the first place you could make a new syntax to input those things in the visually safest manner without waiting for a language revision.
Compile-time computing is precisely about this, e.g.
https://medium.com/@MartinCracauer/a-gentle-introduction-to-compile-time-computing-part-3-scientific-units-8e41d8a727ca https://medium.com/@MartinCracauer/a-gentle-introduction-to-...
- xisukar 7y agoDo you mind explaining how is it related to the article? I'm genuinely interested.
- cracauer 7y agoThe article reasons that you should use the syntax that makes it safest to enter and later change that table you need.
- riffraff 7y agoperl6 also has syntax macros (sort of, I think rakudo does not implement the full perl6 macro stuff).
- b2gills 7y agoPerl6 is “supposed” to have syntax macros. Rakudo has a macro feature, but the current design was deemed not good enough to be part of the Perl6 specification testsuite yet. There has been design work in this area in the 007 project. https://github.com/masak/007 https://github.com/masak/007
- dan-robertson 7y agoPerl 6 includes the ability to modify the grammar and parser on the fly in a way which is much more convenient than reader macros in Common Lisp (and different to macros in CL). Saying “new syntax” is also slightly disingenuous because the only convenient new syntax available is made of parens. That said, this isn’t really an article about syntax but how several language features fit together. Making something slightly similar in CL could be something like: (defmacro with (it &body body) `(let ((it ,it)) (block nil ,@body))) (defmacro having (condition &body body) `(if (smart-match ,condition it) (return-from nil (progn ,@body)) (values))) (defgeneric smart-match (matcher thing)) ... But this makes the behaviour of `having` a bit weird. I feel like this article is much more about how certain perl6 features compose nicely together (in particular smart matching, $_, expressions returning values) in a way that the existing features of given and when compose to give a useful switch mechanism for free.
- sametmax 7y agoAnd of course, your code base will end up riddled with those untested, undocumented customizations. People getting into it will hate you for it, and you will look at them with a smug face, stating how they don't get the power of a true language. There is a reason Lisp based languages are not more popular: most people don't want to learn a new language every time they work on a new project.
- cracauer 7y agoThere is no specific difference between compile-time and run-time (regular) computing when it comes to testing and documenting it. As for learning something new, perl6 is a new language, this construct isn't in perl5, so they are in for a learning. In Lisp no language modification was required to enable this functionality in the first place, and so you do not have to learn any new language or language construct. Yes, you have to learn the library that you or somebody else writes to enable this "enter the data in the safest way possible". But that is learning a library, not a new language, or language evolution. It goes back to object-oriented programming. How badly did they hack up C compilers to implement either C++ or Objective-C? In Lisp the OO system used to this day was implemented as a compile-time library. A library still used today, too. You don't have to wait for anybody to hack up the compiler, and test it, and document it, when compile-time computing is part of the language in the first place. ETA: Another thing you can do with compile-time computing, without waiting for somebody to hack up the compiler: https://medium.com/@MartinCracauer/static-type-checking-in-the-programmable-programming-language-lisp-79bb79eb068a https://medium.com/@MartinCracauer/static-type-checking-in-t...
- b2gills 7y agoActually this feature is in Perl5, you just have to ask the compiler for a recent enough version. Though it has been marked as experimental because the Perl6 design for this didn't fit into Perl5 as well as was hoped for. That is it had edge-cases that need to be worked through before it is recommended for general use. use v5.10; no warnings qw(experimental); given (1) { when (1) { say 'one' } # only prints this line when (1) { say 1 } }
- 7y ago
- otabdeveloper1 7y ago> you could make a new syntax Thanks, but I'd rather not.
- reikonomusha 7y agoWhy not? Do you prefer to manage multiple languages in your stack, or cobble together half-baked “DSL”s with method dot-notation, decorators, etc.? New syntax doesn’t have to mean new lexemes or characters. New syntax can be making something that wasn’t semantically meaningful before now meaningful. In Lisp notation, if I just have a bare (F 5), I’ll get an error: F is undefined. If I define F, in some sense, I’m adding new syntax. I can now write something down that is meaningful. Now, it’s not strictly true that it’s new syntax. But if you agree to that, then maybe you’ll agree that (match X (P1 R1) (P2 R2) ...) isn’t new syntax either. (Lisp programmers, however, call it “new syntax”.) That chunk of code could represent pattern matching X against the patterns Pi, and a successful match will return Ri. Visually, lexically, and structurally, this isn’t actually “new” in a lot of ways. Still has parentheses. Looks like CASE. Doesn’t introduce any foreign evaluation semantics. So why wouldn’t you want to be able to write things like this? What makes functions/classes/methods/variables—which we define day in and day out—more privileged than syntax like this?
- otabdeveloper1 7y ago> Do you prefer to manage multiple languages in your stack, or cobble together half-baked “DSL”s with method dot-notation, decorators, etc.? Yes to both.