Article: 124171 of comp.lang.forth Path: tunews.univie.ac.at!aconews-feed.univie.ac.at!newsfeed.wu-wien.ac.at!newsfeed.utanet.at!news.glorb.com!postnews.google.com!s48g2000cws.googlegroups.com!not-for-mail From: "J Thomas" Newsgroups: comp.lang.forth Subject: Re: Request for Discussion -- (( and multiline comments Date: 2 Feb 2007 08:36:35 -0800 Organization: http://groups.google.com Lines: 158 Message-ID: <1170434195.811414.157640@s48g2000cws.googlegroups.com> References: <1170193856.683826.255320@h3g2000cwc.googlegroups.com> NNTP-Posting-Host: 64.83.8.70 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1170434200 31328 127.0.0.1 (2 Feb 2007 16:36:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 2 Feb 2007 16:36:40 +0000 (UTC) In-Reply-To: <1170193856.683826.255320@h3g2000cwc.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20051106 Firefox/1.0.6,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: s48g2000cws.googlegroups.com; posting-host=64.83.8.70; posting-account=wP2gaA0AAACOjKHjz4G3_054UgCn5G5w Xref: tunews.univie.ac.at comp.lang.forth:124171 RfD -- (( February 2, 2007 * Third Draft * Significant Differences from 2nd Version ============================ Name change from (( to (* Nesting, (* (* *) *) works. Rationale ========= Problem ------- Most Forth users find it useful to have a block comment -- a comment command that covers multiple lines. There are many names for this because there is no standard. Names include (( (* /* ( etc. One standard portable approach is 0 [IF] ..... [THEN] This works on every standard Forth that implements [IF] [THEN] but it is ugly. It's easy to rename 0 [IF] to, say, [DOCUMENTATION] and still end with [THEN] . This solution is not generally accepted as shown by the existence and use of so many alternatives. Current Practice ---------------- Many Forth systems provide this capability. MPE's Forths, Win32Forth, and FPC have used the name (( for a version that does not nest, but several commenters prefer a standard commenting command that does nest. Solution -------- Agree on a common name. The more Forth systems that provide a standard name, the more code will use it and the less trouble it will be porting that code. Code that uses some other name will still run on every system that supports it and software can be easily written to support it elsewhere, but to the extent we use a standard name that bother can be avoided. Proposal ======== 15.6.2.xxxs (* "comments" TOOLS EXT Compilation: Perform the execution semantics given below. Execution: ( "ccc" -- ) Parse text until the whitespace-delimited string *) is found or until the current parse area cannot be refilled. Discard the found *) string. (* commands are nestable. (* is an immediate word. An ambiguous condition exists if the word *) is not found and the parse area cannot be refilled. Typical use ----------- (* This is a comment, it requires supporting statements. These statements can go on their own lines. There might be lots of them. *) (* *************************************************************** People have lots of styles for comenting. They like to make their comments stand out as obvious comments. *************************************************************** *) (* Sometimes people want to increase the range of their comments. : BUGGY-CODE 0 >R ; (* What was I thinking when I wrote this? *) : MORE-BUGGY-CODE DO : (* What a headache. I must have been having fun, why can't I remember? *) Better comment out this whole section. *) Reference Implementation ------------------------ : MAYBE-REFILL ( S: -- flag ) \ refill if at end of line, 0 if can't SOURCE NIP >IN @ > DUP 0= IF DROP REFILL THEN ; : (* ( S: -- ) \ multi-line comment, ended by *) BEGIN BL WORD COUNT 2DUP S" *)" COMPARE WHILE S" (*" COMPARE 0= IF RECURSE THEN MAYBE-REFILL WHILE REPEAT 0 0 CR ." Your system can do anything at this point and still be a standard system." THEN 2DROP ; IMMEDIATE BL WORD COUNT can be replaced by PARSE-NAME when the time comes. It would not be difficult to make a CREATE DOES> word which defines new words like (* with new ending strings different from *) . I may do that. Test Cases ---------- (* CR .( Don't print this.) *) CR .( Print first comment ) (* CR .( Don't print this either. ) CR .( And don't print this. ) *) CR .( Print second comment ) : foo (* CR .( Don't print while compiling ) CR .( Or the second line. ) *) CR ." Print third comment " ; foo (* CR .( Don't print another ) (* CR .( Don't print nested. ) *) CR .( Still don't print ) *) CR .( Print fourth and last comment ) Remarks ------- I don't care what name we use provided we can agree on one. I dislike using /* because there might be some use for files where Forth code is in C comments and vice versa. Also */ is a Forth word. (( has been in use for many years by MPE and by Win32Forth as a non- nestable multiline comment. A nestable version should have a different name. Also, (( is used in iForth for something completely different. Other suggestions for names: \\ --- ( in both cases, the next instance toggles rather than nests) Thanks ------ Thanks to Robert Epprecht, George Hubert, Michael Hore, Bruce McFarling, David N. Williams, Marcel Hendrix, Ed Beroset, Stephen Pelc, and Michael Coughlin.. Comments ========