<?xml version='1.0' encoding='utf-8' ?>

<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>Observations</title>
  <link>https://juan-gandhi.dreamwidth.org/</link>
  <description>Observations - Dreamwidth Studios</description>
  <lastBuildDate>Mon, 01 Jan 2024 00:12:30 GMT</lastBuildDate>
  <generator>LiveJournal / Dreamwidth Studios</generator>
  <lj:journal>juan_gandhi</lj:journal>
  <lj:journaltype>personal</lj:journaltype>
  <image>
    <url>https://v2.dreamwidth.org/18447744/961106</url>
    <title>Observations</title>
    <link>https://juan-gandhi.dreamwidth.org/</link>
    <width>100</width>
    <height>100</height>
  </image>

<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/5596272.html</guid>
  <pubDate>Mon, 01 Jan 2024 00:12:30 GMT</pubDate>
  <title>lists in Lambda in JavaScript</title>
  <link>https://juan-gandhi.dreamwidth.org/5596272.html</link>
  <description>(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&apos;s True
  const p2 = x =&amp;gt; y =&amp;gt; y // did you notice? It&apos;s False
  const Pair = x =&amp;gt; y =&amp;gt; f =&amp;gt; f(x)(y)

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

  // List constructors and operations
  const Nil = Pair(True)(&quot;Nil&quot;)
  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 = &quot;&quot;
    Map(xs)(x =&amp;gt; buf += (x + &quot;:&quot;))
    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(&quot;a&quot;)(Cons(&quot;b&quot;)(Nil))

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

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

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

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

&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=5596272&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/5596272.html</comments>
  <category>list</category>
  <category>javascript</category>
  <category>lambda</category>
  <lj:security>public</lj:security>
  <lj:reply-count>8</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/5595734.html</guid>
  <pubDate>Sat, 30 Dec 2023 23:23:23 GMT</pubDate>
  <title>Option in JavaScript, funny lambda style</title>
  <link>https://juan-gandhi.dreamwidth.org/5595734.html</link>
  <description>// 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&apos;s True&lt;br /&gt;  const p2 = x =&amp;gt; y =&amp;gt; y // did you notice? It&apos;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)(&quot;None&quot;)&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(&quot;Expecting Some &quot;)(Some(42))&lt;br /&gt;  show(&quot;Expecting None &quot;)(None)&lt;br /&gt;&lt;br /&gt;  const isPositive = x =&amp;gt; Bool(x &amp;gt; 0)&lt;br /&gt;  show(&quot;0 positive? &quot;)(Filter(Some(0))(isPositive))&lt;br /&gt;  show(&quot;2 positive? &quot;)(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(&quot;expecting None from None: &quot;)(FlatMap(    None)(dec))&lt;br /&gt;  show(&quot;expecting None from 5: &quot;)   (FlatMap(Some(5) )(dec))&lt;br /&gt;  show(&quot;expecting 32 from 42: &quot;)    (FlatMap(Some(42))(dec))&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=5595734&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/5595734.html</comments>
  <category>lambda</category>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>9</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/5180834.html</guid>
  <pubDate>Mon, 07 Feb 2022 12:51:24 GMT</pubDate>
  <title>inside javascript engine</title>
  <link>https://juan-gandhi.dreamwidth.org/5180834.html</link>
  <description>&lt;a href=&quot;https://blog.devgenius.io/inside-the-javascript-engine-bb7b9f26e84b&quot;&gt;https://blog.devgenius.io/inside-the-javascript-engine-bb7b9f26e84b&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;h2 class=&quot;eu dv dw ce b ev ew ex ey ez fa fb fc fd fe ff fg fh fi fj fk fl&quot; data-selectable-paragraph=&quot;&quot; style=&quot;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;&quot;&gt;A brief explanation of the JavaScript Engine&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=5180834&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/5180834.html</comments>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>4</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/4983819.html</guid>
  <pubDate>Mon, 15 Mar 2021 03:36:25 GMT</pubDate>
  <title>с изумлением обнаружил у себя в коде</title>
  <link>https://juan-gandhi.dreamwidth.org/4983819.html</link>
  <description>&lt;pre style=&quot;background-color:#fdf6e3;color:#586e75;font-family:&amp;#39;Input Mono&amp;#39;,monospace;font-size:9.0pt;&quot;&gt;&lt;br /&gt;const option = x =&amp;gt; &lt;br /&gt;  &lt;span style=&quot;color:#000080;font-weight:bold;&quot;&gt;typeof &lt;/span&gt;x === &lt;span style=&quot;color:#008000;font-weight:bold;&quot;&gt;&apos;undefined&apos; &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=&quot;color:#008000;font-weight:bold;&quot;&gt;&apos;None&apos;&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=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4983819&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/4983819.html</comments>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>3</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/4886887.html</guid>
  <pubDate>Fri, 13 Nov 2020 01:43:28 GMT</pubDate>
  <title>my presentation today</title>
  <link>https://juan-gandhi.dreamwidth.org/4886887.html</link>
  <description>&lt;a href=&quot;https://observablehq.com/@vpatryshev/finger-trees-in-js&quot;&gt;https://observablehq.com/@vpatryshev/finger-trees-in-js&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4886887&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/4886887.html</comments>
  <category>fp</category>
  <category>finger tree</category>
  <category>scala-by-the-bay</category>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>7</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/4771427.html</guid>
  <pubDate>Fri, 29 May 2020 22:05:40 GMT</pubDate>
  <title>the code I teach now</title>
  <link>https://juan-gandhi.dreamwidth.org/4771427.html</link>
  <description>&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=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4771427&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/4771427.html</comments>
  <category>javascript</category>
  <category>sicp</category>
  <lj:security>public</lj:security>
  <lj:reply-count>17</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/4647136.html</guid>
  <pubDate>Thu, 19 Dec 2019 15:41:05 GMT</pubDate>
  <title>the book I just needed</title>
  <link>https://juan-gandhi.dreamwidth.org/4647136.html</link>
  <description>&lt;a href=&quot;https://sicp.comp.nus.edu.sg/&quot;&gt;https://sicp.comp.nus.edu.sg/&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4647136&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/4647136.html</comments>
  <category>sicp</category>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>12</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/4584047.html</guid>
  <pubDate>Thu, 19 Sep 2019 05:41:41 GMT</pubDate>
  <title>JS -&amp;gt; Go -&amp;gt; Rust</title>
  <link>https://juan-gandhi.dreamwidth.org/4584047.html</link>
  <description>&amp;nbsp;&lt;a href=&quot;https://www.quora.com/Why-did-Ryan-Dahl-give-up-upon-Node-js-for-Go&quot;&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=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4584047&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/4584047.html</comments>
  <category>javascript</category>
  <category>go</category>
  <category>rust</category>
  <lj:security>public</lj:security>
  <lj:reply-count>7</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/4308156.html</guid>
  <pubDate>Sun, 02 Sep 2018 23:33:26 GMT</pubDate>
  <title>progress</title>
  <link>https://juan-gandhi.dreamwidth.org/4308156.html</link>
  <description>&lt;a href=&quot;https://github.com/yishn/tikzcd-editor&quot;&gt;&amp;nbsp;https://github.com/yishn/tikzcd-editor&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4308156&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/4308156.html</comments>
  <category>categories</category>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>3</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/4119305.html</guid>
  <pubDate>Tue, 02 Jan 2018 15:55:58 GMT</pubDate>
  <title>140 chars of javascript</title>
  <link>https://juan-gandhi.dreamwidth.org/4119305.html</link>
  <description>&lt;a href=&quot;https://www.dwitter.net/top&quot;&gt;here&lt;/a&gt;&amp;nbsp;- beautiful images!&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=4119305&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/4119305.html</comments>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>9</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://juan-gandhi.dreamwidth.org/3946753.html</guid>
  <pubDate>Sun, 21 May 2017 04:05:19 GMT</pubDate>
  <title>кстати о языцех</title>
  <link>https://juan-gandhi.dreamwidth.org/3946753.html</link>
  <description>Джавасприпт, Хаскель и Скала, и, говорят, OCaml, из-за своей компактности, канают в качестве скриптовых языков.&lt;br /&gt;&lt;br /&gt;Питон в этом смысле тоже ничо, но там, во-первых, споткнуться можно много где, во-вторых, на уровне компиляции нам ничего не скажут. Это уже на продакшене ебанется. То-то квора, которая на питоне, деплоится по сто раз в час (а тесты потом гоняют, и кодревью тоже).&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=juan_gandhi&amp;ditemid=3946753&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://juan-gandhi.dreamwidth.org/3946753.html</comments>
  <category>haskell</category>
  <category>javascript</category>
  <category>scala</category>
  <category>вечерняя философия про языки</category>
  <lj:security>public</lj:security>
  <lj:reply-count>31</lj:reply-count>
</item>
</channel>
</rss>
