; Composable syntax-rules macros via the CK abstract machine ; ; We demonstrate (mutually-) recursive, higher-order applicative ; macros with clausal definitions, defined in the style that looks very ; much like that of ML or (strict) Haskell. ; We write composable, call-by-value--like macros without ; resorting to the continuation-passing-style and thus requiring no ; macro-level lambda. The syntax remains direct-style, with ; nested applications.
; This project was the answer to the question posed by Dan Friedman ; on Mar 20, 2009: ; Write the macro 'permute' that takes any number of arguments and returns ; the list of their permutations ; ; (permute a b c) ==> ((a b c) (b a c) (b c a) (a c b) (c a b) (c b a)) ; The order of the entries in the list is immaterial. One should write ; permute without resorting to CPS. ; ; Our answer is the transliteration of the standard Haskell code ; implementing the straightforward algorithm for all permutations: ; perm :: [a] -> [[a]] ; perm [] = [[]] ; perm (h:t) = concatMap (ins h) (perm t) ; ins :: a -> [a] -> [[a]] ; ins x [] = [[x]] ; ins x (h:t) = (x:h:t) : map (h:) (ins x t) ; We shall see that our code looks pretty much like the above, ; but with more parentheses.
Возможно такой
Небольшой кусочек из http://okmij.org/ftp/Scheme/CK.scm
; Composable syntax-rules macros via the CK abstract machine
;
; We demonstrate (mutually-) recursive, higher-order applicative
; macros with clausal definitions, defined in the style that looks very
; much like that of ML or (strict) Haskell.
; We write composable, call-by-value--like macros without
; resorting to the continuation-passing-style and thus requiring no
; macro-level lambda. The syntax remains direct-style, with
; nested applications.
; This project was the answer to the question posed by Dan Friedman
; on Mar 20, 2009:
; Write the macro 'permute' that takes any number of arguments and returns
; the list of their permutations
;
; (permute a b c) ==> ((a b c) (b a c) (b c a) (a c b) (c a b) (c b a))
; The order of the entries in the list is immaterial. One should write
; permute without resorting to CPS.
;
; Our answer is the transliteration of the standard Haskell code
; implementing the straightforward algorithm for all permutations:
; perm :: [a] -> [[a]]
; perm [] = [[]]
; perm (h:t) = concatMap (ins h) (perm t)
; ins :: a -> [a] -> [[a]]
; ins x [] = [[x]]
; ins x (h:t) = (x:h:t) : map (h:) (ins x t)
; We shall see that our code looks pretty much like the above,
; but with more parentheses.
Reply
Reply
(permute a b c) - это (в хаскелевской нотации) не обязательно
permute a b c, а возможно ещё и синтаксический сахар вокруг
permute [a,b,c]
ответ на вопрос о том, как вот в это воткнуть карринг, по моему очевиден.
Reply
Reply
Reply
Нет, так написать Вы не можете.
Reply
Reply
Reply
Reply
Reply
Leave a comment