Beautiful, exactly what I was looking for. Thanks for the explanations and the links.
On Monday, December 28, 2015 at 12:11:46 PM UTC-8, slytobias wrote: > > Ray, > > The question of what a form is is actually quite an important part of > grasping Lisp/Clojure. Earlier versions of Lisp used the term S-expression > (symbolic expression) extensively. But during the process of defining > Common Lisp, the term was dropped in favor of the notion of forms. Stuart > Shapiro wrote a Common Lisp book that you may find useful in studying > Clojure as well: http://www.cse.buffalo.edu/~shapiro/Commonlisp/ > > In the book’s preface he defines these two terms: > S-expression - syntactic units, sequences of characters that form the > written version of Lisp programs and data structures. > Form - a Common Lisp object that can be evaluated > > In terms of the REPL (read-eval-print loop), an S-expression is the input > to the reader, and a form is the output of the reader, which then becomes > the input to eval. An S-expression is syntax. A form is some sort of > representation in memory. So a simple rule of thumb is that S-expressions > in Lisp often contain parentheses, but there are no parentheses in forms. > > Here are a couple more formal definitions, again from a Common Lisp > perspective: > http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#form > *form* *n.* 1. any *object* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_o.htm#object> > meant > to be *evaluated*. 2. a *symbol* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#symbol>, > a *compound form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#compound_form>, > > or a *self-evaluating object* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#self-evaluating_object>. > > 3. (for an *operator* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_o.htm#operator>, > > as in ``<<*operator*>> *form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#form>'') > a *compound form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#compound_form>having > > that *operator* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_o.htm#operator> > as > its first element. ``A *quote* > <http://www.lispworks.com/documentation/HyperSpec/Body/s_quote.htm#quote> > form > is a constant form.’' > > > A self-evaluating object would be something like a numeric literal: 2.4 or > a string “Yo!”. Compound forms are further defined: > > http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#compound_form > *compound form* *n.* a *non-empty* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_n.htm#non-empty> > *list* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#list> > which > is a *form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#form>: > a *special form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#special_form>, > > a *lambda form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lambda_form>, > > a *macro form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_m.htm#macro_form>, > > or a *function form* > <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#function_form> > . > > Remember that these Common Lisp definitions don’t line up exactly with > Clojure, but they are illuminating. > > Have all good days, > David Sletten > > On Dec 28, 2015, at 11:16 AM, Ray Toal <[email protected] <javascript:>> > wrote: > > I think of it this way too but was really trying to get a formal > definition, if one exists. > > While I've not seen a formal grammar of Clojure anywhere, I have looked at > > > https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java > > which seems to show that forms can be a lot of things, including > READ_FINISHED and READ_EOF, which probably aren't intended for public > consumption. :) > > The actual read() function (or method, as this is all written in Java), > looked promising but was hard to decipher. > > Maybe the term is intentionally vague? I was hoping it wasn't. But the > fact that it is hard to find a hard definition of it makes me wonder. > > Thanks > > > On Monday, December 28, 2015 at 5:08:36 AM UTC-8, Gregg Reynolds wrote: >> >> >> On Dec 28, 2015 6:58 AM, "Ray Toal" <[email protected]> wrote: >> > >> > Throughout the Clojure documentation there are many references to forms. >> > >> > I know about special forms, macros, vars, symbols, keywords, integers, >> doubles, ratios, sets, maps, lists, vectors, booleans, nil, etc. >> > >> > What exactly, though, is a form? >> >> A syntactic unit, as opposed to a lexical unit? Left paren is a lexical >> unit, to "read it you have to find the following balanced right paren, and >> if everything in between is syntactically correct you have a list form. At >> least that's how I think of it. >> >> Gregg >> > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] <javascript:> > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected] <javascript:> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
