Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12337 > unrolled thread

Re: Is there a way to do comment with just one keystroke at the start as

Started byMurray Eisenberg <murray@math.umass.edu>
First post2012-11-14 06:50 +0000
Last post2012-11-20 00:18 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Is there a way to do comment with just one keystroke at the start as Murray Eisenberg <murray@math.umass.edu> - 2012-11-14 06:50 +0000
    Re: Is there a way to do comment with just one keystroke at the start David Bailey <dave@removedbailey.co.uk> - 2012-11-20 00:18 +0000

#12337 — Re: Is there a way to do comment with just one keystroke at the start as

FromMurray Eisenberg <murray@math.umass.edu>
Date2012-11-14 06:50 +0000
SubjectRe: Is there a way to do comment with just one keystroke at the start as
Message-ID<k7vevv$s52$1@smc.vnet.net>
On Nov 13, 2012, at 12:05 AM, Eric Rasmusen <erasmuse61@gmail.com> wrote:
> 
>   The standard way to do comments in Mathematica is like this
> (*Here is a comment*)
>
> In Latex,  a short comment only takes one symbol, at the start of the line:
> %Here is a latex comment
>
> Is there a way to comment in Mathematica without the closing symbols? is there an any easy way to make a macro to imitate latex comments?

Sorry, but that's the way it is.

Of course you could use Text cells instead of embedding comments inside an Input cell.

That won't work, of course, if you need to insert comments within (too?)-long code in an Input cell. In the latter case, you could try the following:

  Comment[blah___] := Null

For example:

  Comment["first we do this"]
1 + 1
Comment[next]
x + 2
Comment[]

The _three_ underscores in the argument pattern blah___ for Comment is to allow the final usage just shown, with no argument, so as to avoid seeing a literal Comment[] returned from it.

The trouble is that the function Comment also requires a closing bracket. At least that's one less symbol than the two in *) closing an ordinary comment. You could avoid even that by using prefix notation, provided you ensure the argument is a single symbol or a string:

  Comment@"first we do this"

Unfortunately, that requires a close-quote, so it's not better than the Comment[=85] construction.

---
Murray Eisenberg                           murray@math.umass.edu
Mathematics & Statistics Dept.      
Lederle Graduate Research Tower            phone 413 549-1020 (H)
University of Massachusetts                      413 545-2838 (W)
710 North Pleasant Street                  fax   413 545-1801
Amherst, MA 01003-9305





[toc] | [next] | [standalone]


#12396 — Re: Is there a way to do comment with just one keystroke at the start

FromDavid Bailey <dave@removedbailey.co.uk>
Date2012-11-20 00:18 +0000
SubjectRe: Is there a way to do comment with just one keystroke at the start
Message-ID<k8ei9b$mhg$1@smc.vnet.net>
In reply to#12337
On 14/11/2012 06:50, Murray Eisenberg wrote:
> On Nov 13, 2012, at 12:05 AM, Eric Rasmusen<erasmuse61@gmail.com>  wrote:
>>
>>    The standard way to do comments in Mathematica is like this
>> (*Here is a comment*)
>>
>> In Latex,  a short comment only takes one symbol, at the start of the line:
>> %Here is a latex comment
>>
>> Is there a way to comment in Mathematica without the closing symbols? is there an any easy way to make a macro to imitate latex comments?
>
> Sorry, but that's the way it is.
>
> Of course you could use Text cells instead of embedding comments inside an Input cell.
>
> That won't work, of course, if you need to insert comments within (too?)-long code in an Input cell. In the latter case, you could try the following:
>
>    Comment[blah___] := Null
>
> For example:
>
>    Comment["first we do this"]
> 1 + 1
> Comment[next]
> x + 2
> Comment[]
>

Unfortunately, this breaks for certain comment positions:

In[809]:= Comment[blah___] := Null

In[810]:= Sin[Comment["angle"] Pi]

Out[810]= Sin[Null \[Pi]]

Possibly a slightly better version would be:

Comment[blah___] := Sequence @@ {}

However, even that will fail if used inside Hold[...], and probably in 
other situations as well, so I don't advise using it.

I think a UNICODE character reserved for comment out of one line would 
be a valuable feature, and maybe also a pair of characters equivalent to 
(* and *), which are IMHO very ugly!

David Bailey
http://www.dbaileyconsultancy.co.uk

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web