Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > NZ Computing > What Will This Print?

Reply
Thread Tools

What Will This Print?

 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      11-08-2009
What output will this Algol 68 produce?

PROC VOID proc1 = BEGIN print(("line 1", new line)); GOTO end END;
print(("line 2", new line));
proc1;
print(("line 3", new line));
end: SKIP

 
Reply With Quote
 
 
 
 
Nik Coughlin
Guest
Posts: n/a
 
      11-08-2009
"Lawrence D'Oliveiro" <(E-Mail Removed)_zealand> wrote in message
news:hd6dkj$e6r$(E-Mail Removed)...
> What output will this Algol 68 produce?
>
> PROC VOID proc1 = BEGIN print(("line 1", new line)); GOTO end END;
> print(("line 2", new line));
> proc1;
> print(("line 3", new line));
> end: SKIP


line 2
line 1




 
Reply With Quote
 
 
 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      11-09-2009
In message <hd7jqo$98a$(E-Mail Removed)-september.org>, Nik Coughlin wrote:

> "Lawrence D'Oliveiro" <(E-Mail Removed)_zealand> wrote in message
> news:hd6dkj$e6r$(E-Mail Removed)...
>
>> What output will this Algol 68 produce?
>>
>> PROC VOID proc1 = BEGIN print(("line 1", new line)); GOTO end END;
>> print(("line 2", new line));
>> proc1;
>> print(("line 3", new line));
>> end: SKIP

>
> line 2
> line 1


Actually it will print

line 1
line 2

Why?
 
Reply With Quote
 
Nik Coughlin
Guest
Posts: n/a
 
      11-09-2009
"Nik Coughlin" <(E-Mail Removed)> wrote in message
news:hd7jqo$98a$(E-Mail Removed)-september.org...
> "Lawrence D'Oliveiro" <(E-Mail Removed)_zealand> wrote in message
> news:hd6dkj$e6r$(E-Mail Removed)...
>> What output will this Algol 68 produce?
>>
>> PROC VOID proc1 = BEGIN print(("line 1", new line)); GOTO end END;
>> print(("line 2", new line));
>> proc1;
>> print(("line 3", new line));
>> end: SKIP

>
> line 2
> line 1


Nope.

line 1
line 2

Algol is quite different to what I'm used to. I'd assumed that the above
was equivalent to (in c-ish pseudocode):

void proc1() {
print( "line1\n" );
goto end;
}

print( "line2\n" );
proc1;
print( "line3\n" );
end: //do nothing

 
Reply With Quote
 
Nik Coughlin
Guest
Posts: n/a
 
      11-09-2009
"Lawrence D'Oliveiro" <(E-Mail Removed)_zealand> wrote in message
news:hd7m2v$5il$(E-Mail Removed)...
> In message <hd7jqo$98a$(E-Mail Removed)-september.org>, Nik Coughlin wrote:
>
>> "Lawrence D'Oliveiro" <(E-Mail Removed)_zealand> wrote in message
>> news:hd6dkj$e6r$(E-Mail Removed)...
>>
>>> What output will this Algol 68 produce?
>>>
>>> PROC VOID proc1 = BEGIN print(("line 1", new line)); GOTO end END;
>>> print(("line 2", new line));
>>> proc1;
>>> print(("line 3", new line));
>>> end: SKIP

>>
>> line 2
>> line 1

>
> Actually it will print
>
> line 1
> line 2
>
> Why?


It looks like what it's doing is executing the first part of the proc when
it's defined, and then executing the GOTO end (which "skips" the "line 3")
when it's called?

So the program flow goes something like this:

proc1 is defined, print "line 1"
print "line 2"
proc1 gets called, goes to the end label which tells it to skip the next
statement (the print "line 3")
done

 
Reply With Quote
 
Nik Coughlin
Guest
Posts: n/a
 
      11-09-2009
"Nik Coughlin" <(E-Mail Removed)> wrote in message
news:hd7msj$57k$(E-Mail Removed)-september.org...
> "Lawrence D'Oliveiro" <(E-Mail Removed)_zealand> wrote in message
> news:hd7m2v$5il$(E-Mail Removed)...
>> In message <hd7jqo$98a$(E-Mail Removed)-september.org>, Nik Coughlin wrote:
>>
>>> "Lawrence D'Oliveiro" <(E-Mail Removed)_zealand> wrote in
>>> message
>>> news:hd6dkj$e6r$(E-Mail Removed)...
>>>
>>>> What output will this Algol 68 produce?
>>>>
>>>> PROC VOID proc1 = BEGIN print(("line 1", new line)); GOTO end END;
>>>> print(("line 2", new line));
>>>> proc1;
>>>> print(("line 3", new line));
>>>> end: SKIP
>>>
>>> line 2
>>> line 1

>>
>> Actually it will print
>>
>> line 1
>> line 2
>>
>> Why?

>
> It looks like what it's doing is executing the first part of the proc when
> it's defined, and then executing the GOTO end (which "skips" the "line 3")
> when it's called?
>
> So the program flow goes something like this:
>
> proc1 is defined, print "line 1"
> print "line 2"
> proc1 gets called, goes to the end label which tells it to skip the next
> statement (the print "line 3")
> done


Why does it do that?

 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      11-09-2009
In message <hd7msj$57k$(E-Mail Removed)-september.org>, Nik Coughlin wrote:

> It looks like what it's doing is executing the first part of the proc when
> it's defined, and then executing the GOTO end (which "skips" the "line 3")
> when it's called?


The subtle point is that in

PROC VOID proc1 = BEGIN print(("line 1", new line)); GOTO end END;

that "BEGIN ... END" clause is not the procedure body. It's just a clause
that's evaluated and is supposed to yield something that's assigned to
proc1. This should be the result from the last expression in the clause.
However, in this case, that last expression happens to be a GOTO statement.

So something funny happens: instead of being executed, the GOTO statement is
turned into the body of a procedure, and that's what's returned to become
the value of proc1.

In short, the above is more equivalent to

print(("line 1", new line));
PROC proc1 = VOID: GOTO end;

In order to for it to mean what you originally thought it meant, it would
have to be written as

PROC proc1 = VOID: BEGIN print(("line 1", new line)); GOTO end END;

 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      11-09-2009
In message <hd7mjh$tdi$(E-Mail Removed)-september.org>, Nik Coughlin wrote:

> Algol is quite different to what I'm used to.


It was designed by computer scientists. Need I say more?
 
Reply With Quote
 
Sailor Sam
Guest
Posts: n/a
 
      11-09-2009
Lawrence D'Oliveiro wrote:
> In message <hd7mjh$tdi$(E-Mail Removed)-september.org>, Nik Coughlin wrote:
>
>> Algol is quite different to what I'm used to.

>
> It was designed by computer scientists. Need I say more?


As was B.
 
Reply With Quote
 
Ted
Guest
Posts: n/a
 
      11-09-2009
On Nov 9, 7:11*pm, Lawrence D'Oliveiro <l...@geek-
central.gen.new_zealand> wrote:
> In message <hd7mjh$(E-Mail Removed)-september.org>, Nik Coughlin wrote:
>
> > Algol is quite different to what I'm used to.

>
> It was designed by computer scientists. Need I say more?


This is what some computer scientists had to say about it at the time:

* The more I see of it, the more unhappy I become - E.W. Dijkstra,
1968 [23]

* [...] it was said that A68's popularity was inversely
proportional to [...] the distance from Amsterdam - Guido van Rossum
[24]

* 1980 quote: '[...] The best we could do was to send with it a
minority report, stating our considered view that, "... as a tool for
the creation of sophisticated programs, the language was a
failure." [...] ' - C. A. R. Hoare, Oct 1980, re: "Dec 1968"

* Original 1968 version: "[...] More than ever it will be required
from an adequate programming tool that it assists, by structure, the
programmer in the most difficult aspects of his job, viz. in the
reliable creation of sophisticated programs. In this respect we fail
to see how the language proposed here [Algol68] is a significant step
forward: on the contrary, we feel that its implicit view of the
programmer's task is very much the same as, say, ten years ago. This
forces upon us the conclusion that, regarded as a programming tool,
the language must be regarded as obsolete. [...]" Signed by: DIJKSTRA,
DUNCAN, GARWICK, HOARE, RANDELL, SEEGMUELLER, TURSKI, WOODGER. And
then on Dec. 23, 1968, Jan V. Garwick[25]

http://en.wikipedia.org/wiki/ALGOL_68

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments