13 ms·
What is a programmable programming language? (2019)
- hyuuu 4y agoshould look into Haxe's macros, so powerful with 1 language transpiles to multiple languages
- eternalban 4y ago> In your mind you can translate it back to English as “The numeric value of the sum of the numbers 2 and 3 is the same as the numeric value of the number 5” You can, but there is a simpler and more natural one to one mapping: 2[two] +[plus] 3[three] =[equals] 5[five]. 'Two plus three equals five'.
- bob1029 4y agoDSL is how we're going to scale our B2B product, which relies on heavy customization per client. We have arrived at a very clear semantic model that both we and our customers can understand. So, we figure we should just get out of the way if possible. Currently, looking at doing a fluent-style interface in C# (same as host language) which is inspected/compiled at runtime using Roslyn.
- jnash 4y agoI use code generation all the time to automate programming in C++. I define what I want (the outcome) and the code generator generates the code needed to do it. It works in any language not just Lisp. It IMHO is better to use Lisp style macros. Because the generated code is straightforward C++, making it easy to read for other programmers, without them having to first learn all the macros.
- mbrodersen 4y agoSame here. The advantage is that it works in any language.
- jmccorm 4y agoI came here expecting at least some mention of Forth. What a nice language that allows you to redefine most of the provided keywords!
- nwatson 4y agoA great language, I cut some of my programming teeth with GraFORTH on Apple II in 1982/1983 in high school. I wish I still had some of my old floppy disks. I did some floating-horizon for plotting f(x,y) and some basic animations. A friend and I did some demo programs for a couple of local entrepreneurs (Romel and Ludimar in case you're out there) selling Apple II clones, the MicroEngenho, in Brasília. Our work, displayed at a trade show, made it onto the nightly news. MicroEngenho: https://www.youtube.com/watch?v=Mu9CsdGHybw https://www.youtube.com/watch?v=Mu9CsdGHybw EDIT: YouTube link
- Someone 4y agoMost? Which ones can’t you redefine? The ‘normal’ way to redefine words in forth is a bit of cheating, though. Redefining a word merely introduces a word with a name that shadows that of the old, still existing word. Words created before the definition still call the old implementation, and, depending on the implementation (a phrase that, I think applies to about any statement about forth) you can still find it when you walk the dictionary and call it. Smalltalk is missing too, and that’s a bigger omission. When you redefine a function there, it starts getting used everywhere. I wonder what a blog post written about this 50 years from now will look like. Would it still mention C and lisp? Would readers of said article still mention forth and smalltalk as missing? Also, what reasonably successful languages from the ‘60s/‘70s already are gone from the collective mind? Being used today to write very popular OSes, I see C still being mentioned, but by then lisp might have fallen into the abyss of history (except for, probably, a few computer historians)
- Zak 4y ago> by then lisp might have fallen into the abyss of history I don't think so, because being a lisp is a trait of a language rather than a specific language. Scheme is a lisp. Racket is a lisp. Clojure is a lisp. People keep making new ones because lisp continues to be a useful idea. It keeps not quite going mainstream, the reasons for which have been subject to much speculation. It's most likely that there will be some semi-popular lisp in 50 years.
- EGreg 4y agoI came expecting them to talk about Lua
- xigoi 4y agoI wish there was a Lisp-like language that was statically typed and compiled to optimized native code. The closest thing I know of is Nim, which has the programmability, but not the simple syntax.
- cb321 4y agoI do not have much personal experience, but SBCL's type inference is supposed to be decent/comparable to the Franz/Allegro/Lisp Works commercial options. I'm not sure if anyone has done "declare-density needed to achieve xyz perf" cross comparisons or the like. There is also https://en.wikipedia.org/wiki/Stalin_(Scheme_implementation) https://en.wikipedia.org/wiki/Stalin_(Scheme_implementation) which was doing lifetime analysis waaay back in the mid 90s, but I don't think Suskind had a declare system at all in Stalin. So, places where inference did not work were probably just "slow to be fixed by users tweaking code" to make inference better. I think he was mostly his own main user. Both Coalton & Carp do look interesting. There can be complaints with how "prefix notation" scales to large expressions. Cython is a gradually typed Python, but late noughties ideas in metaprogramming/macros/etc. never quite took off. There can be an undesirable effect of gradual/optional static types that code starts off "lazy" and then can require surprisingly large efforts to tighten down, especially in team settings. Even with profiling/90-10 heuristic rules, a later dev trying to optimize earlier lazy work can still be 10X, especially if type dynamism was really leaned upon. So, at least having an easy switch to force early/in-development static typing on original authors is likely a good thing (or at least strongly encourage with warnings...).
- samatman 4y agoShen is an interesting offering in this respect https://shenlanguage.org https://shenlanguage.org Probably doesn't cover the 'optimized native code' part but it obviously could, like many programming languages it is, practically speaking, a one-man show. Not only is Shen inherently statically-typed (it's not annotations over a dynamic core language) but the type system is based on sequent calculus and is expressive and powerful. It would be nice to see what a Nim-sized community could do with it over five to ten years.
- 4y ago
- RcouF1uZ4gsC 4y agoA programmable programming language is one where you can alter the fundamental building blocks of the programming language to make it perfect for you. Unfortunately, once you have more than 1 programmer involved in the project, you end up with slightly different versions the same concepts.
- foreigner 4y agoThis was my experience with Ruby. The language makes it easy to create DSLs, so lots of libraries are implemented that way. To work on a large project you actually need to learn dozens of different languages. No thanks.
- brainbag 4y agoThis used to be the case, but once Ruby stopped being the hot language, the examples of "just because you can doesn't mean you should" went to JS. Rake and RSpec format are the only two DSLs that get any major use anymore, and most other spec tools in other languages use similar describe/it DSLs to RSpec.
- giraffe_lady 4y agoOver the last couple years a way I've come to view software is that a sufficiently complex library, class, api, or even just file IS a DSL. I don't see a useful clear line between "code" and "dsl" in the end, certainly not one based on whether you still use strictly the syntax of the base language. I don't necessarily like learning a bunch of DSLs either, but I'm not sure the ruby situation is that different from what is always the case, just more honest about it. I've been trying to pay attention to the problems I solve and noticing early when they benefit from being explicitly defined as a little language and it's been quite successful in a few cases. It reminds me of something a mentor pointed out early in my career that has remained a valuable insight: a whole lot of real world logic is implemented with state machines, but the only reliable and maintainable ones are where the author knew that from the beginning. Often we're using a known pattern to solve a problem without recognizing and naming it, so missing opportunities to apply hard-won knowledge and tools from elsewhere.
- astrange 4y agoLisp advocacy (for the last few decades) is always about how you can write anything in 10 lines of macros, but I never see anyone discuss security or whether the result actually does what you meant it to do.
- reikonomusha 4y agoWhat aspects of security are you seeking to understand vis-a-vis macros? Macros are "just" functions whose inputs are S-expressions and outputs are S-expressions, and they are run at compile-time and not run-time. The semantics of the execution of a macro corresponds more or less to the semantics of Lisp itself, which, in a simplified view, can be completely understood in a first course in computer science (as in SICP). Any statements about correctness of a macro will derive from statements about correctness of code more broadly, for which there's a lot of literature and is an ongoing active and popular field of research. Any statements about the security implications of a macro will derive from (1) statements about the security of a compiler more generally and (2) statements about code more broadly, both of which have lots of literature, and both of which have active research communities. I don't know if there are many useful things to frame around security and correctness about macros specifically (without resorting to the above derivations), which is probably why there's no literature that I know of about it.
- astrange 4y agoI said security of Lisp, not of macros (or maybe I just meant to). Nb “my implementation is memory safe” as a response just means you don’t even know what the problems are - the world’s most popular Scheme implementation, JavaScript, has security issues all the time.
- reikonomusha 4y agoDo you mean of a programming language specification (e.g., ANSI Common Lisp, RnRS Scheme), or of a specific implementation? There is no the implementation of JavaScript. There are several, all with their own issues, security and otherwise.
- dleslie 4y agoThe first question when building such a beast, or using one, is whether your mutations should be hygienic or not. And thereafter you can consider if you're seeking a powerfully modifiable reader, whether through macros or other, or if you're looking to modify the executor.
- rileyphone 4y agoThe irony of the 2 + 3 = 5 example is that it shows how domain-specific languages work best with iconic forms. Paralinguistic symbols as constituency tends toward mismatched metaphors and visual sameness. However, crafted carefully, such tools represent the best available to tame complexity. There is a level of metaprogramming even more fundamental than Lisp macros - the ancient and maligned fexpr [0]. They are almost as if you took lambda and just didn't evaluate the args when called by default. In fact, this is what Kernel [1] elegantly showed, bringing along with it the pure notion of a vau calculus, which can help restore optimization techniques who's absence resulted in the original defamation of the fexpr. [0] https://fexpr.blogspot.com/2011/04/fexpr.html https://fexpr.blogspot.com/2011/04/fexpr.html [1] https://web.cs.wpi.edu/%7Ejshutt/kernel.html https://web.cs.wpi.edu/%7Ejshutt/kernel.html
- gone35 4y ago"Paralinguistic symbols as constituency" You mean constituents? Or operands? "Paralinguistic" I think you mean syncategoremata? "Iconic forms" ? "vau calculus" Interesting. For the interested, see: https://web.wpi.edu/Pubs/ETD/Available/etd-090110-124904/unrestricted/jshutt.pdf https://web.wpi.edu/Pubs/ETD/Available/etd-090110-124904/unr...
- taneq 4y ago> "Paralinguistic" > I think you mean syncategoremata? I think this is the most HN thing I've ever read on this site. :D
- jnash 4y agoI think you will be more successful communicating your ideas if you use less obscure language. Assuming of course that you are actually trying to communicate ideas and not just trying to virtue signal intelligence or education by being intentionally obfuscated.
- fmakunbound 4y ago> Paralinguistic symbols What’s that? I googled and am still confuzled.
- account-5 4y agoI'm wanting to learn lisp, can someone eli5 metaprogramming?
- speed_spread 4y ago> eli5 metaprogramming Metaprogramming is "programming programming". Consider "programming" as writing a series of steps for a computer to follow. Metaprogramming is writing a series of steps for a computer to follow to write a series of steps for a computer to follow. When working with LISP, metaprogramming is just a normal way to program things that's built into the language. Rather than writing everything as a linear program as you would in conventional languages, you can write a program that "writes itself" (or modifies parts of itself). While you could meta-program in many languages (using code generators and whatnot), in LISP this is easy because the programs themselves are written in a way that makes them easy to be manipulated by other parts of the program. This is why you'll see so many parentheses when looking at LISP code. The simplicity of the syntax is also what makes it so powerful. Metaprogramming is a technique that often results in much shorter programs which can make single programmers very effective. The downside is that the higher level of abstraction (leaving ELI5 zone here, sorry) can make the workings of LISP programs quite opaque to newcomers as things seem a lot like magic. Therefore preserving the metaprogramming advantages in larger teams requires _especially_ good documentation and attention to design.
- Shorel 4y agoYou write a program that writes part of the program for you.
- timonoko 4y agoOld lisp makers rule was "macro is like lambda, but with one extra eval in the original environment". In other words: if your function is able to produce (+ 1 2), same function produces 3, when used as macro.
- rurban 4y agomacro is not like lambda. macros are like special forms. a lambda evaluates all it's args, a macro not.
- 3np 4y agoWhy not a single example of actual macro definitions? The reader is only shown what they're replacing and how they might be used. > When I was still researching this fabled obscure language called Lisp one thing people kept saying about it is that “Lisp is a programmable programming language”, but I could never figure out what they meant by that. Somehow I feel they fell into the same trap.
- reikonomusha 4y agoI think the usual reservation is that once you start showing how to write macros, it only follows with more questions. What's the syntax? What is quasiquoting? What is an unquote? Are arguments evaluated? Why not? What's code and what's data? How is it that a singly linked list data structure has anything to do with code that's executed? ...at which point it's almost more economical to just read a book about Lisp. I think showing what instead of how can be instructive and motivating for some readers, but it definitely doesn't satisfy all of them.
- smcl 4y agoI think this happens with a few interesting programming concepts. Haskell has its monads (person learns Haskell, gets excited when they start to grok monads, write a blog post explaining it in terms that make sense to them) and Lisp has macros (person learns Lisp, gets excited by macros, writes a blog post about it in a way that makes sense to them). It's sort of a rite of passage, only reason I don't have a monad blog post is because I made it too long so it sat for ages in my drafts and I lost the motivation to complete it :)
- dingleberry 4y agois it possible to break the grammar? that the first element must be a form example (A' 2 3) to access row 2 and col 3 of a transposed matrix A
- reikonomusha 4y agoShort answer: Yes, but it's preferred to do something a little easier. In Common Lisp, it's much easier if you prefix. It would totally be possible to do something like [A x y] to be an array accessor at indexes x and y by defining reader macros for the characters '[' and ']'. And then one could define the reader macro for the character 'ᵀ' so that ᵀA expands to the transpose of A. Then you could write [ᵀA x y]. If you didn't like this prefix thing, you could instead be more elaborate with '[' and parse something more complicated with postfix notation.
- trashburger 4y agoIf you're interested in something lile this, then check out the Smalltalk family of languages. They're similar to Lisps in the sense that the environment is completely programmable (metaprogramming is just regular programming); however, whereas Lisp uses source code to create new forms and perform metaprogramming, in Smalltalk there is no source code. In Smalltalk-based languages, you perform metaprogramming by acting on live objects (the "source code" is just an in-transit format for the true form of objects).
- lispm 4y agofor Lisp see CLOS & MOP: object-oriented meta-programming in Lisp https://en.wikipedia.org/wiki/The_Art_of_the_Metaobject_Protocol https://en.wikipedia.org/wiki/The_Art_of_the_Metaobject_Prot...
- Qem 4y agoThe Pharo MOOC os a nice place to start getting familiar with the Smalltalk family. https://mooc.pharo.org/ https://mooc.pharo.org/
- igouy 4y ago> … in Smalltalk there is no source code. Please explain why you think that might be "a good thing". (Assuming you do.) Please explain what you think are the differences between "source code" and "an in-transit format" that would allow us to distinguish one from the other.
- xkriva11 4y agoThe more important aspect of the Smalltalk approach is that the method is the basic unit (like having one source file per method). The difference is that the grammar of the transit file is not the language's grammar.
- igouy 4y ago> … in Smalltalk there is no source code. Good? Bad? Unimportant? > … method is the basic unit… Are there method definitions outside the context of a class? > … not the language's grammar. GNU Smalltalk?
- enduku 4y agoREBOL Parse maybe?
- cmacleod4 4y agoStrong support for metaprogramming techniques is one of the underappreciated features of Tcl - see https://wiki.tcl-lang.org/page/Meta+Programming https://wiki.tcl-lang.org/page/Meta+Programming and https://www.magicsplat.com/blog/meta-html/ https://www.magicsplat.com/blog/meta-html/ .
- ngcc_hk 4y agoWhere is the macro I wonder. It was promised in the last paragraph but no link. The link is to the “horrible” test guile source still.