| Deutsch English Français Italiano |
|
<vrbtve$2irc9$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Bart's Language
Date: Tue, 18 Mar 2025 13:54:55 +0000
Organization: A noiseless patient Spider
Lines: 141
Message-ID: <vrbtve$2irc9$1@dont-email.me>
References: <vracit$178ka$1@dont-email.me> <vrbo88$1j3e0$1@paganini.bofh.team>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 18 Mar 2025 14:54:55 +0100 (CET)
Injection-Info: dont-email.me; posting-host="35833daf7a617b7c2106f27a6fe8438d";
logging-data="2715017"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LG5VHBV6UBExNqpCAiLjO"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Y6Kp1xKOQsXljUSYgD8VG2CeruE=
In-Reply-To: <vrbo88$1j3e0$1@paganini.bofh.team>
Content-Language: en-GB
Bytes: 3823
On 18/03/2025 12:17, Waldek Hebisch wrote:
> bart <bc@freeuk.com> wrote:
>>
>> This is the document I produced:
>>
>> https://github.com/sal55/langs/blob/master/MFeatures.md
>>
>> A couple of more substantial demo programs are here:
>> https://github.com/sal55/langs/tree/master/MExamples
>>
>> (The bignum.m file was ported - by hand - to the bignum.c version that I
>> posted recently.)
>
> Looking at features, can you say if the program below works?
> And if it works, what is retrun value of foo? "Equvalent" can
> be written in C, but in C you have to keep sane order.
There were some tweaks needed; it indicates some basic info missing from
my write-up! (For example, that the function call needs to be bar() not
bar; 'const' is only for compile-time expressions; and that C's 'const'
doesn't exist - it only briefly mentions an attempt at 'let'.)
The revised code is shown below, with what I assumed were your
intentions. And below that is that code ported to C. Both versions
produce this output:
Line 1
Line 2
Line 3
Line 4
Line 5
10
Line 1
Line 2
Line 3
Line 4
Line 5
10
Note that both 'b' and 'c' in foo() are used uninitialised. I couldn't
apply 'const' to those, as the const declaration would be separate from
the assignment, and the later assignment is then not possible.
(To answer your presumably implied point, in:
print a
int a:=100
the assignment is done at that place in the code (after print), but the
scope of 'a' is function-wide. My compiler doesn't detect accesses to
unitialised variables, but I could add a debug option to clear
stack-frame variables on function entry.)
--------------------------
proc baz =
println "Line 4"
end
func c3(int x) int =
println "Line 1"
x
end
func foo() int =
int a := b + c3(c)
bar()
int b := c + c2(2)
baz()
int c := c1(10)
end
func c2(int x) int =
println "Line 3"
x
end
proc bar =
println "Line 2"
end
func c1(int x) int =
println "Line 5"
x
end
proc main =
println foo()
println foo()
end
--------------------------
#include <stdio.h>
void baz();
int c3(int);
int c2(int);
void bar();
int c1(int);
void baz() {
puts("Line 4");
}
int c3(int x) {
puts("Line 1");
return x;
}
int foo() {
int b, c;
const int a = b+c3(c);
bar();
b = c + c2(2);
baz();
return (c = c1(10));
}
int c2(int x) {
puts("Line 3");
return x;
}
void bar() {
puts("Line 2");
}
int c1(int x) {
puts("Line 5");
return x;
}
int main(void) {
printf("%d\n", foo());
printf("%d\n", foo());
}
--------------------------