Closed typeless closed 6 years ago
On Wed, 06 Dec 2017 06:07:00 +0000 (UTC), Mura Li notifications@github.com wrote:
use std extern const __bss_start : void# const main = { const fp = __bss_start for fp : (&__bss_start)[:1] ;; }
Output:
Building 6m -I /lib/myr in.myr CRASH: 6m -I /lib/myr in.myr Internal error: mbld: exited with status 1
I am playing around some unusual cases :trollface:
Yep, Generally I don't do that much with externs. The error message has been fixed.
-- Ori Bernstein
Ah, I should have made it clearer. The extern
const declaration without initialization is expected, but the crash happens when the fp
identifier is reused in the for
loop as the iterator. It compiles when I change either one of the two fp
identifiers to another name.
On Wed, 06 Dec 2017 07:32:29 +0000 (UTC), Mura Li notifications@github.com wrote:
Ah, I should have made it clearer. The
extern
const declaration without initialization is expected, but the crash happens when thefp
identifier is reused in thefor
loop as the iterator. It compiles when I change either one of the twofp
identifiers to another name.
Yes, that's by design. The for loop iterator is a pattern match, and you can match against constants.
For example:
const Foo = 123
const Bar = 234
for (Foo, x) in [(Foo, 1), (Bar, 2), (Baz, 3)][:]
std.put("x={}\n")
;;
will print only the first value that matches Foo
:
x=1
You can think of this form of loop as syntax for:
for pat in iterable
/* loop body */
;;
for var i = 0; i < iter.len; i++
match iter[i]
| pat:
/* loop body */
| _:
/* skip */
;;
;;
-- Ori Bernstein
Output:
I am playing around some unusual cases :trollface: