I'm trying to do something very simple, write bytes to a file using the f library:

(require 'f)

And I create a list of bytes:

(setq random-data (loop for i from 0 to 40 collect (random 150)))

So far, so good. However, the unibyte-string function seemingly expects separate arguments so the following doesn't work:

(f-write-bytes (unibyte-string random-data) "file.dat")

This seems painfully easy but I can't get it working, is there a standard way of doing this?


1 Answer 1


You need to apply the function to the list of arguments:

(f-write-bytes (apply 'unibyte-string random-data) "file.dat")

(apply '+ '(1 2 3)) is equivalent to (+ 1 2 3). See the section about calling functions in the elisp manual for more details.

  • Many thanks - I thought there'd be a lispy way of doing it!
    – Dave F
    Sep 28, 2016 at 9:14
  • Yeah, though I had to jog my memory too, my first instinct was "Wasn't there an unpacking operator like Python's *?" ;)
    – dlukes
    Sep 28, 2016 at 9:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.