Expand/Shrink

Comments

Phix supports both line and nested block comments.

Line comments are started by two dashes (or two forwardslashes as of 0.8.2+) and extend to the end of the current line, e.g.
-- this is a comment
// this is also a comment.
Comments are ignored by the compiler and have no effect on execution speed. By default Edita displays comments in navy.

On the first line (only) of your program, you can use a special comment beginning with #!, e.g.
#!/home/pete/phix/p
This is reserved for Linux, to inform the shell that your file should be executed by the Phix interpreter, and gives the full path to the interpreter. If you make your file executable, you can run it just by typing its name, without the need to type "p". On Windows this line is treated as a comment.

Block comments are started with /* or --/* and end with */ or --*/, e.g.
/*
   This is a comment
*/
The --/* and --*/ forms were (and often still are) used for a somewhat dirty little hack.
The following illustrates some differences between handling of block comments by Phix and Euphoiria:
--/* 
include std\console.e           -- Ignored by Phix, included by Eu 
--*/ 
--/* */include builtins\get.e   -- Included by Phix, ignored by Eu 
 
/* 
        puts(1, "Neither Eu nor Phix execute this\n")  
*/ 
 
--/*  
        puts(1, "Eu prints this, Phix does not\n")  
--*/  
 
--/* */ puts(1, "Phix prints this, Eu does not\n")   
 
--/* */ puts(1, "Runs with Phix\n") --/*     
        puts(1, "Runs with Eu\n")   --*/ 
Thanks to ChrisB for suggesting the above. Note that Phix source does not need a space in /* */, but this html seems to.

An alternative (more recent and somewhat saner) way to cope with any required differences is:
ifdef PHIX then 
    puts(1,"this is Phix\n") 
elsedef 
    puts(1,"this is Eu\n") 
end ifdef 
Block comments can also be nested to any depth, though there are a few (rare) edge cases you should be aware of:
/*
    something
    /*
        if token="/*" then while token()!="*/" do next_token() end while end if
    */
    something else
*/
will actually be fine, but really treats the [/*]`" then while token()!="`[*/] as a depth-3-nested-comment, whereas

    /*
    if token="*/" then exit end if
    */
will (as you should be able to see) break trying to compile `" then exit end if\n*/`, in this particular case pointing just past the final if (aka end of line) and declaring "missing closing quote".

In uncommented code, text in string literals is treated specially and any embedded open/close block comments are ignored.
However once that code is made a comment, the whole thing is just text and hence there simply cannot be any special handling of such once-were-string-literals.
Thankfully not very much code embeds (unbalanced) comment markers inside string literals like that, and when it does you should get some pretty obvious clues from the syntax colouring (as long as you’re not using the bare-bones Notepad or any other editor that doesn’t fully understand how phix comments work).

See also: Personal Recommendations