How to merge YAML arrays?

If the aim is to run a sequence of shell commands, you may be able to achieve this as follows: # note: no dash before commands some_stuff: &some_stuff |- a b c combined_stuff: – *some_stuff – d – e – f This is equivalent to: some_stuff: “a\nb\nc” combined_stuff: – “a\nb\nc” – d – e – … Read more

Scala list concatenation, ::: vs ++

Legacy. List was originally defined to be functional-languages-looking: 1 :: 2 :: Nil // a list list1 ::: list2 // concatenation of two lists list match { case head :: tail => “non-empty” case Nil => “empty” } Of course, Scala evolved other collections, in an ad-hoc manner. When 2.8 came out, the collections were … Read more

How to generate all the permutations of elements in a list one at a time in Lisp?

General principle Suppose you have the following range function: (defun range (start end &optional (step 1)) (loop for x from start below end by step collect x)) You can accept another parameter, a function, and call it for each element: (defun range-generator (callback start end &optional (step 1)) (loop for x from start below end … Read more

Convert a matrix to a list of column-vectors

Gavin’s answer is simple and elegant. But if there are many columns, a much faster solution would be: lapply(seq_len(ncol(x)), function(i) x[,i]) The speed difference is 6x in the example below: > x <- matrix(1:1e6, 10) > system.time( as.list(data.frame(x)) ) user system elapsed 1.24 0.00 1.22 > system.time( lapply(seq_len(ncol(x)), function(i) x[,i]) ) user system elapsed 0.2 … Read more

Prolog: Filtering a list?

SWI-Prolog offers exclude/3 and other such meta-predicates. Your original problem can be coded like this: are_identical(X, Y) :- X == Y. filterList(A, In, Out) :- exclude(are_identical(A), In, Out). Usage example: ?- filterList(A, [A, B, A, C, D, A], Out). Out = [B, C, D].