Fork me on GitHub
#squint
<
2022-09-02
>
borkdude10:09:45

I was doing Advent of Code 2021 part 1 and I came to an interesting discovery (after fixing some bugs and adding some core functions). The following gives the correct answer in nbb, but not using clavascript:

(ns aoc01
  (:require ["fs" :as fs]))

(def input
  (mapv js/parseInt (.split (.trim (str (fs/readFileSync "./input/aoc01.txt"))) "\n")))

(defn increases [nums]
  (filter true?
          (map #(< %1 %2)
               nums
               (rest nums))))

(def answer-01 (time (prn (count (increases input)))))

(def sums
  (map #(+ % %2 %3) input (rest input) (rest (rest input))))

(def answer-02 (time (prn (count (increases sums)))))

borkdude10:09:08

It does work when I turn map into mapv. Something about re-using map lazy stuff not handled correctly.

borkdude10:09:58

found the issue and pushed a fix

borkdude13:09:58

I've made a start with clavascript/string.js: https://twitter.com/borkdude/status/1565690878710145026

👍 2
borkdude16:09:17

Just pushed a change which addresses using namespace aliases and cleanly distinguishes those from core or user-defined vars:

$ ./node_cli.js --show -e '(ns foo (:require [clava.string :as str])) (defn split [x] x) (prn (str/split "foo,bar" ","))'
import { prn } from 'clavascript/core.js'
import { split as str_split } from 'clavascript/string.js'
var split = function (x) {
return x;
};
prn(str_split("foo,bar", ","));

export { split }

["foo","bar"]
Without importing * as which some treeshakers do not play well with

🎉 2
lilactown16:09:06

looking around at the various JS runtimes that support ES Modules, and the state of "dynamically reloading code" is dire

lilactown16:09:36

a lot of open issues from 2-3 years ago with people saying "yeah the standard doesn't support this so we have to figure it out... at some point"