Re: Bart's Language

Liste des GroupesRevenir à cl c 
Sujet : Re: Bart's Language
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 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());
}
--------------------------

Date Sujet#  Auteur
18 Mar 25 * Bart's Language57bart
18 Mar 25 `* Re: Bart's Language56Waldek Hebisch
18 Mar 25  `* Re: Bart's Language55bart
18 Mar 25   `* Re: Bart's Language54Waldek Hebisch
18 Mar 25    +* Re: Bart's Language46bart
18 Mar 25    i+* Re: Bart's Language36David Brown
18 Mar 25    ii`* int a = a (Was: Bart's Language)35Kenny McCormack
18 Mar 25    ii +* Re: int a = a (Was: Bart's Language)25Janis Papanagnou
18 Mar 25    ii i+- Re: int a = a (Was: Bart's Language)1Kaz Kylheku
19 Mar 25    ii i`* Re: int a = a (Was: Bart's Language)23David Brown
19 Mar 25    ii i +- Re: int a = a (Was: Bart's Language)1Kaz Kylheku
19 Mar 25    ii i +* Re: int a = a14Keith Thompson
20 Mar 25    ii i i+* Re: int a = a12Tim Rentsch
20 Mar 25    ii i ii`* Re: int a = a11Keith Thompson
20 Mar 25    ii i ii +* Re: int a = a8David Brown
20 Mar 25    ii i ii i`* Re: int a = a7Keith Thompson
21 Mar 25    ii i ii i `* Re: int a = a6David Brown
21 Mar 25    ii i ii i  `* Re: int a = a5Keith Thompson
21 Mar 25    ii i ii i   +- Re: int a = a1David Brown
22 Mar 25    ii i ii i   `* Re: int a = a3Tim Rentsch
22 Mar 25    ii i ii i    `* Re: int a = a2Keith Thompson
28 Apr 25    ii i ii i     `- Re: int a = a1Tim Rentsch
29 Apr 25    ii i ii `* Re: int a = a2Tim Rentsch
29 Apr 25    ii i ii  `- Re: int a = a1Keith Thompson
20 Mar 25    ii i i`- Re: int a = a1David Brown
19 Mar 25    ii i +* Re: int a = a (Was: Bart's Language)5Chris M. Thomasson
20 Mar 25    ii i i`* Re: int a = a (Was: Bart's Language)4David Brown
20 Mar 25    ii i i `* Re: int a = a (Was: Bart's Language)3bart
20 Mar 25    ii i i  `* Re: int a = a (Was: Bart's Language)2David Brown
20 Mar 25    ii i i   `- Re: int a = a (Was: Bart's Language)1wij
20 Mar 25    ii i `* Re: int a = a (Was: Bart's Language)2Tim Rentsch
20 Mar 25    ii i  `- Re: int a = a (Was: Bart's Language)1David Brown
18 Mar 25    ii +* Re: int a = a (Was: Bart's Language)3David Brown
18 Mar 25    ii i`* Re: int a = a (Was: Bart's Language)2Janis Papanagnou
19 Mar 25    ii i `- Re: int a = a (Was: Bart's Language)1David Brown
19 Mar 25    ii `* Re: int a = a (Was: Bart's Language)6Tim Rentsch
19 Mar 25    ii  +* Re: int a = a2Keith Thompson
27 Apr 25    ii  i`- Re: int a = a1Tim Rentsch
19 Mar 25    ii  +- Re: int a = a (Was: Bart's Language)1David Brown
19 Mar 25    ii  `* Re: int a = a (Was: Bart's Language)2Rosario19
20 Mar 25    ii   `- Re: int a = a (Was: Bart's Language)1Tim Rentsch
20 Mar 25    i`* Re: Bart's Language9Waldek Hebisch
21 Mar 25    i `* Re: Bart's Language8Keith Thompson
22 Mar 25    i  +* Re: Bart's Language5Waldek Hebisch
22 Mar 25    i  i`* Re: Bart's Language4James Kuyper
22 Mar 25    i  i +* Re: Bart's Language2Waldek Hebisch
23 Mar 25    i  i i`- Re: Bart's Language1James Kuyper
23 Mar 25    i  i `- By definition... (Was: Bart's Language)1Kenny McCormack
27 Apr 25    i  `* Re: Bart's Language2Tim Rentsch
27 Apr 25    i   `- Re: Bart's Language1Keith Thompson
18 Mar 25    `* Re: Bart's Language7bart
20 Mar 25     `* Re: Bart's Language6Waldek Hebisch
21 Mar 25      +* Re: Bart's Language4Kaz Kylheku
21 Mar 25      i`* Re: Bart's Language3bart
21 Mar 25      i `* Re: Bart's Language2Kaz Kylheku
22 Mar 25      i  `- Re: Bart's Language1Tim Rentsch
21 Mar 25      `- Re: Bart's Language1bart

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal