<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pt">
    <title>jutty.dev - ocaml</title>
    <subtitle>Vazamentos de uma memória nerd-computante</subtitle>
    <link rel="self" type="application/atom+xml" href="https://blog.jutty.dev/pt/tags/ocaml/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://blog.jutty.dev"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2024-02-23T00:00:00+00:00</updated>
    <id>https://blog.jutty.dev/pt/tags/ocaml/atom.xml</id>
    <entry xml:lang="pt">
        <title>Scripts em OCaml</title>
        <published>2024-02-23T00:00:00+00:00</published>
        <updated>2024-02-23T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Juno Takano
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://blog.jutty.dev/pt/posts/scripts-em-ocaml/"/>
        <id>https://blog.jutty.dev/pt/posts/scripts-em-ocaml/</id>
        
        <content type="html" xml:base="https://blog.jutty.dev/pt/posts/scripts-em-ocaml/">&lt;p&gt;Este blog gera suas postagens com o Pandoc, mas quem faz o trabalho lógico de identificar os arquivos e montar os comandos é um pequeno script em OCaml.&lt;&#x2F;p&gt;
&lt;p&gt;Descobri essa linguagem quando comecei a investigar como poderia substituir o Bash como uma linguagem para scripts. Eu acho que o Bash é excelente para cumprir essa função, apesar de bastante inseguro e propenso a erros. O que me incomodava mesmo era ver que todo aquele tempo escrevendo scripts com Bash poderia ser tempo aprendendo uma linguagem cujo conhecimento se transferisse para muitas outras aplicações.&lt;&#x2F;p&gt;
&lt;p&gt;O script se resume a:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;ocaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control&quot;&gt;let&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; pandoc_params&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type&quot;&gt; =&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;  &amp;quot;--css ..&#x2F;..&#x2F;assets&#x2F;style.css -s --to html5 --metadata pagetitle=&amp;#39;basename&amp;#39; &amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control&quot;&gt;let&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; vert&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; md&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt; begin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control&quot;&gt;  if&lt;&#x2F;span&gt;&lt;span&gt; md&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; &amp;lt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;gen.ml&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; md&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; &amp;lt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;html&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-control&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ignore&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; Sys&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;command&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt; (&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;      &amp;quot;pandoc &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; ^&lt;&#x2F;span&gt;&lt;span&gt; pandoc_params&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; ^&lt;&#x2F;span&gt;&lt;span&gt; md&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; ^&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot; -o html&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; ^&lt;&#x2F;span&gt;&lt;span&gt; md&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-regexp&quot;&gt; ^&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;.html &amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;    ) )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;end ;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control&quot;&gt;let&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; contents&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; Array&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;to_list&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;Sys&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;readdir&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;quot;.&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt; in&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;List.map vert contents ;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Primeiro, armazeno em &lt;code&gt;pandoc_params&lt;&#x2F;code&gt; os parâmetros comuns que serão passados ao Pandoc para gerar os arquivos HTML a partir dos arquivos em Markdown.&lt;&#x2F;p&gt;
&lt;p&gt;Em seguida, defino a função &lt;code&gt;vert&lt;&#x2F;code&gt;, que, caso o arquivo não se chame “gen.ml” (o próprio script) nem “html” (o diretório onde os arquivos gerados ficam), o comando do Pandoc é chamado com os nomes dos arquivos de entrada e saída.&lt;&#x2F;p&gt;
&lt;p&gt;Essa função então é aplicada com &lt;code&gt;List.map vert contents&lt;&#x2F;code&gt; a cada arquivo do diretório atual.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;referencias&quot;&gt;Referências
 &lt;a class=&quot;zola-anchor&quot; href=&quot;#referencias&quot; aria-label=&quot;Anchor link for: referencias&quot;&gt;#&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;out-link&quot; rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Walk_a_directory&#x2F;Non-recursively#OCaml&quot;&gt;Walk a directory&#x2F;Non-recursively - Rosetta Code&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;out-link&quot; rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;jez.io&#x2F;pandoc-markdown-css-theme&#x2F;&quot;&gt;Pandoc Markdown CSS Theme&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
</feed>
