Sujet : Re: Bart's Language
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 18. Mar 2025, 14:54:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrbtve$2irc9$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
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());
}
--------------------------