Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: idempotency vs side effects of recognizers #7

Open
ruv opened this issue Jun 11, 2020 · 1 comment
Open

API: idempotency vs side effects of recognizers #7

ruv opened this issue Jun 11, 2020 · 1 comment
Labels
api An API method semantics consideration v4-review Related to the proposal v4 by Matthias Trute

Comments

@ruv
Copy link
Collaborator

ruv commented Jun 11, 2020

Should a recognizer be free of side effects, or at least idempotent?

Recognizer v4 API proposes that a recognizer may have any side effects. E.g., trying to recognize a lexeme may produce read the input source.

This looseness reduces safety of using recognizers. Particularly, when a program or library uses the perceptor (the recognizer currently used by the Forth text interpreter) that was not set by this program or library. Or when a lexeme is taken from an unsafe source (e.g., from the user).

On the other side, any recognizer can be implemented in an idempotent manner.

For example, see an implementation of string literals in such a way that the recognizer doesn't do additional parsing — see at the gist.

Also, recognizing is a generalization of finding definition names and conversion strings to numbers (FIND and >NUMBER or NUMBER?). And these actions never have any side effects.

See also: Issue #8

@ruv ruv added api An API method semantics consideration v4-review Related to the proposal v4 by Matthias Trute labels Jun 11, 2020
@ruv
Copy link
Collaborator Author

ruv commented Aug 27, 2020

Examples of programs that work incorrectly due to side effect of some recognizers — see in the message news:[email protected] (raw archived) "Recognizer protocol" on 2020-07-04.

E.g., the following short correct program:

'!' parse "test passed"! rec-string cr .s cr .

produces "Invalid memory address" error in Gforth 0.7.9_20200618 (see also the corresponding bug report).

See also: news:[email protected] (raw archived) "Recognizer protocol" on 2020-06-28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api An API method semantics consideration v4-review Related to the proposal v4 by Matthias Trute
Projects
None yet
Development

No branches or pull requests

1 participant