coalton-lang / coalton

Coalton is an efficient, statically typed functional programming language that supercharges Common Lisp.

Home Page:https://coalton-lang.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loop variable semantics

eliaslfox opened this issue · comments

I think this needs to be fixed. See this explanation in go.

#986 (comment). Is this the same thing?

If so, I think we're already good. Here are some samples:

COALTON-USER> (coalton 
               (let ((v (vector:new))) 
                 (for x in "hello" 
                      (vector:push! (fn () x) v))
                 (map (fn (f) (f)) v)))
#(#\h #\e #\l #\l #\o)
COALTON-USER> (coalton 
               (let ((v (vector:new))) 
                 (for x in "hello" 
                      (vector:push! (fn () (traceobject "x" x)) v))
                 (for x in v (x))))

x: h
x: e
x: l
x: l
x: o
COMMON-LISP:NIL

The for and while-let forms recycle codegen from pattern matching, which expands matches out into cl:lets. At least, that's my understanding.

If there's more to it than this, could you provide a code sample that elicits the bug?

It's looks like it's correct. Thanks for checking.