Sujet : Re: Bart's Language
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 21. Mar 2025, 01:56:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vridg1$c9ev$2@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
On 20/03/2025 23:45, Kaz Kylheku wrote:
On 2025-03-20, Waldek Hebisch <antispam@fricas.org> wrote:
bart <bc@freeuk.com> wrote:
In this case, just write it like that, and only adjust it for the
somewhat different syntax:
>
func foo:int =
let int c := c1(10)
let int b := c + c2(2)
let int a := b+c3(c)
bar()
baz()
return c
end
>
>> In your description you wrote that declarations can be written
"out of order" and compiler will rearrange them in correct
order. That looked like great opportunity to write obfuscated
code.
I made a language feature like that: mlet.
https://www.nongnu.org/txr/txr-manpage.html#N-2B3072E9
This allows for circular references in order to support
the construction of lazy objects:
1> (mlet ((a (lcons 1 b))
(b (lcons 0 a)))
(take 20 a))
(1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0)
I don't understand what's going on above; the example here is a bit clearer, other than that z at the end:
(mlet ((x (+ y 1))
(y (+ z 1))
(z (+ x 1)))
z)
But this looks like something that goes on at runtime. In the language above, it's all dealt with at compile time. If I create a similar example:
const x = y + 1,
y = z + 1,
z = x + 1
then it is the compiler that reports a circular reference.
Otherwise, in my dynamic (and non-lazy) language, circular references are allowed at runtime, but it is object references rather than names:
a ::= (1,2,3) # create two short lists (::= makes a mutable copy)
b ::= (4,5,6)
a &:= b # append each to the other (concatenate is
b &:= a # well-behaved)
println a
println b
Shows two now infinite lists:
(1,2,3,(4,5,6,(1,2,3,(4,5,6,...))))
(4,5,6,(1,2,3,(4,5,6,(1,2,3,...))))
(An attempt to deep-copy one of those will end badly.)