roc/test/snapshots/lambda_in_collection.md
2025-11-19 10:31:11 -05:00

1.4 KiB

META

description=Lambda inside a collection
type=expr

SOURCE

(
	|
		a,
		b,
	| {
		a + b
	},
	|a, b| {
		a - b
	},
)

EXPECTED

NIL

PROBLEMS

NIL

TOKENS

OpenRound,
OpBar,
LowerIdent,Comma,
LowerIdent,Comma,
OpBar,OpenCurly,
LowerIdent,OpPlus,LowerIdent,
CloseCurly,Comma,
OpBar,LowerIdent,Comma,LowerIdent,OpBar,OpenCurly,
LowerIdent,OpBinaryMinus,LowerIdent,
CloseCurly,Comma,
CloseRound,
EndOfFile,

PARSE

(e-tuple
	(e-lambda
		(args
			(p-ident (raw "a"))
			(p-ident (raw "b")))
		(e-block
			(statements
				(e-binop (op "+")
					(e-ident (raw "a"))
					(e-ident (raw "b"))))))
	(e-lambda
		(args
			(p-ident (raw "a"))
			(p-ident (raw "b")))
		(e-block
			(statements
				(e-binop (op "-")
					(e-ident (raw "a"))
					(e-ident (raw "b")))))))

FORMATTED

NO CHANGE

CANONICALIZE

(e-tuple
	(elems
		(e-lambda
			(args
				(p-assign (ident "a"))
				(p-assign (ident "b")))
			(e-block
				(e-binop (op "add")
					(e-lookup-local
						(p-assign (ident "a")))
					(e-lookup-local
						(p-assign (ident "b"))))))
		(e-lambda
			(args
				(p-assign (ident "a"))
				(p-assign (ident "b")))
			(e-block
				(e-binop (op "sub")
					(e-lookup-local
						(p-assign (ident "a")))
					(e-lookup-local
						(p-assign (ident "b"))))))))

TYPES

(expr (type "(c, c -> c, d, d -> d)"))