roc/test/snapshots/lambda_capture/lambda_capture_three_levels.md
2025-11-23 01:22:01 -05:00

1.8 KiB

META

description=Three-level nested lambda captures - innermost lambda captures from all outer levels
type=expr

SOURCE

(|outer| |middle| |inner| outer + middle + inner)(1)(2)(3)

EXPECTED

NIL

PROBLEMS

NIL

TOKENS

OpenRound,OpBar,LowerIdent,OpBar,OpBar,LowerIdent,OpBar,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,OpPlus,LowerIdent,CloseRound,NoSpaceOpenRound,Int,CloseRound,NoSpaceOpenRound,Int,CloseRound,NoSpaceOpenRound,Int,CloseRound,
EndOfFile,

PARSE

(e-apply
	(e-apply
		(e-apply
			(e-tuple
				(e-lambda
					(args
						(p-ident (raw "outer")))
					(e-lambda
						(args
							(p-ident (raw "middle")))
						(e-lambda
							(args
								(p-ident (raw "inner")))
							(e-binop (op "+")
								(e-binop (op "+")
									(e-ident (raw "outer"))
									(e-ident (raw "middle")))
								(e-ident (raw "inner")))))))
			(e-int (raw "1")))
		(e-int (raw "2")))
	(e-int (raw "3")))

FORMATTED

NO CHANGE

CANONICALIZE

(e-call
	(e-call
		(e-call
			(e-lambda
				(args
					(p-assign (ident "outer")))
				(e-closure
					(captures
						(capture (ident "outer")))
					(e-lambda
						(args
							(p-assign (ident "middle")))
						(e-closure
							(captures
								(capture (ident "outer"))
								(capture (ident "middle")))
							(e-lambda
								(args
									(p-assign (ident "inner")))
								(e-binop (op "add")
									(e-binop (op "add")
										(e-lookup-local
											(p-assign (ident "outer")))
										(e-lookup-local
											(p-assign (ident "middle"))))
									(e-lookup-local
										(p-assign (ident "inner")))))))))
			(e-num (value "1")))
		(e-num (value "2")))
	(e-num (value "3")))

TYPES

(expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))