<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dw="https://www.dreamwidth.org">
  <id>tag:dreamwidth.org,2011-07-30:961106</id>
  <title>Observations</title>
  <subtitle>Views from Souths</subtitle>
  <author>
    <name>Juan-Carlos Gandhi</name>
  </author>
  <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/"/>
  <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom"/>
  <updated>2024-01-01T00:12:30Z</updated>
  <dw:journal username="juan_gandhi" type="personal"/>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:5596272</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/5596272.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=5596272"/>
    <title>lists in Lambda in JavaScript</title>
    <published>2024-01-01T00:12:30Z</published>
    <updated>2024-01-01T00:12:30Z</updated>
    <category term="javascript"/>
    <category term="list"/>
    <category term="lambda"/>
    <dw:security>public</dw:security>
    <dw:reply-count>8</dw:reply-count>
    <content type="html">(disclaimer: this is educational material)&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
  // Definitions for Boolean Logic
  const True  = x =&amp;gt; y =&amp;gt; x
  const False = x =&amp;gt; y =&amp;gt; y
  const Bool = b =&amp;gt; b ? True : False

  // Definitions for pair and projection
  const p1 = x =&amp;gt; y =&amp;gt; x // did you notice? It's True
  const p2 = x =&amp;gt; y =&amp;gt; y // did you notice? It's False
  const Pair = x =&amp;gt; y =&amp;gt; f =&amp;gt; f(x)(y)

  // Option constructors
  const None = Pair(True)("None")
  const Some = x =&amp;gt; Pair(False)(x)

  // List constructors and operations
  const Nil = Pair(True)("Nil")
  const isEmpty = x =&amp;gt; x(p1)
  const Head = z =&amp;gt; z(p2)(p1)
  const HeadOption = z =&amp;gt; z(p1)(None)(Some(z(p2)(p1)))
  const Tail = z =&amp;gt; z(p2)(p2)
 
  const Cons = h =&amp;gt; t =&amp;gt; Pair(False)(Pair(h)(t))
  const Map = z =&amp;gt; f =&amp;gt; (isEmpty(z) (() =&amp;gt; Nil) (() =&amp;gt; Cons(f(Head(z))) (Map(Tail(z))(f))))()

  // visualizer

  const show = text =&amp;gt; xs =&amp;gt; {
    var buf = ""
    Map(xs)(x =&amp;gt; buf += (x + ":"))
    println(`${text} ${buf}Nil`)
  }

  const Filter  = z =&amp;gt; p =&amp;gt;
     (isEmpty(z) 
       (() =&amp;gt; Nil) 
       (() =&amp;gt; (p(Head(z)) (Cons(Head(z))(Filter(Tail(z))(p))) (Filter(Tail(z))(p))))
      )() // have to do it lazily

  // samples
  const ab = Cons("a")(Cons("b")(Nil))

  show("Expecting Nil -&amp;gt;")(Nil)
  show("Expecting a:b:Nil -&amp;gt;")(ab)

  const list1 = Cons(1)(Cons(-2)(Cons(3)(Cons(-4)(Nil))))

  show("three numbers")(list1)
  const isPositive = x =&amp;gt; Bool(x &amp;gt; 0)

  show("squares")(Map(list1)(x =&amp;gt; x*x))
  show("positives")(Filter(list1)(isPositive)) 

&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=5596272" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:5595734</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/5595734.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=5595734"/>
    <title>Option in JavaScript, funny lambda style</title>
    <published>2023-12-30T23:23:23Z</published>
    <updated>2023-12-31T00:34:18Z</updated>
    <category term="lambda"/>
    <category term="javascript"/>
    <dw:security>public</dw:security>
    <dw:reply-count>9</dw:reply-count>
    <content type="html">// Definitions for Boolean Logic&lt;br /&gt;  const True  = x =&amp;gt; y =&amp;gt; x&lt;br /&gt;  const False = x =&amp;gt; y =&amp;gt; y&lt;br /&gt;  const Bool = b =&amp;gt; b ? True : False&lt;br /&gt;&lt;br /&gt;  // Definitions for pair and projection&lt;br /&gt;  const p1 = x =&amp;gt; y =&amp;gt; x // did you notice? It's True&lt;br /&gt;  const p2 = x =&amp;gt; y =&amp;gt; y // did you notice? It's False&lt;br /&gt;  const Pair = x =&amp;gt; y =&amp;gt; f =&amp;gt; f(x)(y)&lt;br /&gt;&lt;br /&gt;  // Option constructors and operations&lt;br /&gt;  const None = Pair(True)("None")&lt;br /&gt;  const Some = x =&amp;gt; Pair(False)(x)&lt;br /&gt;  const isEmpty = x =&amp;gt; x(p1)&lt;br /&gt;  const FlatMap = x =&amp;gt; f =&amp;gt; isEmpty(x) (None) (     f(x(p2)))&lt;br /&gt;  const Map     = x =&amp;gt; f =&amp;gt; isEmpty(x) (None) (Some(f(x(p2))))&lt;br /&gt;  const Filter  = x =&amp;gt; p =&amp;gt; isEmpty(x) (None) (p(x(p2)) (x) (None))&lt;br /&gt;&lt;br /&gt;  // visualizer&lt;br /&gt;  const show = text =&amp;gt; xOpt =&amp;gt; {&lt;br /&gt;    Map(xOpt)(x =&amp;gt; println(text + x))&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // samples&lt;br /&gt;  show("Expecting Some ")(Some(42))&lt;br /&gt;  show("Expecting None ")(None)&lt;br /&gt;&lt;br /&gt;  const isPositive = x =&amp;gt; Bool(x &amp;gt; 0)&lt;br /&gt;  show("0 positive? ")(Filter(Some(0))(isPositive))&lt;br /&gt;  show("2 positive? ")(Filter(Some(2))(isPositive))&lt;br /&gt;&lt;br /&gt;  const dec = n =&amp;gt; n &amp;gt; 10 ? Some(n-10) : None&lt;br /&gt;&lt;br /&gt;  show("expecting None from None: ")(FlatMap(    None)(dec))&lt;br /&gt;  show("expecting None from 5: ")   (FlatMap(Some(5) )(dec))&lt;br /&gt;  show("expecting 32 from 42: ")    (FlatMap(Some(42))(dec))&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=5595734" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:5180834</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/5180834.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=5180834"/>
    <title>inside javascript engine</title>
    <published>2022-02-07T12:51:24Z</published>
    <updated>2022-02-07T12:51:24Z</updated>
    <category term="javascript"/>
    <dw:security>public</dw:security>
    <dw:reply-count>4</dw:reply-count>
    <content type="html">&lt;a href="https://blog.devgenius.io/inside-the-javascript-engine-bb7b9f26e84b"&gt;https://blog.devgenius.io/inside-the-javascript-engine-bb7b9f26e84b&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;h2 class="eu dv dw ce b ev ew ex ey ez fa fb fc fd fe ff fg fh fi fj fk fl" data-selectable-paragraph="" style="box-sizing: inherit; margin: 0.92em 0px -0.42em; font-weight: 400; font-family: sohne, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; line-height: 28px; color: rgb(117, 117, 117); font-size: 22px;"&gt;A brief explanation of the JavaScript Engine&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=5180834" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:4983819</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/4983819.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=4983819"/>
    <title>с изумлением обнаружил у себя в коде</title>
    <published>2021-03-15T03:36:25Z</published>
    <updated>2021-03-15T03:36:25Z</updated>
    <category term="javascript"/>
    <dw:security>public</dw:security>
    <dw:reply-count>3</dw:reply-count>
    <content type="html">&lt;pre style="background-color:#fdf6e3;color:#586e75;font-family:&amp;#39;Input Mono&amp;#39;,monospace;font-size:9.0pt;"&gt;&lt;br /&gt;const option = x =&amp;gt; &lt;br /&gt;  &lt;span style="color:#000080;font-weight:bold;"&gt;typeof &lt;/span&gt;x === &lt;span style="color:#008000;font-weight:bold;"&gt;'undefined' &lt;/span&gt;? None : Some(x)&lt;br /&gt;&lt;br /&gt;const None = {&lt;br /&gt;  map: f =&amp;gt; None,&lt;br /&gt;  flatMap: f =&amp;gt; None,&lt;br /&gt;  toString: () =&amp;gt; &lt;span style="color:#008000;font-weight:bold;"&gt;'None'&lt;br /&gt;&lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;const Some = x =&amp;gt; ({&lt;br /&gt;  flatMap: (f =&amp;gt; f(x)),&lt;br /&gt;  map: (f =&amp;gt; option(f(x))),&lt;br /&gt;  toString: () =&amp;gt; `Some(${x})`&lt;br /&gt;})&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4983819" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:4886887</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/4886887.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=4886887"/>
    <title>my presentation today</title>
    <published>2020-11-13T01:43:28Z</published>
    <updated>2020-11-13T01:43:28Z</updated>
    <category term="javascript"/>
    <category term="finger tree"/>
    <category term="fp"/>
    <category term="scala-by-the-bay"/>
    <dw:security>public</dw:security>
    <dw:reply-count>7</dw:reply-count>
    <content type="html">&lt;a href="https://observablehq.com/@vpatryshev/finger-trees-in-js"&gt;https://observablehq.com/@vpatryshev/finger-trees-in-js&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4886887" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:4771427</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/4771427.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=4771427"/>
    <title>the code I teach now</title>
    <published>2020-05-29T22:05:40Z</published>
    <updated>2020-05-29T22:05:40Z</updated>
    <category term="sicp"/>
    <category term="javascript"/>
    <dw:security>public</dw:security>
    <dw:reply-count>17</dw:reply-count>
    <content type="html">&lt;pre&gt;
const iterate = f =&amp;gt; z =&amp;gt; pair(z, () =&amp;gt; iterate(f)(f(z)));

const integers = iterate(n =&amp;gt; n+1)(0);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4771427" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:4647136</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/4647136.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=4647136"/>
    <title>the book I just needed</title>
    <published>2019-12-19T15:41:05Z</published>
    <updated>2019-12-19T15:41:05Z</updated>
    <category term="javascript"/>
    <category term="sicp"/>
    <dw:security>public</dw:security>
    <dw:reply-count>12</dw:reply-count>
    <content type="html">&lt;a href="https://sicp.comp.nus.edu.sg/"&gt;https://sicp.comp.nus.edu.sg/&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4647136" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:4584047</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/4584047.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=4584047"/>
    <title>JS -&amp;gt; Go -&amp;gt; Rust</title>
    <published>2019-09-19T05:41:41Z</published>
    <updated>2019-09-19T05:41:41Z</updated>
    <category term="rust"/>
    <category term="javascript"/>
    <category term="go"/>
    <dw:security>public</dw:security>
    <dw:reply-count>7</dw:reply-count>
    <content type="html">&amp;nbsp;&lt;a href="https://www.quora.com/Why-did-Ryan-Dahl-give-up-upon-Node-js-for-Go"&gt;https://www.quora.com/Why-did-Ryan-Dahl-give-up-upon-Node-js-for-Go&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4584047" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:4308156</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/4308156.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=4308156"/>
    <title>progress</title>
    <published>2018-09-02T23:33:26Z</published>
    <updated>2018-09-02T23:33:26Z</updated>
    <category term="categories"/>
    <category term="javascript"/>
    <dw:security>public</dw:security>
    <dw:reply-count>3</dw:reply-count>
    <content type="html">&lt;a href="https://github.com/yishn/tikzcd-editor"&gt;&amp;nbsp;https://github.com/yishn/tikzcd-editor&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4308156" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:4119305</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/4119305.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=4119305"/>
    <title>140 chars of javascript</title>
    <published>2018-01-02T15:55:58Z</published>
    <updated>2018-01-02T15:55:58Z</updated>
    <category term="javascript"/>
    <dw:security>public</dw:security>
    <dw:reply-count>9</dw:reply-count>
    <content type="html">&lt;a href="https://www.dwitter.net/top"&gt;here&lt;/a&gt;&amp;nbsp;- beautiful images!&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4119305" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2011-07-30:961106:3946753</id>
    <link rel="alternate" type="text/html" href="https://juan-gandhi.dreamwidth.org/3946753.html"/>
    <link rel="self" type="text/xml" href="https://juan-gandhi.dreamwidth.org/data/atom/?itemid=3946753"/>
    <title>кстати о языцех</title>
    <published>2017-05-21T04:05:19Z</published>
    <updated>2017-05-21T04:45:05Z</updated>
    <category term="scala"/>
    <category term="вечерняя философия про языки"/>
    <category term="javascript"/>
    <category term="haskell"/>
    <dw:security>public</dw:security>
    <dw:reply-count>31</dw:reply-count>
    <content type="html">Джавасприпт, Хаскель и Скала, и, говорят, OCaml, из-за своей компактности, канают в качестве скриптовых языков.&lt;br /&gt;&lt;br /&gt;Питон в этом смысле тоже ничо, но там, во-первых, споткнуться можно много где, во-вторых, на уровне компиляции нам ничего не скажут. Это уже на продакшене ебанется. То-то квора, которая на питоне, деплоится по сто раз в час (а тесты потом гоняют, и кодревью тоже).&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=3946753" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
</feed>
