Mercurial > repos > icfp2014
view code/ll.lm @ 72:a2a5d80abaa0
Add and as a function to gqc to work around parser limitations
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jul 2014 00:42:21 -0700 |
parents | d5ccb66ae98b |
children |
line wrap: on
line source
#{ length <- :lst { len <- [] while: { not: (lst isInteger?)} do: { lst <- lst tail len <- len + 1 } len } reverse <- :lst { new <- [] while: { not: (lst isInteger?)} do: { new <- (lst value) | new lst <- lst tail } new } split:at <- :lst :pos { first <- [] i <- 0 while: { i < pos } do: { first <- (lst value) | first lst <- lst tail i <- i + 1 } #[(reverse: first) lst] } map <- :lst fun { new <- [] while: { not: (lst isInteger?) } do: { new <- (fun: (lst value)) | new lst <- lst tail } reverse: new } fold:with <- :lst acc :fun { while: { not: (lst isInteger?) } do: { acc <- fun: acc (lst value) lst <- lst tail } acc } filter <- :lst pred { new <- [] while: { not: (lst isInteger?) } do: { if: (pred: (lst value)) { new <- (lst value) | new } else: {} lst <- lst tail } reverse: new } flatten <- :lst { fold: lst [] with: :acc el { fold: el acc with: :iacc iel { iel | iacc } } } }