Thread: [q-lang-users] Request to add new reserved words "quote" and "QUOTE" to Q
Brought to you by:
agraef
From: John C. <co...@cc...> - 2006-05-16 04:34:02
|
This is a request to make the identifiers "quote" and "QUOTE" reserved and illegal in Q 7.1 and future releases. In the interest of getting some interoperability between the Lisp family of languages and Q, I'm designing an S-expression representation of Q expressions -- not declarations or definitions, just expressions. Doing this permits a representation of a Q expression to be easily manipulated by Scheme or Common Lisp programs. The basic Q types are integers, floats, booleans, strings, files, symbols, applications, lists, and tuples. Of these, files are hopeless (there is no standardized representation of them). Integers, floats, strings, symbols, and tuples have clear S-expression representations (tuples are Scheme vectors or Common Lisp simple general vectors, in either case notated "#(a b c)". Booleans can be represented in S-expressions by the symbols "true" and "false", just as on the Q side; in Scheme, the special boolean values #t and #f can be mapped back and forth. Lists and applications, however, are both represented by lists in both Scheme and CL, and only context distinguishes them. By reserving the word "quote", we can use "(quote (a b c)) to represent a list and "(a b c)" to represent one or more Q applications (right associative as usual). Because Lisp is not case-sensitive, the internal representation of the symbol named "quote" may be either "quote" or "QUOTE", so both must be reserved in Q. If these words are not reserved, then the Q application "quote [a,b]" would have the same S-expression representation as "[a,b]". This should be a really trivial change to the compiler and interpreter that can be folded into 7.1, I think. -- John Cowan <co...@cc...> http://www.ccil.org/~cowan .e'osai ko sarji la lojban. Please support Lojban! http://www.lojban.org |
From: Albert G. <Dr....@t-...> - 2006-05-16 13:43:41
|
John Cowan wrote: > This is a request to make the identifiers "quote" and "QUOTE" reserved > and illegal in Q 7.1 and future releases. Well, I'm all for a Lisp interface, but I don't like the idea to introduce some special keywords which aren't even used in the language. If the issue is just to disambiguate the s-exp representation, why can't this be done with a Lisp macro, say "q-list", which can't possibly occur as a Q identifier? Or maybe it would be possible to escape Q function symbols? (I'd say that you need an escape mechanism on symbols anyway, if only to distinguish "foo" from "FOO" which are the same symbol in Lisp, right?) Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |
From: John C. <co...@cc...> - 2006-05-16 15:13:17
|
Albert Graef scripsit: > Well, I'm all for a Lisp interface, My intention is to write an "egg" (library package) for Chicken Scheme, an implementation of Scheme that compiles into C. It will provide access to the libqint facilities, but there will also be an upper layer that converts a Scheme datum to a qexpr and vice versa, so that Q expressions can be conveniently constructed using native Scheme facilities. However, I would want there to be just one S-expression representation of Q so that interfaces for other Scheme/Lisp implementations could be constructed in future. By the way, libqint does not appear to expose any mechanism for setting and getting the values of free variables, for implementing something like the Q interpreter's "def". How should this be done? Can you add some appropriate calls? > but I don't like the idea to > introduce some special keywords which aren't even used in the language. > If the issue is just to disambiguate the s-exp representation, why can't > this be done with a Lisp macro, say "q-list", which can't possibly occur ? I was primarily going for the familiarity and convenience of the ' read-macro on the Lisp side: the Lisp user can write an familiar-looking S-expression like (++ '(1 2 3) '(4 5 6)) to represent [1,2,3] ++ [4,5,6]. On reflection, though, the idea's not such a good one, because the result would have to be (quote (1 2 3 4 5 6)) to signal that it was a list and not an application being returned. Stripping this "quote" off would be very annoying. Lisp lists and Q lists are conceptually identical and should be smoothly interchangeable. So I withdraw the request. Instead, I'll go for using some un-Q-ish token to indicate an application, such as (q-call ++ (1 2 3) (4 5 6)). > Or maybe it would be possible to escape Q function > symbols? (I'd say that you need an escape mechanism on symbols anyway, > if only to distinguish "foo" from "FOO" which are the same symbol in > Lisp, right?) The position is this: In Common Lisp, the symbol foo may be "foo" or "FOO" at the implementation's option. The user can get control by writing |foo| or |FOO|; the same mechanism allows otherwise illegal symbols like |'| and |()|. The current Scheme standard (R5RS) officially is case-insensitive and has no such vertical bars, but the majority of Scheme implementations are case-sensitive, use lower-case internally -- that is, (if #t 1 2) works but (IF #T 1 2) does not -- and support vertical bars. The next Scheme standard will be case-sensitive, lower-case for standard symbols, and will allow bars. So the only issue is what symbol the read-macro ' generates (it's functionally the same in Scheme and CL); it could be either QUOTE or quote, but is much more likely to be the latter, especially in Scheme. But none of this matters for this discussion. -- Her he asked if O'Hare Doctor tidings sent from far John Cowan coast and she with grameful sigh him answered that http://ccil.org/~cowan O'Hare Doctor in heaven was. Sad was the man that word co...@cc... to hear that him so heavied in bowels ruthful. All she there told him, ruing death for friend so young, James Joyce, Ulysses algate sore unwilling God's rightwiseness to withsay. "Oxen of the Sun" |
From: Albert G. <Dr....@t-...> - 2006-05-16 21:31:08
|
John Cowan wrote: > My intention is to write an "egg" (library package) for Chicken Scheme, Sounds cool. > By the way, libqint does not appear to expose any mechanism for setting > and getting the values of free variables, for implementing something > like the Q interpreter's "def". How should this be done? Can you add > some appropriate calls? Yes, that's right. I'll see what I can do about this. Do you need full access to the interpreter's command language, or just `def'? (Accessing the value of a variable is already possible. Just evaluate "<varname>".) -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |
From: John C. <co...@cc...> - 2006-05-16 22:39:36
|
Albert Graef scripsit: > Yes, that's right. I'll see what I can do about this. Do you need full > access to the interpreter's command language, or just `def'? (Accessing > the value of a variable is already possible. Just evaluate "<varname>".) Good point, and I think "def" will suffice for now. That allows one to pass a value in to be evaluated by an already-existing expression without having to cons up a new expression. There's a couple of problems with libqint on Cygwin: 1) You have to link with -lqint -lgmp -liconv -lq explicitly in order to satisfy the linker. The -liconv was expected, as Cygwin doesn't have iconv in its default library. Without -lq, it reports: /usr/local/lib/libqint.a(libqint_la-q.o): In function `resolve': /opt/q-7.1/src/q.c:1827: undefined reference to `___libq_init' Should I be using libtool, and if so, how? 2) More seriously, the sample programs in Appendix C crash when trying to pass additional arguments to qexecl and qexeclx, either with a SIGHUP or with a SIGABRT. The poor man's Q interpreter will crash if you give it command-line arguments other than the script, and the hello-world program crashes when it tries to load the internal script. Changing hello.c to use qexeclx(script, strlen(script), 1, strdup("Hello!")); works fine, and changing it to use qexeclx(script, strlen(script), 0) sort of works, except that the value of ARGS is ["/tmp/tc40.2"], Ghu only knows why -- there is no such file. I made a version of hello.c that calls qexeclv instead, but it doesn't help. I realize you probably can't do much about this, but I'm passing it along in hopes that you can think of something. -- A poetical purist named Cowan [that's me: co...@cc...] Once put the rest of us dowan. [on xml-dev] "Your verse would be sweeter http://www.ccil.org/~cowan If it only had metre And rhymes that didn't force me to frowan." [overpacked line!] --Michael Kay |
From: Albert G. <Dr....@t-...> - 2006-05-19 00:38:06
Attachments:
vardef.c
|
John Cowan wrote: > Good point, and I think "def" will suffice for now. That allows one to pass > a value in to be evaluated by an already-existing expression without > having to cons up a new expression. That's in CVS now. A simple example is attached below. > There's a couple of problems with libqint on Cygwin: > > 1) You have to link with -lqint -lgmp -liconv -lq explicitly in order to > satisfy the linker. The -liconv was expected, as Cygwin doesn't have > iconv in its default library. Without -lq, it reports: Looks like Cygwin gcc is not very clever in resolving dependencies in linked shared libs. With both Linux gcc and mingw I only have to specify -lqint. > Should I be using libtool, and if so, how? Then you'll have to use libtool to compile your sources, too. If you want to do this, the easiest way to go is to autotoolize your program and use an automake Makefile. Automake makes handling libtool libraries much easier. > 2) More seriously, the sample programs in Appendix C crash when trying > to pass additional arguments to qexecl and qexeclx, either with a SIGHUP > or with a SIGABRT. The poor man's Q interpreter will crash if you give > it command-line arguments other than the script, and the hello-world > program crashes when it tries to load the internal script. Strange. Both programs work just fine over here, both on Linux and Windows/mingw. Do you have a gdb backtrace? > Changing hello.c to use qexeclx(script, strlen(script), 1, strdup("Hello!")); > works fine, and changing it to use qexeclx(script, strlen(script), 0) > sort of works, except that the value of ARGS is ["/tmp/tc40.2"], Ghu > only knows why -- there is no such file. Everything o.k. with that. qexeclx() creates a temporary script file which is removed again as soon as the interpreter has loaded the script. > I realize you probably can't do much about this, but I'm passing it along > in hopes that you can think of something. Could be a bug in the interpreter's main (although I doubt this since it doesn't show with mingw). Anyway, a backtrace would be helpful since I cannot reproduce the error. ;-) Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |
From: John C. <co...@cc...> - 2006-05-19 02:55:48
|
Albert Graef scripsit: > That's in CVS now. A simple example is attached below. Thanks. > Looks like Cygwin gcc is not very clever in resolving dependencies in > linked shared libs. With both Linux gcc and mingw I only have to specify > -lqint. Not a big deal. > >Should I be using libtool, and if so, how? > > Then you'll have to use libtool to compile your sources, too. If you > want to do this, the easiest way to go is to autotoolize your program > and use an automake Makefile. Automake makes handling libtool libraries > much easier. I don't think I want to go there, at least not yet. > >2) More seriously, the sample programs in Appendix C crash when trying > >to pass additional arguments to qexecl and qexeclx, either with a SIGHUP > >or with a SIGABRT. The poor man's Q interpreter will crash if you give > >it command-line arguments other than the script, and the hello-world > >program crashes when it tries to load the internal script. > > Strange. Both programs work just fine over here, both on Linux and > Windows/mingw. Do you have a gdb backtrace? Well, running under gdb causes an entirely consistent pattern of crashes, no matter how many arguments there are or are not. I've attached gdb traces for pmq and for a modified version of hello (also attached). In essence, there is a SIGSEGV inside cygwin1.dll, the master DLL for Cygwin, when _sigfe is invoked from resolve (q.c:1809). However, there is no explicit reference to _sigfe, so it may be hidden behind a macro. > Everything o.k. with that. qexeclx() creates a temporary script file > which is removed again as soon as the interpreter has loaded the script. Ah. -- John Cowan co...@cc... http://ccil.org/~cowan This great college [Trinity], of this ancient university [Cambridge], has seen some strange sights. It has seen Wordsworth drunk and Porson sober. And here am I, a better poet than Porson, and a better scholar than Wordsworth, somewhere betwixt and between. --A.E. Housman |
From: Albert G. <Dr....@t-...> - 2006-05-19 10:27:47
|
John Cowan wrote: >>That's in CVS now. A simple example is attached below. > > Thanks. Oops, I goofed. Had to fix a memleak and a missing return value, all in CVS now. I also made an attempt to fix the qexecv segfaults that you see on Cygwin. Would be nice if you could check out q.c and try it out again. >>Then you'll have to use libtool to compile your sources, too. If you >>want to do this, the easiest way to go is to autotoolize your program >>and use an automake Makefile. Automake makes handling libtool libraries >>much easier. > > I don't think I want to go there, at least not yet. Already thought so. :) Autotools is quite a time investment, but it pays off eventually. Scons appears to be simpler but it still has to prove itself. -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |
From: John C. <co...@cc...> - 2006-05-19 19:13:13
|
Albert Graef scripsit: > Oops, I goofed. Had to fix a memleak and a missing return value, all in > CVS now. > > I also made an attempt to fix the qexecv segfaults that you see on > Cygwin. Would be nice if you could check out q.c and try it out again. Success! Your defref program does just what it should, and hello and pmq now also work right with any number of arguments. I also reran all the standard tests with "make test", and they are all fine. I think you should add the "-lqint -liconv -lgmp -lq" incantation to Appendix C for Cygwin users. Thanks for everything! -- It was impossible to inveigle John Cowan <co...@cc...> Georg Wilhelm Friedrich Hegel http://www.ccil.org/~cowan Into offering the slightest apology For his Phenomenology. --W. H. Auden, from "People" (1953) |
From: Albert G. <Dr....@t-...> - 2006-05-19 22:06:32
|
John Cowan wrote: > Success! Great. :) > I think you should add the "-lqint -liconv -lgmp -lq" incantation to > Appendix C for Cygwin users. Done. Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |