4 ms·
I kind of make a new language for every project. Rather than writing a program directly, I write pseudocode to solve the program, and then build a language that
by benibela 10y ago
I kind of make a new language for every project. Rather than writing a program directly, I write pseudocode to solve the program, and then build a language that runs just that pseudocode.
I had to query lots of data from webpages, so I made a pattern matching language where the program is a sample of the webpage. E.g. to query the the text of <span id="foo">some text</span>, you write the "program"/pattern <span id="foo">{.}</span>. Or if the webpage had multiple <span class="foo">some text</span>, you would use the pattern <span class="foo">{.}</span>+
Then I noticed, you sometimes need more expressive power than simple patterns, e.g. returning an element depending on the value of another element, so I added variables and allowed some kind of XPath expressions inside the {}. It was not really XPath, because XPath 1 has no variables, but after a while I noticed, XPath 2 has variables. There was no XPath 2 interpreter for the host language, so I implemented a standard-conformant XPath 2 interpreter for this. Not really my language, but my implementation of a language. Later I updated it to XPath 3, which became far more complex than expected, since XPath 3 does not just has variables, but is fully Turing-complete with anonymous functions. And a type system with 50+ different types. Makes JavaScript look trivial. I also noticed, XPath 3 is almost the same as XQuery 3, so I implemented that, too. http://www.videlibri.de/cgi-bin/xidelcgi http://www.videlibri.de/cgi-bin/xidelcgi
Which brings us back to your XmlPl, because XQuery was designed for the same tasks. That example node[] main() { <title>helloString;</title> } would become declare function main() as node() { <title>{$helloString}</title> } in XQuery.
Previously I made a completely different XML processor for my personal webpage. Keep all content in XML files, make an HTML file for the layout of the webpage, and then insert the data from the XML in the HTML at statements like {{$WRITE some/kind/of/xpath }}. It had control structures {{$IF}}, {{$FOREACH}}. I thought it was a good idea to keep the program separate from the markup, but it only looks confusing, so stopped using that language.
Most recently I made a language to sort my mails when they arrive on the server. More a toy than a full programming language, but the cleanest way to keep those filters http://hg.benibela.de/mailfilter/ http://hg.benibela.de/mailfilter/
- hzhou321 10y ago> I kind of make a new language for every project. Rather than writing a program directly, I write pseudocode to solve the program, and then build a language that runs just that pseudocode. I love that approach. Don't let non-essential constraints limit the elegance of your solutions.