DEV Community


Posted on • Updated on


First post, picolisp script

Today I made a oneliner for converting a set of ISO-coded XML files in the current directory to UTF-8.

(for X (dir) (and (match '(@A "." "x" "m" "l") (chop X))(and (out "" (prinl "#! /bin/sh"))(out "" (prinl (pack "iconv -f ISO-8859-1 -t UTF-8 " X " > utf8_" X)))(call 'sh ""]
Enter fullscreen mode Exit fullscreen mode

A more readable, commented version could look like this:

(for X (dir) # for every file name in this directory
        (match '(@A "." "x" "m" "l") (chop X)) # check if *.xml
        (and # it is or this is skipped, so...
            (out "" # we write a new file
                (prinl "#! /bin/sh")) # with a hashbang 
            (out "" # and then add an instruction
                    (pack "iconv -f ISO-8859-1 -t UTF-8 " X " > utf8_" X)))
            (call 'sh ""] # and finally run it 
Enter fullscreen mode Exit fullscreen mode

Now this isn't very lispy, but it can quickly be turned into a more functional style.

(de qconv (Lst) # '(FromCode ToCode OutPrefix InSuffix FileList) 
    (for X (last Lst)
            (match '(@A ~(chop (cadddr Lst))) (chop X))
                (out "" 
                    (prinl "#! /bin/sh"))
                (out "" 
                        (pack "iconv -f " (car Lst) "-t " (cadr Lst) " " X " > " (caddr Lst) X)))
    (call 'rm ""]
Enter fullscreen mode Exit fullscreen mode

Still quite ugly though.

Oldest comments (1)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git