From 1fcfd33230c60d3d34a03df2f043567027a5006c Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Fri, 8 Jun 2018 12:51:34 +0200 Subject: [PATCH] Add array comprehension to builtin syntax This resolves some tasks from #180. --- backend/Builtin/Syntax.icl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/Builtin/Syntax.icl b/backend/Builtin/Syntax.icl index 739bae7..90f043e 100644 --- a/backend/Builtin/Syntax.icl +++ b/backend/Builtin/Syntax.icl @@ -601,8 +601,10 @@ bs_with = bs_zf = { syntax_title = "list comprehension" , syntax_patterns = ["ZF-expression", "ZF", "zf", "comprehension", "<-", "<|-", "<-:", "\\\\", ",", "&", "|"] - , syntax_code = ["[... \\\\ ... <- ...]"] - , syntax_description = "Constructs a list composed of elements drawn from other lists or arrays." + , syntax_code = + ["[... \\\\ ... <- ...]" + ,"{... \\\\ ... <- ...}"] + , syntax_description = "Constructs a list or array composed of elements drawn from other lists or arrays." , syntax_doc_locations = [CLR 6 "4.2.1" "_Toc311798024"] , syntax_examples = map (EXs "macro") [ "cartesian = [(x,y) \\\\ x <- [1,2,3], y <- [10,20]] // Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)" @@ -611,6 +613,7 @@ bs_zf = , "catMaybes ms = [x \\\\ Just x <- ms] // Pattern matching in the selector" , "triangle = [(x,y) \\\\ x <- [1,2,3], y <- [1..x]] // Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)" , "arrToList a = [x \\\\ x <-: a] // <-: for arrays" + , "listToArr l = {x \\\\ x <- l} // <-: for arrays" , "castList xs = [|x \\\\ x <|- xs] // The two pipe characters make both xs and the result overloaded lists" ] } -- GitLab