6.1.0080 ( paren CORE

Compilation:

Perform the execution semantics given below.

Execution:

( "ccc<paren>" -- )

Parse ccc delimited by ) (right parenthesis). ( is an immediate word.

The number of characters in ccc may be zero to the number of characters in the parse area.

See:

Rationale:

Typical use: ... ( ccc) ...

Testing:

\ There is no space either side of the ).
T{ ( A comment)1234 -> }T
T{ : pc1 ( A comment)1234 ; pc1 -> 1234 }T

ContributeContributions

ruvavatar of ruv [132] "(" typo in a testcaseComment2020-02-25 23:15:38

The following line:

T{ ( A comment)1234 -> }T

has a typo, the missed stack effect 1234. It should be:

T{ ( A comment)1234 -> 1234 }T

LSchmidtavatar of LSchmidt

Seems that nobody cares - it's also still wrong in https://forth-standard.org/standard/testsuite#F.6.1.0080 and a bit of a nuisance when bitten by tests failing when basing those on the provided test cases.
I was first contemplating the possible reasons for making ( state smart in this bizarre way ...

AntonErtlavatar of AntonErtl

forth-standard.org currently shows Forth-2012, not the state of the working document, so any bug fixes will not be seen here for a long time. However, if you are interested in tests, Gerry Jackson maintains a test suite that includes the standard tests. Or if you are interested in officially approved tests, you start with the Hayes test suite, and add the tests from the approved CfVs on forth200x.org. I would use Gerry Jackson's more comprehensive test suite, though; in cases where you think there's a bug there, you can check how the test case works on other systems, check the text of the standard, and then discuss it with Gerry Jackson and/or here.

Reply New Version

EricBlakeavatar of EricBlake [380] Can balanced () be nested inside ( and .( comments?Request for clarification2025-06-30 18:21:53

The text is unclear on whether "ccc)" as the text to be parsed after recognition of the "(" and ".(" words may include nesting of (). Table 2.1 in 2.2.3 Parsed text notation states merely

 ccc        a parsed sequence of arbitrary characters, excluding the delimiter character 

which at strict reading would state that a comment cannot contain ")" and therefore probably should not contain "(". But in practice, it seems several Forth implementations have ALWAYS supported comments such as "( n -- n' (n modified by ...) )", and where you can quickly add another layer of () around large blocks of code if "(" automatically refills the input buffer until finding the final balancing ")". For an example, here is the jonesforth implementation: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth.f;h=5c1309574a;hb=66c569981#l216

If this is desirable, the specification for "(" and/or for the Parsed text notation definition of ccc needs to be updated to account for nesting. If it is not desirable to mandate this (but to still allow implementations that support it), the text for "(" and ".(" should probably document that it is ambiguous behavior if "(" appears in the "ccc)" word.

https://www.reddit.com/r/Forth/comments/69nivq/is_there_a_good_way_to_do_nested_comments_in_ans/ is an interesting discussion on the topic.

ruvavatar of ruv

which at strict reading would state that a comment cannot contain ")"

Yes.

and therefore probably should not contain "(".

No. This character is not considered as a delimiter by the word "(".

in practice, it seems several Forth implementations have ALWAYS supported comments such as "( n -- n' (n modified by ...) )",

This is not standard. The following test case should be passed in a standard Forth system:

 t{ ( foo ( bar )  char )  ->  char ) }t

you can quickly add another layer of () around large blocks of code

Just introduce another word for comments, which supports nesting. For example, these are encountered in practice (: ... :), (* ... *), (( ... ))

if "(" automatically refills the input buffer

BTW, it does refilling if the input source is a file (according to 11.6.1.0080). In some systems it does refilling when the input source is the user input device too — since when you copy-n-paste a fragment of code or definition from a file to the console, you expect comments to be interpreted the same way as in a file.

should probably document that it is ambiguous behavior if "(" appears in the "ccc)" word.

This makes some standard programs non-standard. A better way is to use a different (and longer) word for nested comments.

Reply New Version