On Fri, Feb 1, 2013 at 9:47 AM, Terry Raymond <[hidden email]> wrote:
David Leibs has been pushing a well-thought-through facility he calls (and other systems name) "quasi-quote". Here, a string literal contains escape sequences, a little like printf, that allow one to substitute values. Dave's syntax uses square brackets to escape into Smalltalk. So that (IIRC) you say things like
'<html><head></head><body><H1>[myHeading]</H1>' which compiles to something analogous to String streamContents: [:s| s nextPutAll: '<html><head></head><body><H1>'; nextPutAll: myHeading asString; nextPutAll: '</H1>]
But this excellent suggestion has fallen on deaf ears (my own included) for more than a decade.
best, Eliot
|
On Fri, Feb 1, 2013 at 10:28 AM, Eliot Miranda <[hidden email]> wrote:
<blush>, saw quote, brian farted, now realize this is nothing to do with your issue Terry. Apologies</blush>.
But you could come up with some convention to embed in quasi-quote to change the string quote, right? he thing is to choose your escape character(s) with care. You need a quote to escape to and from processing ($[ & $]). You need a literal quote ( $\ ?). Do you need a third quote to change quote interpretation? Or do you need a third quote that turns off single quote as end of string? eg. say $^ indicates no close quote until the matching $^. So the following
'^'my single-quoted string'^' denotes '''my single-quoted string''' and I realize I can't remember how David's proposal distinguishes between quasi-quote strings and normal Smalltalk strings.
best, Eliot
|
In reply to this post by Eliot Miranda-2
On Fri, Feb 1, 2013 at 10:44 AM, Colin Putney <[hidden email]> wrote:
If I had a brain I would have remembered the syntax and hence that it does address Terry's point. The quote character for quasi-quote is ` (back tick), so single ticks are literal inside a quasi-quote. <blush>Sorry</blush>
best, Eliot
|
How about the Groovy way of using:
""" quoted string that preserves all single tick ' occurences as is """ The 3 single or double quote encasing the text. Yes there is always the possibility of the text containing the same, just its less likely to occur.. On Sat, Feb 2, 2013 at 3:22 AM, Eliot Miranda <[hidden email]> wrote:
|
I realize this is a few years old but I wanted to give an update on my quest for quasi-literals. I did a complete quasi-literal framework for Java when I moved over to Oracle Labs. It used the annotation compiler + a few tweeks to the scanner and parser. You could extend the name space of the quasi-literal and have inline SQL or APL. All the parsing, validation, and code rewriting happened at compile time. We proposed it to the Java Product guys and got ignored to death.
As to the characters I did backquote for simple quasi-literal Strings and used Oxford Brackets for the quasi-literals with a language namespace. <| ...|>. Back quote can be hard to see but is nice for String substitute. At this point in time the language that does it most right is JavaScript. Thanks Mark Miller for all the hard work over the years! |
I realize this is a few years old but I wanted to give an update on my quest for quasi-literals. I did a complete quasi-literal framework for Java when I moved over to Oracle Labs. It used the annotation compiler + a few tweeks to the scanner and parser. You could extend the name space of the quasi-literal and have inline SQL or APL. All the parsing, validation, and code rewriting happened at compile time. We proposed it to the Java Product guys and got ignored to death.
As to the characters I did backquote for simple quasi-literal Strings and used Oxford Brackets for the quasi-literals with a language namespace. <| ...|>. Back quote can be hard to see but is nice for String substitute. At this point in time the language that does it most right is JavaScript. Thanks Mark Miller for all the hard work over the years! |
On 2/27/17, DavidLeibs <[hidden email]> wrote:
> I realize this is a few years old but I wanted to give an update on my > quest > for quasi-literals. I did a complete quasi-literal framework for Java when > I moved over to Oracle Labs. It used the annotation compiler + a few > tweeks > to the scanner and parser. You could extend the name space of the > quasi-literal and have inline SQL or APL. All the parsing, validation, and > code rewriting happened at compile time. We proposed it to the Java Product > guys and got ignored to death. > > As to the characters I did backquote for simple quasi-literal Strings and > used Oxford Brackets for the quasi-literals with a language namespace. <| > ...|>. Back quote can be hard to see but is nice for String substitute. > > At this point in time the language that does it most right is JavaScript. > Thanks Mark Miller for all the hard work over the years! Thanks David for following up this discussion. I wonder if just going for JavaScript ES6 solution (back-ticks) would be the most straightforward thing to do? --Hannes https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals Syntax ---------- `string text` `string text line 1 string text line 2` `string text ${expression} string text` tag `string text ${expression} string text` Description ---------------- Template literals are enclosed by the back-tick (` `) (grave accent) character instead of double or single quotes. Template literals can contain place holders. These are indicated by the Dollar sign and curly braces (${expression}). The expressions in the place holders and the text between them get passed to a function. The default function just concatenates the parts into a single string. If there is an expression preceding the template literal (tag here), the template string is called "tagged template literal". In that case, the tag expression (usually a function) gets called with the processed template literal, which you can then manipulate before outputting. To escape a back-tick in a template literal, put a backslash \ before the back-tick. |
Hi Hannes,
On Mon, Feb 27, 2017 at 10:58 AM, H. Hirzel <[hidden email]> wrote: On 2/27/17, DavidLeibs <[hidden email]> wrote: I did a quick hack in Squeak but didn't have time to finish is. I wrote some tests. Complex cases worked, small tricky cases broke the scanner. Compiler.quasiliteral-eem.280 [Derived from Compiler-nice.279, and renamed from the bogusly named Compiler.quasiquote-eem.248] Add a quasi-literal form for "string interpolation", that allows convenient embedding of expressions within a format string, and provides a convenient way of embedding literal strings within an alternative literal string syntax whose string delimiter is different. e.g. `hello [#cruel] world!` evaluates to 'hello cruel world'. `S1[B1]...SN[BN]SN+1` is equivalent to { 'S1'. [B1] value. ... 'SN'. [BN] value. 'SN+1' } concatenateQuasiLiteral where concatenateQuasiLiteral sends asString to each element and answers the concatenation of those elements. however, single-statement blocks are inlined, so e.g. the above `hello [#cruel] world!` is compiled as { 'hello '. #cruel. ' world!' } concatenateQuasiLiteral See e.g. Tests.quasiliteral-eem.296 for tests and examples. Tests.quasiliteral-eem.296 Renamed from the bogus quasiquote to quasiliteral. Added Balazs' errors as failing tests.
_,,,^..^,,,_ best, Eliot |
The ES6 design is sound and if you are in a hurry to get the capability it is a great way to go. Once you start using it and get a taste for quasi-literal little languages you will find that you want more.
Having a quasi-literal that let's you name the little language to parse you open a very interesting door. After the dust settles you need a parser and compiler framework that allows plugins at every stage. You "MUST" have a rich and stable AST and it must be usable as a quasi-literal because transpilers abound. You wind up with transpiler code that is templated and quite "Lispy". At the end of the day you will finally let in Macros. I believe thatJulia got all this right. They stick a "@" in front of their macro invocations so you get rid of a lot of confusion. David Moon made the Julia macro system a thing of true beauty. Perfection actually. At the end of the day you want Smalltalk Compile Time "Staged Meta Evaluation". Still, at a minimum go with the ES6 design. Consider "<|" because " ` " is hard to see. Some fonts do a terrible job with it. You could do both. |
Hi david
What you describe is a bit scary. Because this is just changing the syntax but it is probably also breaking refactorings and probably other. May I ask why would we need macros since after more than 30 years nobody really need them. So do you have good motivating cases for quasi quotes Opal supports compile time evaluation. Stef > The ES6 design is sound and if you are in a hurry to get the capability > it > is a great way to go. Once you start using it and get a taste for > quasi-literal little languages you will find that you want more. > > Having a quasi-literal that let's you name the little language to parse > you > open a very interesting door. After the dust settles you need a parser > and > compiler framework that allows plugins at every stage. You "MUST" have a > rich and stable AST and it must be usable as a quasi-literal because > transpilers abound. You wind up with transpiler code that is templated > and > quite "Lispy". > > At the end of the day you will finally let in Macros. I believe thatJulia > got all this right. They stick a "@" in front of their macro invocations > so > you get rid of a lot of confusion. David Moon made the Julia macro > system a > thing of true beauty. Perfection actually. > > At the end of the day you want Smalltalk Compile Time "Staged Meta > Evaluation". > > Still, at a minimum go with the ES6 design. Consider "<|" because " ` " > is > hard to see. Some fonts do a terrible job with it. You could do both. > > > > > -- > View this message in context: > http://forum.world.st/Re-vwnc-Does-anyone-have-a-new-string-literal-tp4667088p4936429.html > Sent from the Pharo Smalltalk Developers mailing list archive at > Nabble.com. > -- Using Opera's mail client: http://www.opera.com/mail/ |
In reply to this post by DavidLeibs
Hi David
Where can we find - motivation - examples - implementation Did you write a report or something that we can read and assess? Tx > I realize this is a few years old but I wanted to give an update on my > quest > for quasi-literals. I did a complete quasi-literal framework for Java > when > I moved over to Oracle Labs. It used the annotation compiler + a few > tweeks > to the scanner and parser. You could extend the name space of the > quasi-literal and have inline SQL or APL. All the parsing, validation, > and > code rewriting happened at compile time. We proposed it to the Java > Product > guys and got ignored to death. > > As to the characters I did backquote for simple quasi-literal Strings and > used Oxford Brackets for the quasi-literals with a language namespace. <| > ...|>. Back quote can be hard to see but is nice for String substitute. > > At this point in time the language that does it most right is JavaScript. > Thanks Mark Miller for all the hard work over the years! > > > > > -- > View this message in context: > http://forum.world.st/Re-vwnc-Does-anyone-have-a-new-string-literal-tp4667088p4936208.html > Sent from the Pharo Smalltalk Developers mailing list archive at > Nabble.com. > -- Using Opera's mail client: http://www.opera.com/mail/ |
In reply to this post by DavidLeibs
On Mon, 27 Feb 2017 19:30:21 +0100, DavidLeibs <[hidden email]>
wrote: > As to the characters I did backquote for simple quasi-literal Strings and > used Oxford Brackets for the quasi-literals with a language namespace. <| > ...|>. Back quote can be hard to see but is nice for String substitute. what is a language namespace? -- Using Opera's mail client: http://www.opera.com/mail/ |
In reply to this post by DavidLeibs
On Tue, Feb 28, 2017 at 9:23 AM, DavidLeibs <[hidden email]> wrote: The ES6 design is sound and if you are in a hurry to get the capability it Agreed, and ` (back tick) is used in PetitParser for quasi-quote, so it would be lovely not to collide with it.
_,,,^..^,,,_ best, Eliot |
In reply to this post by stepharong
Provides very good background for quasi-liberals. As to macros I would posit that you have been using them in Smalltalk80 all along without the benefit of having the capability for yourself. There are a classic set of selectors that get special processing by the compiler. "to: do:" is an example of one. It gets turned into a while loop by AST transformation. These special selectors that are really macros are known to the compiler in a special table. A proper macro system opens the capability up everyone. As to 30 years without noticing that they were needed, I would say they are long over due. I needed them back in 1997 when Adele Goldberg and I had a company called Neometron. We used them for for a large system that had thousands of templates that had escapes to code (both Smalltalk80 and SQL) embedded within. We did not want string concatenation style coding with errors only found at run time. By having a Smalltalk80 with macros and quasi-literal little languages we compiled method by method in the browser as usual but all the errors in template or sql syntax were found at compile time. The compile time processing also allowed for an order of magnitude performance increase because there was a lot of evaluation done in advance. By doing the work properly in the parser and compiler and making sure code transformations tracked source code offsets proper single stepping in the debugger was preserved. Of course if aggressive rewriting was done you sometimes have to debug in the expansion but code can be emitted that can often help a macro aware debugger. Sadly, I was unable to convince Eliot and Steve Dahl to incorporate the work into Visualworks 20 years ago. Also sadly, I don't spend a lot of effort arguing with people that don't understand the need for some technology I see as useful. :-) For more examples I suggest taking a look at 60 years of Lisp. Stochastic sampeling of the corpus should be revealing. :-) Simple quasi-literally are relatively easy. A real macro system takes careful design that leads to compiler plugins that can go way beyond macros and open up a world of designer application dependent optimizations. On Tue, Feb 28, 2017 at 10:47 AM stepharong <[hidden email]> wrote: Hi david |
In reply to this post by Eliot Miranda-2
On 2/27/17, Eliot Miranda <[hidden email]> wrote:
Hello Eliot Thank you for your quick-hack how an ES6 type template string addition could look like. Which setup do I need to have a look at it? I used http://files.squeak.org/6.0alpha/Squeak6.0alpha-16963-32bit/ And got the error which is attached. Best wishes --Hannes > Hi Hannes, > > On Mon, Feb 27, 2017 at 10:58 AM, H. Hirzel <[hidden email]> > wrote: > >> On 2/27/17, DavidLeibs <[hidden email]> wrote: >> > I realize this is a few years old but I wanted to give an update on my >> > quest >> > for quasi-literals. I did a complete quasi-literal framework for Java >> when >> > I moved over to Oracle Labs. It used the annotation compiler + a few >> > tweeks >> > to the scanner and parser. You could extend the name space of the >> > quasi-literal and have inline SQL or APL. All the parsing, validation, >> and >> > code rewriting happened at compile time. We proposed it to the Java >> Product >> > guys and got ignored to death. >> > >> > As to the characters I did backquote for simple quasi-literal Strings >> > and >> > used Oxford Brackets for the quasi-literals with a language namespace. >> > <| >> > ...|>. Back quote can be hard to see but is nice for String >> > substitute. >> > >> > At this point in time the language that does it most right is >> > JavaScript. >> > Thanks Mark Miller for all the hard work over the years! >> >> Thanks David for following up this discussion. >> >> I wonder if just going for JavaScript ES6 solution (back-ticks) would >> be the most straightforward thing to do? >> > > I did a quick hack in Squeak but didn't have time to finish is. I wrote > some tests. Complex cases worked, small tricky cases broke the scanner. > > MCHttpRepository > location: 'http://source.squeak.org/inbox' > user: '' > password: '' > > Compiler.quasiliteral-eem.280 > > [Derived from Compiler-nice.279, and renamed from > the bogusly named Compiler.quasiquote-eem.248] > > Add a quasi-literal form for "string interpolation", that allows > convenient embedding of expressions within a format string, > and provides a convenient way of embedding literal strings > within an alternative literal string syntax whose string delimiter > is different. > > e.g. > `hello [#cruel] world!` > evaluates to > 'hello cruel world'. > > `S1[B1]...SN[BN]SN+1` > > is equivalent to > { 'S1'. [B1] value. ... 'SN'. [BN] value. 'SN+1' } concatenateQuasiLiteral > where concatenateQuasiLiteral sends asString to each > element and answers the concatenation of those elements. > > however, single-statement blocks are inlined, so e.g. the > above `hello [#cruel] world!` is compiled as > { 'hello '. #cruel. ' world!' } concatenateQuasiLiteral > > See e.g. Tests.quasiliteral-eem.296 for tests and examples. > > Tests.quasiliteral-eem.296 > > Renamed from the bogus quasiquote to quasiliteral. > Added Balazs' errors as failing tests. > > >> --Hannes >> >> >> https://developer.mozilla.org/en/docs/Web/JavaScript/ >> Reference/Template_literals >> >> Syntax >> ---------- >> >> `string text` >> >> `string text line 1 >> string text line 2` >> >> `string text ${expression} string text` >> >> tag `string text ${expression} string text` >> >> >> Description >> ---------------- >> >> Template literals are enclosed by the back-tick (` `) (grave accent) >> character instead of double or single quotes. Template literals can >> contain place holders. These are indicated by the Dollar sign and >> curly braces (${expression}). The expressions in the place holders and >> the text between them get passed to a function. The default function >> just concatenates the parts into a single string. If there is an >> expression preceding the template literal (tag here), the template >> string is called "tagged template literal". In that case, the tag >> expression (usually a function) gets called with the processed >> template literal, which you can then manipulate before outputting. To >> escape a back-tick in a template literal, put a backslash \ before the >> back-tick. >> >> > > > -- > _,,,^..^,,,_ > best, Eliot > FileIn_Compiler.quasiliteral-eem.280_error_2017-03-01.png (325K) Download Attachment |
In reply to this post by stepharong
Let me add some more motivation and background for the discussion. I responded to stepharong@free.fr questions by mail yesterday but it didn't wind up on the forum. Sorry about that.
http://www.erights.org/elang/quasi/overview.html Provides very good background for quasi-liberals. I believe this work lead to the ES6 solution by way of Mark Miller. As to macros I would posit that you have been using them in Smalltalk80 all along without the benefit of having the capability for yourself. There are a classic set of selectors that get special processing by the compiler. "to: do:" is an example of one. It gets turned into a while loop by AST transformation. These special selectors that are really macros are known to the compiler in a special table. A proper macro system opens the capability up everyone. As to 30 years without noticing that macros were needed, I would say they are long over due. I needed them back in 1997 when Adele Goldberg and I had a company called Neometron. We used them for for a large system that had thousands of templates in a template language which had escapes Smalltalk80 code embedded within. Also embedded within the tempting code and Smalltalk code was SQL code. This was allowed to be recursive so it was a little language free for all. We did not want string concatenation style coding with errors only found at run time. By having a Smalltalk80 with macros and quasi-literal little languages we and our non programmer users continued to compile method by method in the browser as usual but all the errors in template or sql syntax were found at compile time. There were no external files and everything continued to work with Change Sets and Change List technology that allowed recovering after a crash. The compile time processing by way of compiler staging plugins also allowed for an order of magnitude performance increase because there was a lot of evaluations that could be done in advance. By doing the work properly in the parser and compiler and making sure code transformations tracked source code offsets proper single stepping in the debugger was preserved. Of course if really aggressive rewriting was done you would sometimes have to debug in the expansion but we emitted code to help the debugger with macros and custom optimizations. The need to debug some macros in the expansion is a very old unsolved problem. Sadly, I was unable to convince Eliot and Steve Dahl to incorporate the work into Visualworks 20 years ago. Also sadly, I don't spend a lot of effort arguing with people that don't understand the need for some technology I see as useful. I have continually had to wait years before the time was right. :-) I know this will sound a bit "Snarky" but for more examples I suggest taking a look at 60 years of Lisp. Stochastic sampeling of the corpus should be revealing. :-) And now for a appeal to authority, "Lisp isn't a language, it's a building material." - Alan Kay and in conclusion: Simple quasi-literally are relatively easy and can be done with out being too disruptive. A real macro system takes very careful design that leads to compiler plugins that can go way beyond macros and open up a world compile time meta programming and the wonderful world of application dependent optimizations. cheers, -David (voice from the distant past) Leibs |
Hi,
Changing the syntax is an expensive thing because every syntactical construct introduces new constraints that can have deep implications in the multiple layers built on top. One reason why our tooling is so nimble is exactly that the AST of the language is so small. It is for this reason that we should approach any syntactical extension with outmost care and rigor. I am not at all convinced that quasi-quoting is relevant enough to have it in the syntax. There are some libraries that can benefit from them, but we could well handle those cases with appropriate API. Perhaps you can change my opinion with concrete examples revealing the value such a construct would add in comparison with a fluent API. That said, I do want to have mechanisms that allow us to embed other languages and DSLs in our environment. In this area I prefer the approach put forward by Helvetia because it is not invasive and highly flexible (and now should even not be expensive to have anymore). Cheers, Doru > On Mar 1, 2017, at 9:15 PM, DavidLeibs <[hidden email]> wrote: > > Let me add some more motivation and background for the discussion. I > responded to [hidden email] questions by mail yesterday but it didn't > wind up on the forum. Sorry about that. > > http://www.erights.org/elang/quasi/overview.html > Provides very good background for quasi-liberals. I believe this work lead > to the ES6 solution by way of Mark Miller. > > As to macros I would posit that you have been using them in Smalltalk80 all > along without the benefit of having the capability for yourself. There are > a classic set of selectors that get special processing by the compiler. "to: > do:" is an example of one. It gets turned into a while loop by AST > transformation. These special selectors that are really macros are known to > the compiler in a special table. A proper macro system opens the capability > up everyone. > > As to 30 years without noticing that macros were needed, I would say they > are long over due. I needed them back in 1997 when Adele Goldberg and I had > a company called Neometron. We used them for for a large system that had > thousands of templates in a template language which had escapes Smalltalk80 > code embedded within. Also embedded within the tempting code and Smalltalk > code was SQL code. This was allowed to be recursive so it was a little > language free for all. We did not want string concatenation style coding > with errors only found at run time. By having a Smalltalk80 with macros and > quasi-literal little languages we and our non programmer users continued to > compile method by method in the browser as usual but all the errors in > template or sql syntax were found at compile time. There were no external > files and everything continued to work with Change Sets and Change List > technology that allowed recovering after a crash. The compile time > processing by way of compiler staging plugins also allowed for an order of > magnitude performance increase because there was a lot of evaluations that > could be done in advance. By doing the work properly in the parser and > compiler and making sure code transformations tracked source code offsets > proper single stepping in the debugger was preserved. Of course if really > aggressive rewriting was done you would sometimes have to debug in the > expansion but we emitted code to help the debugger with macros and custom > optimizations. The need to debug some macros in the expansion is a very old > unsolved problem. > > Sadly, I was unable to convince Eliot and Steve Dahl to incorporate the work > into Visualworks 20 years ago. Also sadly, I don't spend a lot of effort > arguing with people that don't understand the need for some technology I see > as useful. I have continually had to wait years before the time was right. > :-) > > I know this will sound a bit "Snarky" but for more examples I suggest taking > a look at 60 years of Lisp. Stochastic sampeling of the corpus should be > revealing. :-) > > And now for a appeal to authority, > > "Lisp isn't a language, it's a building material." > > - Alan Kay > > > and in conclusion: > > Simple quasi-literally are relatively easy and can be done with out being > too disruptive. A real macro system takes very careful design that leads to > compiler plugins that can go way beyond macros and open up a world compile > time meta programming and the wonderful world of application dependent > optimizations. > > cheers, > -David (voice from the distant past) Leibs > > > > -- > View this message in context: http://forum.world.st/Re-vwnc-Does-anyone-have-a-new-string-literal-tp4667088p4936696.html > Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com. > -- www.tudorgirba.com www.feenk.com "Speaking louder won't make the point worthier." |
Hi Doru,
I understand your argument and I have heard it for years as to the reason not to make a programming language as good as what we have known how to do since the 1970s. I really don't have a very big dog in this fight (meaning that I don't care all that much whether these features end up in Smalltalk80), and I have felt that way for 20 years. I just wound up on this thread because I Googled myself in the context of working with another group on the development of advanced programming tools. I am much more interested in a programming environment that uses several iPad Pros and something like a ES2015+ Morphic framework that uses Force Touch plus Image Recognition on "real world passive objects" as a general approace to the "Use vs. Mention Problem" in graphical programming. The use versus mention problem is about not having any kind of a "run mode" vs. "design mode" switch. Having a finger press with pressure give you a number between: 0 and: 1 beats the hell out of shift+yellowButton hacks. :-) It's funny how the transition between programming and meta-programming is always there. Were I to do anything in Smalltalk and the Compiler and Parser frameworks still supported the #compilerClass and #parserClass invocations at the right place I know what I need to do to give myself a huge leg up in expressibility and performance. cheers, -David Leibs |
On Fri, Mar 3, 2017 at 2:17 AM, DavidLeibs <[hidden email]> wrote: It mentions #compilerClass. I don't know about #parserClass.
hi David, Section 5 might be of interest... Lowcode is here... cheers -ben |
Free forum by Nabble | Edit this page |