Jump to content
eengebruiker

Autolisp: Comment between square brackets?

Recommended Posts

eengebruiker

I just discovered that I can put a line in my lispfile like this: [Some notes].

When I load the lispfile the line is ignored. In other words it acts like comment.

 

Comes in handy because I can use another type of comment, But . . . . . . 

 

Do I rely on a rule here or will I get into trouble later when using the code?

 

Thanks in advance,

 

André

Share this post


Link to post
Share on other sites
Grrr
Posted (edited)

Hi,

Each "word" within the square brackets evaluates to nil evaluates as variable, meaning if you have 9 words you'll get 9 consecutive returns.

Some testing should make it clear:

_$ [Hello World]
nil
nil
_$ [The quick brown fox jumps over the lazy dog]
nil
nil
nil
nil
nil
nil
nil
nil
nil

While using a lisp comment, you'll get a void -

_$ ; Hello World
_$ 

Sometimes I put some strings or list of symbols to act as another type of comment within my code -

_$ "Hello World"
"Hello World"
_$ '(Hello World)
(HELLO WORLD)

but the thing is if you don't know exactly where to place them, you might mess up your lisp routine - by providing such 'comments' as arguments somewhere in your code.

And one might point out the drawback of redundant evaluation.

 

Edited by Grrr

Share this post


Link to post
Share on other sites
rlx

you could also use  ;| ..... |;

this can be used over multiple lines and even within your code

 


(if (= n 1) ;| if my counter is one |; (princ "\nMy counter is one") ;| else |; (princ "\nMy counter is not one"))

 


(princ "\nHere comes the comment...")

;|

this is my comment on the first line

(princ "\nThis was the first line - but it won't be printed boehoehoe")

this is on the second line

and this is my final line of comment

|;

(princ "\nNah, that's all folks")

 

Share this post


Link to post
Share on other sites
BIGAL

Nice RLX bit easier than multi ; every line. Will use.

Share this post


Link to post
Share on other sites
Lee Mac
11 hours ago, eengebruiker said:

I just discovered that I can put a line in my lispfile like this: [Some notes].

When I load the lispfile the line is ignored. In other words it acts like comment.

 

Comes in handy because I can use another type of comment, But . . . Do I rely on a rule here or will I get into trouble later when using the code?

 

The line is not ignored and does not behave like a comment: every symbol separated by whitespace will be evaluated by the LISP interpreter to yield any value it may hold within the document namespace.

 

If you wish to comment your code, either prefix a single-line comment with a semi-colon ( ; ) e.g.:

(defun c:hw ( )

    ; This function prints "Hello World!"

    (princ "\nHello World!")
    (princ)
)

Or enclose multiline comments between multiline comment delimiters ( ;| |; ), e.g.:

(defun c:hw ( )

    ;|

    This function prints the message
    "Hello World!"

    |;

    (princ "\nHello World!")
    (princ)
)

To demonstrate the dangers of using anything other than comment as a comment, consider the following code:

(defun c:test ( )
    (if (= 1 2) [If 1 is equal to 2]
        (princ "\n1 is equal to 2.")
    )
    (princ)
)

You'll discover that this code will not even load correctly, as the if function has actually been supplied with 8 arguments!

Share this post


Link to post
Share on other sites
Grrr
Posted (edited)

I stand corrected at my first reply - each "word" evaluates as variable

_$ (setq [Hello 1)
1
_$ (setq World] "string")
"string"
_$ [Hello World]
1
"string"
_$ 

:facepalm: 

Edited by Grrr

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...