Author: peter.seibel Date: Wed Mar 7 22:20:05 2007 New Revision: 12 Modified: trunk/faq.txt trunk/lispfaq.txt
Log: Reorging lispfaq a bit and moving READ-FROM-STRING question into faq. Modified: trunk/faq.txt ============================================================================== --- trunk/faq.txt (original) +++ trunk/faq.txt Wed Mar 7 22:20:05 2007 @@ -824,6 +824,28 @@ (map-into (make-array 10) #'make-foo) +*** Why does (read-from-string "foobar" :start 3) return FOOBAR instead of BAR? + +\cl{READ-FROM-STRING} is one of the rare functions that takes both +\code{&optional} and \code{&key} arguments. The complete argument list is: + + string &optional eof-error-p eof-value &key :start :end :preserve-whitespace + +When a function takes both types of arguments, all the optional +arguments must be specified explicitly before any of the keyword +arguments may be specified. In the example above, :\code{start} +becomes the value of the optional \code{eof-error-p} parameter and 3 +is the value of the optional \code{eof-value} parameter. + +To get the desired result, you should use \code{(read-from-string +"foobar" t nil :start 3)}. + +There are only three other functions in the COMMON-LISP package that +take both \code{&optional} and \code{&key} arguments and thus are +potentially subject to the same problem: \cl{PARSE-NAMESTRING}, +\cl{WRITE-LINE} and \cl{WRITE-STRING}. + + ** Why doesn't Lisp ... *** Why doesn't Common Lisp have continuations? Modified: trunk/lispfaq.txt ============================================================================== --- trunk/lispfaq.txt (original) +++ trunk/lispfaq.txt Wed Mar 7 22:20:05 2007 @@ -6,7 +6,7 @@ Marsden's attempt to clean up the old comp.lang.lisp FAQ. (Last updated: \datestamp{})} -** FAQ +** Possibly useful *** What is the Lisp equivalent of the \symbol{__FILE__} and \symbol{__LINE__} \acronym{ANSI} C preprocessor macros? How do I find out where an error occurred? @@ -201,59 +201,6 @@ Something which is closer to the canonical "Hello, World!" attempt is \userinput{ (write-line "Hello, World!") } -*** Can you help me with my homework? - -But of course! - -However, we will need the e-mail address of your lecturer or teaching -instructor to best aid you; for it is only fair that if we do the -homework we should get the course credits. Alternatively, should you -wish to hire a consultant from the group, competitive rates can be -arranged. - -Post the assignment, and your attempt so far; state explicitly that it -is homework. You may find a kind soul on the group to explain some -point that you are missing; this is more likely the more visible your -own work is. Posts of the form "my assignment is due tomorrow please -hlep!" are unlikely to engender much sympathy. - -*** How do I manipulate symbols with IMPLODE/EXPLODE? - -Generally, you don't. - -IMPLODE and EXPLODE were functions in old lisps where there was no -string data type, so that symbols were the only way of manipulating -text. Then (explode 'foo) would give you (F O O); you could then do -(implode (cdr (explode 'crash))) to give you back the symbol RASH - -If you are taught today about implode/explode in a lisp programming -class for anything other than historical context, complain loudly to -your lecturer. - -*** What is off-topic on comp.lang.lisp? - -Questions about Scheme, Emacs Lisp and AutoLisp tend not to be -terribly welcome, as they have their own fora in the -\link{\href{news:comp.lang.scheme}\text{comp.lang.scheme}}, -\link{\href{comp.emacs}\text{comp.emacs}} and -\link{\href{comp.cad.autocad}\text{comp.cad.autocad}} newsgroups. - -*** What is on-topic on comp.lang.lisp? - -Discussion of the language defined by the ANSI Common Lisp standard is -definitely on-topic on comp.lang.lisp. Unlike comp.lang.c, we do not -restrict our discussions to the standard, but also actively discuss -the differences between implementations and implementation-specific -extensions. - -Since the Lisp community is remarkably long-lived, discussion of the -history and evolution of Lisp tends also to be welcomed, or at least -tolerated; discussion of non-standard lisps (though generally not -Scheme or Emacs Lisp) is also accepted. Though \acronym{CLOS} (the -Common Lisp Object System) has \link{\href{news:comp.lang.lisp.clos} -\text{its own newsgroup}} it is also part of ANSI CL, and so is a -valid topic for discussion. - *** What online resources are there for lisp users? \variablelist{\varlistentry{\term{\link{\href{http://www.lispworks.com/reference/HyperSpec/Front/} @@ -306,51 +253,6 @@ }}\listitem{\para{A commercial natively multithreaded implementation of Common Lisp for various Unixes.}}}\varlistentry{\term{Symbolics Common Lisp}\listitem{\para{} }}} -*** What is the purpose of \link{\href{news:comp.lang.lisp} -\text{comp.lang.lisp} - -}? - -The charter at -\link{\href{ftp://ftp.uu.net/usenet/control/comp/comp.lang.lisp} -\text{ftp://ftp.uu.net/usenet/control/comp/comp.lang.lisp}} states -that the purpose of comp.lang.lisp is "Discussion about LISP". It is -somewhat in the nature of things that newsgroups' purposes evolve, as -do names. Firstly, the newsgroup has evolved such that the main topic -of discussion is ANSI Common Lisp, though discussion about other lisp -variants is welcome within reasonable bounds. Secondly, the spelling -"LISP" is passé; while it does reflect the initial abbreviation, it no -longer reflects the actual language, so "Lisp" is the preferred -capitalization. - -*** Why does (read-from-string "foobar" :start 3) return FOOBAR instead of BAR? - -\cl{READ-FROM-STRING} is one of the rare functions that takes both -&OPTIONAL and &KEY arguments: \literallayout{\cl{READ-FROM-STRING} -string &OPTIONAL eof-error-p eof-value &KEY :start :end -:preserve-whitespace } - -When a function takes both types of arguments, all the optional -arguments must be specified explicitly before any of the keyword -arguments may be specified. In the example above, :START becomes the -value of the optional EOF-ERROR-P parameter and 3 is the value of the -optional EOF-VALUE parameter. - -To get the desired result, you should use \command{(read-from-string -"foobar" t nil :start 3)}. If you need to understand and use the -optional arguments, please refer to CLTL2 under READ-FROM-STRING, -otherwise, this will behave as desired for most purposes. - -The other functions with this peculiarity in the COMMON-LISP package -are \cl{PARSE-NAMESTRING}, \cl{WRITE-LINE} and \cl{WRITE-STRING}. - -*** How does \userinput{(defun car (x) (car x))} work? - -This code is probably part of the source to a lisp compiler, which -knows how to open-code calls to CAR. However, the interpreter also -needs to know how to call CAR, which is what the above defun is doing. -This is not recommended in user code... - *** The read-eval-print loop is just sitting there after I've typed in my form. What's happening? One possible explanation for this behaviour is that you have typed in @@ -365,6 +267,7 @@ or right parenthesis, respectively. Try typing a few right parentheses followed by Return. +*** How do I run my programme as a script, then? *** Is Scheme a lisp? Scheme is a member of the greater family of Lisp languages, assuming @@ -379,7 +282,6 @@ \text{comp.lang.scheme}}, where discussion would be much more welcome and appropriate. -*** How do I run my programme as a script, then? *** How do I split a string? @@ -414,5 +316,80 @@ To avoid this, use the :predicate defstruct option to eliminate or rename the predicate function, or else use a different slot name. +** Probably obsolete + +*** How do I manipulate symbols with IMPLODE/EXPLODE? + +Generally, you don't. + +IMPLODE and EXPLODE were functions in old lisps where there was no +string data type, so that symbols were the only way of manipulating +text. Then (explode 'foo) would give you (F O O); you could then do +(implode (cdr (explode 'crash))) to give you back the symbol RASH + +If you are taught today about implode/explode in a lisp programming +class for anything other than historical context, complain loudly to +your lecturer. + +*** How does \userinput{(defun car (x) (car x))} work? + +This code is probably part of the source to a lisp compiler, which +knows how to open-code calls to CAR. However, the interpreter also +needs to know how to call CAR, which is what the above defun is doing. +This is not recommended in user code... + +*** What is the purpose of comp.lang.lisp? + +The charter at +\link{\href{ftp://ftp.uu.net/usenet/control/comp/comp.lang.lisp} +\text{ftp://ftp.uu.net/usenet/control/comp/comp.lang.lisp}} states +that the purpose of comp.lang.lisp is "Discussion about LISP". It is +somewhat in the nature of things that newsgroups' purposes evolve, as +do names. Firstly, the newsgroup has evolved such that the main topic +of discussion is ANSI Common Lisp, though discussion about other lisp +variants is welcome within reasonable bounds. Secondly, the spelling +"LISP" is passé; while it does reflect the initial abbreviation, it no +longer reflects the actual language, so "Lisp" is the preferred +capitalization. + +*** What is off-topic on comp.lang.lisp? + +Questions about Scheme, Emacs Lisp and AutoLisp tend not to be +terribly welcome, as they have their own fora in the +\link{\href{news:comp.lang.scheme}\text{comp.lang.scheme}}, +\link{\href{comp.emacs}\text{comp.emacs}} and +\link{\href{comp.cad.autocad}\text{comp.cad.autocad}} newsgroups. + +*** What is on-topic on comp.lang.lisp? + +Discussion of the language defined by the ANSI Common Lisp standard is +definitely on-topic on comp.lang.lisp. Unlike comp.lang.c, we do not +restrict our discussions to the standard, but also actively discuss +the differences between implementations and implementation-specific +extensions. + +Since the Lisp community is remarkably long-lived, discussion of the +history and evolution of Lisp tends also to be welcomed, or at least +tolerated; discussion of non-standard lisps (though generally not +Scheme or Emacs Lisp) is also accepted. Though \acronym{CLOS} (the +Common Lisp Object System) has \link{\href{news:comp.lang.lisp.clos} +\text{its own newsgroup}} it is also part of ANSI CL, and so is a +valid topic for discussion. + + +*** Can you help me with my homework? + +But of course! +However, we will need the e-mail address of your lecturer or teaching +instructor to best aid you; for it is only fair that if we do the +homework we should get the course credits. Alternatively, should you +wish to hire a consultant from the group, competitive rates can be +arranged. + +Post the assignment, and your attempt so far; state explicitly that it +is homework. You may find a kind soul on the group to explain some +point that you are missing; this is more likely the more visible your +own work is. Posts of the form "my assignment is due tomorrow please +hlep!" are unlikely to engender much sympathy. _______________________________________________ cl-faq mailing list cl-faq@lispniks.com http://www.lispniks.com/mailman/listinfo/cl-faq