last day (15 days later) » 

15:26
7
Q: Did the Algol 68 standard allow a procedure to be called before its declaration?

texdr.aftIn Algol 68, is it legal to say this? proc even = (int x) bool: (x = 0 | true | odd(x – 1)); proc odd = (int x) bool: (x = 0 | false | even(x – 1)); Forward references in structures are used in the Revised Report (10.3.5), but this works because, I think, the syntax “expands” the right-hand si...

You have not tried searching for "algol-68 mutual recursion", have you?
@LeoB. I'm more interested in whether and how it's handled by the standard's VW-grammar than in whether the feature was implemented or how to achieve it.
As asked, the question may be simply answered in the positive. Perhaps, in its intended phrasing it would better be suited for CS.SE.
@LeoB. You're right. I've edited the title.
You can experiment with a standard-conforming compiler taken from jmvdveer.home.xs4all.nl/en.algol-68-genie.html
Still, the answer is in the positive. See 4.2.2.3 of the Informal Introduction. A question formulated as "How were the calls to yet undeclared procedures handled in Algol-68 VW-grammar?" posted to CS.SE may be in order.
15:26
@LeoB. Yeah, I see what you mean. I'll ask that tomorrow. Not sure whether to delete this question.
Absolutely the code as shown was legal Algol 68, but how the grammar permits that is a question I can't answer. I never really got to grips with it in any serious way.
I ran the code from the question (after converting to uppercase stropping) with the online genie compiler.
@another-dave I keep getting stack overflow errors but yeah, it parses fine.
Ah, yeah. Your odd was buggy. Consider what happens if we ever ask foreven(1). Fixed in question.
@another-dave Or have odd check for 1 instead of 0
No, the check for 0 is the fix; the check for 1 was the bug. Using the original code: odd(2) -> even(1) -> odd(0) -> even(-1) -> odd(-2)....
15:26
@another-dave Oops! Yes, of course, you're correct.
Upvoted for ALGOL 68 question and would have upvoted several more times for a W-grammar question! (Though that might properly go elsewhere, perhaps CS stack?)
(Unfortunately in "Grammars For Programming Languages" (Cleaveland, Uzgalis, 1977), which is about the only thing I know of that really describes w-grammars, the sample language ASPLE they use to given an example of a full static semantics of a language requires declare before use.)
@davidbak Frank Pagan's Formal specification of programming languages is another source, and it purports to use a w-grammar to describe a language that allows forward references, but I don't understand how.
@texdr.aft - great! I'll look for it! by the way, do you have his "A Practical Guide To ALGOL 68"? if so look at middle of page 101 ... I'll post a (quasi-)answer soon.
@davidbak The link goes to the Internet Archive, where you can read the book for free as long as you have an account. And alas, I don't have that.
@texdr.aft - no, what I (elliptically) meant was: I've had that book in my library for decades - but don't think I've ever cracked it open. Now I will! Thanks much for pointing me to it!

last day (15 days later) »